Implement fixed point fxbits functions in llvm-libc
Some fixed point functions from ISO 18037 are implemented in llvm-libc, but not all of them are implemented. The various fxbits functions should also be added. Copying from the extension:
4.1.7.5 The bitwise integer to fixed-point conversion functions
The bitwise integer to fixed-point conversion functions fxbits, where fx stands for one of hr, r, lr, hk, k, lk, uhr, ur, ulr, uhk, uk or ulk, take one argument with type int_fx_t or uint_fx_t, the result type is a fixed-point type (corresponding to fx).
The bitwise fixed-point to integer conversion functions return an fixed-point value equal to the integer value of the argument divided by 2^F, where F is the number of fractional bits in the fixedpoint result type of the function. For example, if fract has 15 fractional bits, then the value of rbits(0x2000) is 0.25.
These can first be implemented as __builtin_* functions in clang then llvm-libc can provide the wrappers for each of the builtin functions.
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
- Check that no other contributor has already been assigned to this issue. If you believe that no one is actually working on it despite an assignment, ping the person. After one week without a response, the assignee may be changed.
- In the comments of this issue, request for it to be assigned to you, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
- Fix the issue locally.
- Run the test suite locally. Remember that the subdirectories under
test/create fine-grained testing targets, so you can e.g. usemake check-clang-astto only run Clang's AST tests. - Create a Git commit.
- Run
git clang-format HEAD~1to format your changes. - Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.
@llvm/issue-subscribers-good-first-issue
Author: None (PiJoules)
4.1.7.5 The bitwise integer to fixed-point conversion functions
The bitwise integer to fixed-point conversion functions fxbits, where fx stands for one of hr, r, lr, hk, k, lk, uhr, ur, ulr, uhk, uk or ulk, take one argument with type int_fx_t or uint_fx_t, the result type is a fixed-point type (corresponding to fx).
The bitwise fixed-point to integer conversion functions return an fixed-point value equal to the integer value of the argument divided by 2^F, where F is the number of fractional bits in the fixedpoint result type of the function. For example, if fract has 15 fractional bits, then the value of rbits(0x2000) is 0.25.
These can first be implemented as __builtin_* functions in clang then llvm-libc can provide the wrappers for each of the builtin functions.
@llvm/issue-subscribers-libc
Author: None (PiJoules)
4.1.7.5 The bitwise integer to fixed-point conversion functions
The bitwise integer to fixed-point conversion functions fxbits, where fx stands for one of hr, r, lr, hk, k, lk, uhr, ur, ulr, uhk, uk or ulk, take one argument with type int_fx_t or uint_fx_t, the result type is a fixed-point type (corresponding to fx).
The bitwise fixed-point to integer conversion functions return an fixed-point value equal to the integer value of the argument divided by 2^F, where F is the number of fractional bits in the fixedpoint result type of the function. For example, if fract has 15 fractional bits, then the value of rbits(0x2000) is 0.25.
These can first be implemented as __builtin_* functions in clang then llvm-libc can provide the wrappers for each of the builtin functions.
Hi, I'd like to take a crack at this. Please assign it to me.
Hello, I am currently familiarizing myself with the llvm project, and came across this issue. I had a question regarding the ISO18037 descriptions for fixed-point-to-integer, and integer-to-fixed-point:
Section 4.1.7.4 defines the bitwise conversion functions for fixed point to integer, while 4.1.7.5 defines those for integer to fixed point.
Though, the 2nd part of 4.1.7.5 mentions "The bitwise fixed-point to integer conversion functions return an fixed-point value equal to the integer value of the argument divided by 2F, where F is the number of fractional bits in the fixed- point result type of the function"
I may be overlooking something, but i am wondering if this is a typo in ISO 18037. It seems this part of 4.1.7.5 should read "the bitwise integer to fixed point conversion returns a fixed point...."
The functionality lines up with what the integer to fixed-point should be (return an fixed-point value equal to the integer value of the argument divided by 2F, where F is the number of fractional bits in the fixed-point)
Either way i would love to work on this issue, if it can be assigned to me.
I will look more into the fixed point functions that have already been implemented this week to see if i am missing something.
It appears this might be a copy and paste issue, as a part of section 4.1.7.4 reads "return an integer value" while 4.1.7.5 reads "return an fixed point" (the use of "an" vs "a" caught my eye).
Hello, I am currently familiarizing myself with the llvm project, and came across this issue. I had a question regarding the ISO18037 descriptions for fixed-point-to-integer, and integer-to-fixed-point:
Section 4.1.7.4 defines the bitwise conversion functions for fixed point to integer, while 4.1.7.5 defines those for integer to fixed point.
Though, the 2nd part of 4.1.7.5 mentions "The bitwise fixed-point to integer conversion functions return an fixed-point value equal to the integer value of the argument divided by 2F, where F is the number of fractional bits in the fixed- point result type of the function"
I may be overlooking something, but i am wondering if this is a typo in ISO 18037. It seems this part of 4.1.7.5 should read "the bitwise integer to fixed point conversion returns a fixed point...."
The functionality lines up with what the integer to fixed-point should be (return an fixed-point value equal to the integer value of the argument divided by 2F, where F is the number of fractional bits in the fixed-point)
Either way i would love to work on this issue, if it can be assigned to me.
I will look more into the fixed point functions that have already been implemented this week to see if i am missing something.
It appears this might be a copy and paste issue, as a part of section 4.1.7.4 reads "return an integer value" while 4.1.7.5 reads "return an fixed point" (the use of "an" vs "a" caught my eye).
Hi @joedubill , thanks for your interest in this issue, but @smallp-o-p has commented earlier, and so I'm going to assign this issue to @smallp-o-p if you don't mind.
OTOH, since C23 stdbit added a lot of bitwise functions for unsigned integer types (https://libc.llvm.org/stdbit.html#functions), I think we can expand / add similar family of functions for unsigned fixed point type. If you are interested, you can create an issue to add something like stdc_trailing_zeros_u* functions for fixed point types and tag me to assign it to you. Thanks,
@lntue No problem! I'll take a look at these functions this week, thanks.
Still, there may be a typo/ discrepancy in section 4.1.7.5.
4.1.7.4 is for fixed point to integer, and 4.1.7.5 is for integer to fixed point, yet there is an inconsistency in their definitions.
Also, a fixed point to integer function should return an integer, not a fixed point.
I do believe there is a discrepancy here, small, but important.
This will be useful for @smallp-o-p as well
Hello, I am currently familiarizing myself with the llvm project, and came across this issue. I had a question regarding the ISO18037 descriptions for fixed-point-to-integer, and integer-to-fixed-point:
Section 4.1.7.4 defines the bitwise conversion functions for fixed point to integer, while 4.1.7.5 defines those for integer to fixed point.
Though, the 2nd part of 4.1.7.5 mentions "The bitwise fixed-point to integer conversion functions return an fixed-point value equal to the integer value of the argument divided by 2F, where F is the number of fractional bits in the fixed- point result type of the function"
I may be overlooking something, but i am wondering if this is a typo in ISO 18037. It seems this part of 4.1.7.5 should read "the bitwise integer to fixed point conversion returns a fixed point...."
Good catch. Yeah I also think this is a typo.
I also agree that it's a typo, the second section should be bitwise integer to fixed-point conversion. Furthermore it also describes an example of using the _Fract implementation of fxbits.
FWIW I emailed some ISO ppl and they also confirmed it's a typo. Also should this issue be closed now that the relevant patches landed?