-
Notifications
You must be signed in to change notification settings - Fork 13.5k
feat: implement template meta muli #138654
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-libc Author: Naveen Kumar (naveen106) Changesfixing issue #129123. More to be done. Not completed. Full diff: https://github.com/llvm/llvm-project/pull/138654.diff 2 Files Affected:
diff --git a/CppProperties.json b/CppProperties.json
new file mode 100644
index 0000000000000..659bf4ea9068f
--- /dev/null
+++ b/CppProperties.json
@@ -0,0 +1,21 @@
+{
+ "configurations": [
+ {
+ "inheritEnvironments": [
+ "msvc_x86"
+ ],
+ "name": "x86-Debug",
+ "includePath": [
+ "${env.INCLUDE}",
+ "${workspaceRoot}\\**"
+ ],
+ "defines": [
+ "WIN32",
+ "_DEBUG",
+ "UNICODE",
+ "_UNICODE"
+ ],
+ "intelliSenseMode": "windows-msvc-x86"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/libc/src/__support/fixed_point/fx_bits.h b/libc/src/__support/fixed_point/fx_bits.h
index b05f46bd34660..974bb8a8f79bd 100644
--- a/libc/src/__support/fixed_point/fx_bits.h
+++ b/libc/src/__support/fixed_point/fx_bits.h
@@ -194,6 +194,26 @@ countls(T f) {
return cpp::countl_zero(value_bits) - FXRep::SIGN_LEN;
}
+// Multiply an integer with a fixed-point value and return an integer.
+// Overflow behavior is undefined, per ISO 8037.
+template <typename FixedPointT, typename IntT>
+LIBC_INLINE constexpr cpp::enable_if_t <cpp::is_fixed_point_v<FixedPointT> && cpp::is_integral_v<IntT>, IntT >
+muli(FixedPointT f, IntT i) {
+
+ using FXRep = FXRep<FixedPointT>;
+ using BitType = typename FXRep::StorageType;
+ BitType fixed_bits = FXBits<FixedPointT>(f).get_bits();
+
+ // Safely promote types to unsigned for multiplication to avoid signed overflow
+ using UnsignedIntT = cpp::make_unsigned_t<IntT>;
+ using UnsignedFixedT = cpp::make_unsigned_t<BitType>;
+
+ auto product = static_cast<UnsignedIntT>(i) * static_cast<UnsignedFixedT>(fixed_bits);
+
+ // Shift back to remove fractional bits
+ return static_cast<IntT>(product >> FXRep::FRAC_LEN);
+}
+
// fixed-point to integer conversion
template <typename T, typename XType>
LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_fixed_point_v<T>, XType>
|
The implementation looks ok, but could you add tests and the relevant build changes so we can ensure it works properly? You can follow what the other fixed point patches do and replace the names appropriately (#133005 for example). |
5927574
to
11aa948
Compare
@PiJoules |
fixing issue #129123. More to be done. Not completed.