source: trunk/libs/newlib/src/newlib/libc/machine/hppa/strncmp.S @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 7.2 KB
Line 
1/*
2 *  (c) Copyright 1986 HEWLETT-PACKARD COMPANY
3 *
4 *  To anyone who acknowledges that this file is provided "AS IS"
5 *  without any express or implied warranty:
6 *      permission to use, copy, modify, and distribute this file
7 *  for any purpose is hereby granted without fee, provided that
8 *  the above copyright notice and this notice appears in all
9 *  copies, and that the name of Hewlett-Packard Company not be
10 *  used in advertising or publicity pertaining to distribution
11 *  of the software without specific, written prior permission.
12 *  Hewlett-Packard Company makes no representations about the
13 *  suitability of this software for any purpose.
14 */
15
16/* strcmp(s1, s2) */
17/* returns integer: < 0 iff s1 lexicographically less than s2 */
18/*                  > 0 iff s1 lexicographically greater than s2 */
19/*                  = 0 iff s1 lexicographically equal to s2 */
20/*                  = 0 iff s1 lexicographically equal to s2 */
21/*                  quit after n charachters */
22#include "DEFS.h"
23
24#define s1        26
25#define s2        25
26#define tmp1      19
27#define s2word    20
28#define tmp3      21
29#define tmp7      22
30#define s1word    29
31#define save       1
32#define tmp6      23
33#define tmp5      28
34#define count     24
35
36ENTRY(strncmp)
37        combt,<,n       r0,count,search /* N <= 0 yields equality */
38        bv      r0(rp)                  /* */
39        copy    0,ret0                  /* return 0 (DELAY SLOT) */
40search: combf,=,n       s1,s2,findout   /* s1 != s2? */
41        bv      r0(rp)                  /* */
42        copy    0,ret0                  /* return 0 (delay slot)         */
43findout:
44        comibf,=,n      0,s1,checks1    /* s1 == NULL?   */
45        ldbs    0(0,s2),ret0            /* */
46        bv      r0(rp)                  /* */
47        subi    0,ret0,ret0             /* ret0 <- -*s2 */
48checks1:
49        comibf,=,n      0,s2,checkitout /* s2 == NULL?   */
50        bv      r0(rp)                  /* */
51        ldbs    0(0,s1),28              /* return *s1 */
52
53checkitout:
54        extru   s2,31,2,tmp1            /* Extract the low two bits of the s2. */
55        extru   s1,31,2,tmp5            /* Extract the low two bits of the s1 */
56        sub,=   tmp5,tmp1,tmp3          /* Are s1 & s2 aligned with each other? */
57        b       not_aligned             /* It's more complicated (not_aligned) */
58        dep     0,31,2,s1               /* Compute word address of s1 (DELAY SLOT) */
59        dep     0,31,2,s2               /* Compute word address of s2 */
60        ldwm    4(0,s1),s1word          /* get next s1 word  s1+=4 */
61        combt,= tmp5,r0,skipmask        /* skip masking, if we can */
62        ldwm    4(0,s2),s2word          /* get next s2 word  s2+=4 (DELAY SLOT) */
63        add     tmp5,count,count        /* bump count by the number of bytes */
64                                        /*  we are going to mask */
65        sh3add  tmp5,r0,save            /* save now has number of bits to mask */
66        mtctl   save,11
67        zvdepi  -2,32,save              /* load save with proper mask */
68        or      save,s1word,s1word      /* mask s1word (s1) */
69        or      save,s2word,s2word      /* mask s2word (s2) */
70       
71
72skipmask:
73        combt,=,n       s1word,s2word,chknulls  /* are these words equal? */
74
75checkbyte:
76        extru   s1word,7,8,tmp3         /* get first byte (character) */
77ckbyte2:        extru   s2word,7,8,tmp7         /* get first byte (character) */
78        combf,= tmp3,tmp7,done          /* quit if first byte is not equal */
79        sub     tmp3,tmp7,ret0          /* return difference (delay slot) */
80        comibt,=,n      0,tmp3,done     /* have we reached the end of string */
81                                        /* if so done ret0 already has zero */
82        addibt,<=,n     -1,count,done   /* have we checked N chars? ret0 == 0 */
83        extru   s1word,15,8,tmp3        /* get second byte (character) */
84        extru   s2word,15,8,tmp7        /* get second byte (character)   */
85        combf,= tmp3,tmp7,done          /* quit if second byte is not equal */
86        sub     tmp3,tmp7,ret0          /* return difference (delay slot) */
87        comibt,=,n      0,tmp3,done     /* have we reached the end of string */
88                                        /* if so done ret0 already has zero */
89        addibt,<=,n     -1,count,done   /* have we checked N chars? */
90        extru   s1word,23,8,tmp3        /* get third byte (character) */
91        extru   s2word,23,8,tmp7        /* get third byte (character)    */
92        combf,= tmp3,tmp7,done          /* done if third byte is not equal */
93        sub     tmp3,tmp7,ret0          /* return difference (delay slot) */
94        comibt,=,n      0,tmp3,done     /* have we reached the end of string */
95                                        /* if so done ret0 already has zero */
96        addibt,<=,n     -1,count,done   /* have we checked N chars? */
97        extru   s1word,31,8,tmp3        /* get last byte (character) */
98        extru   s2word,31,8,tmp7        /* get last byte (character)     */
99        bv      r0(rp)                  /* */
100        sub     tmp3,tmp7,ret0          /*  the last characters in the word is */
101                                        /*   where the  difference is, so return */
102                                        /*    the difference and we're outta here */
103
104
105chknulls:
106        addibt,<=,n     -4,count,zero   /* have we checked N chars? */
107        uxor,nbz        s1word,0,0      /* don't have to check s2   Just quit */
108        bv      r0(rp)                  /* */
109        copy    0,28                    /* return 0 */
110        ldwm    4(0,s2),s2word          /* get next s2 word  s2+=4 */
111        b       skipmask                /* keep checking */
112        ldwm    4(0,s1),s1word          /* get next s1 word  s1+=4 */
113
114
115not_aligned:
116        dep     r0,31,2,s2              /* Compute word address of s2 */
117        combt,<,n       r0,tmp3,shifts1 /* Do we shift s1 or s2 */
118        sh3add  tmp3,r0,tmp3            /* eight bits per byte so mul by 8 */
119        ldwm    4(0,s1),s1word          /* get first word of s1 */
120        ldwm    4(0,s2),s2word          /* get first word or s2 */
121        combt,=,n       r0,tmp5,masks2  /* Do we need to mask beginning of s1 */
122        add     tmp5,count,count        /* bump count by the number of bytes */
123                                        /*  we are going to mask */
124        sh3add  tmp5,r0,save            /* save now has number of bits to mask */
125        mtctl   save,11
126        zvdepi  -2,32,save              /* load save with proper mask */
127        or      save,s1word,s1word      /* */
128masks2: sh3add  tmp1,r0,save            /* save now has number of bits to mask */
129        mtctl   save,11
130        zvdepi  -2,32,save              /* load save with proper mask */
131        or      save,s2word,s2word      /* */
132        mtctl   tmp3,11                 /* Move shift amount to CR11 */
133more:   uxor,nbz        s2word,r0,r0            /* Is there a null in first word         */
134        b,n     chunk1                  /* */
135        ldwm    4(0,s2),tmp7            /* load second word to enable us to shift */
136        vshd    s2word,tmp7,s2word      /* */
137        combf,=,n       s1word,s2word,ckbyte2   /* */
138        extru   s1word,7,8,tmp3         /* get first byte (DELAY SLOT) */
139        addibt,<=,n     -4,count,zero   /* have we checked N chars? */
140        uxor,nbz        s1word,0,0      /* even though they're equal we could be done */
141        b,n     zero   
142        copy    tmp7,s2word             /* */
143        b       more                    /* keep checking */
144        ldwm    4(0,s1),s1word          /* get next s1 (DELAY SLOT) */
145
146chunk1:
147        vshd    s2word,r0,s2word        /* */
148        b       ckbyte2                 /* */
149        extru   s1word,7,8,tmp3         /* */
150
151
152shifts1:
153        sh3add  tmp3,r0,tmp3            /* eight bits per byte so mul by 4 */
154        sub     r0,tmp3,tmp3            /* Get negative value for left shift */
155        ldwm    4(0,s2),s2word          /* get first word of s2 */
156        ldwm    4(0,s1),s1word          /* get first word or s1 */
157        combt,=,n       r0,tmp1,masks1  /* Do we need to mask beginning of s2 */
158        add     tmp1,count,count        /* bump count by the number of bytes */
159                                        /*  we are going to mask */
160        sh3add  tmp1,r0,save            /* save now has number of bits to mask */
161        mtctl   save,11
162        zvdepi  -2,32,save              /* load save with proper mask */
163        or      save,s2word,s2word      /* */
164masks1: sh3add  tmp5,r0,save            /* save now has number of bits to mask */
165        mtctl   save,11
166        zvdepi  -2,32,save              /* load save with proper mask */
167        or      save,s1word,s1word      /* */
168        mtctl   tmp3,11                 /* Move shift amount to CR11 */
169more1:  uxor,nbz        s1word,r0,r0            /* Is there a null in first byte         */
170        b,n     chunk2                  /* */
171        ldwm    4(0,s1),tmp7            /* load second word to enable us to shift */
172        vshd    s1word,tmp7,s1word      /* */
173        combf,=,n       s2word,s1word,ckbyte2   /* */
174        extru   s1word,7,8,tmp3         /* get first byte (DELAY SLOT) */
175        addibt,<=,n     -4,count,zero   /* have we checked N chars? */
176        uxor,nbz        s2word,0,0      /* even though they're equal we could be done */
177        b,n     zero                    /* zero ret0 and quit */
178        copy    tmp7,s1word             /* */
179        b       more1                   /* keep checking */
180        ldwm    4(0,s2),s2word          /* get next s2 (DELAY SLOT) */
181
182chunk2:
183        vshd    s1word,r0,s1word        /* */
184        b       ckbyte2                 /* */
185        extru   s1word,7,8,tmp3         /* */
186
187zero:   copy    r0,ret0
188done:
189EXIT(strncmp)
Note: See TracBrowser for help on using the repository browser.