[llvm-commits] [llvm] r132613 - in /llvm/trunk: include/llvm/Analysis/BranchProbabilityInfo.h include/llvm/InitializePasses.h lib/Analysis/Analysis.cpp lib/Analysis/BranchProbabilityInfo.cpp lib/Analysis/CMakeLists.txt

Jakob Stoklund Olesen stoklund at 2pi.dk
Tue Jun 7 20:00:37 PDT 2011


On Jun 7, 2011, at 6:49 PM, Andrew Trick wrote:

>>> And many places in LLVM use
>>> (u)int32_t, too.
>>> 
>>> If nothing else, uint32_t is more self-documenting.
>> 
>> If a C implementation decides to take on all the portability issues that come from having a 64-bit int, it has to be because 32-bit arithmetic performance is horrible. The uint32_t type makes sense when you need the compact size, or when you depend on modulo 2^32 arithmetic.

> Then what do we cast to for overflow checking?

uint32_t

This discussion is rather academic. LLVM builds on ILP32, LP64, and LLP64 platforms where an int is 32 bits and plenty fast. I don't think anyone has tried porting it to a platform where that isn't true, but they would likely have to fix a lot of code that uses int/unsigned.

If we start using uint32_t everywhere, they will now have to check if we really meant "I need exactly 32 bits, regardless of performance", or did we really mean to use uint_fast32_t instead.

Either way, they get to look at all the code.

But yeah, if you depend on having exactly 32 bits for an overflow test, use uint32_t.

Of course a C implementation is not required to have a 32-bit type, so uint32_t may not exist. If you want to pretend to write portable code, you have to stick to uint_least32_t and uint_fast32_t. I have never seen code that does that, and we don't even bother defining these types in DataTypes.h

/jakob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110607/c4e11321/attachment.html>


More information about the llvm-commits mailing list