diff options
| author | Joel Sing <joel@sing.id.au> | 2024-09-10 01:16:14 +1000 |
|---|---|---|
| committer | Joel Sing <joel@sing.id.au> | 2025-03-25 06:53:49 -0700 |
| commit | 6bf95d40bb9b0ad90315544d2581e1540a040542 (patch) | |
| tree | ffee4951c5dd6db0e68f4d5f6d44768e1f8fc14e /test/codegen | |
| parent | fd0805b660890d791a7bcfb76491dd6f87b69641 (diff) | |
| download | go-6bf95d40bb9b0ad90315544d2581e1540a040542.tar.xz | |
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>
Diffstat (limited to 'test/codegen')
| -rw-r--r-- | test/codegen/shift.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/codegen/shift.go b/test/codegen/shift.go index b7819d236f..98d621d352 100644 --- a/test/codegen/shift.go +++ b/test/codegen/shift.go @@ -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 +} |
