[cfe-dev] Fixed Point Arithmetic Proposal

Leonard Chan via cfe-dev cfe-dev at lists.llvm.org
Wed Apr 25 10:16:01 PDT 2018

> > The C extensions to support embedded processors defined in chapter 4 of
> > ISO/IEC TR 18037 [1] defines support for fixed-point arithmetic and
> > point data types in C.

> Just curious, do you know the state of fixed-point arithmetic in C++?  I
> recall a talk at CPPcon some while ago, but I don't know that it has made
> any headway.

I believe fixed-point arithmetic currently is only standardized in ISO
N1169 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf). As of
now, only GCC has implemented it (
https://gcc.gnu.org/wiki/FixedPointArithmetic), though I do not think they
have finished a full implementation of the stdfix library. There are also
lots of open source implementations for fixed point types, but none of them
built into the language except for GCC for now.

> > All changes will also be made to Clang only. Expanding this into LLVM
> > be considered down the road.

> "Expanding this into LLVM [later]" implies two things to me.  Might mean
> more things to somebody else.

> First, in the short term the front-end will emit all the scaling
> explicitly.  Does "expanding this into LLVM" include making LLVM
> scaled types natively?  That sounds like a big project.

Yes. Initially, we will only be making changes to clang by performing any
scaling through extra llvm instructions when compiling from C to IR.
Expanding into llvm entails adding fixed point types as llvm types
natively, but from what I've been told, this does sound like a big project
to be considered for later. Right now we're focusing on just the C frontend
and not LLVM itself.

> Second, in the short term the front-end will describe everything in terms
> the same-size same-signedness integer types.  I assume you will eventually
> teach the debug-info metadata to describe scaled types?  DWARF has
> scaled types since v3, I don't know whether CodeView does also.  Adding
> to LLVM should be relatively straightforward.

We have not considered this, but will look into it. In terms of debug info,
we will record all fixed point types as ints, but we are unsure right now
about scaled types.


More information about the cfe-dev mailing list