C ++ int vs long long in a 64-bit machine

My computer has a 64-bit processor, and when I search sizeof(int), sizeof(long)it sizeof(long long)turns out that int and long are 32 bits, and the long long one is 64 bits. I investigated the reason, and it seems that the popular assumption that int in C ++ matches the size of a machine word is wrong. As I understand it, it depends on the compiler to determine what size will be, and mine is Mingw-w64. The reason for my research was the understanding that if using types smaller than the word size is useful for speed (for example, short vs int ) or if it has a negative effect. On a 32-bit system, one popular opinion: because the word sizeint , short will be converted to int , and this will cause additional bit shifts, etc., resulting in poor performance. The opposite view is that there will be an advantage in the cache (I did not delve into it), and using a short one would be useful to save virtual memory. Thus, in addition to the confusion between this dilemma, I also face another problem. My system is 64 bit and it doesn’t matter if I use int or short , it will still be smaller than the size of the word, and I start to think t it’s efficient to use 64 bit long longbecause it is at the level at which the system is designed. I also read that there is another limitation, which is the library (ILP64, LP64) of the OS, which determines the size of the type. In ILP64, the default int is 64 bits, unlike LP64, will it speed up the program if I use an OS that supports ILP64? As soon as I started asking what type should be used to speed up my C ++ program, I came across deeper topics in which I have no experience, and some explanations seem to contradict each other. Could you explain:

1) If it is better to use the long long in x64 to achieve maximum performance even for 1-4 byte data?

2) A compromise using a type smaller than a word (memory gain and additional operations)

3) Does the computer have x64, where the word size & int is 64 bits, is it able to handle the short one using 16-bit word size, using the so-called backward compatibility? Or it should put a 16-bit file into a 64-bit file, and the fact that it can be executed defines the system as backward compatible.

4) Can we force the compiler to do int 64 bits?

5) How to enable ILP64 in a PC that uses LP64?

6) What are the possible problems of using code adapted to the above problems with other compilers, OS and architectures (32-bit processor)?

+9
2

1) long long x64 1-4- ?

No-, , , . , 64- , 32- , , , . .

2) ( )

, , . , , L1, , - L3 .

, , , , (, SSE). , 16- , 64- , .

3) x64, int 64 , , 16- , ? 16- 64- , , , .

, . , 64- 32- 16- , 64- .

, , , , , , .

4) int 64 ?

, . , stdint.h , int64_t, uint64_t ..

5) ILP64 , LP64?

https://software.intel.com/en-us/node/528682

6) , , , (32- )?

, , , . 32- 64- . , , .

, , .

: ! : 1. , . 32- int. , 64- , 0xee ee ee ee, , 0x ee ee ee+ 32 ? 32 , 64 ? 32 , 32 ? , .

.

-, , , . "" 32- 64- , . , , .

, 64- Intel 64- RAX. 32- , EAX, 16- 8- . :

x86_64 rax/eax/ax/al,

1122334455667788
================ rax (64 bits)
        ======== eax (32 bits)
            ====  ax (16 bits)
            ==    ah (8 bits)
              ==  al (8 bits)

, 32- .

-, , . , () (, L3, L2 L1). , , , 4096 ( ). , , , 32 64 . 64 . - , .

, 64- , , 4096 , 64 L3, L2 L1, 64- L1.

. 16 32- , 8 64- . 32 16- 64 8- . , , .

+26

. cpus. , .

, . Instuct . , cpus.

. , , - 64 128 4KiB, . 64Byte L1 Pentium IV. , DDR3/4 RAM .

- . , . int . , .

0

Source: https://habr.com/ru/post/1656285/


All Articles