[PATCH] longlong: Update the checks for "mul" on RISC-V

Palmer Dabbelt palmer@rivosinc.com
Thu Jul 21 19:03:30 GMT 2022


I was poking around the RISC-V C API docs while reading the Zmmul code.
I'd thought that "__riscv_mul" meant "the multiply instructions are
available", but it's actually defined as "the M extension is
available".  Those used to be the same, but with Zmmul they're now
different.  Additionally "__riscv_mul" has been deprecated in favor of
"__riscv_m".

This patch updates the #ifdef test to match the current C API spec,
while retaining compatibility for old toolchains that only set
"__riscv_mul".
---
It's not super clear that keeping glibc support for non-M systems is
even useful, as we're now mandating M in Linux, but what's there might
as well match the docs.

We don't have the zmmul code upstream anywhere else yet, so probably
best to hold off merging this until things get sorted out elsewhere.
---
 stdlib/longlong.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/stdlib/longlong.h b/stdlib/longlong.h
index 9b89469ac2..fe3f1989af 100644
--- a/stdlib/longlong.h
+++ b/stdlib/longlong.h
@@ -1053,7 +1053,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #endif
 
 #if defined(__riscv)
-#ifdef __riscv_mul
+#if defined(__riscv_mul) || defined(__riscv_m) || defined(__riscv_zmmul)
 #define __umulsidi3(u,v) ((UDWtype)(UWtype)(u) * (UWtype)(v))
 #define __muluw3(a, b) ((UWtype)(a) * (UWtype)(b))
 #else
@@ -1076,7 +1076,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
                   : "ra", "a2", "a3"); \
     __op0; \
   })
-#endif /* __riscv_mul */
+#endif /* __riscv_mul || __riscv_m || __riscv_zmmul */
 #define umul_ppmm(w1, w0, u, v) \
   do { \
     UWtype __x0, __x1, __x2, __x3; \
-- 
2.34.1



More information about the Libc-alpha mailing list