[cfe-dev] [RFC] Introduce overflow builtins

Xi Wang xi.wang at gmail.com
Thu Mar 22 06:12:59 PDT 2012


On Mar 22, 2012, at 12:20 AM, Chris Lattner wrote:

> Regardless of whether we expose builtins, it would be nice for the optimizer to recognize common idioms, this is just general goodness for a wide range of already-written code.

I agree.

>> Let's consider adding overflow builtins to Clang, in the form:
>> 
>> 	bool __overflow_*(T*, T, T);
>> 
>> With overflow builtins, programmers can implement the example
>> as follows.
> 
> This sort of prototype makes sense to me, given that C doesn't support multiple return values well.  The builtin should start with __builtin though.  This is a pretty obvious set of functionality, is there any established practice in other compilers (e.g. MSVC, ICC, or even other more obscure ones?).  If there is standing practice somewhere else, it would be best to follow that lead, must so that we don't have to eventually implement both.

Just out of curiosity, why __builtin_*?  We already have __sync_* and __atomic_*. ;-)  Actually I used __builtin_saddo (__builtin_sadd_with_overflow is just too long).  Since this "saddo" looked a little bizarre to me, I changed it to __overflow_sadd.

I was also wondering which would be better, __overflow_*(T*, T, T) or __overflow_*(T, T, T*).

I didn't find overflow intrinsics in msvc and icc.  They do have something like "__int64 __emul(int a, int b)" though.

http://msdn.microsoft.com/en-us/library/26td21ds.aspx

http://software.intel.com/file/6373

- xi



More information about the cfe-dev mailing list