From d0cda4d95f4c889fdb4988750f704604553c35a4 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Thu, 28 Apr 2022 23:20:53 +0800 Subject: [PATCH] internal/bytealg: mask high bit for riscv64 regabi This CL masks byte params which high bits(~0xff) is unused for riscv64 regabi. Currently the compiler only guarantees the low bits contains value. Change-Id: I6dd6c867e60d2143fefde92c866f78c4b007a2f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/402894 Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Run-TryBot: mzh Reviewed-by: Benny Siegert --- src/internal/bytealg/count_riscv64.s | 3 ++- src/internal/bytealg/indexbyte_riscv64.s | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/internal/bytealg/count_riscv64.s b/src/internal/bytealg/count_riscv64.s index 1e081e2c8c..a15d07d768 100644 --- a/src/internal/bytealg/count_riscv64.s +++ b/src/internal/bytealg/count_riscv64.s @@ -15,7 +15,7 @@ TEXT ·Count(SB),NOSPLIT,$0-40 // X11 = b_len // X12 = b_cap (unused) // X13 = byte to count (want in X12) - MOV X13, X12 + AND $0xff, X13, X12 #endif MOV ZERO, X14 // count ADD X10, X11 // end @@ -45,6 +45,7 @@ TEXT ·CountString(SB),NOSPLIT,$0-32 // X10 = s_base // X11 = s_len // X12 = byte to count + AND $0xff, X12 MOV ZERO, X14 // count ADD X10, X11 // end diff --git a/src/internal/bytealg/indexbyte_riscv64.s b/src/internal/bytealg/indexbyte_riscv64.s index e9d3e6be39..a20396592b 100644 --- a/src/internal/bytealg/indexbyte_riscv64.s +++ b/src/internal/bytealg/indexbyte_riscv64.s @@ -15,6 +15,7 @@ TEXT ·IndexByte(SB),NOSPLIT,$0-40 // X11 = b_len // X12 = b_cap (unused) // X13 = byte to find + AND $0xff, X13 MOV X10, X12 // store base for later ADD X10, X11 // end ADD $-1, X10 @@ -47,6 +48,7 @@ TEXT ·IndexByteString(SB),NOSPLIT,$0-32 // X10 = b_base // X11 = b_len // X12 = byte to find + AND $0xff, X12 MOV X10, X13 // store base for later ADD X10, X11 // end ADD $-1, X10 -- 2.50.0