6 Ocak 2020 Pazartesi

uint_fast32_t tipi

Giriş
fast tiplerden çokça var. Açıklaması şöyle.
The following types are required:

int_fast8_t, int_fast16_t, int_fast32_t, int_fast64_t, uint_fast8_t, uint_fast16_t, uint_fast32_t, uint_fast64_t
Fast Tipler Neden Lazım
Açıklaması şöyle.
Imagine a CPU that performs only 64 bit arithmetic operations. Now imagine how you would implement an unsigned 8 bit addition on such CPU. It would necessarily involve more than one operation to get the right result. On such CPU, 64 bit operations are faster than operations on other integer widths. In this situation, all of Xint_fastY_t might presumably be an alias of the 64 bit type.

If a CPU supports fast operations for narrow integer types and thus a wider type is not faster than a narrower one, then Xint_fastY_t will not be an alias of the wider type than is necessary to represent all Y bits.
Eğer Doğruluk Daha Önemli İse
uint_fast32_t pek tercih edilmez. Daha çok uint_32_t kullanılır. Açıklaması şöyle. Çünkü uint_fast32_t bazen 32 bit bazen 64 bit olabiliyor.
uint32_t is guaranteed to have nearly the same properties on any platform that supports it.
uint_fast32_t has very little guarantees about how it behaves on different systems in comparison.

If you switch to a platform where uint_fast32_t has a different size, all code that uses uint_fast32_t has to be retested and validated.
All stability assumptions are going to be out the window. The entire system is going to work differently.
...
Correctness is more important than speed. Premature correctness is thus a better plan than premature optimization.
Örnek
GNU Linux için şöyledir. x86-64 için isminde 32 geçmesine rağmen 64 bit olduğu görülebilir.
┌────╥───────────────────────────────────────────────────────────┐
 Y     sizeof(Xint_fastY_t) * CHAR_BIT                         
    ╟────────┬─────┬───────┬─────┬────────┬──────┬────────┬─────┤
     x86-64  x86  ARM64  ARM  MIPS64  MIPS  MSP430  AVR 
╞════╬════════╪═════╪═══════╪═════╪════════╪══════╪════════╪═════╡
 8   8       8    8      32   8       8     16      8   
 16  64      32   64     32   64      32    16      16  
 32  64      32   64     32   64      32    32      32  
 64  64      64   64     64   64      64    64      64  
└────╨────────┴─────┴───────┴─────┴────────┴──────┴────────┴─────┘

Hiç yorum yok:

Yorum Gönder