|
| 1 | +================ |
| 2 | +StdFix Functions |
| 3 | +================ |
| 4 | + |
| 5 | +.. include:: ../check.rst |
| 6 | + |
| 7 | +Standards |
| 8 | +--------- |
| 9 | + |
| 10 | +- stdfix.h is specified in the `ISO/IEC TR 18037:2008 <https://www.iso.org/standard/51126.html>`_, |
| 11 | + C extensions to support embedded processors . |
| 12 | + |
| 13 | +- Its `specifications <https://standards.iso.org/ittf/PubliclyAvailableStandards/c051126_ISO_IEC_TR_18037_2008.zip>`_. |
| 14 | + |
| 15 | +--------------- |
| 16 | +Source location |
| 17 | +--------------- |
| 18 | + |
| 19 | +- The main source for fixed-point functions is located at: |
| 20 | + ``libc/src/stdfix`` with subdirectories for internal implementations. |
| 21 | + |
| 22 | +--------------------- |
| 23 | +Implementation Status |
| 24 | +--------------------- |
| 25 | + |
| 26 | +Requirements |
| 27 | +============ |
| 28 | + |
| 29 | +- In order to build LLVM libc to support fixed-point arithmetics, we need the |
| 30 | + compiler to support the basic fixed-point types `_Fract` and `_Accum` in |
| 31 | + C++. |
| 32 | + |
| 33 | +- For the users to be able to use the generated headers, their compiler needs |
| 34 | + to support `_Fract` and `_Accum` types in C or C++. |
| 35 | + |
| 36 | +- This compiler support is checked at the beginning of |
| 37 | + `libc/include/llvm-libc-macros/stdfix-macros.h <https://github.com/llvm/llvm-project/tree/main/libc/include/llvm-libc-macros/stdfix-macros.h>`_. |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +Predefined Macros |
| 42 | +================= |
| 43 | + |
| 44 | +- We use the macro `LIBC_COMPILER_HAS_FIXED_POINT` to specify whether the |
| 45 | + compiler support the fixed-point types. |
| 46 | + |
| 47 | +- Other predefined precision macros specified in section 7.18a.3 are defined |
| 48 | + 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>`_ |
| 49 | + using the default configuration of `typical desktop processor` in section |
| 50 | + A.3. |
| 51 | + |
| 52 | + |
| 53 | +Fixed-point Arithmetics |
| 54 | +======================= |
| 55 | + |
| 56 | ++---------------+------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------+ |
| 57 | +| Function Name | _Fract (r) | _Accum (k) | |
| 58 | +| +------------------------------+----------------------------+------------------------------+------------------------------+----------------------------+------------------------------+ |
| 59 | +| | short (hr) | _ (r) | long (lr) | short (hk) | _ (k) | long (lk) | |
| 60 | +| +----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 61 | +| | unsigned (uhr) | signed (hr) | unsigned (ur) | signed (r) | unsigned (ulr) | signed (lr) | unsigned (uhk) | signed (hk) | unsigned (uk) | signed (k) | unsigned (ulk) | signed (lk) | |
| 62 | ++===============+================+=============+===============+============+================+=============+================+=============+===============+============+================+=============+ |
| 63 | +| abs | | | | | | | | | | | | | |
| 64 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 65 | +| bits\* | | | | | | | | | | | | | |
| 66 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 67 | +| \*bits | | | | | | | | | | | | | |
| 68 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 69 | +| countls | | | | | | | | | | | | | |
| 70 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 71 | +| divi | | | | | | | | | | | | | |
| 72 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 73 | +| idivi | | | | | | | | | | | | | |
| 74 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 75 | +| muli | | | | | | | | | | | | | |
| 76 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 77 | +| rdivi | | | | | | | | | | | | | |
| 78 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 79 | +| round | | | | | | | | | | | | | |
| 80 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 81 | +| sqrt | | | | | | | | | | | | | |
| 82 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 83 | + |
| 84 | +================== ========= |
| 85 | +Type Generic Macro Available |
| 86 | +================== ========= |
| 87 | +absfx |
| 88 | +countlsfx |
| 89 | +roundfx |
| 90 | +================== ========= |
| 91 | + |
| 92 | + |
| 93 | +Higher math functions |
| 94 | +===================== |
| 95 | + |
| 96 | ++---------------+------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------+ |
| 97 | +| Function Name | _Fract (r) | _Accum (k) | |
| 98 | +| +------------------------------+----------------------------+------------------------------+------------------------------+----------------------------+------------------------------+ |
| 99 | +| | short (hr) | _ (r) | long (lr) | short (hk) | _ (k) | long (lk) | |
| 100 | +| +----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 101 | +| | unsigned (uhr) | signed (hr) | unsigned (ur) | signed (r) | unsigned (ulr) | signed (lr) | unsigned (uhk) | signed (hk) | unsigned (uk) | signed (k) | unsigned (ulk) | signed (lk) | |
| 102 | ++===============+================+=============+===============+============+================+=============+================+=============+===============+============+================+=============+ |
| 103 | +| cos | | | | | | | | | | | | | |
| 104 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 105 | +| exp | | | | | | | | | | | | | |
| 106 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 107 | +| log | | | | | | | | | | | | | |
| 108 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 109 | +| sin | | | | | | | | | | | | | |
| 110 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 111 | +| tan | | | | | | | | | | | | | |
| 112 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 113 | + |
| 114 | + |
| 115 | +Conversion Functions |
| 116 | +==================== |
| 117 | + |
| 118 | ++---------------+------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------+ |
| 119 | +| Function Name | _Fract (r) | _Accum (k) | |
| 120 | +| +------------------------------+----------------------------+------------------------------+------------------------------+----------------------------+------------------------------+ |
| 121 | +| | short (hr) | _ (r) | long (lr) | short (hk) | _ (k) | long (lk) | |
| 122 | +| +----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 123 | +| | unsigned (uhr) | signed (hr) | unsigned (ur) | signed (r) | unsigned (ulr) | signed (lr) | unsigned (uhk) | signed (hk) | unsigned (uk) | signed (k) | unsigned (ulk) | signed (lk) | |
| 124 | ++===============+================+=============+===============+============+================+=============+================+=============+===============+============+================+=============+ |
| 125 | +| fprintf | | | | | | | | | | | | | |
| 126 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 127 | +| fscanf | | | | | | | | | | | | | |
| 128 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 129 | +| strtofx | | | | | | | | | | | | | |
| 130 | ++---------------+----------------+-------------+---------------+------------+----------------+-------------+----------------+-------------+---------------+------------+----------------+-------------+ |
| 131 | + |
| 132 | + |
| 133 | +Warnings |
| 134 | +======== |
| 135 | + |
| 136 | +This is currently a work-in-progress, its headers, macros, and ABI are still unstable, and might be modified. |
0 commit comments