[M3devel] overshift/overflow

Jay K jay.krell at cornell.edu
Thu Mar 4 10:00:11 CET 2010



  > Word.LeftShift(..., 100); (* where 100 >= BITSIZE(INTEGER),


My mistake, it does generate a warning.
It also seems to not generate the code to do the shift, good.
I had probably hidden 100 behind a function call, inhibiting the front end's checking.
   Or more likely behind something else. I have to look into something. 



  > Why can't a backend simply generate code for the large shift, as if it had been a call to Word.Shift(..., 100)?
 
It would be dead/unreachable code, but not a big deal. It looks like the front end skips the code when it can figure it out. I'll have to look into this more, but it is acting different/better than I realized.
 



[Jay] EVAL -FIRST(INTEGER);
[Jay] I believe the frontend should issue a warning.



[Tony] Why?  The front-end does not reason about overflow (except when computing compile-time constants).  Overflow is a run-time concept!!!!!!!!!!!!!
 
Because it can often easily prove that overflow will occur.
It is worth warning about?
 
if I write:
 
a := 1 + 2;
 
does the front end not optimize that to:
 
a := 3;
 
? Imho it should 1 + 2 provably at compile time does not overflow.
 
 

        > how to enable overflow


> The correct thing to do is introduce different interfaces/modules/types/functions
> which either always do overflow checking, or, perhaps but less likely,
 > new interfaces/modules/types/functions that are runtime configurable, as
> INTEGER was originally speced.



  > NOOOOO!!!!!!!  That will impose an undue expense on targets where such checking is expensive.
 
 I doubt I suggested what you think I did.
 If someone really needs overflow checking, then it will cost them whatever it costs them, on whatever target they care about.
 I am NOT suggesting changing any existing interface/module/type. In fact I am proposing that FloatMode's hypothetical feature to enable overflow checking be removed. That "a + b", "a * b" etc., where a is INTEGER, never ever get overflow checking.
If anyone needs it, they'd use some as yet to be specified and implemented type/interface/module.
Like INTERFACE IntOv; TYPE T = INTEGER; PROCEDURE Add(a, b: T) RAISES Something: T;
etc.
 
or maybe a new compiler-builtin type INTEGEROV.
Maybe use the word "safe" as it is popular for this sort of thing (search the web for "safeint").
 

 - Jay 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100304/43fabc9e/attachment-0002.html>


More information about the M3devel mailing list