From 2b50ab2aee75d3c361fcd1eb39e830e2e73056b6 Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Mon, 7 Dec 2020 19:15:15 +0800 Subject: cmd/compile: optimize single-precision floating point square root Add generic rule to rewrite the single-precision square root expression with one single-precision instruction. The optimization will reduce two times of precision converting between double-precision and single-precision. On arm64 flatform. previous: FCVTSD F0, F0 FSQRTD F0, F0 FCVTDS F0, F0 optimized: FSQRTS S0, S0 And this patch adds the test case to check the correctness. This patch refers to CL 241877, contributed by Alice Xu (dianhong.xu@arm.com) Change-Id: I6de5d02281c693017ac4bd4c10963dd55989bd7e Reviewed-on: https://go-review.googlesource.com/c/go/+/276873 Trust: fannie zhang Run-TryBot: fannie zhang TryBot-Result: Go Bot Reviewed-by: Keith Randall --- test/codegen/math.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/codegen') diff --git a/test/codegen/math.go b/test/codegen/math.go index ac8071400e..243ddb0494 100644 --- a/test/codegen/math.go +++ b/test/codegen/math.go @@ -55,6 +55,17 @@ func sqrt(x float64) float64 { return math.Sqrt(x) } +func sqrt32(x float32) float32 { + // amd64:"SQRTSS" + // 386/sse2:"SQRTSS" 386/softfloat:-"SQRTS" + // arm64:"FSQRTS" + // arm/7:"SQRTF" + // mips/hardfloat:"SQRTF" mips/softfloat:-"SQRTF" + // mips64/hardfloat:"SQRTF" mips64/softfloat:-"SQRTF" + // wasm:"F32Sqrt" + return float32(math.Sqrt(float64(x))) +} + // Check that it's using integer registers func abs(x, y float64) { // amd64:"BTRQ\t[$]63" -- cgit v1.3