[libc-commits] [libc] [libc][stdfix] Implement fixed point bitsfx functions in llvm-libc (PR #116599)
via libc-commits
libc-commits at lists.llvm.org
Tue Nov 26 11:46:22 PST 2024
================
@@ -0,0 +1,19 @@
+//===-- Implementation of bitshk function ---------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "bitshk.h"
+#include "src/__support/common.h"
+#include "src/__support/fixed_point/fx_bits.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+LLVM_LIBC_FUNCTION(int_hk_t, bitshk, (short accum x)) {
+ return cpp::bit_cast<int_hk_t, short accum>(x);
----------------
PiJoules wrote:
Hmm, so I didn't notice this with the fxbits patch, but I think a simple bitcast won't suffice if the fixed point representation has padding bits since the padding could be any value. By default the only upstream representation for fx types doesn't use padding, but anyone use `-fpadding-on-unsigned-fixed-point` might be affected by this. I believe this could be addressed by just masking out the padding bits for the unsigned types after the bit_cast.
https://github.com/llvm/llvm-project/pull/114318/files#diff-aa94f9761108563a2750a9c9be57772371129073ff15c1b4e0a9ab6790a2c260R55 added the mask in `FXBits` which could be borrowed for this patch.
https://github.com/llvm/llvm-project/pull/116599
More information about the libc-commits
mailing list