View | Details | Return to bug 36041 | Differences between
and this patch

Collapse All | Expand All

(-)libgcc/libgcc2.c.jj (+41 lines)
Lines 819-835 const UQItype __popcount_tab[256] = Link Here
819
};
819
};
820
#endif
820
#endif
821
821
822
#if defined(L_popcountsi2) || defined(L_popcountdi2)
823
#define POPCOUNTCST2(x) (((UWtype) x << BITS_PER_UNIT) | x)
824
#define POPCOUNTCST4(x) (((UWtype) x << (2 * BITS_PER_UNIT)) | x)
825
#define POPCOUNTCST8(x) (((UWtype) x << (4 * BITS_PER_UNIT)) | x)
826
#if W_TYPE_SIZE == BITS_PER_UNIT
827
#define POPCOUNTCST(x) x
828
#elif W_TYPE_SIZE == 2 * BITS_PER_UNIT
829
#define POPCOUNTCST(x) POPCOUNTCST2 (x)
830
#elif W_TYPE_SIZE == 4 * BITS_PER_UNIT
831
#define POPCOUNTCST(x) POPCOUNTCST4 (POPCOUNTCST2 (x))
832
#elif W_TYPE_SIZE == 8 * BITS_PER_UNIT
833
#define POPCOUNTCST(x) POPCOUNTCST8 (POPCOUNTCST4 (POPCOUNTCST2 (x)))
834
#endif
835
#endif
836
822
#ifdef L_popcountsi2
837
#ifdef L_popcountsi2
823
#undef int
838
#undef int
824
int
839
int
825
__popcountSI2 (UWtype x)
840
__popcountSI2 (UWtype x)
826
{
841
{
842
  /* Force table lookup on targets like AVR and RL78 which only
843
     pretend they have LIBGCC2_UNITS_PER_WORD 4, but actually
844
     have 1, and other small word targets.  */
845
#if __SIZEOF_INT__ > 2 && defined (POPCOUNTCST) && BITS_PER_UNIT == 8
846
  x = x - ((x >> 1) & POPCOUNTCST (0x55));
847
  x = (x & POPCOUNTCST (0x33)) + ((x >> 2) & POPCOUNTCST (0x33));
848
  x = (x + (x >> 4)) & POPCOUNTCST (0x0F);
849
  return (x * POPCOUNTCST (0x01)) >> (W_TYPE_SIZE - BITS_PER_UNIT);
850
#else
827
  int i, ret = 0;
851
  int i, ret = 0;
828
852
829
  for (i = 0; i < W_TYPE_SIZE; i += 8)
853
  for (i = 0; i < W_TYPE_SIZE; i += 8)
830
    ret += __popcount_tab[(x >> i) & 0xff];
854
    ret += __popcount_tab[(x >> i) & 0xff];
831
855
832
  return ret;
856
  return ret;
857
#endif
833
}
858
}
834
#endif
859
#endif
835
860
Lines 838-849 __popcountSI2 (UWtype x) Link Here
838
int
863
int
839
__popcountDI2 (UDWtype x)
864
__popcountDI2 (UDWtype x)
840
{
865
{
866
  /* Force table lookup on targets like AVR and RL78 which only
867
     pretend they have LIBGCC2_UNITS_PER_WORD 4, but actually
868
     have 1, and other small word targets.  */
869
#if __SIZEOF_INT__ > 2 && defined (POPCOUNTCST) && BITS_PER_UNIT == 8
870
  const DWunion uu = {.ll = x};
871
  UWtype x1 = uu.s.low, x2 = uu.s.high;
872
  x1 = x1 - ((x1 >> 1) & POPCOUNTCST (0x55));
873
  x2 = x2 - ((x2 >> 1) & POPCOUNTCST (0x55));
874
  x1 = (x1 & POPCOUNTCST (0x33)) + ((x1 >> 2) & POPCOUNTCST (0x33));
875
  x2 = (x2 & POPCOUNTCST (0x33)) + ((x2 >> 2) & POPCOUNTCST (0x33));
876
  x1 = (x1 + (x1 >> 4)) & POPCOUNTCST (0x0F);
877
  x2 = (x2 + (x2 >> 4)) & POPCOUNTCST (0x0F);
878
  x1 += x2;
879
  return (x1 * POPCOUNTCST (0x01)) >> (W_TYPE_SIZE - BITS_PER_UNIT);
880
#else
841
  int i, ret = 0;
881
  int i, ret = 0;
842
882
843
  for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
883
  for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
844
    ret += __popcount_tab[(x >> i) & 0xff];
884
    ret += __popcount_tab[(x >> i) & 0xff];
845
885
846
  return ret;
886
  return ret;
887
#endif
847
}
888
}
848
#endif
889
#endif
849
890

Return to bug 36041