? test_hand.ilk ? test_hand.pdb ? vc90.pdb Index: hand.c =================================================================== RCS file: /usr/cvs/cm3/m3-libs/m3core/src/Csupport/Common/hand.c,v retrieving revision 1.95 diff -u -r1.95 hand.c --- hand.c 7 Mar 2010 02:37:04 -0000 1.95 +++ hand.c 7 Mar 2010 03:19:30 -0000 @@ -472,125 +472,10 @@ 0xf0000000, 0xe0000000, 0xc0000000, 0x80000000, 0x0 }; -#define LOW_BITS_ADJUST 0 - -#if ULONG_MAX == 0xffffffff - -#if 1 /* UINT == 0xffffffff */ - -/* If possible, combine tables. - If unsigned long and unsigned int are both 32 bit integers, then - LoBits and _lowbits are the same except that _lowbits has 0 inserted in the first entry, - HiBits and _highbits are the same except _highbits has 0 added at the end. - That is, LoBits can be replaced with _lowbits if you add one to the index. - HiBits can be replaced by _highbits directly. - - Now, a) it does not matter if unsigned int is exactly 32 bits, it need only be - at least 32 bits b) it can't be larger than unsigned long anyway. So drop the condition - and always combine these tables, for 32 bit unsigned long. -*/ -#undef LOW_BITS_ADJUST -#define LOW_BITS_ADJUST 1 -#define LoBits _lowbits -#define HiBits _highbits - -#else - -static const ulong LoBits[] = { -0x00000001,0x00000003,0x00000007,0x0000000f, -0x0000001f,0x0000003f,0x0000007f,0x000000ff, -0x000001ff,0x000003ff,0x000007ff,0x00000fff, -0x00001fff,0x00003fff,0x00007fff,0x0000ffff, -0x0001ffff,0x0003ffff,0x0007ffff,0x000fffff, -0x001fffff,0x003fffff,0x007fffff,0x00ffffff, -0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff, -0x1fffffff,0x3fffffff,0x7fffffff,0xffffffff -}; - -static const ulong HiBits[] = { -0xffffffff,0xfffffffe,0xfffffffc,0xfffffff8, -0xfffffff0,0xffffffe0,0xffffffc0,0xffffff80, -0xffffff00,0xfffffe00,0xfffffc00,0xfffff800, -0xfffff000,0xffffe000,0xffffc000,0xffff8000, -0xffff0000,0xfffe0000,0xfffc0000,0xfff80000, -0xfff00000,0xffe00000,0xffc00000,0xff800000, -0xff000000,0xfe000000,0xfc000000,0xf8000000, -0xf0000000,0xe0000000,0xc0000000,0x80000000 -}; - -#endif - -#elif ULONG_MAX == 0xffffffffffffffff - -static const size_t LoBits[] = { -0x0000000000000001,0x0000000000000003,0x0000000000000007,0x000000000000000f, -0x000000000000001f,0x000000000000003f,0x000000000000007f,0x00000000000000ff, -0x00000000000001ff,0x00000000000003ff,0x00000000000007ff,0x0000000000000fff, -0x0000000000001fff,0x0000000000003fff,0x0000000000007fff,0x000000000000ffff, -0x000000000001ffff,0x000000000003ffff,0x000000000007ffff,0x00000000000fffff, -0x00000000001fffff,0x00000000003fffff,0x00000000007fffff,0x0000000000ffffff, -0x0000000001ffffff,0x0000000003ffffff,0x0000000007ffffff,0x000000000fffffff, -0x000000001fffffff,0x000000003fffffff,0x000000007fffffff,0x00000000ffffffff, -0x00000001ffffffff,0x00000003ffffffff,0x00000007ffffffff,0x0000000fffffffff, -0x0000001fffffffff,0x0000003fffffffff,0x0000007fffffffff,0x000000ffffffffff, -0x000001ffffffffff,0x000003ffffffffff,0x000007ffffffffff,0x00000fffffffffff, -0x00001fffffffffff,0x00003fffffffffff,0x00007fffffffffff,0x0000ffffffffffff, -0x0001ffffffffffff,0x0003ffffffffffff,0x0007ffffffffffff,0x000fffffffffffff, -0x001fffffffffffff,0x003fffffffffffff,0x007fffffffffffff,0x00ffffffffffffff, -0x01ffffffffffffff,0x03ffffffffffffff,0x07ffffffffffffff,0x0fffffffffffffff, -0x1fffffffffffffff,0x3fffffffffffffff,0x7fffffffffffffff,0xffffffffffffffff -}; - -static const size_t HiBits[] = { -0xffffffffffffffff,0xfffffffffffffffe,0xfffffffffffffffc,0xfffffffffffffff8, -0xfffffffffffffff0,0xffffffffffffffe0,0xffffffffffffffc0,0xffffffffffffff80, -0xffffffffffffff00,0xfffffffffffffe00,0xfffffffffffffc00,0xfffffffffffff800, -0xfffffffffffff000,0xffffffffffffe000,0xffffffffffffc000,0xffffffffffff8000, -0xffffffffffff0000,0xfffffffffffe0000,0xfffffffffffc0000,0xfffffffffff80000, -0xfffffffffff00000,0xffffffffffe00000,0xffffffffffc00000,0xffffffffff800000, -0xffffffffff000000,0xfffffffffe000000,0xfffffffffc000000,0xfffffffff8000000, -0xfffffffff0000000,0xffffffffe0000000,0xffffffffc0000000,0xffffffff80000000, -0xffffffff00000000,0xfffffffe00000000,0xfffffffc00000000,0xfffffff800000000, -0xfffffff000000000,0xffffffe000000000,0xffffffc000000000,0xffffff8000000000, -0xffffff0000000000,0xfffffe0000000000,0xfffffc0000000000,0xfffff80000000000, -0xfffff00000000000,0xffffe00000000000,0xffffc00000000000,0xffff800000000000, -0xffff000000000000,0xfffe000000000000,0xfffc000000000000,0xfff8000000000000, -0xfff0000000000000,0xffe0000000000000,0xffc0000000000000,0xff80000000000000, -0xff00000000000000,0xfe00000000000000,0xfc00000000000000,0xf800000000000000, -0xf000000000000000,0xe000000000000000,0xc000000000000000,0x8000000000000000 -}; - -#else -#error unknown size of ulong -#endif - -void __stdcall set_range - ANSI(( size_t b, size_t a, size_t* s)) - KR((b, a, s) size_t b; size_t a; size_t* s;) -{ - if (b < a) { - /* no bits to set */ - } else { - size_t a_word = a / SET_GRAIN; - size_t a_bit = a % SET_GRAIN; - size_t b_word = b / SET_GRAIN; - size_t b_bit = b % SET_GRAIN; - size_t i; - - if (a_word == b_word) { - s [a_word] |= (HiBits [a_bit] & LoBits [b_bit + LOW_BITS_ADJUST]); - } else { - s [a_word] |= HiBits [a_bit]; - for (i = a_word+1; i < b_word; i++) s[i] = ~0UL; - s [b_word] |= LoBits [b_bit + LOW_BITS_ADJUST]; - } - } -} - #define HIGH_BITS(a) ((~(size_t)0) << (a)) #define LOW_BITS(a) ((~(size_t)0) >> (SET_GRAIN - (a) - 1)) -static void __stdcall set_range_new +static void __stdcall set_range ANSI(( size_t b, size_t a, size_t* s)) KR((b, a, s) size_t b; size_t a; size_t* s;) { Index: test_hand.c =================================================================== RCS file: /usr/cvs/cm3/m3-libs/m3core/src/Csupport/Common/test_hand.c,v retrieving revision 1.12 diff -u -r1.12 test_hand.c --- test_hand.c 7 Mar 2010 03:06:29 -0000 1.12 +++ test_hand.c 7 Mar 2010 03:19:30 -0000 @@ -26,114 +26,6 @@ #include #include -static void BuildTables () -{ - unsigned i; - size_t LoBits[SET_GRAIN] = { 0 }; /* LoBits32[i] = SET { 0..i } */ - size_t HiBits[SET_GRAIN] = { 0 }; /* HiBits32[i] = SET { i..31 } */ - uint32 LoBits32[32] = { 0 }; /* LoBits32[i] = SET { 0..i } */ - uint32 HiBits32[32] = { 0 }; /* HiBits32[i] = SET { i..31 } */ - uint64 LoBits64[64] = { 0 }; /* LoBits64[i] = SET { 0..i } */ - uint64 HiBits64[64] = { 0 }; /* HiBits64[i] = SET { i..63 } */ - - { - uint32 j; - - /* LoBits [i] = SET { 0..i } */ - j = 0; /* == SET { } */ - for (i = 0; i != 32; i++) { - j = (j << 1) + 1; - LoBits32[i] = j; - } - - /* HiBits [i] = SET { i..GRAIN-1 } */ - j = ~ (uint32) 0; /* == SET { 0..GRAIN-1 } */ - for (i = 0; i != 32; i++) { - HiBits32[i] = j; - j = (j << 1); - } - } - - { - uint64 j; - - /* LoBits [i] = SET { 0..i } */ - j = 0; /* == SET { } */ - for (i = 0; i != 64; i++) { - j = (j << 1) + 1; - LoBits64[i] = j; - } - - /* HiBits [i] = SET { i..GRAIN-1 } */ - j = ~ (uint64) 0; /* == SET { 0..GRAIN-1 } */ - for (i = 0; i != 64; i++) { - HiBits64[i] = j; - j = (j << 1); - } - } - - { - size_t j; - - /* LoBits [i] = SET { 0..i } */ - j = 0; /* == SET { } */ - for (i = 0; i != SET_GRAIN; i++) { - j = (j << 1) + 1; - LoBits[i] = j; - } - - /* HiBits [i] = SET { i..GRAIN-1 } */ - j = ~ (size_t) 0; /* == SET { 0..GRAIN-1 } */ - for (i = 0; i != SET_GRAIN; i++) { - HiBits[i] = j; - j = (j << 1); - } - - for (i = 0; i != SET_GRAIN; i++) { -#ifdef _WIN32 - assert(LoBits[i] == LoBits32[i]); - assert(HiBits[i] == HiBits32[i]); - assert(LoBits[i] == _lowbits[i + 1]); - assert(HiBits[i] == _highbits[i]); -#else - assert((LoBits[i] == LoBits32[i]) || (LoBits[i] == LoBits64[i])); - assert((HiBits[i] == HiBits32[i]) || (HiBits[i] == HiBits64[i])); -#endif - } - } - - printf("#include \n\n"); - - printf("typedef unsigned long ulong;\n\n"); - - printf("#if ULONG_MAX == 0xffffffff\n\n"); - - printf("static const size_t LoBits[] = {\n"); - - for (i = 0; i != 32; i++) - printf("0x%08lx%s%s", (ulong) LoBits32[i], &","[i == 31], &"\n"[!!((i + 1) % 4)]); - - printf("};\n\nstatic const size_t HiBits[] = {\n"); - - for (i = 0; i != 32; i++) - printf("0x%08lx%s%s", (ulong) HiBits32[i], &","[i == 31], &"\n"[!!((i + 1) % 4)]); - - printf("};\n\n"); - printf("#elif ULONG_MAX == 0xffffffffffffffff\n\n"); - - printf("static const size_t LoBits[] = {\n"); - - for (i = 0; i != 64; i++) - printf("0x%08lx%08lx%s%s", (ulong) (LoBits64[i] >> 32), (ulong) LoBits64[i], &","[i == 63], &"\n"[!!((i + 1) % 4)]); - - printf("};\n\nstatic const size_t HiBits[] = {\n"); - - for (i = 0; i != 64; i++) - printf("0x%08lx%08lx%s%s", (ulong) (HiBits64[i] >> 32), (ulong) HiBits64[i], &","[i == 63], &"\n"[!!((i + 1) % 4)]); - - printf("\n#else\n#error unknown size of ulong\n#endif\n\n"); -} - static int64 values[] = { INT64_MIN, INT64_MIN + 1, @@ -289,12 +181,6 @@ { unsigned i; - for (i = 0; i < SET_GRAIN; ++i) - { - assert(HIGH_BITS(i) == HiBits[i]); - assert(LOW_BITS(i) == LoBits[i + LOW_BITS_ADJUST]); - } - if (sizeof(int) == sizeof(size_t)) { for (i = 0; i <= 32; ++i) @@ -317,74 +203,6 @@ | ((a & 0x01) ? 0x80 : 0); } -static void PrintSet(void* a, size_t b) -{ - size_t c; - for (c = 0; c < b; ++c) - printf("%02x ", reverse(((unsigned char*)a)[c])); -} - -static void TestSetRangex(unsigned a, unsigned b) -{ - size_t bits[4]; - size_t bits_new[4]; - - memset(bits, 0, sizeof(bits)); - memset(bits_new, 0, sizeof(bits_new)); - set_range(a, b, bits); - set_range_new(a, b, bits_new); - assert(memcmp(bits, bits_new, sizeof(bits)) == 0); - /* - printf("set_range(%u, %u):", a, b); - PrintSet(bits, sizeof(bits)); - printf("\n"); - */ -} - -static void TestSetRange(void) -{ - size_t bits[100]; - unsigned a, b; - double t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0; - - for (a = 0; a < 4 * SET_GRAIN; ++a) - for (b = 0; b < 4 * SET_GRAIN; ++b) - TestSetRangex(a, b); - -#ifdef _MSC_VER - t1 = (double)__rdtsc(); /* read time stamp counter */ -#else - t1 = (double)time(NULL); -#endif - - for (a = 0; a < 100 * SET_GRAIN; ++a) - for (b = 0; b < 100 * SET_GRAIN; ++b) - set_range(a, b, bits); - -#ifdef _MSC_VER - t2 = (double)__rdtsc(); -#else - t2 = (double)time(NULL); -#endif - - for (a = 0; a < 100 * SET_GRAIN; ++a) - for (b = 0; b < 100 * SET_GRAIN; ++b) - set_range_new(a, b, bits); - -#ifdef _MSC_VER - t3 = (double)__rdtsc(); -#else - t3 = (double)time(NULL); -#endif - - t4 = (t2 - t1); - t5 = (t3 - t2); - - printf("old:%f\n", t4); - printf("new:%f\n", t5); - printf("diff:%f\n", (t5 - t4) / t4); -} - static void TestInsert() { uint32 a32 = { 0 }; @@ -502,15 +320,12 @@ int main() { - /*BuildTables();*/ /*TestDiv();*/ /*TestMod();*/ /*printf("errors_div:%d errors_mod:%d\n", errors_div, errors_mod);*/ TestHighLowBits(); - TestSetRange(); - /*TestInsert();*/ /*TestExtract();*/