I have a 64-bit i7 machine. Suppose I allocate memory for n 32-bit integers. How many physical registers will actually be used in the allocation: n, or n/2?
I tried to write the following simple programme to find out.
#include <iostream>
#include <cstdlib>
using namespace std;
int main (int argc, char *argv[]) {
int a[4];
cout << &a[0] << "\t" << &a[3] << endl;
cin.ignore (1);
return 0;
} // End main ()
The output is:
0018FA04 0018FA10
They seem further apart than they should be. Why aren’t the addresses 04 and 07? And does this mean that the system is actually allocating four (or more) integers, instead of packing the four 32-bit integers into two 64-bit registers?
Thanks in advance for your help.
A 64-bit i7 machine is a x86_64 architecture.
On this architecture an array of 32-bit integers will be allocated fully-packed, meaning the size of the array will be 4n bytes.
If by physical registers you mean machine words, and you consider a machine word to be 64-bit on x86_64, than yes it will use n/2 machine words.
I wouldn’t use the word physical registers, this can be confused with cpu registers, which is not where an array (unless very small and optimizer is aggressive) is allocated.
Because the architecture is byte-addressed not word-addressed. They are 12 bytes apart as expected.