home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.arch      Apparently more than just beeps & boops      131,241 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 129,877 of 131,241   
   EricP to Brian G. Lucas   
   Re: sign/zero/garbage extension   
   09 Oct 25 22:45:36   
   
   From: ThatWouldBeTelling@thevillage.com   
      
   Brian G. Lucas wrote:   
   > On 10/6/25 8:38 PM, Kent Dickey wrote:   
   > [SNIP]   
   >> For C and C++ code, the standard dictates that all integer operations are   
   >> done with "int" precision, unless some operand is larger than int, and   
   >> then   
   >> do it in that precision.  So there's no real need for 8-bit and 16-bit   
   >> operations to be natively by the CPU--these operations are actually done   
   >> as int's already.  If you have a variable which is a byte, then assigning   
   >> to that variable, and then using that variable again you will need to   
   >> zero-extend, but honestly, this is not usually a performance path.  It's   
   >> likely to be stored to memory instead, so no masking or sign extending   
   >> should be needed.   
   >>   
   > [SNIP]   
   >> Kent   
   >   
   > Can you point me to the section in "the standard" which indicates   
   > 'all integer operations are done with "int" precision'?   
   >   
   > What if the wording was changed to:   
   > 'all integer operations are done with _at least_ "int" precision',   
   > e.g. one could use long.  Would that break conforming code?   
   >   
   > Brian   
      
   I was wondering this myself. The down-cast rule to a smaller size   
   appears to be in C12 standard:   
   6.3.1.3(3) implementation-defined or throw an exception if out-of-range.   
      
   "   
   6.3 Conversions   
   6.3.1.3 Signed and unsigned integers   
      
   1 When a value with integer type is converted to another integer type   
   other than _Bool, if the value can be represented by the new type,   
   it is unchanged.   
      
   2 Otherwise, if the new type is unsigned, the value is converted by   
   repeatedly adding or subtracting one more than the maximum value that   
   can be represented in the new type until the value is in the range of   
   the new type.60)   
      
      [EricP: this is the same as zero extend]   
      
   3 Otherwise, the new type is signed and the value cannot be   
   represented in it; either the result is implementation-defined or   
   an implementation-defined signal is raised.   
   "   
      
   --- 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