Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo commit in src/patchsets/glibc/2.12.1/ports: 6027_all_alpha-fix-memchr.patch 6028_all_alpha-fix-memchr.patch 6029_all_alpha-fix-memchr.patch
Date: Wed, 29 Sep 2010 23:54:59
Message-Id: 20100929235455.4BFE620054@flycatcher.gentoo.org
1 vapier 10/09/29 23:54:55
2
3 Modified: 6027_all_alpha-fix-memchr.patch
4 Added: 6028_all_alpha-fix-memchr.patch
5 6029_all_alpha-fix-memchr.patch
6 Log:
7 grab more alpha memchr fixes from upstream
8
9 Revision Changes Path
10 1.2 src/patchsets/glibc/2.12.1/ports/6027_all_alpha-fix-memchr.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/glibc/2.12.1/ports/6027_all_alpha-fix-memchr.patch?rev=1.2&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/glibc/2.12.1/ports/6027_all_alpha-fix-memchr.patch?rev=1.2&content-type=text/plain
14 diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/glibc/2.12.1/ports/6027_all_alpha-fix-memchr.patch?r1=1.1&r2=1.2
15
16 Index: 6027_all_alpha-fix-memchr.patch
17 ===================================================================
18 RCS file: /var/cvsroot/gentoo/src/patchsets/glibc/2.12.1/ports/6027_all_alpha-fix-memchr.patch,v
19 retrieving revision 1.1
20 retrieving revision 1.2
21 diff -u -r1.1 -r1.2
22 --- 6027_all_alpha-fix-memchr.patch 5 Aug 2010 17:20:40 -0000 1.1
23 +++ 6027_all_alpha-fix-memchr.patch 29 Sep 2010 23:54:55 -0000 1.2
24 @@ -1,8 +1,24 @@
25 -2009-07-27 Aurelien Jarno <aurelien@×××××××.net>
26 +From 200b5faee1cfac10d831e9b278ef294ca3119f53 Mon Sep 17 00:00:00 2001
27 +From: Richard Henderson <rth@×××××××.net>
28 +Date: Tue, 4 May 2010 09:06:15 -0700
29 +Subject: [PATCH] alpha: fix memchr to not cause memory faults.
30
31 +http://www.mail-archive.com/debian-alpha@××××××××××××.org/msg25088.html
32 +
33 +2010-05-03 Aurelien Jarno <aurelien@×××××××.net>
34 +
35 * sysdeps/alpha/memchr.S: Use prefetch load.
36 * sysdeps/alpha/alphaev6/memchr.S: Likewise.
37
38 +Signed-off-by: Matt Turner <mattst88@×××××.com>
39 +---
40 + ChangeLog.alpha | 5 +++++
41 + sysdeps/alpha/alphaev6/memchr.S | 26 +++++++++++++-------------
42 + sysdeps/alpha/memchr.S | 22 +++++++++++-----------
43 + 3 files changed, 29 insertions(+), 24 deletions(-)
44 +
45 +diff --git a/sysdeps/alpha/alphaev6/memchr.S b/sysdeps/alpha/alphaev6/memchr.S
46 +index 88e91fa..fe77cd8 100644
47 --- ports/sysdeps/alpha/alphaev6/memchr.S
48 +++ ports/sysdeps/alpha/alphaev6/memchr.S
49 @@ -127,7 +127,7 @@ $first_quad:
50 @@ -65,6 +81,8 @@
51 nop # E :
52 bne $18, $last_quad # U :
53
54 +diff --git a/sysdeps/alpha/memchr.S b/sysdeps/alpha/memchr.S
55 +index 5d713d5..87c7fb1 100644
56 --- ports/sysdeps/alpha/memchr.S
57 +++ ports/sysdeps/alpha/memchr.S
58 @@ -119,7 +119,7 @@ $first_quad:
59 @@ -115,3 +133,5 @@
60 bne a2, $last_quad # e1 :
61
62 $not_found:
63 +--
64 +1.7.3
65
66
67
68 1.1 src/patchsets/glibc/2.12.1/ports/6028_all_alpha-fix-memchr.patch
69
70 file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/glibc/2.12.1/ports/6028_all_alpha-fix-memchr.patch?rev=1.1&view=markup
71 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/glibc/2.12.1/ports/6028_all_alpha-fix-memchr.patch?rev=1.1&content-type=text/plain
72
73 Index: 6028_all_alpha-fix-memchr.patch
74 ===================================================================
75 From 926cf114f7ca2b19116cac005303040648e17e77 Mon Sep 17 00:00:00 2001
76 From: Richard Henderson <rth@×××××××.net>
77 Date: Wed, 15 Sep 2010 10:41:43 -0700
78 Subject: [PATCH] alpha: rewrite memchr.
79
80 [BZ #12019]
81 The new implementation does not read too much data.
82
83 2010-09-23 Richard Henderson <rth@××××××.com>
84
85 [BZ #12019]
86 * sysdeps/alpha/alphaev6/memchr.S: Remove.
87 * sysdeps/alpha/memchr.S: Remove.
88 * sysdeps/alpha/memchr.c: New.
89
90 ---
91 ChangeLog.alpha | 9 ++-
92 sysdeps/alpha/alphaev6/memchr.S | 193 ---------------------------------------
93 sysdeps/alpha/memchr.S | 176 -----------------------------------
94 sysdeps/alpha/memchr.c | 175 +++++++++++++++++++++++++++++++++++
95 4 files changed, 183 insertions(+), 370 deletions(-)
96 delete mode 100644 sysdeps/alpha/alphaev6/memchr.S
97 delete mode 100644 sysdeps/alpha/memchr.S
98 create mode 100644 sysdeps/alpha/memchr.c
99
100 diff --git a/sysdeps/alpha/alphaev6/memchr.S b/sysdeps/alpha/alphaev6/memchr.S
101 deleted file mode 100644
102 index fe77cd8..0000000
103 --- ports/sysdeps/alpha/alphaev6/memchr.S
104 +++ /dev/null
105 @@ -1,193 +0,0 @@
106 -/* Copyright (C) 2000, 2003 Free Software Foundation, Inc.
107 - This file is part of the GNU C Library.
108 - Contributed by David Mosberger (davidm@××××××××××.edu).
109 - EV6 optimized by Rick Gorton <rick.gorton@×××××××××××××××.com>.
110 -
111 - The GNU C Library is free software; you can redistribute it and/or
112 - modify it under the terms of the GNU Lesser General Public
113 - License as published by the Free Software Foundation; either
114 - version 2.1 of the License, or (at your option) any later version.
115 -
116 - The GNU C Library is distributed in the hope that it will be useful,
117 - but WITHOUT ANY WARRANTY; without even the implied warranty of
118 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
119 - Lesser General Public License for more details.
120 -
121 - You should have received a copy of the GNU Lesser General Public
122 - License along with the GNU C Library; if not, write to the Free
123 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
124 - 02111-1307 USA. */
125 -
126 -#include <sysdep.h>
127 -
128 - .arch ev6
129 - .set noreorder
130 - .set noat
131 -
132 -ENTRY(__memchr)
133 -#ifdef PROF
134 - ldgp gp, 0(pv)
135 - lda AT, _mcount
136 - jsr AT, (AT), _mcount
137 - .prologue 1
138 -#else
139 - .prologue 0
140 -#endif
141 -
142 - # Hack -- if someone passes in (size_t)-1, hoping to just
143 - # search til the end of the address space, we will overflow
144 - # below when we find the address of the last byte. Given
145 - # that we will never have a 56-bit address space, cropping
146 - # the length is the easiest way to avoid trouble.
147 - zap $18, 0x80, $5 # U : Bound length
148 - beq $18, $not_found # U :
149 - ldq_u $1, 0($16) # L : load first quadword Latency=3
150 - and $17, 0xff, $17 # E : L L U U : 00000000000000ch
151 -
152 - insbl $17, 1, $2 # U : 000000000000ch00
153 - cmpult $18, 9, $4 # E : small (< 1 quad) string?
154 - or $2, $17, $17 # E : 000000000000chch
155 - lda $3, -1($31) # E : U L L U
156 -
157 - sll $17, 16, $2 # U : 00000000chch0000
158 - addq $16, $5, $5 # E : Max search address
159 - or $2, $17, $17 # E : 00000000chchchch
160 - sll $17, 32, $2 # U : U L L U : chchchch00000000
161 -
162 - or $2, $17, $17 # E : chchchchchchchch
163 - extql $1, $16, $7 # U : $7 is upper bits
164 - beq $4, $first_quad # U :
165 - ldq_u $6, -1($5) # L : L U U L : eight or less bytes to search Latency=3
166 -
167 - extqh $6, $16, $6 # U : 2 cycle stall for $6
168 - mov $16, $0 # E :
169 - nop # E :
170 - or $7, $6, $1 # E : L U L U $1 = quadword starting at $16
171 -
172 - # Deal with the case where at most 8 bytes remain to be searched
173 - # in $1. E.g.:
174 - # $18 = 6
175 - # $1 = ????c6c5c4c3c2c1
176 -$last_quad:
177 - negq $18, $6 # E :
178 - xor $17, $1, $1 # E :
179 - srl $3, $6, $6 # U : $6 = mask of $18 bits set
180 - cmpbge $31, $1, $2 # E : L U L U
181 -
182 - nop
183 - nop
184 - and $2, $6, $2 # E :
185 - beq $2, $not_found # U : U L U L
186 -
187 -$found_it:
188 -#if defined(__alpha_fix__) && defined(__alpha_cix__)
189 - /*
190 - * Since we are guaranteed to have set one of the bits, we don't
191 - * have to worry about coming back with a 0x40 out of cttz...
192 - */
193 - cttz $2, $3 # U0 :
194 - addq $0, $3, $0 # E : All done
195 - nop # E :
196 - ret # L0 : L U L U
197 -#else
198 - /*
199 - * Slow and clunky. It can probably be improved.
200 - * An exercise left for others.
201 - */
202 - negq $2, $3 # E :
203 - and $2, $3, $2 # E :
204 - and $2, 0x0f, $1 # E :
205 - addq $0, 4, $3 # E :
206 -
207 - cmoveq $1, $3, $0 # E : Latency 2, extra map cycle
208 - nop # E : keep with cmov
209 - and $2, 0x33, $1 # E :
210 - addq $0, 2, $3 # E : U L U L : 2 cycle stall on $0
211 -
212 - cmoveq $1, $3, $0 # E : Latency 2, extra map cycle
213 - nop # E : keep with cmov
214 - and $2, 0x55, $1 # E :
215 - addq $0, 1, $3 # E : U L U L : 2 cycle stall on $0
216 -
217 - cmoveq $1, $3, $0 # E : Latency 2, extra map cycle
218 - nop
219 - nop
220 - ret # L0 : L U L U
221 -#endif
222 -
223 - # Deal with the case where $18 > 8 bytes remain to be
224 - # searched. $16 may not be aligned.
225 - .align 4
226 -$first_quad:
227 - andnot $16, 0x7, $0 # E :
228 - insqh $3, $16, $2 # U : $2 = 0000ffffffffffff ($16<0:2> ff)
229 - xor $1, $17, $1 # E :
230 - or $1, $2, $1 # E : U L U L $1 = ====ffffffffffff
231 -
232 - cmpbge $31, $1, $2 # E :
233 - bne $2, $found_it # U :
234 - # At least one byte left to process.
235 - ldq $31, 8($0) # L :
236 - subq $5, 1, $18 # E : U L U L
237 -
238 - addq $0, 8, $0 # E :
239 - # Make $18 point to last quad to be accessed (the
240 - # last quad may or may not be partial).
241 - andnot $18, 0x7, $18 # E :
242 - cmpult $0, $18, $2 # E :
243 - beq $2, $final # U : U L U L
244 -
245 - # At least two quads remain to be accessed.
246 -
247 - subq $18, $0, $4 # E : $4 <- nr quads to be processed
248 - and $4, 8, $4 # E : odd number of quads?
249 - bne $4, $odd_quad_count # U :
250 - # At least three quads remain to be accessed
251 - nop # E : L U L U : move prefetched value to correct reg
252 -
253 - .align 4
254 -$unrolled_loop:
255 - ldq $1, 0($0) # L : load quad
256 - xor $17, $1, $2 # E :
257 - ldq $31, 8($0) # L : prefetch next quad
258 - cmpbge $31, $2, $2 # E : U L U L
259 -
260 - bne $2, $found_it # U :
261 - addq $0, 8, $0 # E :
262 - nop # E :
263 - nop # E :
264 -
265 -$odd_quad_count:
266 - ldq $1, 0($0) # L : load quad
267 - xor $17, $1, $2 # E :
268 - ldq $31, 8($0) # L : prefetch $4
269 - cmpbge $31, $2, $2 # E :
270 -
271 - addq $0, 8, $6 # E :
272 - bne $2, $found_it # U :
273 - cmpult $6, $18, $6 # E :
274 - addq $0, 8, $0 # E :
275 -
276 - bne $6, $unrolled_loop # U :
277 - nop # E :
278 - nop # E :
279 - nop # E :
280 -
281 -$final: ldq $1, 0($0) # L : load last quad
282 - subq $5, $0, $18 # E : $18 <- number of bytes left to do
283 - nop # E :
284 - bne $18, $last_quad # U :
285 -
286 -$not_found:
287 - mov $31, $0 # E :
288 - nop # E :
289 - nop # E :
290 - ret # L0 :
291 -
292 - END(__memchr)
293 -
294 -weak_alias (__memchr, memchr)
295 -#if !__BOUNDED_POINTERS__
296 -weak_alias (__memchr, __ubp_memchr)
297 -#endif
298 -libc_hidden_builtin_def (memchr)
299 diff --git a/sysdeps/alpha/memchr.S b/sysdeps/alpha/memchr.S
300 deleted file mode 100644
301 index 87c7fb1..0000000
302 --- ports/sysdeps/alpha/memchr.S
303 +++ /dev/null
304 @@ -1,176 +0,0 @@
305 -/* Copyright (C) 1996, 2000, 2003 Free Software Foundation, Inc.
306 - This file is part of the GNU C Library.
307 - Contributed by David Mosberger (davidm@××××××××××.edu).
308 -
309 - The GNU C Library is free software; you can redistribute it and/or
310 - modify it under the terms of the GNU Lesser General Public
311 - License as published by the Free Software Foundation; either
312 - version 2.1 of the License, or (at your option) any later version.
313 -
314 - The GNU C Library is distributed in the hope that it will be useful,
315 - but WITHOUT ANY WARRANTY; without even the implied warranty of
316 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
317 - Lesser General Public License for more details.
318 -
319 - You should have received a copy of the GNU Lesser General Public
320 - License along with the GNU C Library; if not, write to the Free
321 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
322 - 02111-1307 USA. */
323 -
324 -/* Finds characters in a memory area. Optimized for the Alpha:
325 -
326 - - memory accessed as aligned quadwords only
327 - - uses cmpbge to compare 8 bytes in parallel
328 - - does binary search to find 0 byte in last
329 - quadword (HAKMEM needed 12 instructions to
330 - do this instead of the 9 instructions that
331 - binary search needs).
332 -
333 -For correctness consider that:
334 -
335 - - only minimum number of quadwords may be accessed
336 - - the third argument is an unsigned long
337 -*/
338 -
339 -#include <sysdep.h>
340 -
341 - .set noreorder
342 - .set noat
343 -
344 -ENTRY(__memchr)
345 -#ifdef PROF
346 - ldgp gp, 0(pv)
347 - lda AT, _mcount
348 - jsr AT, (AT), _mcount
349 - .prologue 1
350 -#else
351 - .prologue 0
352 -#endif
353 -
354 - # Hack -- if someone passes in (size_t)-1, hoping to just
355 - # search til the end of the address space, we will overflow
356 - # below when we find the address of the last byte. Given
357 - # that we will never have a 56-bit address space, cropping
358 - # the length is the easiest way to avoid trouble.
359 - zap a2, 0x80, t4 #-e0 :
360 -
361 - beq a2, $not_found # .. e1 :
362 - ldq_u t0, 0(a0) # e1 : load first quadword
363 - insbl a1, 1, t1 # .. e0 : t1 = 000000000000ch00
364 - and a1, 0xff, a1 #-e0 : a1 = 00000000000000ch
365 - cmpult a2, 9, t3 # .. e1 :
366 - or t1, a1, a1 # e0 : a1 = 000000000000chch
367 - lda t2, -1(zero) # .. e1 :
368 - sll a1, 16, t1 #-e0 : t1 = 00000000chch0000
369 - addq a0, t4, t4 # .. e1 :
370 - or t1, a1, a1 # e1 : a1 = 00000000chchchch
371 - unop # :
372 - sll a1, 32, t1 #-e0 : t1 = chchchch00000000
373 - or t1, a1, a1 # e1 : a1 = chchchchchchchch
374 - extql t0, a0, t6 # e0 :
375 - beq t3, $first_quad # .. e1 :
376 -
377 - ldq_u t5, -1(t4) #-e1 : eight or less bytes to search
378 - extqh t5, a0, t5 # .. e0 :
379 - mov a0, v0 # e0 :
380 - or t6, t5, t0 # .. e1 : t0 = quadword starting at a0
381 -
382 - # Deal with the case where at most 8 bytes remain to be searched
383 - # in t0. E.g.:
384 - # a2 = 6
385 - # t0 = ????c6c5c4c3c2c1
386 -$last_quad:
387 - negq a2, t5 #-e0 :
388 - xor a1, t0, t0 # .. e1 :
389 - srl t2, t5, t5 # e0 : t5 = mask of a2 bits set
390 - cmpbge zero, t0, t1 # .. e1 :
391 - and t1, t5, t1 #-e0 :
392 - beq t1, $not_found # .. e1 :
393 -
394 -$found_it:
395 - # Now, determine which byte matched:
396 - negq t1, t2 # e0 :
397 - and t1, t2, t1 # e1 :
398 -
399 - and t1, 0x0f, t0 #-e0 :
400 - addq v0, 4, t2 # .. e1 :
401 - cmoveq t0, t2, v0 # e0 :
402 -
403 - addq v0, 2, t2 # .. e1 :
404 - and t1, 0x33, t0 #-e0 :
405 - cmoveq t0, t2, v0 # .. e1 :
406 -
407 - and t1, 0x55, t0 # e0 :
408 - addq v0, 1, t2 # .. e1 :
409 - cmoveq t0, t2, v0 #-e0 :
410 -
411 -$done: ret # .. e1 :
412 -
413 - # Deal with the case where a2 > 8 bytes remain to be
414 - # searched. a0 may not be aligned.
415 - .align 4
416 -$first_quad:
417 - andnot a0, 0x7, v0 #-e1 :
418 - insqh t2, a0, t1 # .. e0 : t1 = 0000ffffffffffff (a0<0:2> ff)
419 - xor t0, a1, t0 # e0 :
420 - or t0, t1, t0 # e1 : t0 = ====ffffffffffff
421 - cmpbge zero, t0, t1 #-e0 :
422 - bne t1, $found_it # .. e1 :
423 -
424 - # At least one byte left to process.
425 -
426 - ldq zero, 8(v0) # e0 : prefetch next quad
427 - subq t4, 1, a2 # .. e1 :
428 - addq v0, 8, v0 #-e0 :
429 -
430 - # Make a2 point to last quad to be accessed (the
431 - # last quad may or may not be partial).
432 -
433 - andnot a2, 0x7, a2 # .. e1 :
434 - cmpult v0, a2, t1 # e0 :
435 - beq t1, $final # .. e1 :
436 -
437 - # At least two quads remain to be accessed.
438 -
439 - subq a2, v0, t3 #-e0 : t3 <- nr quads to be processed
440 - and t3, 8, t3 # e1 : odd number of quads?
441 - bne t3, $odd_quad_count # e1 :
442 -
443 - # At least three quads remain to be accessed
444 -
445 - .align 4
446 -$unrolled_loop:
447 - ldq t0, 0(v0) # e0 : load quad
448 - xor a1, t0, t1 # .. e1 :
449 - ldq zero, 8(v0) # e0 : prefetch next quad
450 - cmpbge zero, t1, t1 # .. e1:
451 - bne t1, $found_it # e0 :
452 -
453 - addq v0, 8, v0 # e1 :
454 -$odd_quad_count:
455 - ldq t0, 0(v0) # e0 : load quad
456 - xor a1, t0, t1 # .. e1 :
457 - ldq zero, 8(v0) # e0 : prefetch next quad
458 - cmpbge zero, t1, t1 # .. e1 :
459 - addq v0, 8, t5 #-e0 :
460 - bne t1, $found_it # .. e1 :
461 -
462 - cmpult t5, a2, t5 # e0 :
463 - addq v0, 8, v0 # .. e1 :
464 - bne t5, $unrolled_loop #-e1 :
465 -
466 -$final: ldq t0, 0(v0) # e0 : load last quad
467 - subq t4, v0, a2 # .. e1 : a2 <- number of bytes left to do
468 - bne a2, $last_quad # e1 :
469 -
470 -$not_found:
471 - mov zero, v0 #-e0 :
472 - ret # .. e1 :
473 -
474 - END(__memchr)
475 -
476 -weak_alias (__memchr, memchr)
477 -#if !__BOUNDED_POINTERS__
478 -weak_alias (__memchr, __ubp_memchr)
479 -#endif
480 -libc_hidden_builtin_def (memchr)
481 diff --git a/sysdeps/alpha/memchr.c b/sysdeps/alpha/memchr.c
482 new file mode 100644
483 index 0000000..c52841b
484 --- /dev/null
485 +++ ports/sysdeps/alpha/memchr.c
486 @@ -0,0 +1,175 @@
487 +/* Copyright (C) 2010 Free Software Foundation, Inc.
488 + This file is part of the GNU C Library.
489 +
490 + The GNU C Library is free software; you can redistribute it and/or
491 + modify it under the terms of the GNU Lesser General Public
492 + License as published by the Free Software Foundation; either
493 + version 2.1 of the License, or (at your option) any later version.
494 +
495 + The GNU C Library is distributed in the hope that it will be useful,
496 + but WITHOUT ANY WARRANTY; without even the implied warranty of
497 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
498 + Lesser General Public License for more details.
499 +
500 + You should have received a copy of the GNU Lesser General Public
501 + License along with the GNU C Library; if not, write to the Free
502 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
503 + 02111-1307 USA. */
504 +
505 +#include <string.h>
506 +
507 +typedef unsigned long word;
508 +
509 +static inline word
510 +ldq_u(const void *s)
511 +{
512 + return *(const word *)((word)s & -8);
513 +}
514 +
515 +#define unlikely(X) __builtin_expect ((X), 0)
516 +#define prefetch(X) __builtin_prefetch ((void *)(X), 0)
517 +
518 +#define cmpbeq0(X) __builtin_alpha_cmpbge(0, (X))
519 +#define find(X, Y) cmpbeq0 ((X) ^ (Y))
520 +
521 +/* Search no more than N bytes of S for C. */
522 +
523 +void *
524 +__memchr (const void *s, int xc, size_t n)
525 +{
526 + const word *s_align;
527 + word t, current, found, mask, offset;
528 +
529 + if (unlikely (n == 0))
530 + return 0;
531 +
532 + current = ldq_u (s);
533 +
534 + /* Replicate low byte of XC into all bytes of C. */
535 + t = xc & 0xff; /* 0000000c */
536 + t = (t << 8) | t; /* 000000cc */
537 + t = (t << 16) | t; /* 0000cccc */
538 + const word c = (t << 32) | t; /* cccccccc */
539 +
540 + /* Align the source, and decrement the count by the number
541 + of bytes searched in the first word. */
542 + s_align = (const word *)(s & -8);
543 + n += (s & 7);
544 +
545 + /* Deal with misalignment in the first word for the comparison. */
546 + mask = (1ul << (s & 7)) - 1;
547 +
548 + /* If the entire string fits within one word, we may need masking
549 + at both the front and the back of the string. */
550 + if (unlikely (n <= 8))
551 + {
552 + mask |= -1ul << n;
553 + goto last_quad;
554 + }
555 +
556 + found = find (current, c) & ~mask;
557 + if (unlikely (found))
558 + goto found_it;
559 +
560 + s_align++;
561 + n -= 8;
562 +
563 + /* If the block is sufficiently large, align to cacheline and prefetch. */
564 + if (unlikely (n >= 256))
565 + {
566 + /* Prefetch 3 cache lines beyond the one we're working on. */
567 + prefetch (s_align + 8);
568 + prefetch (s_align + 16);
569 + prefetch (s_align + 24);
570 +
571 + while ((word)s_align & 63)
572 + {
573 + current = *s_align;
574 + found = find (current, c);
575 + if (found)
576 + goto found_it;
577 + s_align++;
578 + n -= 8;
579 + }
580 +
581 + /* Within each cacheline, advance the load for the next word
582 + before the test for the previous word is complete. This
583 + allows us to hide the 3 cycle L1 cache load latency. We
584 + only perform this advance load within a cacheline to prevent
585 + reading across page boundary. */
586 +#define CACHELINE_LOOP \
587 + do { \
588 + word i, next = s_align[0]; \
589 + for (i = 0; i < 7; ++i) \
590 + { \
591 + current = next; \
592 + next = s_align[1]; \
593 + found = find (current, c); \
594 + if (unlikely (found)) \
595 + goto found_it; \
596 + s_align++; \
597 + } \
598 + current = next; \
599 + found = find (current, c); \
600 + if (unlikely (found)) \
601 + goto found_it; \
602 + s_align++; \
603 + n -= 64; \
604 + } while (0)
605 +
606 + /* While there's still lots more data to potentially be read,
607 + continue issuing prefetches for the 4th cacheline out. */
608 + while (n >= 256)
609 + {
610 + prefetch (s_align + 24);
611 + CACHELINE_LOOP;
612 + }
613 +
614 + /* Up to 3 cache lines remaining. Continue issuing advanced
615 + loads, but stop prefetching. */
616 + while (n >= 64)
617 + CACHELINE_LOOP;
618 +
619 + /* We may have exhausted the buffer. */
620 + if (n == 0)
621 + return NULL;
622 + }
623 +
624 + /* Quadword aligned loop. */
625 + current = *s_align;
626 + while (n > 8)
627 + {
628 + found = find (current, c);
629 + if (unlikely (found))
630 + goto found_it;
631 + current = *++s_align;
632 + n -= 8;
633 + }
634 +
635 + /* The last word may need masking at the tail of the compare. */
636 + mask = -1ul << n;
637 + last_quad:
638 + found = find (current, c) & ~mask;
639 + if (found == 0)
640 + return NULL;
641 +
642 + found_it:
643 +#ifdef __alpha_cix__
644 + offset = __builtin_alpha_cttz (found);
645 +#else
646 + /* Extract LSB. */
647 + found &= -found;
648 +
649 + /* Binary search for the LSB. */
650 + offset = (found & 0x0f ? 0 : 4);
651 + offset += (found & 0x33 ? 0 : 2);
652 + offset += (found & 0x55 ? 0 : 1);
653 +#endif
654 +
655 + return (void *)((word)s_align + offset);
656 +}
657 +
658 +#ifdef weak_alias
659 +weak_alias (__memchr, BP_SYM (memchr))
660 +#endif
661 +libc_hidden_builtin_def (memchr)
662 --
663 1.7.3
664
665
666
667 1.1 src/patchsets/glibc/2.12.1/ports/6029_all_alpha-fix-memchr.patch
668
669 file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/glibc/2.12.1/ports/6029_all_alpha-fix-memchr.patch?rev=1.1&view=markup
670 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/glibc/2.12.1/ports/6029_all_alpha-fix-memchr.patch?rev=1.1&content-type=text/plain
671
672 Index: 6029_all_alpha-fix-memchr.patch
673 ===================================================================
674 From b54f998dc380ce327a7faf2c40e569fb2cf39bf0 Mon Sep 17 00:00:00 2001
675 From: Michael Cree <mcree@×××××××××.nz>
676 Date: Sun, 26 Sep 2010 21:15:51 +1300
677 Subject: [PATCH] alpha: Fix compile errors in memchr
678
679 Include missing header file and make some casts explicit.
680 ---
681 sysdeps/alpha/memchr.c | 7 ++++---
682 1 files changed, 4 insertions(+), 3 deletions(-)
683
684 diff --git a/sysdeps/alpha/memchr.c b/sysdeps/alpha/memchr.c
685 index c52841b..7e16f8a 100644
686 --- ports/sysdeps/alpha/memchr.c
687 +++ ports/sysdeps/alpha/memchr.c
688 @@ -17,6 +17,7 @@
689 02111-1307 USA. */
690
691 #include <string.h>
692 +#include <bp-sym.h>
693
694 typedef unsigned long word;
695
696 @@ -53,11 +54,11 @@ __memchr (const void *s, int xc, size_t n)
697
698 /* Align the source, and decrement the count by the number
699 of bytes searched in the first word. */
700 - s_align = (const word *)(s & -8);
701 - n += (s & 7);
702 + s_align = (const word *)((word)s & -8);
703 + n += ((word)s & 7);
704
705 /* Deal with misalignment in the first word for the comparison. */
706 - mask = (1ul << (s & 7)) - 1;
707 + mask = (1ul << ((word)s & 7)) - 1;
708
709 /* If the entire string fits within one word, we may need masking
710 at both the front and the back of the string. */
711 --
712 1.7.3