github.com/chenzhuoyu/iasm@v0.9.1/x86_64/arch.go (about) 1 package x86_64 2 3 import ( 4 `fmt` 5 ) 6 7 // ISA represents an extension to x86-64 instruction set. 8 type ISA uint64 9 10 const ( 11 ISA_CPUID ISA = 1 << iota 12 ISA_RDTSC 13 ISA_RDTSCP 14 ISA_CMOV 15 ISA_MOVBE 16 ISA_POPCNT 17 ISA_LZCNT 18 ISA_TBM 19 ISA_BMI 20 ISA_BMI2 21 ISA_ADX 22 ISA_MMX 23 ISA_MMX_PLUS 24 ISA_FEMMS 25 ISA_3DNOW 26 ISA_3DNOW_PLUS 27 ISA_SSE 28 ISA_SSE2 29 ISA_SSE3 30 ISA_SSSE3 31 ISA_SSE4A 32 ISA_SSE4_1 33 ISA_SSE4_2 34 ISA_FMA3 35 ISA_FMA4 36 ISA_XOP 37 ISA_F16C 38 ISA_AVX 39 ISA_AVX2 40 ISA_AVX512F 41 ISA_AVX512BW 42 ISA_AVX512DQ 43 ISA_AVX512VL 44 ISA_AVX512PF 45 ISA_AVX512ER 46 ISA_AVX512CD 47 ISA_AVX512VBMI 48 ISA_AVX512IFMA 49 ISA_AVX512VPOPCNTDQ 50 ISA_AVX512_4VNNIW 51 ISA_AVX512_4FMAPS 52 ISA_PREFETCH 53 ISA_PREFETCHW 54 ISA_PREFETCHWT1 55 ISA_CLFLUSH 56 ISA_CLFLUSHOPT 57 ISA_CLWB 58 ISA_CLZERO 59 ISA_RDRAND 60 ISA_RDSEED 61 ISA_PCLMULQDQ 62 ISA_AES 63 ISA_SHA 64 ISA_MONITOR 65 ISA_MONITORX 66 ISA_ALL = ^ISA(0) 67 ) 68 69 var _ISA_NAMES = map[ISA]string { 70 ISA_CPUID : "CPUID", 71 ISA_RDTSC : "RDTSC", 72 ISA_RDTSCP : "RDTSCP", 73 ISA_CMOV : "CMOV", 74 ISA_MOVBE : "MOVBE", 75 ISA_POPCNT : "POPCNT", 76 ISA_LZCNT : "LZCNT", 77 ISA_TBM : "TBM", 78 ISA_BMI : "BMI", 79 ISA_BMI2 : "BMI2", 80 ISA_ADX : "ADX", 81 ISA_MMX : "MMX", 82 ISA_MMX_PLUS : "MMX+", 83 ISA_FEMMS : "FEMMS", 84 ISA_3DNOW : "3dnow!", 85 ISA_3DNOW_PLUS : "3dnow!+", 86 ISA_SSE : "SSE", 87 ISA_SSE2 : "SSE2", 88 ISA_SSE3 : "SSE3", 89 ISA_SSSE3 : "SSSE3", 90 ISA_SSE4A : "SSE4A", 91 ISA_SSE4_1 : "SSE4.1", 92 ISA_SSE4_2 : "SSE4.2", 93 ISA_FMA3 : "FMA3", 94 ISA_FMA4 : "FMA4", 95 ISA_XOP : "XOP", 96 ISA_F16C : "F16C", 97 ISA_AVX : "AVX", 98 ISA_AVX2 : "AVX2", 99 ISA_AVX512F : "AVX512F", 100 ISA_AVX512BW : "AVX512BW", 101 ISA_AVX512DQ : "AVX512DQ", 102 ISA_AVX512VL : "AVX512VL", 103 ISA_AVX512PF : "AVX512PF", 104 ISA_AVX512ER : "AVX512ER", 105 ISA_AVX512CD : "AVX512CD", 106 ISA_AVX512VBMI : "AVX512VBMI", 107 ISA_AVX512IFMA : "AVX512IFMA", 108 ISA_AVX512VPOPCNTDQ : "AVX512VPOPCNTDQ", 109 ISA_AVX512_4VNNIW : "AVX512_4VNNIW", 110 ISA_AVX512_4FMAPS : "AVX512_4FMAPS", 111 ISA_PREFETCH : "PREFETCH", 112 ISA_PREFETCHW : "PREFETCHW", 113 ISA_PREFETCHWT1 : "PREFETCHWT1", 114 ISA_CLFLUSH : "CLFLUSH", 115 ISA_CLFLUSHOPT : "CLFLUSHOPT", 116 ISA_CLWB : "CLWB", 117 ISA_CLZERO : "CLZERO", 118 ISA_RDRAND : "RDRAND", 119 ISA_RDSEED : "RDSEED", 120 ISA_PCLMULQDQ : "PCLMULQDQ", 121 ISA_AES : "AES", 122 ISA_SHA : "SHA", 123 ISA_MONITOR : "MONITOR", 124 ISA_MONITORX : "MONITORX", 125 } 126 127 var _ISA_MAPPING = map[string]ISA { 128 "CPUID" : ISA_CPUID, 129 "RDTSC" : ISA_RDTSC, 130 "RDTSCP" : ISA_RDTSCP, 131 "CMOV" : ISA_CMOV, 132 "MOVBE" : ISA_MOVBE, 133 "POPCNT" : ISA_POPCNT, 134 "LZCNT" : ISA_LZCNT, 135 "TBM" : ISA_TBM, 136 "BMI" : ISA_BMI, 137 "BMI2" : ISA_BMI2, 138 "ADX" : ISA_ADX, 139 "MMX" : ISA_MMX, 140 "MMX+" : ISA_MMX_PLUS, 141 "FEMMS" : ISA_FEMMS, 142 "3dnow!" : ISA_3DNOW, 143 "3dnow!+" : ISA_3DNOW_PLUS, 144 "SSE" : ISA_SSE, 145 "SSE2" : ISA_SSE2, 146 "SSE3" : ISA_SSE3, 147 "SSSE3" : ISA_SSSE3, 148 "SSE4A" : ISA_SSE4A, 149 "SSE4.1" : ISA_SSE4_1, 150 "SSE4.2" : ISA_SSE4_2, 151 "FMA3" : ISA_FMA3, 152 "FMA4" : ISA_FMA4, 153 "XOP" : ISA_XOP, 154 "F16C" : ISA_F16C, 155 "AVX" : ISA_AVX, 156 "AVX2" : ISA_AVX2, 157 "AVX512F" : ISA_AVX512F, 158 "AVX512BW" : ISA_AVX512BW, 159 "AVX512DQ" : ISA_AVX512DQ, 160 "AVX512VL" : ISA_AVX512VL, 161 "AVX512PF" : ISA_AVX512PF, 162 "AVX512ER" : ISA_AVX512ER, 163 "AVX512CD" : ISA_AVX512CD, 164 "AVX512VBMI" : ISA_AVX512VBMI, 165 "AVX512IFMA" : ISA_AVX512IFMA, 166 "AVX512VPOPCNTDQ" : ISA_AVX512VPOPCNTDQ, 167 "AVX512_4VNNIW" : ISA_AVX512_4VNNIW, 168 "AVX512_4FMAPS" : ISA_AVX512_4FMAPS, 169 "PREFETCH" : ISA_PREFETCH, 170 "PREFETCHW" : ISA_PREFETCHW, 171 "PREFETCHWT1" : ISA_PREFETCHWT1, 172 "CLFLUSH" : ISA_CLFLUSH, 173 "CLFLUSHOPT" : ISA_CLFLUSHOPT, 174 "CLWB" : ISA_CLWB, 175 "CLZERO" : ISA_CLZERO, 176 "RDRAND" : ISA_RDRAND, 177 "RDSEED" : ISA_RDSEED, 178 "PCLMULQDQ" : ISA_PCLMULQDQ, 179 "AES" : ISA_AES, 180 "SHA" : ISA_SHA, 181 "MONITOR" : ISA_MONITOR, 182 "MONITORX" : ISA_MONITORX, 183 } 184 185 func (self ISA) String() string { 186 if v, ok := _ISA_NAMES[self]; ok { 187 return v 188 } else { 189 return fmt.Sprintf("(invalid: %#x)", uint64(self)) 190 } 191 } 192 193 // ParseISA parses name into ISA, it will panic if the name is invalid. 194 func ParseISA(name string) ISA { 195 if v, ok := _ISA_MAPPING[name]; ok { 196 return v 197 } else { 198 panic("invalid ISA name: " + name) 199 } 200 } 201 202 // Arch represents the x86_64 architecture. 203 type Arch struct { 204 isa ISA 205 } 206 207 // DefaultArch is the default architecture with all ISA enabled. 208 var DefaultArch = CreateArch() 209 210 // CreateArch creates a new Arch with all ISA enabled. 211 func CreateArch() *Arch { 212 return new(Arch).EnableISA(ISA_ALL) 213 } 214 215 // HasISA checks if a particular ISA was enabled. 216 func (self *Arch) HasISA(isa ISA) bool { 217 return (self.isa & isa) != 0 218 } 219 220 // EnableISA enables a particular ISA. 221 func (self *Arch) EnableISA(isa ISA) *Arch { 222 self.isa |= isa 223 return self 224 } 225 226 // DisableISA disables a particular ISA. 227 func (self *Arch) DisableISA(isa ISA) *Arch { 228 self.isa &^= isa 229 return self 230 } 231 232 // CreateProgram creates a new empty program. 233 func (self *Arch) CreateProgram() *Program { 234 return newProgram(self) 235 }