Override elf_nacl.xr linker script so that libc_pic.os links correctly
[glibc/nacl-glibc.git] / sysdeps / sparc / sparc64 / memcmp.S
blobf9502d63f55ef992b84102b763452ef58a3a9cf8
1 /* Compare two memory blocks for differences in the first COUNT bytes.
2    For SPARC v9.
3    Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5    Contributed by Jan Vondrak <jvon4518@ss1000.ms.mff.cuni.cz> and
6                   Jakub Jelinek <jj@ultra.linux.cz>.
8    The GNU C Library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public
10    License as published by the Free Software Foundation; either
11    version 2.1 of the License, or (at your option) any later version.
13    The GNU C Library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
18    You should have received a copy of the GNU Lesser General Public
19    License along with the GNU C Library; if not, write to the Free
20    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21    02111-1307 USA.  */
23 #include <sysdep.h>
24 #include <asm/asi.h>
25 #ifndef XCC
26 #define XCC xcc
27 #define USE_BPR
28         .register       %g2, #scratch
29         .register       %g3, #scratch
30 #endif
32         .text
33         .align          32
34 ENTRY(memcmp)
35 #ifdef USE_BPR
36         brz,pn          %o2, 3f                         /* CTI+IEU1     Group           */
37 #else
38         tst             %o2                             /* IEU1         Group           */
39         be,pn           %XCC, 3f                        /* CTI                          */
40 #endif
41          andcc          %o0, 7, %g0                     /* IEU1         Group           */
42         bne,pn          %icc, 8f                        /* CTI                          */
43 1:       andcc          %o1, 7, %g1                     /* IEU1         Group           */
45         bne,pn          %icc, 10f                       /* CTI                          */
46          mov            64, %g3                         /* IEU0                         */
47         ldx             [%o0], %g1                      /* Load         Group           */
48         sub             %o1, %o0, %o1                   /* IEU0                         */
50         ldx             [%o0 + %o1], %g2                /* Load         Group           */
51         add             %o0, 8, %o0                     /* IEU0                         */
52 2:      mov             %g1, %o3                        /* IEU0         Group           */
53         subcc           %o2, 8, %o2                     /* IEU1                         */
55         bl,pn           %XCC, 5f                        /* CTI                          */
56          ldxa           [%o0] ASI_PNF, %g1              /* Load         Group           */
57         mov             %g2, %o4                        /* IEU0                         */
58         ldxa            [%o0 + %o1] ASI_PNF, %g2        /* Load         Group           */
60         cmp             %o3, %o4                        /* IEU1                         */
61         be,pt           %xcc, 2b                        /* CTI                          */
62          add            %o0, 8, %o0                     /* IEU0                         */
63 7:      mov             -1, %o0                         /* IEU1                         */
65         retl                                            /* CTI+IEU1     Group           */
66          movgu          %xcc, 1, %o0                    /* Single       Group           */
67 3:      retl                                            /* CTI+IEU1     Group           */
68          clr            %o0                             /* IEU0                         */
70         .align          16
71 5:      mov             %g2, %o4                        /* IEU0                         */
72 6:      cmp             %o2, -8                         /* IEU1                         */
73         be,pn           %XCC, 3b                        /* CTI                          */
74          sub            %g0, %o2, %o2                   /* IEU0         Group           */
76         sllx            %o2, 3, %o2                     /* IEU0         Group           */
77         srlx            %o3, %o2, %o3                   /* IEU0         Group           */
78         srlx            %o4, %o2, %o4                   /* IEU0         Group           */
79         clr             %o0                             /* IEU1                         */
81         cmp             %o3, %o4                        /* IEU1         Group           */
82         movgu           %xcc, 1, %o0                    /* Single       Group           */
83         retl                                            /* CTI+IEU1     Group           */
84          movlu          %xcc, -1, %o0                   /* Single       Group           */
86 8:      ldub            [%o0], %o3                      /* Load                         */
87         add             %o0, 1, %o0                     /* IEU0                         */
88         ldub            [%o1], %o4                      /* Load         Group           */
89         add             %o1, 1, %o1                     /* IEU0                         */
91 9:      cmp             %o3, %o4                        /* IEU1         Group           */
92         bne,pn          %xcc, 12f                       /* CTI                          */
93          subcc          %o2, 1, %o2                     /* IEU1         Group           */
94         be,pn           %XCC, 3b                        /* CTI                          */
96          lduba          [%o0] ASI_PNF, %o3              /* Load                         */
97         andcc           %o0, 7, %g0                     /* IEU1         Group           */
98         be,pn           %icc, 1b                        /* CTI                          */
99          lduba          [%o1] ASI_PNF, %o4              /* Load                         */
101         add             %o0, 1, %o0                     /* IEU0         Group           */
102         ba,pt           %xcc, 9b                        /* CTI                          */
103          add            %o1, 1, %o1                     /* IEU1                         */
105         .align          16
106 12:     mov             -1, %o0                         /* IEU0         Group           */
107         cmp             %o3, %o4                        /* IEU1                         */
108         retl                                            /* CTI+IEU1     Group           */
109          movgu          %xcc, 1, %o0                    /* Single       Group           */
111         .align          16
112         nop                                             /* Stub                         */
113 10:     sllx            %g1, 3, %g2                     /* IEU0         Group           */
114         sub             %o1, %g1, %o1                   /* IEU1                         */
115         sub             %g3, %g2, %g3                   /* IEU0         Group           */
117         ldxa            [%o0] ASI_PNF, %g5              /* Load                         */
118         sub             %o1, %o0, %o1                   /* IEU1                         */
119         ldxa            [%o0 + %o1] ASI_PNF, %g4        /* Load         Group           */
120         add             %o0, 8, %o0                     /* IEU0                         */
122 11:     sllx            %g4, %g2, %o4                   /* IEU0         Group           */
123         ldxa            [%o0 + %o1] ASI_PNF, %g4        /* Load                         */
124         srlx            %g4, %g3, %o5                   /* IEU0         Group           */
125         mov             %g5, %o3                        /* IEU1                         */
127         ldxa            [%o0] ASI_PNF, %g5              /* Load                         */
128         subcc           %o2, 8, %o2                     /* IEU1         Group           */
129         bl,pn           %XCC, 6b                        /* CTI                          */
130          or             %o4, %o5, %o4                   /* IEU0                         */
132         cmp             %o3, %o4                        /* IEU1         Group           */
133         be,pt           %xcc, 11b                       /* CTI                          */
134          add            %o0, 8, %o0                     /* IEU0                         */
135         mov             -1, %o0                         /* IEU0                         */
137         retl                                            /* CTI+IEU1     Group           */
138          movgu          %xcc, 1, %o0                    /* Single       Group           */
139 END(memcmp)
141 #undef bcmp
142 weak_alias (memcmp, bcmp)
143 libc_hidden_builtin_def (memcmp)