github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/engine/wazevo/backend/isa/amd64/cond.go (about) 1 package amd64 2 3 import ( 4 "fmt" 5 6 "github.com/tetratelabs/wazero/internal/engine/wazevo/ssa" 7 ) 8 9 type cond byte 10 11 const ( 12 // condO represents (overflow) condition. 13 condO cond = iota 14 // condNO represents (no overflow) condition. 15 condNO 16 // condB represents (< unsigned) condition. 17 condB 18 // condNB represents (>= unsigned) condition. 19 condNB 20 // condZ represents (zero) condition. 21 condZ 22 // condNZ represents (not-zero) condition. 23 condNZ 24 // condBE represents (<= unsigned) condition. 25 condBE 26 // condNBE represents (> unsigned) condition. 27 condNBE 28 // condS represents (negative) condition. 29 condS 30 // condNS represents (not-negative) condition. 31 condNS 32 // condP represents (parity) condition. 33 condP 34 // condNP represents (not parity) condition. 35 condNP 36 // condL represents (< signed) condition. 37 condL 38 // condNL represents (>= signed) condition. 39 condNL 40 // condLE represents (<= signed) condition. 41 condLE 42 // condNLE represents (> signed) condition. 43 condNLE 44 45 condInvalid 46 ) 47 48 func (c cond) String() string { 49 switch c { 50 case condO: 51 return "o" 52 case condNO: 53 return "no" 54 case condB: 55 return "b" 56 case condNB: 57 return "nb" 58 case condZ: 59 return "z" 60 case condNZ: 61 return "nz" 62 case condBE: 63 return "be" 64 case condNBE: 65 return "nbe" 66 case condS: 67 return "s" 68 case condNS: 69 return "ns" 70 case condL: 71 return "l" 72 case condNL: 73 return "nl" 74 case condLE: 75 return "le" 76 case condNLE: 77 return "nle" 78 case condP: 79 return "p" 80 case condNP: 81 return "np" 82 default: 83 panic("unreachable") 84 } 85 } 86 87 func condFromSSAIntCmpCond(origin ssa.IntegerCmpCond) cond { 88 switch origin { 89 case ssa.IntegerCmpCondEqual: 90 return condZ 91 case ssa.IntegerCmpCondNotEqual: 92 return condNZ 93 case ssa.IntegerCmpCondSignedLessThan: 94 return condL 95 case ssa.IntegerCmpCondSignedGreaterThanOrEqual: 96 return condNL 97 case ssa.IntegerCmpCondSignedGreaterThan: 98 return condNLE 99 case ssa.IntegerCmpCondSignedLessThanOrEqual: 100 return condLE 101 case ssa.IntegerCmpCondUnsignedLessThan: 102 return condB 103 case ssa.IntegerCmpCondUnsignedGreaterThanOrEqual: 104 return condNB 105 case ssa.IntegerCmpCondUnsignedGreaterThan: 106 return condNBE 107 case ssa.IntegerCmpCondUnsignedLessThanOrEqual: 108 return condBE 109 default: 110 panic("unreachable") 111 } 112 } 113 114 func condFromSSAFloatCmpCond(origin ssa.FloatCmpCond) cond { 115 switch origin { 116 case ssa.FloatCmpCondGreaterThanOrEqual: 117 return condNB 118 case ssa.FloatCmpCondGreaterThan: 119 return condNBE 120 case ssa.FloatCmpCondEqual, ssa.FloatCmpCondNotEqual, ssa.FloatCmpCondLessThan, ssa.FloatCmpCondLessThanOrEqual: 121 panic(fmt.Sprintf("cond %s must be treated as a special case", origin)) 122 default: 123 panic("unreachable") 124 } 125 } 126 127 func (c cond) encoding() byte { 128 return byte(c) 129 } 130 131 func (c cond) invert() cond { 132 switch c { 133 case condO: 134 return condNO 135 case condNO: 136 return condO 137 case condB: 138 return condNB 139 case condNB: 140 return condB 141 case condZ: 142 return condNZ 143 case condNZ: 144 return condZ 145 case condBE: 146 return condNBE 147 case condNBE: 148 return condBE 149 case condS: 150 return condNS 151 case condNS: 152 return condS 153 case condP: 154 return condNP 155 case condNP: 156 return condP 157 case condL: 158 return condNL 159 case condNL: 160 return condL 161 case condLE: 162 return condNLE 163 case condNLE: 164 return condLE 165 default: 166 panic("unreachable") 167 } 168 }