Re: Integer Overflow



On 2010-12-30, Ian Collins <ian-news@xxxxxxxxxxx> wrote:
"What could possibly be a cheaper way to detect overflow than reading a
status register?"

Ahh, that's an interesting question. I'm not sure, actually; there's a lot
of ideas that might come to mind, but it's not obvious that any of them
are necessarily cheaper.

That said, there is almost certainly at least one implementation out there
where calculating-in-advance whether or not something will overflow would
be orders of magnitude cheaper than checking the status register. So, you
do your check of the form
if (INT_MAX - b < a)
...
and the resulting instructions execute faster than the equivalent of:
c = a + b;
if (_overflow())
...

Who knows? CPUs surprise us. When I was a kid, I was told to avoid floating
point math because it was so much slower than integer.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@xxxxxxxxx
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
.



Relevant Pages

  • Re: Another classic RugbyHeaven poll.
    ... everyone to only vote once and not lie about where their support ... probably been another 200 or so register and vote; ... "Be who you are and say what you feel, because those who mind don't ... matter, and those who matter don't mind." ...
    (rec.sport.rugby.union)
  • Re: Tithe Maps & Land ownership
    ... boundaries of what is popularly called "common land". ... register of that going back through history. ... I have in mind things ...
    (soc.genealogy.britain)
  • Re: What for exactly?
    ... >>> 's tempting. ... Mind, I'm not sure that they'd let you register ... >>> shpxbsstony. ...
    (uk.rec.sheds)
  • Re: Mancmoot
    ... policy that I can find on the site. ... (Do I have to register to find ... I mean, I don't mind, I'm not coy about my age, but I don't see why ... (OTOH arLizz, ...
    (uk.rec.sheds)