Topic: Overflow


Author: Lawrence Crowl <crowl@googlers.com>
Date: Mon, 17 Dec 2012 17:16:42 -0800
Raw View
On 12/16/12, cooky451@gmail.com <cooky451@gmail.com> wrote:
> 2. Overflow-checks. While many (most?) CPUs have some kind of
> carry/overflow bit, getting the compiler to actually use this
> information doesn't seem straight forward or even possible for
> all cases to me. The usual C++ approach is to use some arithmetic
> "tricks" to figure out if an operation would overflow or not. In
> most cases this seems to be much slower than just using the
> dedicated CPU flags. With library functions like
>
> bool std::safe_multiply(uint32_t a, uint32_t b, uint32_t& c)
> bool std::safe_multiply(int32_t a, int32_t b, int32_t& c)
> // State of c is implementation-/undefined if function returns false
> // Add functions for addition etc., for all integer types.
>
> the implementation could actually use the scope of the platform
> to provide optimal performance in a standard conforming way. I
> think this feature could be very useful for things like safe_int
> or unsigned_integer<uint64_t, 8> (arbitrary precision).
>
> Okay, now have fun destroying me. :)

There has been some discussion of this kind of facility within SG6.
The issue is designing the facility to work well with the other
facilities in flight.  We'd really like to have one comprehensive
system rather than 10 single-point solutions.

--
Lawrence Crowl

--




.


Author: Beman Dawes <bdawes@acm.org>
Date: Mon, 17 Dec 2012 21:47:32 -0500
Raw View
On Mon, Dec 17, 2012 at 8:16 PM, Lawrence Crowl <crowl@googlers.com> wrote:
> On 12/16/12, cooky451@gmail.com <cooky451@gmail.com> wrote:
>> 2. Overflow-checks. While many (most?) CPUs have some kind of
>> carry/overflow bit, getting the compiler to actually use this
>> information doesn't seem straight forward or even possible for
>> all cases to me. The usual C++ approach is to use some arithmetic
>> "tricks" to figure out if an operation would overflow or not. In
>> most cases this seems to be much slower than just using the
>> dedicated CPU flags. With library functions like
>>
>> bool std::safe_multiply(uint32_t a, uint32_t b, uint32_t& c)
>> bool std::safe_multiply(int32_t a, int32_t b, int32_t& c)
>> // State of c is implementation-/undefined if function returns false
>> // Add functions for addition etc., for all integer types.
>>
>> the implementation could actually use the scope of the platform
>> to provide optimal performance in a standard conforming way. I
>> think this feature could be very useful for things like safe_int
>> or unsigned_integer<uint64_t, 8> (arbitrary precision).
>>
>> Okay, now have fun destroying me. :)
>
> There has been some discussion of this kind of facility within SG6.
> The issue is designing the facility to work well with the other
> facilities in flight.  We'd really like to have one comprehensive
> system rather than 10 single-point solutions.

+1

-- Beman

--




.