tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] TCC bug wilt long long


From: Benoit DUPONT-DE-DINECHIN
Subject: [Tinycc-devel] TCC bug wilt long long
Date: Tue, 2 May 2006 23:10:28 +0200

Reproduce using the C file supplied:

  gcc BugTCC.c  && ./a.out > OK
  tcc BugTCC.c  && ./a.out > KO
  diff OK KO

Benoit
#include <stdio.h>
#include<stdint.h>

static inline int
HackerU32_popc(uint32_t word)
{
  uint32_t v = word;
  uint32_t w = v - ((v >> 1) & 0x55555555);
  uint32_t x = (w & 0x33333333) + ((w >> 2) & 0x33333333);
  uint32_t y = (x + (x >> 4)) & 0x0F0F0F0F;
  uint16_t z = (y * 0x01010101) >> 24;
  return z;
}

static inline int
HackerU64_popc(uint64_t word)
{
  uint32_t word0 = word, word1 = word >> 32;
  return HackerU32_popc(word0) + HackerU32_popc(word1);
}

//@XCC_.h
static inline int
HackerU64_popcBasic(uint64_t word)
{
  int bitCount = 0;
  while (word) {
    if (word & 1) ++bitCount;
    word >>= 1;
  }
  return bitCount;
}

//@XCC_.h
static inline int
HackerU64_popcSparse(uint64_t word)
{
  int bitCount = 0;
  while (word) {
    word &= word - 1;
    ++bitCount;
  }
  return bitCount;
}


int main()
{
  int64_t word = 0xdeadbeef12345678LL;
  while (word != 0) {
    int popc = HackerU64_popc(word);
    int popcBasic = HackerU64_popcBasic(word);
    int popcSparse = HackerU64_popcSparse(word);
    printf("popc(%llx)=%d\n", word, popc);
    if (popc != popcBasic) printf("Errror:\tpopc=%d\tpopcBasic=%d\n", popc, 
popcBasic);
    if (popc != popcSparse) printf("Errror:\tpopc=%d\tpopcSparse=%d\n", popc, 
popcSparse);
    word <<= 1;
  }
  return 0;
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]