Skip to content
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

Implement fixed point bitsfx functions in llvm-libc #113359

Closed
PiJoules opened this issue Oct 22, 2024 · 13 comments · Fixed by #128413 · May be fixed by #116599
Closed

Implement fixed point bitsfx functions in llvm-libc #113359

PiJoules opened this issue Oct 22, 2024 · 13 comments · Fixed by #128413 · May be fixed by #116599
Assignees
Labels
good first issue https://github.com/llvm/llvm-project/contribute libc

Comments

@PiJoules
Copy link
Contributor

Some fixed point functions from ISO 18037 are implemented in llvm-libc, but not all of them are implemented. The various bitsfx functions should also be added. Copying from the extension:

4.1.7.4 The bitwise fixed-point to integer conversion functions

The bitwise fixed-point to integer conversion functions bitsfx, where fx stands for one of hr, r, lr, hk, k, lk, uhr, ur, ulr, uhk, uk or ulk, take one fixed-point type argument (corresponding to fx); the type of the function is an implementation-defined integer type int_fx_t (for signed fixed-point types) or uint_fx_t (for unsigned fixed-point types), defined in the <stdfix.h> headerfile, that is large enough to hold all the bits in the fixed-point type.

The bitwise fixed-point to integer conversion functions return an integer value equal to the fixedpoint value of the argument multiplied by 2^F, where F is the number of fractional bits in the fixed point type. The result type is an integer type big enough to hold all valid result values for the given fixed-point argument type. For example, if the fract type has 15 fractional bits, then after the declaration

  fract a = 0.5;

the value of bitsr(a) is 0.5 * 2^15 = 0x4000.

These can first be implemented as __builtin_* functions in clang then llvm-libc can provide the wrappers for each of the builtin functions.

@PiJoules PiJoules added good first issue https://github.com/llvm/llvm-project/contribute clang Clang issues not falling into any other category libc labels Oct 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2024

@llvm/issue-subscribers-libc

Author: None (PiJoules)

Some fixed point functions from ISO 18037 are implemented in llvm-libc, but not all of them are implemented. The various bits`fx` functions should also be added. Copying from the extension:
4.1.7.4 The bitwise fixed-point to integer conversion functions

The bitwise fixed-point to integer conversion functions bitsfx, where fx stands for one of hr, r, lr, hk, k, lk, uhr, ur, ulr, uhk, uk or ulk, take one fixed-point type argument (corresponding to fx); the type of the function is an implementation-defined integer type int_fx_t (for signed fixed-point types) or uint_fx_t (for unsigned fixed-point types), defined in the &lt;stdfix.h&gt; headerfile, that is large enough to hold all the bits in the fixed-point type.

The bitwise fixed-point to integer conversion functions return an integer value equal to the fixedpoint value of the argument multiplied by 2^F, where F is the number of fractional bits in the fixed point type. The result type is an integer type big enough to hold all valid result values for the given fixed-point argument type. For example, if the fract type has 15 fractional bits, then after the declaration

  fract a = 0.5;

the value of bitsr(a) is 0.5 * 2^15 = 0x4000.

These can first be implemented as __builtin_* functions in clang then llvm-libc can provide the wrappers for each of the builtin functions.

@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2024

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:

  1. 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.
  2. 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.
  3. Fix the issue locally.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. 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.

@llvmbot
Copy link
Member

llvmbot commented Oct 22, 2024

@llvm/issue-subscribers-good-first-issue

Author: None (PiJoules)

Some fixed point functions from ISO 18037 are implemented in llvm-libc, but not all of them are implemented. The various bits`fx` functions should also be added. Copying from the extension:
4.1.7.4 The bitwise fixed-point to integer conversion functions

The bitwise fixed-point to integer conversion functions bitsfx, where fx stands for one of hr, r, lr, hk, k, lk, uhr, ur, ulr, uhk, uk or ulk, take one fixed-point type argument (corresponding to fx); the type of the function is an implementation-defined integer type int_fx_t (for signed fixed-point types) or uint_fx_t (for unsigned fixed-point types), defined in the &lt;stdfix.h&gt; headerfile, that is large enough to hold all the bits in the fixed-point type.

The bitwise fixed-point to integer conversion functions return an integer value equal to the fixedpoint value of the argument multiplied by 2^F, where F is the number of fractional bits in the fixed point type. The result type is an integer type big enough to hold all valid result values for the given fixed-point argument type. For example, if the fract type has 15 fractional bits, then after the declaration

  fract a = 0.5;

the value of bitsr(a) is 0.5 * 2^15 = 0x4000.

These can first be implemented as __builtin_* functions in clang then llvm-libc can provide the wrappers for each of the builtin functions.

@EugeneZelenko EugeneZelenko added clang:headers Headers provided by Clang, e.g. for intrinsics and removed clang Clang issues not falling into any other category labels Oct 22, 2024
@braw-lee
Copy link
Contributor

I can try this, assign me pls

@braw-lee
Copy link
Contributor

also, are there any previously merged PR's that I can refer on how to implement libc functions?
@PiJoules

@lntue
Copy link
Contributor

lntue commented Oct 29, 2024

also, are there any previously merged PR's that I can refer on how to implement libc functions? @PiJoules

Maybe something like #84391 (modulo the math part) to add new functions and tests to the stdfix.h header.

@PiJoules
Copy link
Contributor Author

PiJoules commented Oct 29, 2024

Initially I was thinking this could be a __builtin_ function that would be exposed through llvm-libc but I think from #113357 (comment), it would also work to just have this function do a cpp::bit_cast and avoid having to do clang-side changes.

Thanks for taking this on also!

@PiJoules
Copy link
Contributor Author

@braw-lee if you're still working on this, you might be able to leverage some of the stuff added in #114912

@braw-lee
Copy link
Contributor

oh thanks, that will be helpful

@erichkeane
Copy link
Collaborator

@braw-lee : Your original patch got a lot of feedback that you haven't responded to. Are you intending to continue working on it, or should we mark this as 'unassigned' so someone else can pick up the effort?

@krishna2803
Copy link
Contributor

hi! @PiJoules @erichkeane i would like to take this up

@krishna2803
Copy link
Contributor

@PiJoules @erichkeane

@lntue lntue assigned krishna2803 and unassigned braw-lee Feb 17, 2025
@PiJoules
Copy link
Contributor Author

hi! @PiJoules @erichkeane i would like to take this up

Yup, thanks for taking this up! Sorry for the delayed response also

@lntue lntue closed this as completed in f6bfa33 Feb 27, 2025
@EugeneZelenko EugeneZelenko removed the clang:headers Headers provided by Clang, e.g. for intrinsics label Feb 27, 2025
jph-13 pushed a commit to jph-13/llvm-project that referenced this issue Feb 28, 2025
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this issue Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue https://github.com/llvm/llvm-project/contribute libc
Projects
None yet
7 participants