[cfe-dev] Extending C to support non power of two bit variables

Chris Lattner clattner at apple.com
Sun Jun 15 20:57:03 PDT 2008

On Jun 14, 2008, at 9:48 PM, Eli Friedman wrote:
>> I hoped there
>> was an easier way to do this. Would such a patch be accepted into
>> clang ? It seems like if I were to implement non power of two  
>> variables
>> I would have to maintain a fork of clang.
> I think it would be accepted; for the attribute itself, it seems
> potentially useful, and the attribute implementation itself isn't very
> much code.  Having the types around would be useful for other things,
> like an implementation of the mode attribute that isn't dependent on
> the target having appropriate regular integer types.

I agree.  If the patch was done well, I think it would be great to  
have support for this in clang.

> A couple of small things which I just thought of: one, I'm not sure
> whether the LLVM arbitrary-width integers do exactly what you expect
> in terms of data layout.  The way it works is that the data layout is
> the same as that of the next-largest integer type (see
> http://llvm.org/docs/LangRef.html#datalayout).  The other thing is
> something I didn't quite state explicitly: because of the C integer
> promotion rules, an int5 will be immediately promoted to int whenever
> its value is used.

Right.  Arbitrary bit sized values are most useful for scalar  
expressions.  For example, if you are synthesizing hardware from LLVM  
IR, an i13 multiply is cheaper than an i16 multiply etc.


More information about the cfe-dev mailing list