-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc][stdfix] Generate stdfix.h header with fixed point precision macros according to ISO/IEC TR 18037:2008 standard, and add fixed point type support detection. #81255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
61cc872
[libc][stdfix] Generate stdfix.h header with fixed point precision ma…
lntue a8ebbc1
Move to stdc_ext.td and remove test file.
lntue 9fdc037
Address comments.
lntue 1eceaf6
Address comments.
lntue dd25d98
Add documentations for stdfix.
lntue 8d2527f
Fix docs.
lntue e2a9af5
Update the standard name and links.
lntue fd42032
Fix format.
lntue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "include/llvm-libc-macross/stdfix_macros.h" | ||
|
||
#ifndef LIBC_COMPILER_HAS_FIXED_POINT | ||
#error unsupported | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
================ | ||
StdFix Functions | ||
================ | ||
|
||
.. include:: ../check.rst | ||
|
||
Standards | ||
--------- | ||
|
||
- stdfix.h is specified in the `ISO/IEC TR 18037:2008 <https://www.iso.org/standard/51126.html>`_, | ||
C extensions to support embedded processors . | ||
|
||
- Its `specifications <https://standards.iso.org/ittf/PubliclyAvailableStandards/c051126_ISO_IEC_TR_18037_2008.zip>`_. | ||
|
||
--------------- | ||
Source location | ||
--------------- | ||
|
||
- The main source for fixed-point functions is located at: | ||
``libc/src/stdfix`` with subdirectories for internal implementations. | ||
|
||
--------------------- | ||
Implementation Status | ||
--------------------- | ||
|
||
Requirements | ||
============ | ||
|
||
- In order to build LLVM libc to support fixed-point arithmetics, we need the | ||
compiler to support the basic fixed-point types `_Fract` and `_Accum` in | ||
C++. | ||
|
||
- For the users to be able to use the generated headers, their compiler needs | ||
to support `_Fract` and `_Accum` types in C or C++. | ||
|
||
- This compiler support is checked at the beginning of | ||
`libc/include/llvm-libc-macros/stdfix-macros.h <https://github.com/llvm/llvm-project/tree/main/libc/include/llvm-libc-macros/stdfix-macros.h>`_. | ||
|
||
|
||
|
||
Predefined Macros | ||
================= | ||
|
||
- We use the macro `LIBC_COMPILER_HAS_FIXED_POINT` to specify whether the | ||
compiler support the fixed-point types. | ||
|
||
- Other predefined precision macros specified in section 7.18a.3 are defined | ||
in `libc/include/llvm-libc-macros/stdfix-macros.h <https://github.com/llvm/llvm-project/tree/main/libc/include/llvm-libc-macros/stdfix-macros.h>`_ | ||
using the default configuration of `typical desktop processor` in section | ||
A.3. | ||
|
||
|
||
Fixed-point Arithmetics | ||
======================= | ||
|
||
+---------------+------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------+ | ||
| Function Name | _Fract (r) | _Accum (k) | | ||
| +------------------------------+----------------------------+------------------------------+------------------------------+----------------------------+------------------------------+ | ||
| | short (hr) | _ (r) | long (lr) | short (hk) | _ (k) | long (lk) | | ||
| +----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| | unsigned (uhr) | signed (hr) | unsigned (ur) | signed (r) | unsigned (ulr) | signed (lr) | unsigned (uhk) | signed (hk) | unsigned (uk) | signed (k) | unsigned (ulk) | signed (lk) | | ||
+===============+================+=============+===============+============+================+=============+================+=============+===============+============+================+=============+ | ||
| abs | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| bits\* | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| \*bits | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| countls | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| divi | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| idivi | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| muli | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| rdivi | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| round | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| sqrt | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
|
||
================== ========= | ||
Type Generic Macro Available | ||
================== ========= | ||
absfx | ||
countlsfx | ||
roundfx | ||
================== ========= | ||
|
||
|
||
Higher math functions | ||
===================== | ||
|
||
+---------------+------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------+ | ||
| Function Name | _Fract (r) | _Accum (k) | | ||
| +------------------------------+----------------------------+------------------------------+------------------------------+----------------------------+------------------------------+ | ||
| | short (hr) | _ (r) | long (lr) | short (hk) | _ (k) | long (lk) | | ||
| +----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| | unsigned (uhr) | signed (hr) | unsigned (ur) | signed (r) | unsigned (ulr) | signed (lr) | unsigned (uhk) | signed (hk) | unsigned (uk) | signed (k) | unsigned (ulk) | signed (lk) | | ||
+===============+================+=============+===============+============+================+=============+================+=============+===============+============+================+=============+ | ||
| cos | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| exp | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| log | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| sin | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| tan | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
|
||
|
||
Conversion Functions | ||
==================== | ||
|
||
+---------------+------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------+ | ||
| Function Name | _Fract (r) | _Accum (k) | | ||
| +------------------------------+----------------------------+------------------------------+------------------------------+----------------------------+------------------------------+ | ||
| | short (hr) | _ (r) | long (lr) | short (hk) | _ (k) | long (lk) | | ||
| +----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| | unsigned (uhr) | signed (hr) | unsigned (ur) | signed (r) | unsigned (ulr) | signed (lr) | unsigned (uhk) | signed (hk) | unsigned (uk) | signed (k) | unsigned (ulk) | signed (lk) | | ||
+===============+================+=============+===============+============+================+=============+================+=============+===============+============+================+=============+ | ||
| fprintf | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| fscanf | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
| strtofx | | | | | | | | | | | | | | ||
+---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ | ||
|
||
|
||
Warnings | ||
======== | ||
|
||
This is currently a work-in-progress, its headers, macros, and ABI are still unstable, and might be modified. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,3 +227,9 @@ add_macro_header( | |
HDR | ||
inttypes-macros.h | ||
) | ||
|
||
add_macro_header( | ||
stdfix_macros | ||
HDR | ||
stdfix-macros.h | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.