MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / Saturate

Function Saturate

arch/armv7/il.cpp:595–635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

593
594
595static void Saturate(LowLevelILFunction& il, uint32_t dest, ExprId to_saturate, ExprId saturate_to, bool is_signed)
596{
597
598 LowLevelILLabel trueCode, falseCode, endCode;
599 LowLevelILLabel trueCode2, falseCode2, endCode2;
600
601 if (is_signed)
602 {
603 il.AddInstruction(il.If(il.CompareSignedLessThan(4, to_saturate, il.Neg(4, saturate_to)), trueCode, falseCode));
604 il.MarkLabel(trueCode);
605 il.AddInstruction(il.SetRegister(4, dest, il.Neg(4, saturate_to)));
606 il.AddInstruction(il.Goto(endCode));
607 il.MarkLabel(falseCode);
608 il.MarkLabel(endCode);
609
610 il.AddInstruction(il.If(il.CompareSignedGreaterThan(4, to_saturate, saturate_to), trueCode2, falseCode2));
611 il.MarkLabel(trueCode2);
612 il.AddInstruction(il.SetRegister(4, dest, saturate_to));
613 il.AddInstruction(il.Goto(endCode2));
614 il.MarkLabel(falseCode2);
615 il.AddInstruction(il.SetRegister(4, dest, to_saturate));
616 il.MarkLabel(endCode2);
617 }
618 else
619 {
620 il.AddInstruction(il.If(il.CompareSignedLessThan(4, to_saturate, il.Const(4, 0)), trueCode, falseCode));
621 il.MarkLabel(trueCode);
622 il.AddInstruction(il.SetRegister(4, dest, il.Const(4, 0)));
623 il.AddInstruction(il.Goto(endCode));
624 il.MarkLabel(falseCode);
625 il.MarkLabel(endCode);
626
627 il.AddInstruction(il.If(il.CompareSignedGreaterThan(4, to_saturate, saturate_to), trueCode2, falseCode2));
628 il.MarkLabel(trueCode2);
629 il.AddInstruction(il.SetRegister(4, dest, saturate_to));
630 il.AddInstruction(il.Goto(endCode2));
631 il.MarkLabel(falseCode2);
632 il.AddInstruction(il.SetRegister(4, dest, to_saturate));
633 il.MarkLabel(endCode2);
634 }
635}
636
637
638uint32_t GetNumberOfRegs(uint16_t regList)

Callers 1

Calls 9

SetRegisterMethod · 0.80
AddInstructionMethod · 0.45
IfMethod · 0.45
CompareSignedLessThanMethod · 0.45
NegMethod · 0.45
MarkLabelMethod · 0.45
GotoMethod · 0.45
ConstMethod · 0.45

Tested by

no test coverage detected