Re: Integer Overflow
- From: Seebs <usenet-nospam@xxxxxxxxx>
- Date: 30 Dec 2010 22:39:18 GMT
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.
.
- References:
- Integer Overflow
- From: arnuld
- Re: Integer Overflow
- From: jacob navia
- Re: Integer Overflow
- From: BGB
- Re: Integer Overflow
- From: Keith Thompson
- Re: Integer Overflow
- From: jacob navia
- Re: Integer Overflow
- From: BGB
- Re: Integer Overflow
- From: jacob navia
- Re: Integer Overflow
- From: Keith Thompson
- Re: Integer Overflow
- From: jacob navia
- Re: Integer Overflow
- From: Keith Thompson
- Re: Integer Overflow
- From: jacob navia
- Re: Integer Overflow
- From: Ike Naar
- Re: Integer Overflow
- From: jacob navia
- Re: Integer Overflow
- From: Ben Bacarisse
- Re: Integer Overflow
- From: jacob navia
- Re: Integer Overflow
- From: Ben Bacarisse
- Re: Integer Overflow
- From: tm
- Re: Integer Overflow
- From: Ian Collins
- Re: Integer Overflow
- From: Seebs
- Re: Integer Overflow
- From: Ian Collins
- Integer Overflow
- Prev by Date: Re: Integer Overflow
- Next by Date: Re: Integer Overflow
- Previous by thread: Re: Integer Overflow
- Next by thread: Re: Integer Overflow
- Index(es):
Relevant Pages
|