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