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,261 of 243,242    |
|    David Brown to Philipp Klaus Krause    |
|    Re: _BitInt(N)    |
|    30 Nov 25 12:28:02    |
      From: david.brown@hesbynett.no              On 30/11/2025 11:41, Philipp Klaus Krause wrote:       > Am 30.11.25 um 11:22 schrieb Michael S:       >>       >> I fail to see the difficulty for implementer.       >> For arithmetic ops, _BitInt(1187) is almost the same as _BitInt(1216).       >> You just add one 'and by constant' operation applied to MS word at the       >> very end. You only have do it for unsigned variant, since for signed       >> variant overflow is undefined, anyway. So, for signed, you can do       >> nothing or you can do the same as unsigned, if you fill that it's       >> simpler.       >> The same goes for left shift.       >> For right shift and for logical ops, _BitInt(1187) is exactly the same       >> as _BitInt(1216).       >> So what is all the fuss about?       >       > I see two implementation strategies:       >       > * Just ignore the values of the padding bits. You don't need to and or       > anything after arithmetic operations. Makes arithmetic as fast as       > possible. But you need special handling at comparisons and casts.       >       > * Always keep the padding bits in line with the value, i.e. and after       > arithemetic operations for unsigned, copy value of sign bit for signed.       > Extra effort at arithmetic operations, but no extra effort at casts and       > comparisons.       >              That sounds about right. It's much the same as the implementation of       _Bool. You either ignore the padding bits while doing the calculations       and filter them out when they later get in the way, or you keep them       neat and consistent (signed or unsigned extended, as appropriate) during       calculations and it's all fine for other operations. I have no idea       what might be the most efficient choice overall - it could vary by       application, but I expect implementations to have one fixed strategy.              --- 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