This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA: Add builtin bitcounting bitops for xstormy16


Hi Richard,

+ static const unsigned char __popcount_tab[] =

Why are you replicating this table? It's already present in libgcc2.c, emitted to its own object file.

Just me being stupid. I mistakenly thought that it was being kept local to the implementation of __popcountSI2.


See longlong.h. You can simplify these fairly well for fewer bits.

Thanks - I have taken your suggestions, tweaked them slightly, built and tested the new versions of these routines and so here is a revised patch.


May I apply this version please ?

Cheers
  Nick

gcc/ChangeLog
2005-09-07  Nick Clifton  <nickc@redhat.com>

	* config/stormy16/stormy16-lib2.c (__popcount_tab[]): Delete - use
	the one defined in libgcc2.c instead.
	(__clzhi2, __ctzhi2): Define using the __clz_tab[] array defined
	in libgcc2.c.

Index: gcc/config/stormy16/stormy16-lib2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/stormy16/stormy16-lib2.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 stormy16-lib2.c
*** gcc/config/stormy16/stormy16-lib2.c	2 Sep 2005 14:17:36 -0000	1.2
--- gcc/config/stormy16/stormy16-lib2.c	7 Sep 2005 11:19:30 -0000
*************** __lshrsi3 (USItype a, USItype b)
*** 141,161 ****
    return a;
  }

- static const unsigned char __popcount_tab[] =
- {
-   0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
-   1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
-   1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
-   2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
-   1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
-   2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
-   2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
-   3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
- };
-
  int
  __popcounthi2 (unsigned int x)
  {
    unsigned int ret;

    ret = __popcount_tab [x & 0xff];
--- 141,151 ----
    return a;
  }

  int
  __popcounthi2 (unsigned int x)
  {
+   /* Defined in libgcc2.c, exported in _popcountsi2.o.  */
+   extern const unsigned char __popcount_tab[];
    unsigned int ret;

    ret = __popcount_tab [x & 0xff];
*************** __parityhi2 (unsigned int x)
*** 173,191 ****
    return (0x6996 >> x) & 1;
  }

  int
! __ctzhi2 (unsigned int x)
  {
!   extern int __ctzsi2 (unsigned long);
!   unsigned long y = x;
!
!   return __ctzsi2 (y << 16) - 16;
  }

  int
! __clzhi2 (unsigned int x)
  {
!   extern int __clzsi2 (unsigned long);
!
!   return __clzsi2 (x) - 16;
  }
--- 163,191 ----
    return (0x6996 >> x) & 1;
  }

+ /* The __clz_tab array is defined in libgcc2.c and exported from _clzsi2.o.
+ It contains the bit position of the first set bit for the numbers 0 -
+ 255. It is done this way to avoid needing a seperate table for the
+ trailing zero computation. */
+ extern const unsigned char __clz_tab[];
+
int
! __clzhi2 (unsigned int x)
{
! if (x > 0xff)
! return 8 - __clz_tab[x >> 8];
! return 16 - __clz_tab[x];
}


int
! __ctzhi2 (unsigned int x)
{
! /* This is cunning. It converts X into a number with only the one bit set,
! the bit was the least significant bit in X. From this we can use the
! __clz_tab[] array to compute the number of trailing bits. */
! x &= - x;
!
! if (x > 0xff)
! return __clz_tab[x >> 8] + 7;
! return __clz_tab[x] - 1;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]