This is an archive of the discontinued LLVM Phabricator instance.

[Fixed Point Arithmetic] Predefined Precision Macros
Needs ReviewPublic

Authored by leonardchan on May 16 2018, 9:53 AM.

Details

Summary

This patch contains the addition of the precision macros for integral and fractional bits according to clause 7.18a.3 of http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf. The macros are integer constants and added as predefined macros.

// Fractional bits of _Accum types
__SACCUM_FBIT__
__ACCUM_FBIT__
__LACCUM_FBIT__
__USACCUM_FBIT__
__UACCUM_FBIT__
__ULACCUM_FBIT__

// Fractional bits of _Fract types
__SFRACT_FBIT__
__FRACT_FBIT__
__LFRACT_FBIT__
__USFRACT_FBIT__
__UFRACT_FBIT__
__ULFRACT_FBIT__

// Integral bits of _Accum types
__SACCUM_IBIT__
__ACCUM_IBIT__
__LACCUM_IBIT__
__USACCUM_IBIT__
__UACCUM_IBIT__
__ULACCUM_IBIT__

Diff Detail

Repository
rC Clang

Event Timeline

leonardchan created this revision.May 16 2018, 9:53 AM
ebevhan added inline comments.
include/clang/Lex/Preprocessor.h
185

You should not reserve identifiers like this for built-in limit/precision macros. See InitPreprocessor.cpp to see how it's supposed to be done.

We have implemented all of these (at least for DSP-C, but it should not be difficult to port this to Embedded-C) in our downstream port. You will also need routines to print fixed-point numbers for the rest of the macros in 7.18a.3. We can provide these patches on request.

Ka-Ka added a subscriber: Ka-Ka.May 23 2018, 1:08 AM