Hardware Traps for Integer Overflow

2014-05-29 Thread bearophile via Digitalmars-d
A request for hardware overflow tests: http://blog.regehr.org/archives/1154 From the blog post: Processors should support integer math instructions that optionally trap on overflow. Because popular architectures lack this feature, otherwise excellent modern systems programming languages, such

Re: Hardware Traps for Integer Overflow

2014-05-29 Thread Wanderer via Digitalmars-d
I don't see any valid alternatives. What should ideally happen if you increment 0x..? Should the value remain the same? That's not much better than resetting back to zero, still a mathematical error. Throw an exception? That would kill performance and break lots of existing code. If y

Re: Hardware Traps for Integer Overflow

2014-05-29 Thread bearophile via Digitalmars-d
Wanderer: If you need perfect calculations, you can always use an according library for numbers with arbitrary precision. The D Zen points in the opposite direction: if you don't care of having bogus results in your code, then use unsafe integers :-) Bye, bearophile

Re: Hardware Traps for Integer Overflow

2014-05-29 Thread Tobias Pankrath via Digitalmars-d
On Thursday, 29 May 2014 at 15:32:54 UTC, Wanderer wrote: I don't see any valid alternatives. What should ideally happen if you increment 0x..? Should the value remain the same? I know at least one firmware running in cars from several manufacturers where this is the desired behavior i

Re: Hardware Traps for Integer Overflow

2014-05-29 Thread John Colvin via Digitalmars-d
On Thursday, 29 May 2014 at 20:01:25 UTC, Tobias Pankrath wrote: On Thursday, 29 May 2014 at 15:32:54 UTC, Wanderer wrote: I don't see any valid alternatives. What should ideally happen if you increment 0x..? Should the value remain the same? I know at least one firmware running in ca

Re: Hardware Traps for Integer Overflow

2014-05-30 Thread Marco Leise via Digitalmars-d
Am Thu, 29 May 2014 20:10:13 + schrieb "John Colvin" : > On Thursday, 29 May 2014 at 20:01:25 UTC, Tobias Pankrath wrote: > > On Thursday, 29 May 2014 at 15:32:54 UTC, Wanderer wrote: > >> I don't see any valid alternatives. What should ideally happen > >> if you increment 0x..? Shoul

Re: Hardware Traps for Integer Overflow

2014-05-30 Thread John Colvin via Digitalmars-d
On Friday, 30 May 2014 at 07:00:58 UTC, Marco Leise wrote: Am Thu, 29 May 2014 20:10:13 + schrieb "John Colvin" : On Thursday, 29 May 2014 at 20:01:25 UTC, Tobias Pankrath wrote: > On Thursday, 29 May 2014 at 15:32:54 UTC, Wanderer wrote: >> I don't see any valid alternatives. What should

Re: Hardware Traps for Integer Overflow

2014-05-30 Thread Wanderer via Digitalmars-d
Actually such instructions exist since MMX on Intel CPUs. The question is: Can these new SSE instructions replace integer math seemlessly? My opinion is "no". When you increment an integer value (any value), you at least expect its lower bit to change. All cryptographic algorithms would crash