import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / alpha / lib / memset.S
1 /*
2  * linux/arch/alpha/memset.S
3  *
4  * This is an efficient (and small) implementation of the C library "memset()"
5  * function for the alpha.
6  *
7  *      (C) Copyright 1996 Linus Torvalds
8  *
9  * This routine is "moral-ware": you are free to use it any way you wish, and
10  * the only obligation I put on you is a moral one: if you make any improvements
11  * to the routine, please send me your improvements for me to use similarly.
12  *
13  * The scheduling comments are according to the EV5 documentation (and done by 
14  * hand, so they might well be incorrect, please do tell me about it..)
15  */
16
17         .set noat
18         .set noreorder
19 .text
20         .globl __memset
21         .globl __memsetw
22         .globl __constant_c_memset
23         .ent __memset
24 .align 5
25 __memset:
26         .frame $30,0,$26,0
27         .prologue 0
28
29         and $17,255,$1          /* E1 */
30         insbl $17,1,$17         /* .. E0 */
31         bis $17,$1,$17          /* E0 (p-c latency, next cycle) */
32         sll $17,16,$1           /* E1 (p-c latency, next cycle) */
33
34         bis $17,$1,$17          /* E0 (p-c latency, next cycle) */
35         sll $17,32,$1           /* E1 (p-c latency, next cycle) */
36         bis $17,$1,$17          /* E0 (p-c latency, next cycle) */
37         ldq_u $31,0($30)        /* .. E1 */
38
39 .align 5
40 __constant_c_memset:
41         addq $18,$16,$6         /* E0 */
42         bis $16,$16,$0          /* .. E1 */
43         xor $16,$6,$1           /* E0 */
44         ble $18,end             /* .. E1 */
45
46         bic $1,7,$1             /* E0 */
47         beq $1,within_one_quad  /* .. E1 (note EV5 zero-latency forwarding) */
48         and $16,7,$3            /* E0 */
49         beq $3,aligned          /* .. E1 (note EV5 zero-latency forwarding) */
50
51         ldq_u $4,0($16)         /* E0 */
52         bis $16,$16,$5          /* .. E1 */
53         insql $17,$16,$2        /* E0 */
54         subq $3,8,$3            /* .. E1 */
55
56         addq $18,$3,$18         /* E0   $18 is new count ($3 is negative) */
57         mskql $4,$16,$4         /* .. E1 (and possible load stall) */
58         subq $16,$3,$16         /* E0   $16 is new aligned destination */
59         bis $2,$4,$1            /* .. E1 */
60
61         bis $31,$31,$31         /* E0 */
62         ldq_u $31,0($30)        /* .. E1 */
63         stq_u $1,0($5)          /* E0 */
64         bis $31,$31,$31         /* .. E1 */
65
66 .align 4
67 aligned:
68         sra $18,3,$3            /* E0 */
69         and $18,7,$18           /* .. E1 */
70         bis $16,$16,$5          /* E0 */
71         beq $3,no_quad          /* .. E1 */
72
73 .align 3
74 loop:
75         stq $17,0($5)           /* E0 */
76         subq $3,1,$3            /* .. E1 */
77         addq $5,8,$5            /* E0 */
78         bne $3,loop             /* .. E1 */
79
80 no_quad:
81         bis $31,$31,$31         /* E0 */
82         beq $18,end             /* .. E1 */
83         ldq $7,0($5)            /* E0 */
84         mskqh $7,$6,$2          /* .. E1 (and load stall) */
85
86         insqh $17,$6,$4         /* E0 */
87         bis $2,$4,$1            /* .. E1 */
88         stq $1,0($5)            /* E0 */
89         ret $31,($26),1         /* .. E1 */
90
91 .align 3
92 within_one_quad:
93         ldq_u $1,0($16)         /* E0 */
94         insql $17,$16,$2        /* E1 */
95         mskql $1,$16,$4         /* E0 (after load stall) */
96         bis $2,$4,$2            /* E0 */
97
98         mskql $2,$6,$4          /* E0 */
99         mskqh $1,$6,$2          /* .. E1 */
100         bis $2,$4,$1            /* E0 */
101         stq_u $1,0($16)         /* E0 */
102
103 end:
104         ret $31,($26),1         /* E1 */
105         .end __memset
106
107         .align 5
108         .ent __memsetw
109 __memsetw:
110         .prologue 0
111
112         inswl $17,0,$1          /* E0 */
113         inswl $17,2,$2          /* E0 */
114         inswl $17,4,$3          /* E0 */
115         or $1,$2,$1             /* .. E1 */
116         inswl $17,6,$4          /* E0 */
117         or $1,$3,$1             /* .. E1 */
118         or $1,$4,$17            /* E0 */
119         br __constant_c_memset  /* .. E1 */
120
121         .end __memsetw
122
123 #ifdef __ELF__
124  .weak memset; memset = __memset
125 #else
126  .weakext memset, __memset
127 #endif