Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-3]: src/lib/libc/arch/arm/string Pull up revision 1.8 (requested ...



details:   https://anonhg.NetBSD.org/src/rev/2810a244bce2
branches:  netbsd-3
changeset: 575712:2810a244bce2
user:      tron <tron%NetBSD.org@localhost>
date:      Sat May 07 11:49:39 2005 +0000

description:
Pull up revision 1.8 (requested by rearnsha in ticket #255):
On ARMv5 reduce the value to the LSB before using CLZ.  Otherwise we'll
calculate the position of the MSB not the LSB.

diffstat:

 lib/libc/arch/arm/string/ffs.S |  11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diffs (39 lines):

diff -r 80c68bf580b3 -r 2810a244bce2 lib/libc/arch/arm/string/ffs.S
--- a/lib/libc/arch/arm/string/ffs.S    Sat May 07 11:47:22 2005 +0000
+++ b/lib/libc/arch/arm/string/ffs.S    Sat May 07 11:49:39 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs.S,v 1.7 2004/08/21 13:08:29 rearnsha Exp $ */
+/*     $NetBSD: ffs.S,v 1.7.2.1 2005/05/07 11:49:39 tron Exp $ */
 /*
  * Copyright (c) 2001 Christopher Gilbert
  * All rights reserved.
@@ -30,7 +30,7 @@
 
 #include <machine/asm.h>
 
-RCSID("$NetBSD: ffs.S,v 1.7 2004/08/21 13:08:29 rearnsha Exp $")
+RCSID("$NetBSD: ffs.S,v 1.7.2.1 2005/05/07 11:49:39 tron Exp $")
 
 /*
  * ffs - find first set bit, this algorithm isolates the first set
@@ -38,8 +38,8 @@
  * 6 bits as an index into the table.  This algorithm should be a win
  * over the checking each bit in turn as per the C compiled version.
  *
- * under ARMv5 there's an instruction called CLZ (count leading Zero's) that
- * could be used
+ * On ARMv5 we use CLZ (count leading Zero's) and then subtract the result
+ * from 32.
  *
  * This is the ffs algorithm devised by d.seal and posted to comp.sys.arm on
  * 16 Feb 1994.
@@ -47,6 +47,9 @@
 
 ENTRY(ffs)
 #ifdef _ARM_ARCH_5
+       /* (X & -X) gives LSB or zero.  */
+       rsb     r1, r0, #0
+       and     r0, r0, r1
        clz     r0, r0
        rsb     r0, r0, #32
        RET



Home | Main Index | Thread Index | Old Index