test/codegen: add combined conversion and shift tests

This adds tests for type conversion and shifts, detailing various
poor bad code generation that currently exists for riscv64. This
will be addressed in future CLs.

Change-Id: Ie1d366dfe878832df691600f8500ef383da92848
Reviewed-on: https://go-review.googlesource.com/c/go/+/615678
Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
Reviewed-by: Mark Ryan <markdryan@rivosinc.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
This commit is contained in:
Joel Sing 2024-09-10 01:16:14 +10:00
parent fd0805b660
commit 6bf95d40bb

View File

@ -592,3 +592,67 @@ func checkLeftShiftWithAddition(a int64, b int64) int64 {
a = a + b<<3
return a
}
//
// Convert and shift.
//
func rsh64Uto32U(v uint64) uint32 {
x := uint32(v)
// riscv64:"MOVWU"
if x > 8 {
// riscv64:"SRLIW",-"MOVWU",-"SLLI"
x >>= 2
}
return x
}
func rsh64Uto16U(v uint64) uint16 {
x := uint16(v)
// riscv64:"MOVHU"
if x > 8 {
// riscv64:"SLLI","SRLI"
x >>= 2
}
return x
}
func rsh64Uto8U(v uint64) uint8 {
x := uint8(v)
// riscv64:"MOVBU"
if x > 8 {
// riscv64:"SLLI","SRLI"
x >>= 2
}
return x
}
func rsh64to32(v int64) int32 {
x := int32(v)
// riscv64:"MOVW"
if x > 8 {
// riscv64:"SRAIW",-"MOVW",-"SLLI"
x >>= 2
}
return x
}
func rsh64to16(v int64) int16 {
x := int16(v)
// riscv64:"MOVH"
if x > 8 {
// riscv64:"SLLI","SRAI"
x >>= 2
}
return x
}
func rsh64to8(v int64) int8 {
x := int8(v)
// riscv64:"MOVB"
if x > 8 {
// riscv64:"SLLI","SRAI"
x >>= 2
}
return x
}