Source file 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 // riscv64:"FMADDS\t" 74 return x*y + z 75 } 76 77 func FusedSub32_a(x, y, z float32) float32 { 78 // s390x:"FMSUBS\t" 79 // ppc64x:"FMSUBS\t" 80 // riscv64:"FMSUBS\t" 81 return x*y - z 82 } 83 84 func FusedSub32_b(x, y, z float32) float32 { 85 // arm64:"FMSUBS" 86 // riscv64:"FNMSUBS\t" 87 return z - x*y 88 } 89 90 func FusedAdd64(x, y, z float64) float64 { 91 // s390x:"FMADD\t" 92 // ppc64x:"FMADD\t" 93 // arm64:"FMADDD" 94 // riscv64:"FMADDD\t" 95 return x*y + z 96 } 97 98 func FusedSub64_a(x, y, z float64) float64 { 99 // s390x:"FMSUB\t" 100 // ppc64x:"FMSUB\t" 101 // riscv64:"FMSUBD\t" 102 return x*y - z 103 } 104 105 func FusedSub64_b(x, y, z float64) float64 { 106 // arm64:"FMSUBD" 107 // riscv64:"FNMSUBD\t" 108 return z - x*y 109 } 110 111 func Cmp(f float64) bool { 112 // arm64:"FCMPD","(BGT|BLE|BMI|BPL)",-"CSET\tGT",-"CBZ" 113 return f > 4 || f < -4 114 } 115 116 func CmpZero64(f float64) bool { 117 // s390x:"LTDBR",-"FCMPU" 118 return f <= 0 119 } 120 121 func CmpZero32(f float32) bool { 122 // s390x:"LTEBR",-"CEBR" 123 return f <= 0 124 } 125 126 func CmpWithSub(a float64, b float64) bool { 127 f := a - b 128 // s390x:-"LTDBR" 129 return f <= 0 130 } 131 132 func CmpWithAdd(a float64, b float64) bool { 133 f := a + b 134 // s390x:-"LTDBR" 135 return f <= 0 136 } 137 138 // ---------------- // 139 // Non-floats // 140 // ---------------- // 141 142 // We should make sure that the compiler doesn't generate floating point 143 // instructions for non-float operations on Plan 9, because floating point 144 // operations are not allowed in the note handler. 145 146 func ArrayZero() [16]byte { 147 // amd64:"MOVUPS" 148 // plan9/amd64/:-"MOVUPS" 149 var a [16]byte 150 return a 151 } 152 153 func ArrayCopy(a [16]byte) (b [16]byte) { 154 // amd64:"MOVUPS" 155 // plan9/amd64/:-"MOVUPS" 156 b = a 157 return 158 } 159