diff options
| author | Junyang Shao <shaojunyang@google.com> | 2025-11-25 21:02:44 +0000 |
|---|---|---|
| committer | Junyang Shao <shaojunyang@google.com> | 2025-11-25 15:19:18 -0800 |
| commit | f3a306527c1ad06965b65f6d6b39b17d2bbcb8ef (patch) | |
| tree | 9d9e3d2f80266fef8c86bdceaf48f95118c3eb8c /src/simd | |
| parent | d6564ed088a60dbffbe7f12ac64f5a8be3f70918 (diff) | |
| download | go-f3a306527c1ad06965b65f6d6b39b17d2bbcb8ef.tar.xz | |
[dev.simd] simd, cmd/compile: add float -> float conversions
This should mark the end of the conversion table, except for float16
which does not exist on Go yet.
The rounding logic documentation of float64 -> float32 is based on
abi-internal default MXCSR:
| RC | 14/13 | 0 (RN) | Round to nearest |
Change-Id: I27a86560e8d74d20f21350bf78314b4eada20ec0
Reviewed-on: https://go-review.googlesource.com/c/go/+/724440
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/simd')
| -rw-r--r-- | src/simd/_gen/simdgen/gen_utility.go | 4 | ||||
| -rw-r--r-- | src/simd/_gen/simdgen/ops/Converts/categories.yaml | 4 | ||||
| -rw-r--r-- | src/simd/_gen/simdgen/ops/Converts/go.yaml | 22 | ||||
| -rw-r--r-- | src/simd/ops_amd64.go | 28 |
4 files changed, 55 insertions, 3 deletions
diff --git a/src/simd/_gen/simdgen/gen_utility.go b/src/simd/_gen/simdgen/gen_utility.go index cf91f4a65e..424ba41466 100644 --- a/src/simd/_gen/simdgen/gen_utility.go +++ b/src/simd/_gen/simdgen/gen_utility.go @@ -337,7 +337,9 @@ func (op *Operation) sortOperand() { // adjustAsm adjusts the asm to make it align with Go's assembler. func (op *Operation) adjustAsm() { - if op.Asm == "VCVTTPD2DQ" || op.Asm == "VCVTTPD2UDQ" || op.Asm == "VCVTQQ2PS" || op.Asm == "VCVTUQQ2PS" { + if op.Asm == "VCVTTPD2DQ" || op.Asm == "VCVTTPD2UDQ" || + op.Asm == "VCVTQQ2PS" || op.Asm == "VCVTUQQ2PS" || + op.Asm == "VCVTPD2PS" { switch *op.In[0].Bits { case 128: op.Asm += "X" diff --git a/src/simd/_gen/simdgen/ops/Converts/categories.yaml b/src/simd/_gen/simdgen/ops/Converts/categories.yaml index 61ab195765..dd33284063 100644 --- a/src/simd/_gen/simdgen/ops/Converts/categories.yaml +++ b/src/simd/_gen/simdgen/ops/Converts/categories.yaml @@ -32,12 +32,12 @@ // When a conversion is inexact, a truncated (round toward zero) value is returned. // If a converted result cannot be represented in uint64, an implementation-defined // architecture-specific value is returned. -- go: "ConvertToFloat32" +- go: "ConvertToFloat32" # Also float64 -> float32 commutative: false regexpTag: "convert" documentation: !string |- // NAME converts element values to float32. -- go: "ConvertToFloat64" +- go: "ConvertToFloat64" # Also float32 -> float64 commutative: false regexpTag: "convert" documentation: !string |- diff --git a/src/simd/_gen/simdgen/ops/Converts/go.yaml b/src/simd/_gen/simdgen/ops/Converts/go.yaml index ec28b57681..af058124fb 100644 --- a/src/simd/_gen/simdgen/ops/Converts/go.yaml +++ b/src/simd/_gen/simdgen/ops/Converts/go.yaml @@ -112,6 +112,28 @@ out: - base: float bits: 256|512 +# float64 -> float32 +- go: ConvertToFloat32 + regexpTag: "convert" + asm: "VCVTPD2PS" + addDoc: + !string |- + // The result vector's elements are rounded to the nearest value. + in: &fp64 + - base: float + elemBits: 64 + out: &fp32 + - base: float + elemBits: 32 +# float32 -> float64 +- go: ConvertToFloat64 + regexpTag: "convert" + asm: "VCVTPS2PD" + in: *fp32 + out: + - base: float + elemBits: 64 + bits: 256|512 # Widening integer conversions. # uint8 -> uint16 diff --git a/src/simd/ops_amd64.go b/src/simd/ops_amd64.go index 5722fb2543..7280e873a0 100644 --- a/src/simd/ops_amd64.go +++ b/src/simd/ops_amd64.go @@ -1547,6 +1547,24 @@ func (x Uint8x64) ConcatShiftBytesRightGrouped(constant uint8, y Uint8x64) Uint8 /* ConvertToFloat32 */ // ConvertToFloat32 converts element values to float32. +// The result vector's elements are rounded to the nearest value. +// +// Asm: VCVTPD2PSX, CPU Feature: AVX +func (x Float64x2) ConvertToFloat32() Float32x4 + +// ConvertToFloat32 converts element values to float32. +// The result vector's elements are rounded to the nearest value. +// +// Asm: VCVTPD2PSY, CPU Feature: AVX +func (x Float64x4) ConvertToFloat32() Float32x4 + +// ConvertToFloat32 converts element values to float32. +// The result vector's elements are rounded to the nearest value. +// +// Asm: VCVTPD2PS, CPU Feature: AVX512 +func (x Float64x8) ConvertToFloat32() Float32x8 + +// ConvertToFloat32 converts element values to float32. // // Asm: VCVTDQ2PS, CPU Feature: AVX func (x Int32x4) ConvertToFloat32() Float32x4 @@ -1610,6 +1628,16 @@ func (x Uint64x8) ConvertToFloat32() Float32x8 // ConvertToFloat64 converts element values to float64. // +// Asm: VCVTPS2PD, CPU Feature: AVX +func (x Float32x4) ConvertToFloat64() Float64x4 + +// ConvertToFloat64 converts element values to float64. +// +// Asm: VCVTPS2PD, CPU Feature: AVX512 +func (x Float32x8) ConvertToFloat64() Float64x8 + +// ConvertToFloat64 converts element values to float64. +// // Asm: VCVTDQ2PD, CPU Feature: AVX func (x Int32x4) ConvertToFloat64() Float64x4 |
