Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/arch/arm/string On ARMv5 reduce the value to the LS...



details:   https://anonhg.NetBSD.org/src/rev/4cecbd3cee8e
branches:  trunk
changeset: 580725:4cecbd3cee8e
user:      rearnsha <rearnsha%NetBSD.org@localhost>
date:      Fri May 06 09:50:25 2005 +0000

description:
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 7422f3b3fc53 -r 4cecbd3cee8e lib/libc/arch/arm/string/ffs.S
--- a/lib/libc/arch/arm/string/ffs.S    Fri May 06 09:40:40 2005 +0000
+++ b/lib/libc/arch/arm/string/ffs.S    Fri May 06 09:50:25 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.8 2005/05/06 09:50:25 rearnsha 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.8 2005/05/06 09:50:25 rearnsha 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