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

BrowserUk:

I don't have a 64 bit box to run on, but I think this is a good start. Note: I hacked the ALIGN_BITS and SLOT_BITS macros to use unsigned long long rather than void * because a pointer on this box isn't 64 bits. I think you'll be able to retain your original definition for those macros on a 64 bit box.

#include <stdio.h> #define ALIGN_BITS ( sizeof(unsigned long long) >> 1 ) #define BIT_BITS 3 #define BYTE_BITS 14 #define SLOT_BITS ( sizeof(unsigned long long) * 8 )-( ALIGN_BITS + +BIT_BITS + BYTE_BITS ) #define BYTES_PER_SLOT 1 << BYTE_BITS #define TRACKING_SLOTS 8192 // max. 8192 for 4GB/32-bit machine int check_new( unsigned long long p ) { unsigned long long slot = ( p >> (BYTE_BITS + BIT_BITS + ALIGN_BIT +S) ); unsigned long long byte = ( p >> (ALIGN_BITS + BIT_BITS)) & 0x0000 +3fffULL; unsigned long long bit = ( p >> ALIGN_BITS) & 0x000 +00007ULL; unsigned long long nop = p & 0x3UL +L; printf( "address: %016llx slot: %016llx byte: %4llx bit: %4llx nop:%ll +x\n", p, slot, byte, bit, nop ); return 1; } int main( void ) { unsigned long long p; for( p = 123456ULL; p < ( 1ULL << 34 ); p += ( 1ULL << 29 ) ) { check_new( p ); } return 1; }

Here on my (32 bit Linux) box, it's doing this:

roboticus@Boink:~ $ gcc 879044.cpp -lstdc++ roboticus@Boink:~ $ ./a.out 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

Update 2: You can use 'X' instead of 'x' in your printf specification to get upper-case in your hex strings, if that's important:

printf( "address: %016llX slot: %016llX byte: %4llX bit: %4llX nop:%ll +X\n", p, slot, byte, bit, nop );

Update: Moved signature to correct location.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: 64-bit *nix/gcc expertise required
by BrowserUk (Patriarch) on Dec 24, 2010 at 15:43 UTC

    Unfortunately that won't 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.