Re: Integer Overflow



On 12/31/10 10:26 AM, tm wrote:
On 30 Dez., 20:21, Ben Bacarisse<ben.use...@xxxxxxxxx> wrote:
jacob navia<ja...@xxxxxxxxxxxx> writes:
You just do not test ALL operations but only the ones where you
are interested in avoiding overflows. You use the form

if (_overflow(expression))

This is new form that, so far as I know, is unimplemented and not yet
defined. My comments may well have been different if this had been
the proposal you seemed to be putting forward.

Originally, you seemed to be suggesting a compiler intrinsic to access the
processor's overflow flag.

I think this is approach is too simple.
I use C as target language for my Seed7 to C compiler.
I would be happy if C had some overflow checking.
But I understand that there are also places where the
classic behaviour without overflow checking is needed.
I want to raise overflow exceptions (emulated with
setjmp, longjmp) in Seed7. C with overflow checking
would make this easier.

Checking the processor's overflow flag costs time and
there should be a cheaper way to handle overflows.

What could possibly be cheaper than reading a status register? If you want a software interrupt, the cost of a context switch will swamp the the cycle or two to read the status.

--
Ian Collins
.



Relevant Pages

  • Re: Integer Overflow
    ... What could possibly be cheaper than reading a status register? ... The conditional jump on overflow will be predicted as not taken ... the correctly predicted conditionaljump will NOT disturb the pipeline. ...
    (comp.lang.c)
  • Re: Integer Overflow
    ... What could possibly be cheaper than reading a status register? ... Such a check, even if it is a single conditional jump, would be needed on every single checked operation, whether or not an overflow occurred. ... there is zero cost unless an overflow actually occurs. ...
    (comp.lang.c)
  • Re: Integer Overflow
    ... Such a check, even if it is a single conditional jump, would ... there is zero cost unless an overflow actually occurs. ... This switching could still be cheaper than checking ...
    (comp.lang.c)
  • Re: Integer Overflow
    ... a runtime penalty for the normal case (no overflow occurs). ... Seed7 and probably many more. ... unlimited precision libraries use fixed size arithmetic ... for small numbers and change to the unlimited representation ...
    (comp.lang.c)
  • Re: spinoza programming language and big numbers
    ... Seed7 doesn't coerce ints to longs automagically? ... I did qualify my comments by saying they were suggestions ... With qualifications or not the bignum tags aren't worthless. ... overflow checking is overwhelmed by ...
    (comp.programming)