3 ms·
Typically, the assembly instruction that would do the read in arr[i] can do something like: x = *(y + z); where y and z are both 64-bit integers. If I had
by remexre 5y ago
Typically, the assembly instruction that would do the read in arr[i] can do something like:
x = *(y + z);
where y and z are both 64-bit integers. If I had
int arr[1000];
initialize(&arr);
int i = read_int();
int x = arr[i];
print(x);
then to get x I'd need to do something like,
tmp = i * 4;
tmp1 = (uint64_t)tmp;
x = *(arr + tmp1);
Which, since i is signed, can't just be a cheap shift, and then needs to be upcasted to a uint64_t (which is cheap, at least).