Adjusted.
[glibc.git] / sysdeps / ia64 / strcpy.S
blob2a2e7e9a4a93876cdc732f036110e8423c7669e4
1 /* Optimized version of the standard strcpy() function.
2    This file is part of the GNU C Library.
3    Copyright (C) 2000 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 Library General Public License as
8    published by the Free Software Foundation; either version 2 of the
9    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    Library General Public License for more details.
16    You should have received a copy of the GNU Library General Public
17    License along with the GNU C Library; see the file COPYING.LIB.  If not,
18    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.  */
21 /* Return: dest
23    Inputs:
24         in0:    dest
25         in1:    src
27    In this form, it assumes little endian mode.  For big endian mode, the
28    the two shifts in .l2 must be inverted:
30         shl     value = r[1], sh1       // value = w0 << sh1
31         shr.u   tmp = r[0], sh2         // tmp = w1 >> sh2
32  */
34 #include <sysdep.h>
35 #undef ret
37 #define saved_pfs       r14
38 #define saved_lc        r15
39 #define saved_pr        r16
40 #define thresh          r17
41 #define dest            r19
42 #define src             r20
43 #define len             r21
44 #define asrc            r22
45 #define tmp             r23
46 #define pos             r24
47 #define w0              r25
48 #define w1              r26
49 #define c               r27
50 #define sh2             r28
51 #define sh1             r29
52 #define loopcnt         r30
53 #define value           r31
55 ENTRY(strcpy)
56         alloc   saved_pfs = ar.pfs, 2, 0, 30, 32
58 #define MEMLAT 2
59         .rotr   r[MEMLAT + 2]
60         .rotp   p[MEMLAT + 1]
62         mov     ret0 = in0              // return value = dest
63         mov     saved_pr = pr           // save the predicate registers
64         mov     saved_lc = ar.lc        // save the loop counter
65         sub     tmp = r0, in0 ;;        // tmp = -dest
66         mov     dest = in0              // dest
67         mov     src = in1               // src
68         and     loopcnt = 7, tmp ;;     // loopcnt = -dest % 8
69         cmp.eq  p6, p0 = loopcnt, r0
70         adds    loopcnt = -1, loopcnt   // --loopcnt
71 (p6)    br.cond.sptk .dest_aligned ;;
72         mov     ar.lc = loopcnt
73 .l1:                                    // copy -dest % 8 bytes
74         ld1     c = [src], 1            // c = *src++
75         ;;
76         st1     [dest] = c, 1           // *dest++ = c
77         cmp.eq  p6, p0 = c, r0
78 (p6)    br.cond.dpnt .restore_and_exit
79         br.cloop.dptk .l1 ;;
80 .dest_aligned:
81         and     sh1 = 7, src            // sh1 = src % 8
82         mov     ar.lc = -1              // "infinite" loop
83         and     asrc = -8, src ;;       // asrc = src & -OPSIZ  -- align src
84         sub     thresh = 8, sh1
85         mov     pr.rot = 1 << 16        // set rotating predicates
86         cmp.ne  p7, p0 = r0, r0         // clear p7
87         shl     sh1 = sh1, 3 ;;         // sh1 = 8 * (src % 8)
88         sub     sh2 = 64, sh1           // sh2 = 64 - sh1
89         cmp.eq  p6, p0 = sh1, r0        // is the src aligned?
90 (p6)    br.cond.sptk .src_aligned ;;
91         ld8     r[1] = [asrc],8 ;;
93         .align  32
94 .l2:
95         ld8.s   r[0] = [asrc], 8
96         shr.u   value = r[1], sh1 ;;    // value = w0 >> sh1
97         czx1.r  pos = value ;;          // do we have an "early" zero
98         cmp.lt  p7, p0 = pos, thresh    // in w0 >> sh1?
99 (p7)    br.cond.dpnt .found0
100         chk.s   r[0], .recovery2        // it is safe to do that only
101 .back2:                                 // after the previous test
102         shl     tmp = r[0], sh2         // tmp = w1 << sh2
103         ;;
104         or      value = value, tmp ;;   // value |= tmp
105         czx1.r  pos = value ;;
106         cmp.ne  p7, p0 = 8, pos
107 (p7)    br.cond.dpnt .found0
108         st8     [dest] = value, 8       // store val to dest
109         br.ctop.dptk    .l2 ;;
110 .src_aligned:
111 .l3:
112 (p[0])          ld8.s   r[0] = [src], 8
113 (p[MEMLAT])     chk.s   r[MEMLAT], .recovery3
114 .back3:
115 (p[MEMLAT])     mov     value = r[MEMLAT]
116 (p[MEMLAT])     czx1.r  pos = r[MEMLAT] ;;
117 (p[MEMLAT])     cmp.ne  p7, p0 = 8, pos
118 (p7)            br.cond.dpnt .found0
119 (p[MEMLAT])     st8     [dest] = r[MEMLAT], 8
120                 br.ctop.dptk .l3 ;;
121 .found0:
122         mov     ar.lc = pos
123 .l4:
124         extr.u  c = value, 0, 8         // c = value & 0xff
125         shr.u   value = value, 8
126         ;;
127         st1     [dest] = c, 1
128         br.cloop.dptk   .l4 ;;
129 .restore_and_exit:
130         mov     ar.pfs = saved_pfs      // restore the PFS
131         mov     ar.lc = saved_lc        // restore the loop counter
132         mov     pr = saved_pr, -1       // restore the predicate registers
133         br.ret.sptk.many b0
134 .recovery2:
135         add     tmp = -8, asrc ;;
136         ld8     r[0] = [tmp]
137         br.cond.sptk .back2
138 .recovery3:
139         add     tmp = -(MEMLAT + 1) * 8, src ;;
140         ld8     r[MEMLAT] = [tmp]
141         br.cond.sptk .back3
142 END(strcpy)