Live data from Hacker News

We Need Hardware Traps for Integer Overflow

blog.regehr.org

1–10 of 112 posts

Re: We Need Hardware Traps for Integer Overflow

#4
post #2

In case anyone has the same difficulty reading this as I did, "integer types that wrap" is supposed to refer to arithmetic modulo 2^n. I thought at first he was talking about wrapped integer types.

> wrapped integer types

A google search for "wrapped integer types" gives me the Wikipedia article on Integer Overflow as its first result. The other hits seem to be related.

What else do you mean by "wrapped integer types" if not arithmetic modulo 2^n?

Re: We Need Hardware Traps for Integer Overflow

#5
post #4
post #2

In case anyone has the same difficulty reading this as I did, "integer types that wrap" is supposed to refer to arithmetic modulo 2^n. I thought at first he was talking about wrapped integer types.

> wrapped integer types A google search for "wrapped integer types" gives me the Wikipedia article on Integer Overflow as its first result. The other hits seem to be related. What else do you mean by "wrapped integer types" if not arithmetic modulo 2^n?

I think he probably means boxed integer types: http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx

Re: We Need Hardware Traps for Integer Overflow

#6
post #4
post #2

In case anyone has the same difficulty reading this as I did, "integer types that wrap" is supposed to refer to arithmetic modulo 2^n. I thought at first he was talking about wrapped integer types.

> wrapped integer types A google search for "wrapped integer types" gives me the Wikipedia article on Integer Overflow as its first result. The other hits seem to be related. What else do you mean by "wrapped integer types" if not arithmetic modulo 2^n?

[deleted]

Re: We Need Hardware Traps for Integer Overflow

#7
Personally, I'd like to see more programming done in languages that simply don't allow integer overflow in the first place. Most current languages have arbitrary-precision integers; well-implemented arbitrary-precision integers are quite efficient when they fit in a machine word, and as efficient as possible when larger. Sure, you'll lose a bit of performance due to checks for overflow, but those checks need to exist anyway, in which case it seems preferable to Just Work rather than failing.

Re: We Need Hardware Traps for Integer Overflow

#8
post #3

I found it weird that nobody mentioned it, but was this posted because Apple's new language Swift has integer overflow detection (with operators &+, &-, etc. operators for doing conventional C-style modulo integer math)?

It was posted to reddit six days ago[1], four days before Swift.

[1] http://www.reddit.com/r/programming/comments/26s8iu/we_need_...

Re: We Need Hardware Traps for Integer Overflow

#9
Modern CPUs don't like traps ("exceptions"). The exception causes a pipeline flush which kills performance for math-intensive code.

For example, detecting integer overflow on x86 and x86_64 CPUs is easy: check the overflow flag after every arithmetic operation. It would only be slightly more difficult to detect overflow for SSE (vector) operations, which would require doing some bit masking and shifting.

For a language such as Swift, building it in is simple.

Re: We Need Hardware Traps for Integer Overflow

#10
post #4
post #2

In case anyone has the same difficulty reading this as I did, "integer types that wrap" is supposed to refer to arithmetic modulo 2^n. I thought at first he was talking about wrapped integer types.

> wrapped integer types A google search for "wrapped integer types" gives me the Wikipedia article on Integer Overflow as its first result. The other hits seem to be related. What else do you mean by "wrapped integer types" if not arithmetic modulo 2^n?

A google search for "striped horse" gives me the Wikipedia article for Zebra as its first result. Similarly a google search for "wrapped integer types" takes you to a Wikipedia page for "integer overflow" that never uses the phrase "wrapped integer."

simcop2387 is correct that I assumed he was talking about boxing at first.

Post reply on HN