From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <72df5b2f8511578a5fbec740d3e6b69b.axp-list@archive.invalid> X-Archive-Original-Message-ID: Date: Sat, 20 Apr 1996 02:19:26 -0500 (CDT) From: Richard Henderson Subject: axp in-line assembly improvements Here are a couple of things that I noticed going through the header files the other day. There are a few more that seem to tell gcc that it needs more registers than it should, but my fixes cause gcc to bitch. I think these are bugs that I shall eventually look into, however.... r~ ----- --- bitops.h.asm Fri Apr 19 15:20:51 1996 +++ bitops.h Fri Apr 19 17:20:42 1996 @@ -82,36 +82,38 @@ extern __inline__ unsigned long test_bit(int nr, const void * addr) { - return 1UL & (((int *) addr)[nr >> 5] >> (nr & 31)); + return 1UL & (((const int *) addr)[nr >> 5] >> (nr & 31)); } /* * ffz = Find First Zero in word. Undefined if no zero exists, * so code should check against ~0UL first.. * - * This uses the cmpbge insn to check which byte contains the zero. - * I don't know if that's actually a good idea, but it's fun and the - * resulting LBS tests should be natural on the alpha.. Besides, I'm - * just teaching myself the asm of the alpha anyway. + * Do a binary search on the bits. Due to the nature of large + * constants on the alpha, it is worthwhile to split the search. */ +extern inline unsigned long ffz_b(unsigned long x) +{ + unsigned long sum = 0; + + x = ~x & -~x; /* set first 0 bit, clear others */ + if (x & 0xF0) sum += 4; + if (x & 0xCC) sum += 2; + if (x & 0xAA) sum += 1; + + return sum; +} + extern inline unsigned long ffz(unsigned long word) { - unsigned long result = 0; - unsigned long tmp; + unsigned long bits, qofs, bofs; + + __asm__("cmpbge %1,%2,%0" : "=r"(bits) : "r"(word), "r"(~0UL)); + qofs = ffz_b(bits); + __asm__("extbl %1,%2,%0" : "=r"(bits) : "r"(word), "r"(qofs)); + bofs = ffz_b(bits); - __asm__("cmpbge %1,%0,%0" - :"=r" (tmp) - :"r" (word), "0" (~0UL)); - while (tmp & 1) { - word >>= 8; - tmp >>= 1; - result += 8; - } - while (word & 1) { - result++; - word >>= 1; - } - return result; + return qofs*8 + bofs; } /* --- system.h.asm Fri Apr 19 17:12:22 1996 +++ system.h Fri Apr 19 17:25:23 1996 @@ -118,33 +118,29 @@ extern __inline__ unsigned long xchg_u32(volatile int * m, unsigned long val) { - unsigned long dummy, dummy2; - + unsigned long dummy; __asm__ __volatile__( "\n1:\t" - "ldl_l %0,0(%1)\n\t" - "bis %2,%2,%3\n\t" - "stl_c %3,0(%1)\n\t" - "beq %3,1b\n" - : "=r" (val), "=r" (m), "=r" (dummy), "=r" (dummy2) - : "1" (m), "2" (val) - : "memory"); + "ldl_l %0,%2\n\t" + "bis %3,%3,%1\n\t" + "stl_c %1,%2\n\t" + "beq %1,1b\n" + : "=&r" (val), "=&r" (dummy), "=m" (*m) + : "r" (val), "m" (*m)); return val; } extern __inline__ unsigned long xchg_u64(volatile long * m, unsigned long val) { - unsigned long dummy, dummy2; - + unsigned long dummy; __asm__ __volatile__( "\n1:\t" - "ldq_l %0,0(%1)\n\t" - "bis %2,%2,%3\n\t" - "stq_c %3,0(%1)\n\t" - "beq %3,1b\n" - : "=r" (val), "=r" (m), "=r" (dummy), "=r" (dummy2) - : "1" (m), "2" (val) - : "memory"); + "ldq_l %0,%2\n\t" + "bis %3,%3,%1\n\t" + "stq_c %1,%2\n\t" + "beq %1,1b\n" + : "=&r" (val), "=&r" (dummy), "=m" (*m) + : "r" (val), "m" (*m)); return val; }