* sysdeps/unix/sysv/linux/m68k/sysdep.h (INLINE_SYSCALL): Don't
[glibc.git] / sysdeps / ia64 / memset.S
blob56db66fd0b64a7a48734b087dc4fd0041d7fb791
1 /* Optimized version of the standard memset() function.
2    This file is part of the GNU C Library.
3    Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4    Contributed by Dan Pop <Dan.Pop@cern.ch>.
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, write to the Free
18    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
21 /* Return: dest
22   
23    Inputs:
24         in0:    dest
25         in1:    value
26         in2:    count
28    The algorithm is fairly straightforward: set byte by byte until we
29    we get to a word aligned address, then set word by word as much as
30    possible; the remaining few bytes are set one by one.  */
32 #include <sysdep.h>
33 #undef ret
35 #define dest            in0
36 #define byteval         in1
37 #define cnt             in2
39 #define save_pfs        loc0
40 #define ptr1            loc1
41 #define ptr2            loc2
42 #define tmp             loc3
43 #define loopcnt         loc4
44 #define save_lc         loc5
45 #define wordval         loc6
47 ENTRY(memset)
48         .prologue
49         alloc   save_pfs = ar.pfs, 3, 7, 0, 0   
50         .save ar.lc, save_lc
51         mov     save_lc = ar.lc
52         .body
53         mov     ret0 = dest
54         and     tmp = 7, dest
55         cmp.eq  p6, p0 = cnt, r0
56 (p6)    br.cond.spnt .restore_and_exit ;;
57         mov     ptr1 = dest
58         sub     loopcnt = 8, tmp
59         cmp.gt  p6, p0 = 16, cnt
60 (p6)    br.cond.spnt .set_few;;
61         cmp.eq  p6, p0 = tmp, r0
62 (p6)    br.cond.sptk .dest_aligned
63         sub     cnt = cnt, loopcnt
64         adds    loopcnt = -1, loopcnt;;
65         mov     ar.lc = loopcnt;;       
66 .l1:
67         st1     [ptr1] = byteval, 1
68         br.cloop.dptk   .l1 ;;
69 .dest_aligned:
70         adds    ptr2 = 8, ptr1
71         mux1    wordval = byteval, @brcst
72         shr.u   loopcnt = cnt, 4 ;;     // loopcnt = cnt / 16
73         cmp.eq  p6, p0 = loopcnt, r0
74 (p6)    br.cond.spnt    .one_more
75         and     cnt = 0xf, cnt          // compute the remaining cnt
76         adds    loopcnt = -1, loopcnt;;
77         mov     ar.lc = loopcnt;;       
78 .l2:
79         st8     [ptr1] = wordval, 16
80         st8     [ptr2] = wordval, 16
81         br.cloop.dptk .l2
82         cmp.le  p6, p0 = 8, cnt ;;
83 .one_more:
84 (p6)    st8     [ptr1] = wordval, 8
85 (p6)    adds    cnt = -8, cnt ;;
86         cmp.eq  p6, p0 = cnt, r0
87 (p6)    br.cond.spnt    .restore_and_exit
88 .set_few:
89         adds    loopcnt = -1, cnt;;
90         mov     ar.lc = loopcnt;;
91 .l3:    
92         st1     [ptr1] = byteval, 1
93         br.cloop.dptk   .l3 ;;  
94 .restore_and_exit:
95         mov     ar.lc = save_lc
96         mov     ar.pfs = save_pfs
97         br.ret.sptk.many b0                                     
98 END(memset)