]> Cypherpunks.ru repositories - gostls13.git/blob - test/codegen/floats.go
cmd/compile: improve FP FMA performance on riscv64
[gostls13.git] / test / codegen / floats.go
1 // asmcheck
2
3 // Copyright 2018 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package codegen
8
9 // This file contains codegen tests related to arithmetic
10 // simplifications and optimizations on float types.
11 // For codegen tests on integer types, see arithmetic.go.
12
13 // --------------------- //
14 //    Strength-reduce    //
15 // --------------------- //
16
17 func Mul2(f float64) float64 {
18         // 386/sse2:"ADDSD",-"MULSD"
19         // amd64:"ADDSD",-"MULSD"
20         // arm/7:"ADDD",-"MULD"
21         // arm64:"FADDD",-"FMULD"
22         // ppc64x:"FADD",-"FMUL"
23         // riscv64:"FADDD",-"FMULD"
24         return f * 2.0
25 }
26
27 func DivPow2(f1, f2, f3 float64) (float64, float64, float64) {
28         // 386/sse2:"MULSD",-"DIVSD"
29         // amd64:"MULSD",-"DIVSD"
30         // arm/7:"MULD",-"DIVD"
31         // arm64:"FMULD",-"FDIVD"
32         // ppc64x:"FMUL",-"FDIV"
33         // riscv64:"FMULD",-"FDIVD"
34         x := f1 / 16.0
35
36         // 386/sse2:"MULSD",-"DIVSD"
37         // amd64:"MULSD",-"DIVSD"
38         // arm/7:"MULD",-"DIVD"
39         // arm64:"FMULD",-"FDIVD"
40         // ppc64x:"FMUL",-"FDIVD"
41         // riscv64:"FMULD",-"FDIVD"
42         y := f2 / 0.125
43
44         // 386/sse2:"ADDSD",-"DIVSD",-"MULSD"
45         // amd64:"ADDSD",-"DIVSD",-"MULSD"
46         // arm/7:"ADDD",-"MULD",-"DIVD"
47         // arm64:"FADDD",-"FMULD",-"FDIVD"
48         // ppc64x:"FADD",-"FMUL",-"FDIV"
49         // riscv64:"FADDD",-"FMULD",-"FDIVD"
50         z := f3 / 0.5
51
52         return x, y, z
53 }
54
55 func indexLoad(b0 []float32, b1 float32, idx int) float32 {
56         // arm64:`FMOVS\s\(R[0-9]+\)\(R[0-9]+<<2\),\sF[0-9]+`
57         return b0[idx] * b1
58 }
59
60 func indexStore(b0 []float64, b1 float64, idx int) {
61         // arm64:`FMOVD\sF[0-9]+,\s\(R[0-9]+\)\(R[0-9]+<<3\)`
62         b0[idx] = b1
63 }
64
65 // ----------- //
66 //    Fused    //
67 // ----------- //
68
69 func FusedAdd32(x, y, z float32) float32 {
70         // s390x:"FMADDS\t"
71         // ppc64x:"FMADDS\t"
72         // arm64:"FMADDS"
73         return x*y + z
74 }
75
76 func FusedSub32_a(x, y, z float32) float32 {
77         // s390x:"FMSUBS\t"
78         // ppc64x:"FMSUBS\t"
79         return x*y - z
80 }
81
82 func FusedSub32_b(x, y, z float32) float32 {
83         // arm64:"FMSUBS"
84         return z - x*y
85 }
86
87 func FusedAdd64(x, y, z float64) float64 {
88         // s390x:"FMADD\t"
89         // ppc64x:"FMADD\t"
90         // arm64:"FMADDD"
91         // riscv64:"FMADDD\t"
92         return x*y + z
93 }
94
95 func FusedSub64_a(x, y, z float64) float64 {
96         // s390x:"FMSUB\t"
97         // ppc64x:"FMSUB\t"
98         // riscv64:"FMSUBD\t"
99         return x*y - z
100 }
101
102 func FusedSub64_b(x, y, z float64) float64 {
103         // arm64:"FMSUBD"
104         // riscv64:"FNMSUBD\t"
105         return z - x*y
106 }
107
108 func Cmp(f float64) bool {
109         // arm64:"FCMPD","(BGT|BLE|BMI|BPL)",-"CSET\tGT",-"CBZ"
110         return f > 4 || f < -4
111 }
112
113 func CmpZero64(f float64) bool {
114         // s390x:"LTDBR",-"FCMPU"
115         return f <= 0
116 }
117
118 func CmpZero32(f float32) bool {
119         // s390x:"LTEBR",-"CEBR"
120         return f <= 0
121 }
122
123 func CmpWithSub(a float64, b float64) bool {
124         f := a - b
125         // s390x:-"LTDBR"
126         return f <= 0
127 }
128
129 func CmpWithAdd(a float64, b float64) bool {
130         f := a + b
131         // s390x:-"LTDBR"
132         return f <= 0
133 }
134
135 // ---------------- //
136 //    Non-floats    //
137 // ---------------- //
138
139 // We should make sure that the compiler doesn't generate floating point
140 // instructions for non-float operations on Plan 9, because floating point
141 // operations are not allowed in the note handler.
142
143 func ArrayZero() [16]byte {
144         // amd64:"MOVUPS"
145         // plan9/amd64/:-"MOVUPS"
146         var a [16]byte
147         return a
148 }
149
150 func ArrayCopy(a [16]byte) (b [16]byte) {
151         // amd64:"MOVUPS"
152         // plan9/amd64/:-"MOVUPS"
153         b = a
154         return
155 }