From d592ed6dafbb134553bf3a0b8ee70ff7f2049aba Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 3 Jun 2026 21:25:55 -0700 Subject: Add bswap, popcnt, clz, ctz, cls, and rbit instructions --- mediumlevelilinstruction.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'mediumlevelilinstruction.cpp') diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index 37a102d8..18610a55 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -304,6 +304,12 @@ static constexpr std::array s_instructionOperandUsage = { OperandUsage{MLIL_VAR_PHI, {DestSSAVariableMediumLevelOperandUsage, SourceSSAVariablesMediumLevelOperandUsages}}, OperandUsage{MLIL_MEM_PHI, {DestMemoryVersionMediumLevelOperandUsage, SourceMemoryVersionsMediumLevelOperandUsage}}, OperandUsage{MLIL_BLOCK_TO_EXPAND, {SourceExprsMediumLevelOperandUsage}}, + OperandUsage{MLIL_BSWAP, {SourceExprMediumLevelOperandUsage}}, + OperandUsage{MLIL_POPCNT, {SourceExprMediumLevelOperandUsage}}, + OperandUsage{MLIL_CLZ, {SourceExprMediumLevelOperandUsage}}, + OperandUsage{MLIL_CTZ, {SourceExprMediumLevelOperandUsage}}, + OperandUsage{MLIL_RBIT, {SourceExprMediumLevelOperandUsage}}, + OperandUsage{MLIL_CLS, {SourceExprMediumLevelOperandUsage}}, }; VALIDATE_INSTRUCTION_ORDER(s_instructionOperandUsage); @@ -1514,6 +1520,12 @@ void MediumLevelILInstruction::VisitExprs(bn::base::function_ref(), GetSourceMemoryVersion(), loc); case MLIL_NEG: case MLIL_NOT: + case MLIL_BSWAP: + case MLIL_POPCNT: + case MLIL_CLZ: + case MLIL_CTZ: + case MLIL_RBIT: + case MLIL_CLS: case MLIL_SX: case MLIL_ZX: case MLIL_LOW_PART: @@ -2864,6 +2882,42 @@ ExprId MediumLevelILFunction::Not(size_t size, ExprId src, const ILSourceLocatio } +ExprId MediumLevelILFunction::ByteSwap(size_t size, ExprId src, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_BSWAP, loc, size, src); +} + + +ExprId MediumLevelILFunction::PopulationCount(size_t size, ExprId src, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_POPCNT, loc, size, src); +} + + +ExprId MediumLevelILFunction::CountLeadingZeros(size_t size, ExprId src, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_CLZ, loc, size, src); +} + + +ExprId MediumLevelILFunction::CountTrailingZeros(size_t size, ExprId src, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_CTZ, loc, size, src); +} + + +ExprId MediumLevelILFunction::ReverseBits(size_t size, ExprId src, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_RBIT, loc, size, src); +} + + +ExprId MediumLevelILFunction::CountLeadingSigns(size_t size, ExprId src, const ILSourceLocation& loc) +{ + return AddExprWithLocation(MLIL_CLS, loc, size, src); +} + + ExprId MediumLevelILFunction::SignExtend(size_t size, ExprId src, const ILSourceLocation& loc) { return AddExprWithLocation(MLIL_SX, loc, size, src); -- cgit v1.3.1