Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c    |    Meh, in C you gotta define EVERYTHING    |    243,242 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 242,066 of 243,242    |
|    Waldek Hebisch to bart    |
|    Re: _BitInt(N)    |
|    23 Nov 25 17:55:38    |
   
   From: antispam@fricas.org   
      
   bart wrote:   
   > On 23/11/2025 13:32, Waldek Hebisch wrote:   
   >> Philipp Klaus Krause wrote:   
   >>> Am 22.10.25 um 14:45 schrieb Thiago Adams:   
   >>>>   
   >>>>   
   >>>> Is anyone using or planning to use this new C23 feature?   
   >>>> What could be the motivation?   
   >>>>   
   >>>>   
   >>>   
   >>> Saving memory by using the smallest multiple-of-8 N that will do.   
   >>   
   >> IIUC nothing in the standard says that it is smallest multiple-of-8.   
   >> Using gcc-15.1 on AMD-64 is get 'sizeof(_BitInt(22))' equal to 4,   
   >> while the number cound fit in 3 bytes.   
   >   
   > The rationale mentions a use-case where there is a custom processor that   
   > might actually have a 22-bit hardware types.   
   >   
   > Implementing such odd-size types on regular 8/16/32/64-bit hardware is   
   > full of problems if you want to do it without padding (in order to get   
   > the savings). On even with padding (to get the desired overflow semantics).   
   >   
   > Such as working out how pointers to them will work.   
      
   Yes. That is why type is rounded up. For unsigned types compiler   
   may need to generate explicit masking operation (to discard excess   
   bits), but for signed types compiler may perform operations   
   in increased precision.   
      
   >>> Also   
   >>> being able to use bit-fields wider than int.   
   >>   
   >> For me main gain is reasonably standard syntax for integers bigger   
   >> that 64 bits.   
   >   
   > Standard syntax I guess would be something like int128_t and int256_t.   
   > Such wider integers tend to be powers of two.   
      
   Powers of two are used when hardware operates only on power of two   
   sized pieces. But for multiword integers in general there is no reason   
   to use even number of words and AFAICS gcc uses odd number of   
   words when it is enough.   
      
   Note that for arithmetic on sub-word numbers on modern machines   
   promoting them to words usually gives the same performance.   
   But smaller number of words is likely to lead to faster   
   operation, so it makes no sense to insist on powers of two.   
      
   --   
    Waldek Hebisch   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca