mercredi 27 septembre 2017

What is a fast integer ? What defines how fast an integer is?

I am not a c++ expert but I started learning through www.learncpp.com which is great btw and I suggest for any new c++ learner and in this topic:

http://ift.tt/2frKsDb

it was mentioned that

The fast type (int_fast#_t) gives you an integer that’s the fastest type with a width of at least # bits (where # = 8, 16, 32, or 64). For example, int_fast32_t will give you the fastest integer type that’s at least 32 bits.

What does he mean by the fastest integer type ? what defines the speed ?

I assume that not all integers are accessed the same way, some are easier to access than the others but what I need to know what could lead to that speed of access ?

I have read in one question that:

On some processors, if a variable gets stored in a register which is longer, the compiler may have to add extra code to lop off any extra bits. For example, if uint16_t x; gets stored in a 32-bit register on the ARM7-TDMI, the code x++; may need to be evaluated as x=((x+1)<<16)>>16);. On compilers for that platform, uint_fast16_t would most likely be defined as synonymous with uint32_t to avoid that.

What makes that faster ? As in either case 32 bits will be looped over in the register level.

Aucun commentaire:

Enregistrer un commentaire