Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/arch/sparc64/string Sample code to implement ffs() ...



details:   https://anonhg.NetBSD.org/src/rev/8a07920ad508
branches:  trunk
changeset: 480006:8a07920ad508
user:      eeh <eeh%NetBSD.org@localhost>
date:      Thu Dec 30 15:30:26 1999 +0000

description:
Sample code to implement ffs() using the popc insn (if it's ever implemented).

diffstat:

 lib/libc/arch/sparc64/string/ffs.S |  26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diffs (43 lines):

diff -r ab57b921d35f -r 8a07920ad508 lib/libc/arch/sparc64/string/ffs.S
--- a/lib/libc/arch/sparc64/string/ffs.S        Thu Dec 30 09:52:03 1999 +0000
+++ b/lib/libc/arch/sparc64/string/ffs.S        Thu Dec 30 15:30:26 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs.S,v 1.2 1998/09/13 23:54:44 eeh Exp $      */
+/*     $NetBSD: ffs.S,v 1.3 1999/12/30 15:30:26 eeh Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -44,10 +44,32 @@
 #if 0
        .asciz "@(#)ffs.s       8.1 (Berkeley) 6/4/93"
 #else
-       RCSID("$NetBSD: ffs.S,v 1.2 1998/09/13 23:54:44 eeh Exp $")
+       RCSID("$NetBSD: ffs.S,v 1.3 1999/12/30 15:30:26 eeh Exp $")
 #endif
 #endif  /* LIBC_SCCS and not lint */
 
+#if 0
+       /*
+        * We have a popcount instruction -- use it.
+        * only uses %o0, %o1, %o2
+        *
+        * Here's the pseudo-code from the v9 spec:
+        *
+        * int ffs(unsigned zz) {
+        *      return popc( zz ^ ( ~ (-zz)));
+        * }
+        *
+        * XXXX sptifires and blackbirds don't implement popc,
+        * so we won't use this nice clean code 8^(.
+        */
+ENTRY(ffs)
+       neg     %o0, %o1                                ! %o1 = -zz
+       xnor    %o0, %o1, %o2                           ! %o2 = zz ^ ~ -zz
+       popc    %o2, %o1
+       movrz   %o0, %g0, %o1                           ! result of ffs(0) should be zero
+       retl
+        mov    %o1, %o0
+#endif
 /*
  * ffs returns the number of the rightmost bit set in its argument,
  * i.e., the lowest value such that (x & (ffs(x) - 1)) is nonzero.



Home | Main Index | Thread Index | Old Index