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

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.
  • Comment on Re^6: 64-bit *nix/gcc expertise required

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

    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

      Tux Many thanks for your assistance. Up for a bit more?

      In theory, based on my reading the gcc headers, this should compile clean under 32/64-bit. It probably won't, but once you recover from your seasonal revelries, I'd appreciated seeing the warnings/errors produced on your various platforms.

      #include <stdio.h> #define __STDC_LIMIT_MACROS #include <stdint.h> #include <stddef.h> #define ALIGN_BITS ( sizeof(void*) >> __UINT64_C( 1 ) ) #define BIT_BITS __UINT64_C( 3 ) #define BYTE_BITS __UINT64_C( 14 ) #define SLOT_BITS ( sizeof( void*) * 8 ) - ( ALIGN_BITS + BIT_BITS + + BYTE_BITS ) #define BYTES_PER_SLOT __UINT64_C( 1 ) << BYTE_BITS #define TRACKING_SLOTS 8192 // max. 8192 for 4GB/32-bit machine int check_new( uintptr_t p ) { ptrdiff_t slot = ( p >> (BYTE_BITS + BIT_BITS + ALIGN_BITS) ); ptrdiff_t byte = ( p >> (ALIGN_BITS + BIT_BITS)) & __UINT64_C( 0x0 +0003fff ) ptrdiff_t bit = ( p >> ALIGN_BITS) & __UINT64_C( 0x0 +0000007 ); ptrdiff_t nop = p & __UINT64_C( 0x3 + ); printf( "address: %p slot: %p byte: %4x bit: %4x nop:%x\n", p, slot, byte, bit, nop ); return 1; } void main( void ) { uintptr_t p; for( p = __UINT64_C( 123456 ); p < ( __UINT64_C( 1 ) << 34 ); p += + ( __UINT64_C( 1 ) << 29 ) ) { check_new( p ); } }

      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.

        ; missing on line 16, the return type of main (int argc, char *argv[]) should be int. Besides that, lets try simple ...

        $ cat test2.c
        $ gcc -dumpversion 4.2.4 $ gcc -o test2 test2.c test2.c: In function 'main': test2.c:29: warning: left shift count >= width of type ld: Unsatisfied symbol "__UINT64_C" in file /tmp/ccAAXIbg.o 1 errors. $ gcc -mlp64 -fno-strict-aliasing -pipe -fPIC -o test2 test2.c test2.c: In function 'main': test2.c:29: warning: left shift count >= width of type ld: Unsatisfied symbol "__UINT64_C" in file /tmp/ccvHbmFn.o 1 errors.

        Did you actually try this yourself, and with what version of gcc? If this is gcc-only code I could try on my various platforms, but I'm sure that that would work just as on any 32bit capable 64bit platform.

        Older versions of gcc do not know about stdint.h

        $ gcc -dumpversion 3.4.6 $ gcc -fno-strict-aliasing -pipe -fPIC -o test2 test2.c test2.c:3:20: stdint.h: No such file or directory test2.c: In function `main': test2.c:29: warning: left shift count >= width of type $

        Above won't compile with HP C-ANSI-C for example.


        Enjoy, Have FUN! H.Merijn
      Change 34 to 31 to get some output.
        $ cc -Ae +DD32 -z +Z +w -o z test.c "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 << 31); p += (1ULL < +< 29)) ^ "test.c", line 29: warning #2171-D: invalid type conversion for (p = (ull_p)123456ULL; p < (ull_p)(1ULL << 31); p += (1ULL < +< 29)) ^ $ file z z: ELF-32 executable object file - IA64 $ ./z address: 00000001e240 slot: 000000000000 byte: f12 bit: 0 nop: 0 address: 00002001e240 slot: 000000000400 byte: f12 bit: 0 nop: 0 address: 00004001e240 slot: 000000000800 byte: f12 bit: 0 nop: 0 address: 00006001e240 slot: 000000000c00 byte: f12 bit: 0 nop: 0 $

        Enjoy, Have FUN! H.Merijn