initial commit
[glibc.git] / debian / patches / alpha / local-string-functions.diff
1 The alpha assembly version of various string functions do not work
2 correctly on some corner cases, and thus doesn't pass the testsuite.
3 This patch removes them.
4
5 ---
6 sysdeps/alpha/alphaev67/stpncpy.S | 114 ---------------
7 sysdeps/alpha/alphaev67/strncat.S | 85 -----------
8 sysdeps/alpha/stpncpy.S | 105 --------------
9 sysdeps/alpha/strcmp.S | 193 --------------------------
10 sysdeps/alpha/strncat.S | 93 ------------
11 sysdeps/alpha/strncmp.S | 276 --------------------------------------
12 sysdeps/alpha/strncpy.S | 86 -----------
13 7 files changed, 952 deletions(-)
14
15 --- a/sysdeps/alpha/alphaev67/stpncpy.S
16 +++ /dev/null
17 @@ -1,114 +0,0 @@
18 -/* Copyright (C) 2000-2022 Free Software Foundation, Inc.
19 - This file is part of the GNU C Library.
20 -
21 - The GNU C Library is free software; you can redistribute it and/or
22 - modify it under the terms of the GNU Lesser General Public
23 - License as published by the Free Software Foundation; either
24 - version 2.1 of the License, or (at your option) any later version.
25 -
26 - The GNU C Library is distributed in the hope that it will be useful,
27 - but WITHOUT ANY WARRANTY; without even the implied warranty of
28 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 - Lesser General Public License for more details.
30 -
31 - You should have received a copy of the GNU Lesser General Public
32 - License along with the GNU C Library. If not, see
33 - <https://www.gnu.org/licenses/>. */
34 -
35 -/* Copy no more than N bytes from SRC to DEST, returning the address of
36 - the terminating '\0' in DEST. */
37 -
38 -#include <sysdep.h>
39 -
40 - .arch ev6
41 - .set noat
42 - .set noreorder
43 - .text
44 -
45 -ENTRY(__stpncpy)
46 - ldgp gp, 0(pv)
47 -#ifdef PROF
48 - lda AT, _mcount
49 - jsr AT, (AT), _mcount
50 -#endif
51 - .prologue 1
52 -
53 - mov a0, v0
54 - beq a2, $zerocount
55 -
56 - .align 4
57 - nop
58 - nop
59 - jsr t9, __stxncpy # do the work of the copy
60 -
61 - cttz t8, t4
62 - zapnot t0, t8, t5
63 - andnot a0, 7, a0
64 - bne a2, $multiword # do we have full words left?
65 -
66 - subq t8, 1, t2
67 - subq t10, 1, t3
68 - cmpult zero, t5, t5
69 - addq a0, t4, v0
70 -
71 - or t2, t8, t2
72 - or t3, t10, t3
73 - addq v0, t5, v0
74 - andnot t3, t2, t3
75 -
76 - zap t0, t3, t0
77 - nop
78 - stq t0, 0(a0)
79 - ret
80 -
81 -$multiword:
82 - subq t8, 1, t7 # clear the final bits in the prev word
83 - cmpult zero, t5, t5
84 - or t7, t8, t7
85 - zapnot t0, t7, t0
86 -
87 - subq a2, 1, a2
88 - stq t0, 0(a0)
89 - addq a0, 8, a1
90 - beq a2, 1f # loop over full words remaining
91 -
92 - nop
93 - nop
94 - nop
95 - blbc a2, 0f
96 -
97 - stq zero, 0(a1)
98 - subq a2, 1, a2
99 - addq a1, 8, a1
100 - beq a2, 1f
101 -
102 -0: stq zero, 0(a1)
103 - subq a2, 2, a2
104 - nop
105 - nop
106 -
107 - stq zero, 8(a1)
108 - addq a1, 16, a1
109 - nop
110 - bne a2, 0b
111 -
112 -1: ldq t0, 0(a1) # clear the leading bits in the final word
113 - subq t10, 1, t7
114 - addq a0, t4, v0
115 - nop
116 -
117 - or t7, t10, t7
118 - addq v0, t5, v0
119 - zap t0, t7, t0
120 - stq t0, 0(a1)
121 -
122 -$zerocount:
123 - nop
124 - nop
125 - nop
126 - ret
127 -
128 - END(__stpncpy)
129 -
130 -libc_hidden_def (__stpncpy)
131 -weak_alias (__stpncpy, stpncpy)
132 --- a/sysdeps/alpha/alphaev67/strncat.S
133 +++ /dev/null
134 @@ -1,85 +0,0 @@
135 -/* Copyright (C) 2000-2022 Free Software Foundation, Inc.
136 - This file is part of the GNU C Library.
137 -
138 - The GNU C Library is free software; you can redistribute it and/or
139 - modify it under the terms of the GNU Lesser General Public
140 - License as published by the Free Software Foundation; either
141 - version 2.1 of the License, or (at your option) any later version.
142 -
143 - The GNU C Library is distributed in the hope that it will be useful,
144 - but WITHOUT ANY WARRANTY; without even the implied warranty of
145 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
146 - Lesser General Public License for more details.
147 -
148 - You should have received a copy of the GNU Lesser General Public
149 - License along with the GNU C Library. If not, see
150 - <https://www.gnu.org/licenses/>. */
151 -
152 -/* Append no more than COUNT characters from the null-terminated string SRC
153 - to the null-terminated string DST. Always null-terminate the new DST. */
154 -
155 -#include <sysdep.h>
156 -
157 - .arch ev6
158 - .set noreorder
159 - .text
160 -
161 -ENTRY(strncat)
162 - ldgp gp, 0(pv)
163 -#ifdef PROF
164 - .set noat
165 - lda AT, _mcount
166 - jsr AT, (AT), _mcount
167 - .set at
168 -#endif
169 - .prologue 1
170 -
171 - mov a0, v0 # set up return value
172 - beq a2, $zerocount # U :
173 - /* Find the end of the string. */
174 - ldq_u t0, 0(a0) # L : load first quadword (a0 may be misaligned)
175 - lda t1, -1 # E :
176 -
177 - insqh t1, v0, t1 # U :
178 - andnot a0, 7, a0 # E :
179 - nop # E :
180 - or t1, t0, t0 # E :
181 -
182 - nop # E :
183 - nop # E :
184 - cmpbge zero, t0, t1 # E : bits set iff byte == 0
185 - bne t1, $found # U :
186 -
187 -$loop: ldq t0, 8(a0) # L :
188 - addq a0, 8, a0 # E :
189 - cmpbge zero, t0, t1 # E :
190 - beq t1, $loop # U :
191 -
192 -$found: cttz t1, t2 # U0 :
193 - addq a0, t2, a0 # E :
194 - jsr t9, __stxncpy # L0 : Now do the append.
195 -
196 - /* Worry about the null termination. */
197 -
198 - cttz t10, t2 # U0: byte offset of end-of-count.
199 - bic a0, 7, a0 # E : word align the last write address.
200 - zapnot t0, t8, t1 # U : was last byte a null?
201 - nop # E :
202 -
203 - bne t1, 0f # U :
204 - nop # E :
205 - nop # E :
206 - ret # L0 :
207 -
208 -0: addq t2, a0, a0 # E : address of end-of-count
209 - stb zero, 1(a0) # L :
210 - nop # E :
211 - ret # L0 :
212 -
213 -$zerocount:
214 - nop # E :
215 - nop # E :
216 - nop # E :
217 - ret # L0 :
218 -
219 - END(strncat)
220 --- a/sysdeps/alpha/stpncpy.S
221 +++ /dev/null
222 @@ -1,105 +0,0 @@
223 -/* Copyright (C) 1996-2022 Free Software Foundation, Inc.
224 - This file is part of the GNU C Library.
225 -
226 - The GNU C Library is free software; you can redistribute it and/or
227 - modify it under the terms of the GNU Lesser General Public
228 - License as published by the Free Software Foundation; either
229 - version 2.1 of the License, or (at your option) any later version.
230 -
231 - The GNU C Library is distributed in the hope that it will be useful,
232 - but WITHOUT ANY WARRANTY; without even the implied warranty of
233 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
234 - Lesser General Public License for more details.
235 -
236 - You should have received a copy of the GNU Lesser General Public
237 - License along with the GNU C Library. If not, see
238 - <https://www.gnu.org/licenses/>. */
239 -
240 -/* Copy no more than COUNT bytes of the null-terminated string from
241 - SRC to DST. If SRC does not cover all of COUNT, the balance is
242 - zeroed. Return the address of the terminating null in DEST, if
243 - any, else DEST + COUNT. */
244 -
245 -#include <sysdep.h>
246 -
247 - .set noat
248 - .set noreorder
249 -
250 - .text
251 -
252 -ENTRY(__stpncpy)
253 - ldgp gp, 0(pv)
254 -#ifdef PROF
255 - lda AT, _mcount
256 - jsr AT, (AT), _mcount
257 -#endif
258 - .prologue 1
259 -
260 - beq a2, $zerocount
261 - jsr t9, __stxncpy # do the work of the copy
262 -
263 - and t8, 0xf0, t3 # binary search for byte offset of the
264 - and t8, 0xcc, t2 # last byte written.
265 - and t8, 0xaa, t1
266 - andnot a0, 7, v0
267 - cmovne t3, 4, t3
268 - cmovne t2, 2, t2
269 - cmovne t1, 1, t1
270 - addq v0, t3, v0
271 - addq t1, t2, t1
272 - addq v0, t1, v0
273 -
274 - bne a2, $multiword # do we have full words left?
275 -
276 - .align 3
277 - zapnot t0, t8, t4 # e0 : was last byte a null?
278 - subq t8, 1, t2 # .. e1 :
279 - addq v0, 1, t5 # e0 :
280 - subq t10, 1, t3 # .. e1 :
281 - or t2, t8, t2 # e0 : clear the bits between the last
282 - or t3, t10, t3 # .. e1 : written byte and the last byte in
283 - andnot t3, t2, t3 # e0 : COUNT
284 - cmovne t4, t5, v0 # .. e1 : if last written wasnt null, inc v0
285 - zap t0, t3, t0 # e0 :
286 - stq_u t0, 0(a0) # e1 :
287 - ret # .. e1 :
288 -
289 - .align 3
290 -$multiword:
291 - subq t8, 1, t7 # e0 : clear the final bits in the prev
292 - or t7, t8, t7 # e1 : word
293 - zapnot t0, t7, t0 # e0 :
294 - subq a2, 1, a2 # .. e1 :
295 - stq_u t0, 0(a0) # e0 :
296 - addq a0, 8, a0 # .. e1 :
297 -
298 - beq a2, 1f # e1 :
299 - blbc a2, 0f # e1 :
300 -
301 - stq_u zero, 0(a0) # e0 : zero one word
302 - subq a2, 1, a2 # .. e1 :
303 - addq a0, 8, a0 # e0 :
304 - beq a2, 1f # .. e1 :
305 -
306 -0: stq_u zero, 0(a0) # e0 : zero two words
307 - subq a2, 2, a2 # .. e1 :
308 - stq_u zero, 8(a0) # e0 :
309 - addq a0, 16, a0 # .. e1 :
310 - bne a2, 0b # e1 :
311 - unop
312 -
313 -1: ldq_u t0, 0(a0) # e0 : clear the leading bits in the final
314 - subq t10, 1, t7 # .. e1 : word
315 - or t7, t10, t7 # e0 :
316 - zap t0, t7, t0 # e1 (stall)
317 - stq_u t0, 0(a0) # e0 :
318 - ret # .. e1 :
319 -
320 -$zerocount:
321 - mov a0, v0
322 - ret
323 -
324 - END(__stpncpy)
325 -
326 -libc_hidden_def (__stpncpy)
327 -weak_alias (__stpncpy, stpncpy)
328 --- a/sysdeps/alpha/strcmp.S
329 +++ /dev/null
330 @@ -1,193 +0,0 @@
331 -/* Copyright (C) 1996-2022 Free Software Foundation, Inc.
332 - This file is part of the GNU C Library.
333 -
334 - The GNU C Library is free software; you can redistribute it and/or
335 - modify it under the terms of the GNU Lesser General Public
336 - License as published by the Free Software Foundation; either
337 - version 2.1 of the License, or (at your option) any later version.
338 -
339 - The GNU C Library is distributed in the hope that it will be useful,
340 - but WITHOUT ANY WARRANTY; without even the implied warranty of
341 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
342 - Lesser General Public License for more details.
343 -
344 - You should have received a copy of the GNU Lesser General Public
345 - License along with the GNU C Library. If not, see
346 - <https://www.gnu.org/licenses/>. */
347 -
348 -/* Bytewise compare two null-terminated strings. */
349 -
350 -#include <sysdep.h>
351 -
352 - .set noat
353 - .set noreorder
354 -
355 - .text
356 -
357 -ENTRY(strcmp)
358 -#ifdef PROF
359 - ldgp gp, 0(pv)
360 - lda AT, _mcount
361 - jmp AT, (AT), _mcount
362 - .prologue 1
363 -#else
364 - .prologue 0
365 -#endif
366 -
367 - ldq_u t0, 0(a0) # e0 : give cache time to catch up
368 - xor a0, a1, t2 # .. e1 : are s1 and s2 co-aligned?
369 - ldq_u t1, 0(a1) # e0 :
370 - and t2, 7, t2 # .. e1 :
371 - lda t3, -1 # e0 :
372 - bne t2, $unaligned # .. e1 :
373 -
374 - /* On entry to this basic block:
375 - t0 == the first destination word for masking back in
376 - t1 == the first source word.
377 - t3 == -1. */
378 -
379 -$aligned:
380 - mskqh t3, a0, t3 # e0 :
381 - nop # .. e1 :
382 - ornot t1, t3, t1 # e0 :
383 - ornot t0, t3, t0 # .. e1 :
384 - cmpbge zero, t1, t7 # e0 : bits set iff null found
385 - bne t7, $eos # e1 (zdb)
386 -
387 - /* Aligned compare main loop.
388 - On entry to this basic block:
389 - t0 == an s1 word.
390 - t1 == an s2 word not containing a null. */
391 -
392 -$a_loop:
393 - xor t0, t1, t2 # e0 :
394 - bne t2, $wordcmp # .. e1 (zdb)
395 - ldq_u t1, 8(a1) # e0 :
396 - ldq_u t0, 8(a0) # .. e1 :
397 - addq a1, 8, a1 # e0 :
398 - addq a0, 8, a0 # .. e1 :
399 - cmpbge zero, t1, t7 # e0 :
400 - beq t7, $a_loop # .. e1 (zdb)
401 - br $eos # e1 :
402 -
403 - /* The two strings are not co-aligned. Align s1 and cope. */
404 -
405 -$unaligned:
406 - and a0, 7, t4 # e0 : find s1 misalignment
407 - and a1, 7, t5 # .. e1 : find s2 misalignment
408 - subq a1, t4, a1 # e0 :
409 -
410 - /* If s2 misalignment is larger than s2 misalignment, we need
411 - extra startup checks to avoid SEGV. */
412 -
413 - cmplt t4, t5, t8 # .. e1 :
414 - beq t8, $u_head # e1 :
415 -
416 - mskqh t3, t5, t3 # e0 :
417 - ornot t1, t3, t3 # e0 :
418 - cmpbge zero, t3, t7 # e1 : is there a zero?
419 - beq t7, $u_head # e1 :
420 -
421 - /* We've found a zero in the first partial word of s2. Align
422 - our current s1 and s2 words and compare what we've got. */
423 -
424 - extql t1, t5, t1 # e0 :
425 - extql t0, a0, t0 # e0 :
426 - cmpbge zero, t1, t7 # .. e1 : find that zero again
427 - br $eos # e1 : and finish up
428 -
429 - .align 3
430 -$u_head:
431 - /* We know just enough now to be able to assemble the first
432 - full word of s2. We can still find a zero at the end of it.
433 -
434 - On entry to this basic block:
435 - t0 == first word of s1
436 - t1 == first partial word of s2. */
437 -
438 - ldq_u t2, 8(a1) # e0 : load second partial s2 word
439 - lda t3, -1 # .. e1 : create leading garbage mask
440 - extql t1, a1, t1 # e0 : create first s2 word
441 - mskqh t3, a0, t3 # e0 :
442 - extqh t2, a1, t4 # e0 :
443 - ornot t0, t3, t0 # .. e1 : kill s1 garbage
444 - or t1, t4, t1 # e0 : s2 word now complete
445 - cmpbge zero, t0, t7 # .. e1 : find zero in first s1 word
446 - ornot t1, t3, t1 # e0 : kill s2 garbage
447 - lda t3, -1 # .. e1 :
448 - mskql t3, a1, t3 # e0 : mask for s2[1] bits we have seen
449 - bne t7, $eos # .. e1 :
450 - xor t0, t1, t4 # e0 : compare aligned words
451 - bne t4, $wordcmp # .. e1 (zdb)
452 - or t2, t3, t3 # e0 :
453 - cmpbge zero, t3, t7 # e1 :
454 - bne t7, $u_final # e1 :
455 -
456 - /* Unaligned copy main loop. In order to avoid reading too much,
457 - the loop is structured to detect zeros in aligned words from s2.
458 - This has, unfortunately, effectively pulled half of a loop
459 - iteration out into the head and half into the tail, but it does
460 - prevent nastiness from accumulating in the very thing we want
461 - to run as fast as possible.
462 -
463 - On entry to this basic block:
464 - t2 == the unshifted low-bits from the next s2 word. */
465 -
466 - .align 3
467 -$u_loop:
468 - extql t2, a1, t3 # e0 :
469 - ldq_u t2, 16(a1) # .. e1 : load next s2 high bits
470 - ldq_u t0, 8(a0) # e0 : load next s1 word
471 - addq a1, 8, a1 # .. e1 :
472 - addq a0, 8, a0 # e0 :
473 - nop # .. e1 :
474 - extqh t2, a1, t1 # e0 :
475 - cmpbge zero, t0, t7 # .. e1 : find zero in current s1 word
476 - or t1, t3, t1 # e0 :
477 - bne t7, $eos # .. e1 :
478 - xor t0, t1, t4 # e0 : compare the words
479 - bne t4, $wordcmp # .. e1 (zdb)
480 - cmpbge zero, t2, t4 # e0 : find zero in next low bits
481 - beq t4, $u_loop # .. e1 (zdb)
482 -
483 - /* We've found a zero in the low bits of the last s2 word. Get
484 - the next s1 word and align them. */
485 -$u_final:
486 - ldq_u t0, 8(a0) # e1 :
487 - extql t2, a1, t1 # .. e0 :
488 - cmpbge zero, t1, t7 # e0 :
489 -
490 - /* We've found a zero somewhere in a word we just read.
491 - On entry to this basic block:
492 - t0 == s1 word
493 - t1 == s2 word
494 - t7 == cmpbge mask containing the zero. */
495 -
496 - .align 3
497 -$eos:
498 - negq t7, t6 # e0 : create bytemask of valid data
499 - and t6, t7, t8 # e1 :
500 - subq t8, 1, t6 # e0 :
501 - or t6, t8, t7 # e1 :
502 - zapnot t0, t7, t0 # e0 : kill the garbage
503 - zapnot t1, t7, t1 # .. e1 :
504 - xor t0, t1, v0 # e0 : and compare
505 - beq v0, $done # .. e1 :
506 -
507 - /* Here we have two differing co-aligned words in t0 & t1.
508 - Bytewise compare them and return (t0 > t1 ? 1 : -1). */
509 -$wordcmp:
510 - cmpbge t0, t1, t2 # e0 : comparison yields bit mask of ge
511 - cmpbge t1, t0, t3 # .. e1 :
512 - xor t2, t3, t0 # e0 : bits set iff t0/t1 bytes differ
513 - negq t0, t1 # e1 : clear all but least bit
514 - and t0, t1, t0 # e0 :
515 - lda v0, -1 # .. e1 :
516 - and t0, t2, t1 # e0 : was bit set in t0 > t1?
517 - cmovne t1, 1, v0 # .. e1 (zdb)
518 -
519 -$done:
520 - ret # e1 :
521 -
522 - END(strcmp)
523 -libc_hidden_builtin_def (strcmp)
524 --- a/sysdeps/alpha/strncat.S
525 +++ /dev/null
526 @@ -1,93 +0,0 @@
527 -/* Copyright (C) 1996-2022 Free Software Foundation, Inc.
528 - This file is part of the GNU C Library.
529 -
530 - The GNU C Library is free software; you can redistribute it and/or
531 - modify it under the terms of the GNU Lesser General Public
532 - License as published by the Free Software Foundation; either
533 - version 2.1 of the License, or (at your option) any later version.
534 -
535 - The GNU C Library is distributed in the hope that it will be useful,
536 - but WITHOUT ANY WARRANTY; without even the implied warranty of
537 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
538 - Lesser General Public License for more details.
539 -
540 - You should have received a copy of the GNU Lesser General Public
541 - License along with the GNU C Library. If not, see
542 - <https://www.gnu.org/licenses/>. */
543 -
544 -/* Append no more than COUNT characters from the null-terminated string SRC
545 - to the null-terminated string DST. Always null-terminate the new DST. */
546 -
547 -#include <sysdep.h>
548 -
549 - .text
550 -
551 -ENTRY(strncat)
552 - ldgp gp, 0(pv)
553 -#ifdef PROF
554 - .set noat
555 - lda AT, _mcount
556 - jsr AT, (AT), _mcount
557 - .set at
558 -#endif
559 - .prologue 1
560 -
561 - mov a0, v0 # set up return value
562 - beq a2, $zerocount
563 -
564 - /* Find the end of the string. */
565 -
566 - ldq_u t0, 0(a0) # load first quadword (a0 may be misaligned)
567 - lda t1, -1(zero)
568 - insqh t1, a0, t1
569 - andnot a0, 7, a0
570 - or t1, t0, t0
571 - cmpbge zero, t0, t1 # t1 <- bitmask: bit i == 1 <==> i-th byte == 0
572 - bne t1, $found
573 -
574 -$loop: ldq t0, 8(a0)
575 - addq a0, 8, a0 # addr += 8
576 - cmpbge zero, t0, t1
577 - beq t1, $loop
578 -
579 -$found: negq t1, t2 # clear all but least set bit
580 - and t1, t2, t1
581 -
582 - and t1, 0xf0, t2 # binary search for that set bit
583 - and t1, 0xcc, t3
584 - and t1, 0xaa, t4
585 - cmovne t2, 4, t2
586 - cmovne t3, 2, t3
587 - cmovne t4, 1, t4
588 - addq t2, t3, t2
589 - addq a0, t4, a0
590 - addq a0, t2, a0
591 -
592 - /* Now do the append. */
593 -
594 - jsr t9, __stxncpy
595 -
596 - /* Worry about the null termination. */
597 -
598 - zapnot t0, t8, t1 # was last byte a null?
599 - bne t1, 0f
600 - ret
601 -
602 -0: and t10, 0x80, t1
603 - bne t1, 1f
604 -
605 - /* Here there are bytes left in the current word. Clear one. */
606 - addq t10, t10, t10 # end-of-count bit <<= 1
607 - zap t0, t10, t0
608 - stq_u t0, 0(a0)
609 - ret
610 -
611 -1: /* Here we must read the next DST word and clear the first byte. */
612 - ldq_u t0, 8(a0)
613 - zap t0, 1, t0
614 - stq_u t0, 8(a0)
615 -
616 -$zerocount:
617 - ret
618 -
619 - END(strncat)
620 --- a/sysdeps/alpha/strncmp.S
621 +++ /dev/null
622 @@ -1,276 +0,0 @@
623 -/* Copyright (C) 1996-2022 Free Software Foundation, Inc.
624 - This file is part of the GNU C Library.
625 -
626 - The GNU C Library is free software; you can redistribute it and/or
627 - modify it under the terms of the GNU Lesser General Public
628 - License as published by the Free Software Foundation; either
629 - version 2.1 of the License, or (at your option) any later version.
630 -
631 - The GNU C Library is distributed in the hope that it will be useful,
632 - but WITHOUT ANY WARRANTY; without even the implied warranty of
633 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
634 - Lesser General Public License for more details.
635 -
636 - You should have received a copy of the GNU Lesser General Public
637 - License along with the GNU C Library. If not, see
638 - <https://www.gnu.org/licenses/>. */
639 -
640 -/* Bytewise compare two null-terminated strings of length no longer than N. */
641 -
642 -#include <sysdep.h>
643 -
644 - .set noat
645 - .set noreorder
646 -
647 -/* EV6 only predicts one branch per octaword. We'll use these to push
648 - subsequent branches back to the next bundle. This will generally add
649 - a fetch+decode cycle to older machines, so skip in that case. */
650 -#ifdef __alpha_fix__
651 -# define ev6_unop unop
652 -#else
653 -# define ev6_unop
654 -#endif
655 -
656 - .text
657 -
658 -ENTRY(strncmp)
659 -#ifdef PROF
660 - ldgp gp, 0(pv)
661 - lda AT, _mcount
662 - jsr AT, (AT), _mcount
663 - .prologue 1
664 -#else
665 - .prologue 0
666 -#endif
667 -
668 - xor a0, a1, t2 # are s1 and s2 co-aligned?
669 - beq a2, $zerolength
670 - ldq_u t0, 0(a0) # load asap to give cache time to catch up
671 - ldq_u t1, 0(a1)
672 - lda t3, -1
673 - and t2, 7, t2
674 - srl t3, 1, t6
675 - and a0, 7, t4 # find s1 misalignment
676 - and a1, 7, t5 # find s2 misalignment
677 - cmovlt a2, t6, a2 # bound neg count to LONG_MAX
678 - addq a1, a2, a3 # s2+count
679 - addq a2, t4, a2 # bias count by s1 misalignment
680 - and a2, 7, t10 # ofs of last byte in s1 last word
681 - srl a2, 3, a2 # remaining full words in s1 count
682 - bne t2, $unaligned
683 -
684 - /* On entry to this basic block:
685 - t0 == the first word of s1.
686 - t1 == the first word of s2.
687 - t3 == -1. */
688 -$aligned:
689 - mskqh t3, a1, t8 # mask off leading garbage
690 - ornot t1, t8, t1
691 - ornot t0, t8, t0
692 - cmpbge zero, t1, t7 # bits set iff null found
693 - beq a2, $eoc # check end of count
694 - bne t7, $eos
695 - beq t10, $ant_loop
696 -
697 - /* Aligned compare main loop.
698 - On entry to this basic block:
699 - t0 == an s1 word.
700 - t1 == an s2 word not containing a null. */
701 -
702 - .align 4
703 -$a_loop:
704 - xor t0, t1, t2 # e0 :
705 - bne t2, $wordcmp # .. e1 (zdb)
706 - ldq_u t1, 8(a1) # e0 :
707 - ldq_u t0, 8(a0) # .. e1 :
708 -
709 - subq a2, 1, a2 # e0 :
710 - addq a1, 8, a1 # .. e1 :
711 - addq a0, 8, a0 # e0 :
712 - beq a2, $eoc # .. e1 :
713 -
714 - cmpbge zero, t1, t7 # e0 :
715 - beq t7, $a_loop # .. e1 :
716 -
717 - br $eos
718 -
719 - /* Alternate aligned compare loop, for when there's no trailing
720 - bytes on the count. We have to avoid reading too much data. */
721 - .align 4
722 -$ant_loop:
723 - xor t0, t1, t2 # e0 :
724 - ev6_unop
725 - ev6_unop
726 - bne t2, $wordcmp # .. e1 (zdb)
727 -
728 - subq a2, 1, a2 # e0 :
729 - beq a2, $zerolength # .. e1 :
730 - ldq_u t1, 8(a1) # e0 :
731 - ldq_u t0, 8(a0) # .. e1 :
732 -
733 - addq a1, 8, a1 # e0 :
734 - addq a0, 8, a0 # .. e1 :
735 - cmpbge zero, t1, t7 # e0 :
736 - beq t7, $ant_loop # .. e1 :
737 -
738 - br $eos
739 -
740 - /* The two strings are not co-aligned. Align s1 and cope. */
741 - /* On entry to this basic block:
742 - t0 == the first word of s1.
743 - t1 == the first word of s2.
744 - t3 == -1.
745 - t4 == misalignment of s1.
746 - t5 == misalignment of s2.
747 - t10 == misalignment of s1 end. */
748 - .align 4
749 -$unaligned:
750 - /* If s1 misalignment is larger than s2 misalignment, we need
751 - extra startup checks to avoid SEGV. */
752 - subq a1, t4, a1 # adjust s2 for s1 misalignment
753 - cmpult t4, t5, t9
754 - subq a3, 1, a3 # last byte of s2
755 - bic a1, 7, t8
756 - mskqh t3, t5, t7 # mask garbage in s2
757 - subq a3, t8, a3
758 - ornot t1, t7, t7
759 - srl a3, 3, a3 # remaining full words in s2 count
760 - beq t9, $u_head
761 -
762 - /* Failing that, we need to look for both eos and eoc within the
763 - first word of s2. If we find either, we can continue by
764 - pretending that the next word of s2 is all zeros. */
765 - lda t2, 0 # next = zero
766 - cmpeq a3, 0, t8 # eoc in the first word of s2?
767 - cmpbge zero, t7, t7 # eos in the first word of s2?
768 - or t7, t8, t8
769 - bne t8, $u_head_nl
770 -
771 - /* We know just enough now to be able to assemble the first
772 - full word of s2. We can still find a zero at the end of it.
773 -
774 - On entry to this basic block:
775 - t0 == first word of s1
776 - t1 == first partial word of s2.
777 - t3 == -1.
778 - t10 == ofs of last byte in s1 last word.
779 - t11 == ofs of last byte in s2 last word. */
780 -$u_head:
781 - ldq_u t2, 8(a1) # load second partial s2 word
782 - subq a3, 1, a3
783 -$u_head_nl:
784 - extql t1, a1, t1 # create first s2 word
785 - mskqh t3, a0, t8
786 - extqh t2, a1, t4
787 - ornot t0, t8, t0 # kill s1 garbage
788 - or t1, t4, t1 # s2 word now complete
789 - cmpbge zero, t0, t7 # find eos in first s1 word
790 - ornot t1, t8, t1 # kill s2 garbage
791 - beq a2, $eoc
792 - subq a2, 1, a2
793 - bne t7, $eos
794 - mskql t3, a1, t8 # mask out s2[1] bits we have seen
795 - xor t0, t1, t4 # compare aligned words
796 - or t2, t8, t8
797 - bne t4, $wordcmp
798 - cmpbge zero, t8, t7 # eos in high bits of s2[1]?
799 - cmpeq a3, 0, t8 # eoc in s2[1]?
800 - or t7, t8, t7
801 - bne t7, $u_final
802 -
803 - /* Unaligned copy main loop. In order to avoid reading too much,
804 - the loop is structured to detect zeros in aligned words from s2.
805 - This has, unfortunately, effectively pulled half of a loop
806 - iteration out into the head and half into the tail, but it does
807 - prevent nastiness from accumulating in the very thing we want
808 - to run as fast as possible.
809 -
810 - On entry to this basic block:
811 - t2 == the unshifted low-bits from the next s2 word.
812 - t10 == ofs of last byte in s1 last word.
813 - t11 == ofs of last byte in s2 last word. */
814 - .align 4
815 -$u_loop:
816 - extql t2, a1, t3 # e0 :
817 - ldq_u t2, 16(a1) # .. e1 : load next s2 high bits
818 - ldq_u t0, 8(a0) # e0 : load next s1 word
819 - addq a1, 8, a1 # .. e1 :
820 -
821 - addq a0, 8, a0 # e0 :
822 - subq a3, 1, a3 # .. e1 :
823 - extqh t2, a1, t1 # e0 :
824 - cmpbge zero, t0, t7 # .. e1 : eos in current s1 word
825 -
826 - or t1, t3, t1 # e0 :
827 - beq a2, $eoc # .. e1 : eoc in current s1 word
828 - subq a2, 1, a2 # e0 :
829 - cmpbge zero, t2, t4 # .. e1 : eos in s2[1]
830 -
831 - xor t0, t1, t3 # e0 : compare the words
832 - ev6_unop
833 - ev6_unop
834 - bne t7, $eos # .. e1 :
835 -
836 - cmpeq a3, 0, t5 # e0 : eoc in s2[1]
837 - ev6_unop
838 - ev6_unop
839 - bne t3, $wordcmp # .. e1 :
840 -
841 - or t4, t5, t4 # e0 : eos or eoc in s2[1].
842 - beq t4, $u_loop # .. e1 (zdb)
843 -
844 - /* We've found a zero in the low bits of the last s2 word. Get
845 - the next s1 word and align them. */
846 - .align 3
847 -$u_final:
848 - ldq_u t0, 8(a0)
849 - extql t2, a1, t1
850 - cmpbge zero, t1, t7
851 - bne a2, $eos
852 -
853 - /* We've hit end of count. Zero everything after the count
854 - and compare whats left. */
855 - .align 3
856 -$eoc:
857 - mskql t0, t10, t0
858 - mskql t1, t10, t1
859 - cmpbge zero, t1, t7
860 -
861 - /* We've found a zero somewhere in a word we just read.
862 - On entry to this basic block:
863 - t0 == s1 word
864 - t1 == s2 word
865 - t7 == cmpbge mask containing the zero. */
866 - .align 3
867 -$eos:
868 - negq t7, t6 # create bytemask of valid data
869 - and t6, t7, t8
870 - subq t8, 1, t6
871 - or t6, t8, t7
872 - zapnot t0, t7, t0 # kill the garbage
873 - zapnot t1, t7, t1
874 - xor t0, t1, v0 # ... and compare
875 - beq v0, $done
876 -
877 - /* Here we have two differing co-aligned words in t0 & t1.
878 - Bytewise compare them and return (t0 > t1 ? 1 : -1). */
879 - .align 3
880 -$wordcmp:
881 - cmpbge t0, t1, t2 # comparison yields bit mask of ge
882 - cmpbge t1, t0, t3
883 - xor t2, t3, t0 # bits set iff t0/t1 bytes differ
884 - negq t0, t1 # clear all but least bit
885 - and t0, t1, t0
886 - lda v0, -1
887 - and t0, t2, t1 # was bit set in t0 > t1?
888 - cmovne t1, 1, v0
889 -$done:
890 - ret
891 -
892 - .align 3
893 -$zerolength:
894 - clr v0
895 - ret
896 -
897 - END(strncmp)
898 -libc_hidden_builtin_def (strncmp)
899 --- a/sysdeps/alpha/strncpy.S
900 +++ /dev/null
901 @@ -1,86 +0,0 @@
902 -/* Copyright (C) 1996-2022 Free Software Foundation, Inc.
903 - This file is part of the GNU C Library.
904 -
905 - The GNU C Library is free software; you can redistribute it and/or
906 - modify it under the terms of the GNU Lesser General Public
907 - License as published by the Free Software Foundation; either
908 - version 2.1 of the License, or (at your option) any later version.
909 -
910 - The GNU C Library is distributed in the hope that it will be useful,
911 - but WITHOUT ANY WARRANTY; without even the implied warranty of
912 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
913 - Lesser General Public License for more details.
914 -
915 - You should have received a copy of the GNU Lesser General Public
916 - License along with the GNU C Library. If not, see
917 - <https://www.gnu.org/licenses/>. */
918 -
919 -/* Copy no more than COUNT bytes of the null-terminated string from
920 - SRC to DST. If SRC does not cover all of COUNT, the balance is
921 - zeroed. */
922 -
923 -#include <sysdep.h>
924 -
925 - .set noat
926 - .set noreorder
927 -
928 - .text
929 -
930 -ENTRY(strncpy)
931 - ldgp gp, 0(pv)
932 -#ifdef PROF
933 - lda AT, _mcount
934 - jsr AT, (AT), _mcount
935 -#endif
936 - .prologue 1
937 -
938 - mov a0, v0 # set return value now
939 - beq a2, $zerocount
940 - jsr t9, __stxncpy # do the work of the copy
941 -
942 - bne a2, $multiword # do we have full words left?
943 -
944 - .align 3
945 - subq t8, 1, t2 # e0 : guess not
946 - subq t10, 1, t3 # .. e1 :
947 - or t2, t8, t2 # e0 : clear the bits between the last
948 - or t3, t10, t3 # .. e1 : written byte and the last byte in
949 - andnot t3, t2, t3 # e0 : COUNT
950 - zap t0, t3, t0 # e1 :
951 - stq_u t0, 0(a0) # e0 :
952 - ret # .. e1 :
953 -
954 -$multiword:
955 - subq t8, 1, t7 # e0 : clear the final bits in the prev
956 - or t7, t8, t7 # e1 : word
957 - zapnot t0, t7, t0 # e0 :
958 - subq a2, 1, a2 # .. e1 :
959 - stq_u t0, 0(a0) # e0 :
960 - addq a0, 8, a0 # .. e1 :
961 -
962 - beq a2, 1f # e1 :
963 - blbc a2, 0f # e1 :
964 -
965 - stq_u zero, 0(a0) # e0 : zero one word
966 - subq a2, 1, a2 # .. e1 :
967 - addq a0, 8, a0 # e0 :
968 - beq a2, 1f # .. e1 :
969 -
970 -0: stq_u zero, 0(a0) # e0 : zero two words
971 - subq a2, 2, a2 # .. e1 :
972 - stq_u zero, 8(a0) # e0 :
973 - addq a0, 16, a0 # .. e1 :
974 - bne a2, 0b # e1 :
975 - unop
976 -
977 -1: ldq_u t0, 0(a0) # e0 : clear the leading bits in the final
978 - subq t10, 1, t7 # .. e1 : word
979 - or t7, t10, t7 # e0 :
980 - zap t0, t7, t0 # e1 (stall)
981 - stq_u t0, 0(a0) # e0 :
982 -
983 -$zerocount:
984 - ret # .. e1 :
985 -
986 - END(strncpy)
987 -libc_hidden_builtin_def (strncpy)