From: Joel Sing Date: Mon, 9 Sep 2024 15:16:14 +0000 (+1000) Subject: test/codegen: add combined conversion and shift tests X-Git-Tag: go1.25rc1~608 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6bf95d40bb9b0ad90315544d2581e1540a040542;p=gostls13.git 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 Reviewed-by: Mark Ryan LUCI-TryBot-Result: Go LUCI Reviewed-by: David Chase Reviewed-by: Carlos Amedee --- 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 +}