In the following piece of code ( i changed this a little ) suppose row
is 15. The question is, does the&data[row >> 6]
is referencing to an address outside of its nomimal address value ?
uint64_t volatile *data;
int numRows = 45;
numWords = (numRows + 63) >> 6;
data= new uint64_t[numWords];
memset((void*)data, 0, sizeof(uint64_t) * numWords);
int row = 15;
uint64_t bit = 1LL << (row & 63);
Or64(&data[row >> 6], bit);
Running a modified code I noticed that &data[1]
points to starting address +8, &data[2]
starting address +16 and so on.
So, If starting address of the data variable (64bit length) is 0x00000001 where referene &data[row >> 6]
should point to ?
The code above is supposed to change some bits inside the data variable, how to explain this ?
Ok after a closer look now it seems pretty clear. The code just set some bits inside an int 64bit value as a mask array flag.
In a single 64bit number we can have 64 different bit flags positions, BUT if we need more flags position than this number, then we have to take one more 64bit number side by side. The data= new uint64_t[numWords];
allocates such numbers of 64bit integers as it is shown by the quotient of the numwords
/ 64 division (shifting right by 1 is equal with a division by 2).
Now, To access the right 64bit mask array we do almost the same thing. First we try to find in which 64bit array flag belongs the given row
number. If row > 63 then is laying to a next 64bit bit mask array ( a number bigger than 63 and smaller than 128 that is shifting right by 6 it returns 0 ). After that we can set the appropriate bit flag.
User contributions licensed under CC BY-SA 3.0