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

Nadav Rotem nadav256 at gmail.com
Mon Jun 16 10:08:33 PDT 2008


On Sun, 2008-06-15 at 20:57 -0700, Chris Lattner wrote:
> 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.

Thank your for quick response. I agree. I plan to extend Clang for use
in my high level hardware synthesis system. Since I wrote the
hardware-backend for my system, I am free to synthesize hardware with a
reduced size. I found the arbitrary-width integers support in LLVM to be
very helpful. I now base my project on the gcc frontend but I hope to
migrate it to Clang in the near future. 

Thank you,
Nadav
> 
> -Chris




More information about the cfe-dev mailing list