In article ,   
   Bernd Linsel wrote:   
   >On 27.03.2024 13:28, Krishna Myneni wrote:   
   >>   
   >> I really think it is a bad idea to have UB in the spec of LSHIFT and   
   >> RSHIFT due to the arbitrariness of low level shift operations at the   
   > > hardware level.   
   >   
   >It's not UB, it is IB and thus it should be required that an implementer   
   >documents the respective behaviour of their system.   
   >   
   > > Here we have a chance to remove that UB and guarantee that>   
   >> 1 BITS_PER_CELL LSHIFTÂ returns zero   
   >> and   
   >> 1 BITS_PER_CELL RSHIFTÂ returns zero   
   >>   
   >> so that the expected result for a shift operation on the cell operand   
   >> does not have UB.   
   >>   
   >> Efficiency because of extra instructions needed to implement this   
   >> guarantee are not even worth bothering about -- we are not C.   
   >   
   >Forth does care about efficiency. Otherwise you could eliminate over the   
   >half of the ambiguous conditions in the Forth standard that only arise   
   >from the fact that hardware platforms differ in their behaviour.   
   >   
   >[snip]   
   >   
   >For the rare situation that a variable shift count is needed, and is not   
   >per se restricted to 0..ADDRESS-UNIT-BITS - 1, you can always write either   
   >   
   >0 MAX S" ADDRESS-UNIT-BITS" 1- MIN LSHIFT ( or RSHIFT)   
   >   
   >or   
   >   
   >DUP 0< INVERT IF DUP S" ADDRESS-UNIT-BITS" < IF LSHIFT ( or RSHIFT)   
   >ELSE ( whatever to do if shift-amount < 0)   
   >ELSE ( whatever to do if shift-amount >= cell width)   
   >THEN THEN   
   >   
   >or simply   
   >   
   >DUP 0< ABORT" shift amount less than 0"   
   >DUP S" ADDRESS-UNIT-BITS" 1- > ABORT" shift amount greater/equal cell width)   
   >LSHIFT ( or RSHIFT)   
      
   I hate ABORT in this context. Are you sure that you want to shut down   
   the nuclear power plant in this situation?   
      
   >   
   >NB: The behaviour of most processors to only regard the 5 or 6 LSBs is   
   >useful for expressions like -1 64 - LSHIFT to produce bit masks,   
   >these can simply be expressed as NEGATE LSHIFT (with an   
   >environmental dependency on processors that behave this way).   
   >   
   >   
   >--   
   >Bernd Linsel   
   --   
   Don't praise the day before the evening. One swallow doesn't make spring.   
   You must not say "hey" before you have crossed the bridge. Don't sell the   
   hide of the bear until you shot it. Better one bird in the hand than ten in   
   the air. First gain is a cat purring. - the Wise from Antrim -   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|