[cfe-dev] [RFC] Introduce overflow builtins
Xi Wang
xi.wang at gmail.com
Sun Apr 1 22:59:38 PDT 2012
On Apr 2, 2012, at 1:30 AM, Dave Zarzycki wrote:
> Also, this error could be more clear:
>
> +def err_overflow_builtin_pointer_size : Error<
> + "first argument to overflow builtin must be a pointer to 2, 4, or 8 "
> + "type (%0 invalid)">;
>
> To:
>
> +def err_overflow_builtin_pointer_size : Error<
> + "first argument to overflow builtin must be a pointer to a 16-bit, 32-bit, or 64-bit integer "
> + "type (%0 invalid)">;
Nice catch! Thanks. The word "byte" was missing when copied from err_atomic_builtin_pointer_size, my bad..
Again, the updated patch (including sign inference) is available at
https://github.com/xiw/clang/compare/master...builtin-overflow
> 1) Make __builtin_mul_with_overflow() return the "high" half of the result instead of a bool. You should be able to use the normal LLVM multiplication intrinsics for this instead of llvm.*mul.with.overflow.*.
I guess you mean something like MSVC's intrinsics:
__int64 _mul128(
__int64 Multiplier,
__int64 Multiplicand,
__int64 *HighProduct
);
__int64 __mulh(
__int64 a,
__int64 b
);
http://msdn.microsoft.com/en-us/library/82cxdw50.aspx
http://msdn.microsoft.com/en-us/library/17wa28cw.aspx
I don't think you need a new builtin here. For example, converting a and b to __int128_t should do the trick.
> 2) Make __builtin_*_with_overflow work with 8-bit integers.
Actually I doubt if types smaller than `int' would require overflow checking in practice..
> 3) Add __builtin_add_with_carry() and __builtin_sub_with_borrow().
What could benefit from them?
- xi
More information about the cfe-dev
mailing list