rvc_insns = {
    "C_ADDI4SPN",
    "C_FLD",
    "C_LW",
    "C_LD",
    "C_FSD",
    "C_SW",
    "C_SD",
    "C_ADDI",
    "C_ADDIW",
    "C_LI",
    "C_LUI",
    "C_ADDI16SP",
    "MISC-ALU",
    "C_J",
    "C_BEQZ",
    "C_BNEZ",
    "C_SLLI",
    "C_FLDSP",
    "C_LWSP",
    "C_LDSP",
    "C_JAR",
    "C_JLR",
    "C_JALR",
    "C_MV",
    "C_ADD",
    "C_FSDSP",
    "C_SWSP",
    "C_SDSP",
}

mask_matches = {
    "BEQ": (0x707F, 0x63),
    "BNE": (0x707F, 0x1063),
    "BLT": (0x707F, 0x4063),
    "BGE": (0x707F, 0x5063),
    "BLTU": (0x707F, 0x6063),
    "BGEU": (0x707F, 0x7063),
    "JALR": (0x707F, 0x67),
    "JAL": (0x7F, 0x6F),
    "LUI": (0x7F, 0x37),
    "AUIPC": (0x7F, 0x17),
    "ADDI": (0x707F, 0x13),
    "SLLI": (0xFC00707F, 0x1013),
    "SLTI": (0x707F, 0x2013),
    "SLTIU": (0x707F, 0x3013),
    "XORI": (0x707F, 0x4013),
    "SRLI": (0xFC00707F, 0x5013),
    "SRAI": (0xFC00707F, 0x40005013),
    "ORI": (0x707F, 0x6013),
    "ANDI": (0x707F, 0x7013),
    "ADD": (0xFE00707F, 0x33),
    "SUB": (0xFE00707F, 0x40000033),
    "SLL": (0xFE00707F, 0x1033),
    "SLT": (0xFE00707F, 0x2033),
    "SLTU": (0xFE00707F, 0x3033),
    "XOR": (0xFE00707F, 0x4033),
    "SRL": (0xFE00707F, 0x5033),
    "SRA": (0xFE00707F, 0x40005033),
    "OR": (0xFE00707F, 0x6033),
    "AND": (0xFE00707F, 0x7033),
    "ADDIW": (0x707F, 0x1B),
    "SLLIW": (0xFE00707F, 0x101B),
    "SRLIW": (0xFE00707F, 0x501B),
    "SRAIW": (0xFE00707F, 0x4000501B),
    "ADDW": (0xFE00707F, 0x3B),
    "SUBW": (0xFE00707F, 0x4000003B),
    "SLLW": (0xFE00707F, 0x103B),
    "SRLW": (0xFE00707F, 0x503B),
    "SRAW": (0xFE00707F, 0x4000503B),
    "LB": (0x707F, 0x3),
    "LH": (0x707F, 0x1003),
    "LW": (0x707F, 0x2003),
    "LD": (0x707F, 0x3003),
    "LBU": (0x707F, 0x4003),
    "LHU": (0x707F, 0x5003),
    "LWU": (0x707F, 0x6003),
    "SB": (0x707F, 0x23),
    "SH": (0x707F, 0x1023),
    "SW": (0x707F, 0x2023),
    "SD": (0x707F, 0x3023),
    "FENCE": (0x707F, 0xF),
    "FENCE_I": (0x707F, 0x100F),
    "MUL": (0xFE00707F, 0x2000033),
    "MULH": (0xFE00707F, 0x2001033),
    "MULHSU": (0xFE00707F, 0x2002033),
    "MULHU": (0xFE00707F, 0x2003033),
    "DIV": (0xFE00707F, 0x2004033),
    "DIVU": (0xFE00707F, 0x2005033),
    "REM": (0xFE00707F, 0x2006033),
    "REMU": (0xFE00707F, 0x2007033),
    "MULW": (0xFE00707F, 0x200003B),
    "DIVW": (0xFE00707F, 0x200403B),
    "DIVUW": (0xFE00707F, 0x200503B),
    "REMW": (0xFE00707F, 0x200603B),
    "REMUW": (0xFE00707F, 0x200703B),
    "AMOADD_W": (0xF800707F, 0x202F),
    "AMOXOR_W": (0xF800707F, 0x2000202F),
    "AMOOR_W": (0xF800707F, 0x4000202F),
    "AMOAND_W": (0xF800707F, 0x6000202F),
    "AMOMIN_W": (0xF800707F, 0x8000202F),
    "AMOMAX_W": (0xF800707F, 0xA000202F),
    "AMOMINU_W": (0xF800707F, 0xC000202F),
    "AMOMAXU_W": (0xF800707F, 0xE000202F),
    "AMOSWAP_W": (0xF800707F, 0x800202F),
    "LR_W": (0xF9F0707F, 0x1000202F),
    "SC_W": (0xF800707F, 0x1800202F),
    "AMOADD_D": (0xF800707F, 0x302F),
    "AMOXOR_D": (0xF800707F, 0x2000302F),
    "AMOOR_D": (0xF800707F, 0x4000302F),
    "AMOAND_D": (0xF800707F, 0x6000302F),
    "AMOMIN_D": (0xF800707F, 0x8000302F),
    "AMOMAX_D": (0xF800707F, 0xA000302F),
    "AMOMINU_D": (0xF800707F, 0xC000302F),
    "AMOMAXU_D": (0xF800707F, 0xE000302F),
    "AMOSWAP_D": (0xF800707F, 0x800302F),
    "LR_D": (0xF9F0707F, 0x1000302F),
    "SC_D": (0xF800707F, 0x1800302F),
    "SRET": (0xFFFFFFFF, 0x10200073),
    "MRET": (0xFFFFFFFF, 0x30200073),
    "DRET": (0xFFFFFFFF, 0x7B200073),
    "SFENCE_VMA": (0xFE007FFF, 0x12000073),
    "WFI": (0xFFFFFFFF, 0x10500073),
    "CEASE": (0xFFFFFFFF, 0x30500073),
    "CFLUSH_D_L1": (0xFFF07FFF, 0xFC000073),
    "CSRRW": (0x707F, 0x1073),
    "CSRRS": (0x707F, 0x2073),
    "CSRRC": (0x707F, 0x3073),
    "CSRRWI": (0x707F, 0x5073),
    "CSRRSI": (0x707F, 0x6073),
    "CSRRCI": (0x707F, 0x7073),
    "FADD_S": (0xFE00007F, 0x53),
    "FSUB_S": (0xFE00007F, 0x8000053),
    "FMUL_S": (0xFE00007F, 0x10000053),
    "FDIV_S": (0xFE00007F, 0x18000053),
    "FSGNJ_S": (0xFE00707F, 0x20000053),
    "FSGNJN_S": (0xFE00707F, 0x20001053),
    "FSGNJX_S": (0xFE00707F, 0x20002053),
    "FMIN_S": (0xFE00707F, 0x28000053),
    "FMAX_S": (0xFE00707F, 0x28001053),
    "FSQRT_S": (0xFFF0007F, 0x58000053),
    "FADD_D": (0xFE00007F, 0x2000053),
    "FSUB_D": (0xFE00007F, 0xA000053),
    "FMUL_D": (0xFE00007F, 0x12000053),
    "FDIV_D": (0xFE00007F, 0x1A000053),
    "FSGNJ_D": (0xFE00707F, 0x22000053),
    "FSGNJN_D": (0xFE00707F, 0x22001053),
    "FSGNJX_D": (0xFE00707F, 0x22002053),
    "FMIN_D": (0xFE00707F, 0x2A000053),
    "FMAX_D": (0xFE00707F, 0x2A001053),
    "FCVT_S_D": (0xFFF0007F, 0x40100053),
    "FCVT_D_S": (0xFFF0007F, 0x42000053),
    "FSQRT_D": (0xFFF0007F, 0x5A000053),
    "FLE_S": (0xFE00707F, 0xA0000053),
    "FLT_S": (0xFE00707F, 0xA0001053),
    "FEQ_S": (0xFE00707F, 0xA0002053),
    "FLE_D": (0xFE00707F, 0xA2000053),
    "FLT_D": (0xFE00707F, 0xA2001053),
    "FEQ_D": (0xFE00707F, 0xA2002053),
    "FCVT_W_S": (0xFFF0007F, 0xC0000053),
    "FCVT_WU_S": (0xFFF0007F, 0xC0100053),
    "FCVT_L_S": (0xFFF0007F, 0xC0200053),
    "FCVT_LU_S": (0xFFF0007F, 0xC0300053),
    "FCLASS_S": (0xFFF0707F, 0xE0001053),
    "FCVT_W_D": (0xFFF0007F, 0xC2000053),
    "FCVT_WU_D": (0xFFF0007F, 0xC2100053),
    "FCVT_L_D": (0xFFF0007F, 0xC2200053),
    "FCVT_LU_D": (0xFFF0007F, 0xC2300053),
    "FMV_X_D": (0xFFF0707F, 0xE2000053),
    "FCLASS_D": (0xFFF0707F, 0xE2001053),
    "FCVT_S_W": (0xFFF0007F, 0xD0000053),
    "FCVT_S_WU": (0xFFF0007F, 0xD0100053),
    "FCVT_S_L": (0xFFF0007F, 0xD0200053),
    "FCVT_S_LU": (0xFFF0007F, 0xD0300053),
    "FCVT_D_W": (0xFFF0007F, 0xD2000053),
    "FCVT_D_WU": (0xFFF0007F, 0xD2100053),
    "FCVT_D_L": (0xFFF0007F, 0xD2200053),
    "FCVT_D_LU": (0xFFF0007F, 0xD2300053),
    "FMV_D_X": (0xFFF0707F, 0xF2000053),
    "FLW": (0x707F, 0x2007),
    "FLD": (0x707F, 0x3007),
    "FSW": (0x707F, 0x2027),
    "FSD": (0x707F, 0x3027),
    "FMADD_S": (0x600007F, 0x43),
    "FMSUB_S": (0x600007F, 0x47),
    "FNMSUB_S": (0x600007F, 0x4B),
    "FNMADD_S": (0x600007F, 0x4F),
    "FMADD_D": (0x600007F, 0x2000043),
    "FMSUB_D": (0x600007F, 0x2000047),
    "FNMSUB_D": (0x600007F, 0x200004B),
    "FNMADD_D": (0x600007F, 0x200004F),
    "SLLI_RV32": (0xFE00707F, 0x1013),
    "SRLI_RV32": (0xFE00707F, 0x5013),
    "SRAI_RV32": (0xFE00707F, 0x40005013),
    "SCALL": (0xFFFFFFFF, 0x73),
    "SBREAK": (0xFFFFFFFF, 0x100073),
    "FMV_X_S": (0xFFF0707F, 0xE0000053),
    "FMV_S_X": (0xFFF0707F, 0xF0000053),
}
