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

Message ID 20220721190330.9739-1-palmer@rivosinc.com
State Changes Requested, archived
Headers
Series longlong: Update the checks for "mul" on RISC-V |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Palmer Dabbelt July 21, 2022, 7:03 p.m. UTC
  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(-)
  

Comments

Andreas Schwab July 21, 2022, 7:37 p.m. UTC | #1
On Jul 21 2022, Palmer Dabbelt wrote:

> 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.

longlong.h should be kept in sync with gcc, so it should not assume
linux-only.  It used to be shared with gmp as well, but they have
diverted quite a bit by now.
  
Palmer Dabbelt July 21, 2022, 7:48 p.m. UTC | #2
On Thu, 21 Jul 2022 12:37:25 PDT (-0700), schwab@linux-m68k.org wrote:
> On Jul 21 2022, Palmer Dabbelt wrote:
>
>> 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.
>
> longlong.h should be kept in sync with gcc, so it should not assume
> linux-only.  It used to be shared with gmp as well, but they have
> diverted quite a bit by now.

Thanks, I didn't know/remember that.  Looks like it's supposed to be 
updated in GCC first, so we can do it when we do the Zmmul support which 
makes things a bit easier.
  

Patch

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; \