pub const ALL_MNEMONICS: &[&str] = &[
"absd",
"absf",
"adcq",
"addd",
"addf",
"addi",
"addis",
"addlshiftp",
"addp",
"addps",
"addq",
"addqs",
"andd",
"andf",
"andi",
"andp",
"andq",
"atomicloadb",
"atomicloadh",
"atomicloadi",
"atomicloadq",
"atomicweakcasb",
"atomicweakcash",
"atomicweakcasi",
"atomicweakcasq",
"atomicxchgaddb",
"atomicxchgaddh",
"atomicxchgaddi",
"atomicxchgaddq",
"atomicxchgb",
"atomicxchgclearb",
"atomicxchgclearh",
"atomicxchgcleari",
"atomicxchgclearq",
"atomicxchgh",
"atomicxchgi",
"atomicxchgorb",
"atomicxchgorh",
"atomicxchgori",
"atomicxchgorq",
"atomicxchgq",
"atomicxchgsubb",
"atomicxchgsubh",
"atomicxchgsubi",
"atomicxchgsubq",
"atomicxchgxorb",
"atomicxchgxorh",
"atomicxchgxori",
"atomicxchgxorq",
"baddinz",
"baddio",
"baddis",
"baddiz",
"baddpnz",
"baddpo",
"baddps",
"baddpz",
"baddqnz",
"baddqo",
"baddqs",
"baddqz",
"batomicweakcasb",
"batomicweakcash",
"batomicweakcasi",
"batomicweakcasq",
"bba",
"bbaeq",
"bbb",
"bbbeq",
"bbeq",
"bbgt",
"bbgteq",
"bblt",
"bblteq",
"bbneq",
"bcd2i",
"bdeq",
"bdequn",
"bdgt",
"bdgteq",
"bdgtequn",
"bdgtun",
"bdlt",
"bdlteq",
"bdltequn",
"bdltun",
"bdneq",
"bdnequn",
"bfeq",
"bfgt",
"bfgteq",
"bfgtequn",
"bfgtun",
"bfiq",
"bflt",
"bfltequn",
"bfltun",
"bia",
"biaeq",
"bib",
"bibeq",
"bieq",
"bigt",
"bigteq",
"bilt",
"bilteq",
"bineq",
"bmulinz",
"bmulio",
"bmulis",
"bmuliz",
"bmulpnz",
"bmulpo",
"bmulps",
"bmulpz",
"bmulqnz",
"bmulqo",
"bmulqs",
"bmulqz",
"bnz",
"bo",
"borinz",
"borio",
"boris",
"boriz",
"borpnz",
"borpo",
"borps",
"borpz",
"borqnz",
"borqo",
"borqs",
"borqz",
"bpa",
"bpaeq",
"bpb",
"bpbeq",
"bpeq",
"bpgt",
"bpgteq",
"bplt",
"bplteq",
"bpneq",
"bqa",
"bqaeq",
"bqb",
"bqbeq",
"bqeq",
"bqgt",
"bqgteq",
"bqlt",
"bqlteq",
"bqneq",
"break",
"bs",
"bsubinz",
"bsubio",
"bsubis",
"bsubiz",
"bsubpnz",
"bsubpo",
"bsubps",
"bsubpz",
"bsubqnz",
"bsubqo",
"bsubqs",
"bsubqz",
"bswapi",
"bswapq",
"btbnz",
"btbs",
"btbz",
"btd2i",
"btinz",
"btis",
"btiz",
"btpnz",
"btps",
"btpz",
"btqnz",
"btqs",
"btqz",
"bz",
"call",
"cba",
"cbaeq",
"cbb",
"cbbeq",
"cbeq",
"cbgt",
"cbgteq",
"cblt",
"cblteq",
"cbneq",
"cd2f",
"cdeq",
"cdgt",
"cdgteq",
"cdlt",
"cdlteq",
"cdneq",
"cdnequn",
"cdqi",
"ceild",
"ceilf",
"cf2d",
"cfeq",
"cfgt",
"cfgteq",
"cflt",
"cflteq",
"cfneq",
"cfnequn",
"ci2d",
"ci2ds",
"ci2f",
"ci2fs",
"cia",
"ciaeq",
"cib",
"cibeq",
"cieq",
"cigt",
"cigteq",
"cilt",
"cilteq",
"cineq",
"cmov",
"cmovz",
"cpa",
"cpaeq",
"cpb",
"cpbeq",
"cpeq",
"cpgt",
"cpgteq",
"cplt",
"cplteq",
"cpneq",
"cq2d",
"cq2ds",
"cq2f",
"cq2fs",
"cqa",
"cqaeq",
"cqb",
"cqbeq",
"cqeq",
"cqgt",
"cqgteq",
"cqlt",
"cqlteq",
"cqneq",
"cqoq",
"divd",
"divf",
"divi",
"divis",
"divq",
"divqs",
"dmax",
"dmin",
"emit",
"fd2q",
"fence",
"ff2i",
"fi2f",
"floord",
"floorf",
"fmaddd",
"fmaddf",
"fmax",
"fmin",
"fmsubd",
"fmsubf",
"fnmaddd",
"fnmaddf",
"fnmsubd",
"fnmsubf",
"fq2d",
"globaladdr",
"idivi",
"idivq",
"jmp",
"la",
"leai",
"leap",
"loadb",
"loadbsi",
"loadbsq",
"loadd",
"loadf",
"loadh",
"loadhsi",
"loadhsq",
"loadi",
"loadis",
"loadlinkacqb",
"loadlinkacqh",
"loadlinkacqi",
"loadlinkacqq",
"loadp",
"loadpaird",
"loadpairi",
"loadpairp",
"loadpairq",
"loadpairv",
"loadq",
"loadqinc",
"loadv",
"lrotatei",
"lrotateq",
"lshifti",
"lshiftp",
"lshiftq",
"lzcnti",
"lzcntq",
"memfence",
"movdz",
"move",
"moved",
"movev",
"movn",
"movz",
"muld",
"mulf",
"muli",
"mulp",
"mulq",
"negd",
"negf",
"negi",
"negp",
"negq",
"nop",
"noti",
"notq",
"ord",
"orf",
"orh",
"ori",
"oris",
"orp",
"orq",
"pause",
"pcrtoaddr",
"peek",
"poke",
"pop",
"popCalleeSaves",
"popcnti",
"popcntq",
"popv",
"push",
"pushCalleeSaves",
"pushv",
"remi",
"remis",
"removeArrayPtrTag",
"removeCodePtrTag",
"remq",
"remqs",
"ret",
"rloopCallNative",
"rloopCallNativeFunction",
"rloopCallSlowPath",
"rloopCallSlowPath3",
"rloopCallSlowPath4",
"rloopCallSlowPathVoid",
"rloopCrash",
"rloopDo",
"roundd",
"roundf",
"rrotatei",
"rrotateq",
"rshifti",
"rshiftp",
"rshiftq",
"sbcq",
"slt",
"sltu",
"smulhq",
"smulli",
"sqrtd",
"sqrtf",
"storeb",
"storecondrelb",
"storecondrelh",
"storecondreli",
"storecondrelq",
"stored",
"storef",
"storeh",
"storei",
"storep",
"storepaird",
"storepairi",
"storepairp",
"storepairq",
"storepairv",
"storeq",
"storev",
"subd",
"subf",
"subi",
"subis",
"subp",
"subq",
"subqs",
"sxb2i",
"sxb2p",
"sxb2q",
"sxh2i",
"sxh2q",
"sxi2q",
"tagCodePtr",
"tagReturnAddress",
"tbnz",
"tbs",
"tbz",
"td2i",
"tinz",
"tis",
"tiz",
"tls_leap",
"tls_loadb",
"tls_loadh",
"tls_loadi",
"tls_loadp",
"tls_loadq",
"tls_storeb",
"tls_storeh",
"tls_storei",
"tls_storep",
"tls_storeq",
"tpnz",
"tps",
"tpz",
"tqnz",
"tqs",
"tqz",
"transferi",
"transferp",
"transferq",
"truncated",
"truncated2i",
"truncated2is",
"truncated2q",
"truncated2qs",
"truncatef",
"truncatef2i",
"truncatef2is",
"truncatef2q",
"truncatef2qs",
"tzcnti",
"tzcntq",
"udivi",
"udivq",
"umovb",
"umovh",
"umovi",
"umovq",
"umulhq",
"umulli",
"untagArrayPtr",
"untagReturnAddress",
"urshifti",
"urshiftp",
"urshiftq",
"xori",
"xorp",
"xorq",
"zxb2i",
"zxb2q",
"zxh2i",
"zxh2q",
"zxi2q",
];
pub fn lookup(name: &str) -> bool {
ALL_MNEMONICS.binary_search(&name).is_ok()
}
pub const MACRO_INSTRUCTIONS: &[&str] = &[
"emit",
"addi",
"andi",
"andf",
"andd",
"lshifti",
"lshiftp",
"lshiftq",
"muli",
"negi",
"negp",
"negq",
"noti",
"ori",
"orf",
"ord",
"orh",
"rshifti",
"urshifti",
"rshiftp",
"urshiftp",
"rshiftq",
"urshiftq",
"lrotatei",
"lrotateq",
"rrotatei",
"rrotateq",
"subi",
"xori",
"loadi",
"loadis",
"loadb",
"loadbsi",
"loadbsq",
"loadh",
"loadhsi",
"loadhsq",
"storei",
"storeh",
"storeb",
"transferi",
"transferq",
"transferp",
"loadf",
"loadd",
"loadv",
"moved",
"storef",
"stored",
"storev",
"addf",
"addd",
"divf",
"divd",
"subf",
"subd",
"mulf",
"muld",
"sqrtf",
"sqrtd",
"floorf",
"floord",
"roundf",
"roundd",
"truncatef",
"truncated",
"truncatef2i",
"truncatef2q",
"truncated2q",
"truncated2i",
"truncatef2is",
"truncated2is",
"truncatef2qs",
"truncated2qs",
"ci2d",
"ci2ds",
"ci2f",
"ci2fs",
"cq2f",
"cq2fs",
"cq2d",
"cq2ds",
"cd2f",
"cf2d",
"fq2d",
"fd2q",
"bdeq",
"bdneq",
"bdgt",
"bdgteq",
"bdlt",
"bdlteq",
"bdequn",
"bdnequn",
"bdgtun",
"bdgtequn",
"bdltun",
"bdltequn",
"bfeq",
"bfgt",
"bflt",
"bfgtun",
"bfgtequn",
"bfltun",
"bfltequn",
"btd2i",
"td2i",
"bcd2i",
"movdz",
"pop",
"popv",
"push",
"pushv",
"pushCalleeSaves",
"popCalleeSaves",
"move",
"cmov",
"cmovz",
"sxi2q",
"zxi2q",
"sxb2i",
"sxh2i",
"sxb2q",
"sxb2p",
"sxh2q",
"zxb2i",
"zxh2i",
"zxb2q",
"zxh2q",
"nop",
"bieq",
"bineq",
"bia",
"biaeq",
"bib",
"bibeq",
"bigt",
"bigteq",
"bilt",
"bilteq",
"bbeq",
"bbneq",
"bba",
"bbaeq",
"bbb",
"bbbeq",
"bbgt",
"bbgteq",
"bblt",
"bblteq",
"btis",
"btiz",
"btinz",
"btbs",
"btbz",
"btbnz",
"jmp",
"baddio",
"baddis",
"baddiz",
"baddinz",
"bsubio",
"bsubis",
"bsubiz",
"bsubinz",
"bmulio",
"bmulis",
"bmuliz",
"bmulinz",
"borio",
"boris",
"boriz",
"borinz",
"break",
"call",
"ret",
"cbeq",
"cbneq",
"cba",
"cbaeq",
"cbb",
"cbbeq",
"cbgt",
"cbgteq",
"cblt",
"cblteq",
"cieq",
"cineq",
"cia",
"ciaeq",
"cib",
"cibeq",
"cigt",
"cigteq",
"cilt",
"cilteq",
"tis",
"tiz",
"tinz",
"tbs",
"tbz",
"tbnz",
"tps",
"tpz",
"tpnz",
"peek",
"poke",
"bpeq",
"bpneq",
"bpa",
"bpaeq",
"bpb",
"bpbeq",
"bpgt",
"bpgteq",
"bplt",
"bplteq",
"addp",
"mulp",
"andp",
"orp",
"subp",
"xorp",
"loadp",
"cpeq",
"cpneq",
"cpa",
"cpaeq",
"cpb",
"cpbeq",
"cpgt",
"cpgteq",
"cplt",
"cplteq",
"storep",
"btps",
"btpz",
"btpnz",
"baddpo",
"baddps",
"baddpz",
"baddpnz",
"tqs",
"tqz",
"tqnz",
"bqeq",
"bqneq",
"bqa",
"bqaeq",
"bqb",
"bqbeq",
"bqgt",
"bqgteq",
"bqlt",
"bqlteq",
"addq",
"mulq",
"andq",
"orq",
"subq",
"xorq",
"loadq",
"cqeq",
"cqneq",
"cqa",
"cqaeq",
"cqb",
"cqbeq",
"cqgt",
"cqgteq",
"cqlt",
"cqlteq",
"storeq",
"btqs",
"btqz",
"btqnz",
"baddqo",
"baddqs",
"baddqz",
"baddqnz",
"bsubqo",
"bsubqs",
"bsubqz",
"bsubqnz",
"bsubpo",
"bsubps",
"bsubpz",
"bsubpnz",
"bmulqo",
"bmulqs",
"bmulqz",
"bmulqnz",
"bmulpo",
"bmulps",
"bmulpz",
"bmulpnz",
"borqo",
"borqs",
"borqz",
"borqnz",
"borpo",
"borps",
"borpz",
"borpnz",
"bo",
"bs",
"bz",
"bnz",
"leai",
"leap",
"memfence",
"tagCodePtr",
"tagReturnAddress",
"untagReturnAddress",
"removeCodePtrTag",
"untagArrayPtr",
"removeArrayPtrTag",
"tzcnti",
"tzcntq",
"lzcnti",
"lzcntq",
"absf",
"absd",
"negf",
"negd",
"ceilf",
"ceild",
"cfeq",
"cdeq",
"cfneq",
"cfnequn",
"cdneq",
"cdnequn",
"cflt",
"cdlt",
"cflteq",
"cdlteq",
"cfgt",
"cdgt",
"cfgteq",
"cdgteq",
"fi2f",
"ff2i",
"tls_leap",
"tls_loadb",
"tls_loadh",
"tls_loadi",
"tls_loadp",
"tls_loadq",
"tls_storeb",
"tls_storeh",
"tls_storei",
"tls_storep",
"tls_storeq",
"bfgteq",
"popcnti",
"popcntq",
"movev",
"bswapi",
"bswapq",
"fmin",
"fmax",
"dmin",
"dmax",
"fmaddf",
"fmaddd",
"fmsubf",
"fmsubd",
"fnmaddf",
"fnmaddd",
"fnmsubf",
"fnmsubd",
"pause",
];
pub const X86_INSTRUCTIONS: &[&str] = &[
"cdqi",
"idivi",
"udivi",
"cqoq",
"idivq",
"udivq",
"notq",
"atomicxchgaddb",
"atomicxchgaddh",
"atomicxchgaddi",
"atomicxchgaddq",
"atomicxchgsubb",
"atomicxchgsubh",
"atomicxchgsubi",
"atomicxchgsubq",
"atomicxchgb",
"atomicxchgh",
"atomicxchgi",
"atomicxchgq",
"batomicweakcasb",
"batomicweakcash",
"batomicweakcasi",
"batomicweakcasq",
"atomicweakcasb",
"atomicweakcash",
"atomicweakcasi",
"atomicweakcasq",
"atomicloadb",
"atomicloadh",
"atomicloadi",
"atomicloadq",
"fence",
"adcq",
"sbcq",
"umulhq",
"smulhq",
];
pub const X86_SIMD_INSTRUCTIONS: &[&str] = &[];
pub const ARM64_INSTRUCTIONS: &[&str] = &[
"bfiq",
"pcrtoaddr",
"globaladdr",
"notq",
"loadqinc",
"loadlinkacqb",
"loadlinkacqh",
"loadlinkacqi",
"loadlinkacqq",
"storecondrelb",
"storecondrelh",
"storecondreli",
"storecondrelq",
"fence",
"atomicxchgaddb",
"atomicxchgaddh",
"atomicxchgaddi",
"atomicxchgaddq",
"atomicxchgclearb",
"atomicxchgclearh",
"atomicxchgcleari",
"atomicxchgclearq",
"atomicxchgorb",
"atomicxchgorh",
"atomicxchgori",
"atomicxchgorq",
"atomicxchgxorb",
"atomicxchgxorh",
"atomicxchgxori",
"atomicxchgxorq",
"atomicxchgb",
"atomicxchgh",
"atomicxchgi",
"atomicxchgq",
"atomicweakcasb",
"atomicweakcash",
"atomicweakcasi",
"atomicweakcasq",
"atomicloadb",
"atomicloadh",
"atomicloadi",
"atomicloadq",
"loadpairq",
"loadpairp",
"loadpairi",
"storepairq",
"storepairp",
"storepairi",
"loadpaird",
"storepaird",
"loadpairv",
"storepairv",
"addlshiftp",
"addqs",
"subqs",
"adcq",
"sbcq",
"smulhq",
"umulhq",
];
pub const ARM64_SIMD_INSTRUCTIONS: &[&str] = &["umovb", "umovh", "umovi", "umovq"];
pub const RISC_INSTRUCTIONS: &[&str] = &[
"smulli", "umulli", "addis", "subis", "oris", "addps", "divi", "divis", "divq", "divqs",
"remi", "remis", "remq", "remqs",
];
pub const MIPS_INSTRUCTIONS: &[&str] = &["la", "movz", "movn", "slt", "sltu"];
pub const RLOOP_INSTRUCTIONS: &[&str] = &[
"rloopCrash",
"rloopCallNativeFunction",
"rloopCallNative",
"rloopCallSlowPath",
"rloopCallSlowPathVoid",
"rloopCallSlowPath3",
"rloopCallSlowPath4",
"rloopDo",
];
pub fn all_instructions() -> Vec<&'static str> {
let mut v = Vec::new();
v.extend_from_slice(MACRO_INSTRUCTIONS);
v.extend_from_slice(X86_INSTRUCTIONS);
v.extend_from_slice(X86_SIMD_INSTRUCTIONS);
v.extend_from_slice(ARM64_INSTRUCTIONS);
v.extend_from_slice(ARM64_SIMD_INSTRUCTIONS);
v.extend_from_slice(RISC_INSTRUCTIONS);
v.extend_from_slice(MIPS_INSTRUCTIONS);
v.extend_from_slice(RLOOP_INSTRUCTIONS);
v
}
pub fn is_instruction_name(name: &str) -> bool {
lookup(name)
}
pub fn is_branch(instruction: &str) -> bool {
instruction.starts_with('b')
}
pub fn has_fall_through(instruction: &str) -> bool {
instruction != "ret" && instruction != "jmp"
}
pub fn is_power_of_two(value: i128) -> bool {
if value <= 0 {
return false;
}
(value & (value - 1)) == 0
}