in reply to Re^3: 64-bit *nix/gcc expertise required
in thread 64-bit *nix/gcc expertise required (THIS IS NOT OFF TOPIC!)

I don't think that is not going to work, p in main, and the arg to check_new() must be pointers. That's what makes this a problem.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^4: 64-bit *nix/gcc expertise required

Replies are listed 'Best First'.
Re^5: 64-bit *nix/gcc expertise required
by Tux (Canon) on Dec 24, 2010 at 16:19 UTC

    I can do it with a pointer, but in that case, the pointer should be a pointer to a char, and not to an unsigned int.

    #include <stdio.h> #define ALIGN_BITS (sizeof (void *) >> 1LL) #define BIT_BITS 3LL #define BYTE_BITS 14LL #define SLOT_BITS (sizeof (void *) * 8) - (ALIGN_BITS + BIT_BITS + + BYTE_BITS) #define BYTES_PER_SLOT 1LL << BYTE_BITS #define TRACKING_SLOTS 8192 typedef unsigned long long ull_t; typedef unsigned char *ull_p; int check_new (ull_p p) { ull_t slot = ((ull_t)p >> (BYTE_BITS + BIT_BITS + ALIGN_BITS)); ull_t byte = ((ull_t)p >> (ALIGN_BITS + BIT_BITS)) & 0x00003fffLL; ull_t bit = ((ull_t)p >> ALIGN_BITS) & 0x00000007LL; ull_t nop = (ull_t)p & 0x3LL; printf ("address: %012p slot: %012p byte: %4llx bit: %4llx nop: %l +lx\n", p, (ull_p)slot, byte, bit, nop); return (1); } /* check_new */ int main (int argc, char *argv[]) { ull_p p; for (p = (ull_p)123456ULL; p < (ull_p)(1ULL << 34); p += (1ULL << +29)) check_new (p); } /* main */

    Will yield

    address: 000000000001e240 slot: 0000000000000000 byte: 3c4 bit: 4 +nop: 0 address: 000000002001e240 slot: 0000000000000100 byte: 3c4 bit: 4 +nop: 0 address: 000000004001e240 slot: 0000000000000200 byte: 3c4 bit: 4 +nop: 0 address: 000000006001e240 slot: 0000000000000300 byte: 3c4 bit: 4 +nop: 0 address: 000000008001e240 slot: 0000000000000400 byte: 3c4 bit: 4 +nop: 0 address: 00000000a001e240 slot: 0000000000000500 byte: 3c4 bit: 4 +nop: 0 address: 00000000c001e240 slot: 0000000000000600 byte: 3c4 bit: 4 +nop: 0 address: 00000000e001e240 slot: 0000000000000700 byte: 3c4 bit: 4 +nop: 0 address: 000000010001e240 slot: 0000000000000800 byte: 3c4 bit: 4 +nop: 0 address: 000000012001e240 slot: 0000000000000900 byte: 3c4 bit: 4 +nop: 0 address: 000000014001e240 slot: 0000000000000a00 byte: 3c4 bit: 4 +nop: 0 address: 000000016001e240 slot: 0000000000000b00 byte: 3c4 bit: 4 +nop: 0 address: 000000018001e240 slot: 0000000000000c00 byte: 3c4 bit: 4 +nop: 0 address: 00000001a001e240 slot: 0000000000000d00 byte: 3c4 bit: 4 +nop: 0 address: 00000001c001e240 slot: 0000000000000e00 byte: 3c4 bit: 4 +nop: 0 address: 00000001e001e240 slot: 0000000000000f00 byte: 3c4 bit: 4 +nop: 0 address: 000000020001e240 slot: 0000000000001000 byte: 3c4 bit: 4 +nop: 0 address: 000000022001e240 slot: 0000000000001100 byte: 3c4 bit: 4 +nop: 0 address: 000000024001e240 slot: 0000000000001200 byte: 3c4 bit: 4 +nop: 0 address: 000000026001e240 slot: 0000000000001300 byte: 3c4 bit: 4 +nop: 0 address: 000000028001e240 slot: 0000000000001400 byte: 3c4 bit: 4 +nop: 0 address: 00000002a001e240 slot: 0000000000001500 byte: 3c4 bit: 4 +nop: 0 address: 00000002c001e240 slot: 0000000000001600 byte: 3c4 bit: 4 +nop: 0 address: 00000002e001e240 slot: 0000000000001700 byte: 3c4 bit: 4 +nop: 0 address: 000000030001e240 slot: 0000000000001800 byte: 3c4 bit: 4 +nop: 0 address: 000000032001e240 slot: 0000000000001900 byte: 3c4 bit: 4 +nop: 0 address: 000000034001e240 slot: 0000000000001a00 byte: 3c4 bit: 4 +nop: 0 address: 000000036001e240 slot: 0000000000001b00 byte: 3c4 bit: 4 +nop: 0 address: 000000038001e240 slot: 0000000000001c00 byte: 3c4 bit: 4 +nop: 0 address: 00000003a001e240 slot: 0000000000001d00 byte: 3c4 bit: 4 +nop: 0 address: 00000003c001e240 slot: 0000000000001e00 byte: 3c4 bit: 4 +nop: 0 address: 00000003e001e240 slot: 0000000000001f00 byte: 3c4 bit: 4 +nop: 0

    And for short *:

    address: 000000000001e240 slot: 0000000000000000 byte: 3c4 bit: 4 +nop: 0 address: 000000004001e240 slot: 0000000000000200 byte: 3c4 bit: 4 +nop: 0 address: 000000008001e240 slot: 0000000000000400 byte: 3c4 bit: 4 +nop: 0 address: 00000000c001e240 slot: 0000000000000600 byte: 3c4 bit: 4 +nop: 0 address: 000000010001e240 slot: 0000000000000800 byte: 3c4 bit: 4 +nop: 0 address: 000000014001e240 slot: 0000000000000a00 byte: 3c4 bit: 4 +nop: 0 address: 000000018001e240 slot: 0000000000000c00 byte: 3c4 bit: 4 +nop: 0 address: 00000001c001e240 slot: 0000000000000e00 byte: 3c4 bit: 4 +nop: 0 address: 000000020001e240 slot: 0000000000001000 byte: 3c4 bit: 4 +nop: 0 address: 000000024001e240 slot: 0000000000001200 byte: 3c4 bit: 4 +nop: 0 address: 000000028001e240 slot: 0000000000001400 byte: 3c4 bit: 4 +nop: 0 address: 00000002c001e240 slot: 0000000000001600 byte: 3c4 bit: 4 +nop: 0 address: 000000030001e240 slot: 0000000000001800 byte: 3c4 bit: 4 +nop: 0 address: 000000034001e240 slot: 0000000000001a00 byte: 3c4 bit: 4 +nop: 0 address: 000000038001e240 slot: 0000000000001c00 byte: 3c4 bit: 4 +nop: 0

    And for int *:

    address: 000000000001e240 slot: 0000000000000000 byte: 3c4 bit: 4 +nop: 0 address: 000000008001e240 slot: 0000000000000400 byte: 3c4 bit: 4 +nop: 0 address: 000000010001e240 slot: 0000000000000800 byte: 3c4 bit: 4 +nop: 0 address: 000000018001e240 slot: 0000000000000c00 byte: 3c4 bit: 4 +nop: 0 address: 000000020001e240 slot: 0000000000001000 byte: 3c4 bit: 4 +nop: 0 address: 000000028001e240 slot: 0000000000001400 byte: 3c4 bit: 4 +nop: 0 address: 000000030001e240 slot: 0000000000001800 byte: 3c4 bit: 4 +nop: 0 address: 000000038001e240 slot: 0000000000001c00 byte: 3c4 bit: 4 +nop: 0

    And for long long *:

    address: 000000000001e240 slot: 0000000000000000 byte: 3c4 bit: 4 +nop: 0 address: 000000010001e240 slot: 0000000000000800 byte: 3c4 bit: 4 +nop: 0 address: 000000020001e240 slot: 0000000000001000 byte: 3c4 bit: 4 +nop: 0 address: 000000030001e240 slot: 0000000000001800 byte: 3c4 bit: 4 +nop: 0

    Enjoy, Have FUN! H.Merijn

      That looks a lot closer, but what happens if compile that for 32-bit? (The for loop will never terminate, but that's inconsequential to the real use>)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        That - as expected - gives us warnings:

        "test.c", line 21: warning #2171-D: invalid type conversion p, (ull_p)slot, byte, bit, nop); ^ "test.c", line 29: warning #2171-D: invalid type conversion for (p = (ull_p)123456ULL; p < (ull_p)(1ULL << 34); p += (1ULL < +< 29)) ^ "test.c", line 29: warning #2171-D: invalid type conversion for (p = (ull_p)123456ULL; p < (ull_p)(1ULL << 34); p += (1ULL < +< 29)) ^ "test.c", line 29: remark #4274-D: comparison of pointer with integer +zero for (p = (ull_p)123456ULL; p < (ull_p)(1ULL << 34); p += (1ULL < +< 29)) ^

        And when running ...

        ELF-32 executable object file - IA64 No output at all

        Enjoy, Have FUN! H.Merijn