Skip to content
Snippets Groups Projects
Commit 879dbfb6 authored by an7s's avatar an7s
Browse files

Implemented saturating arithmetic for overflows

Former-commit-id: d9b9be8e008695b8755f06a078fdfdc023ed9e8b
parent 833e6af5
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ class IntegerTransform : public Transform
private:
void handleOverflowCheck(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, int p_policy);
void handleUnderflowCheck(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, int p_policy);
void handleSignedness(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, int p_policy);
void handleTruncation(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, int p_policy);
......@@ -27,12 +28,15 @@ class IntegerTransform : public Transform
void addTruncationCheck(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, int p_policy);
void addOverflowCheck(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, int p_policy, AddressID_t *p_original = NULL);
void addUnderflowCheck(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, int p_policy);
void addOverflowCheckNoFlag(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, int p_policy);
void addOverflowCheckNoFlag_RegPlusReg(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, const Register::RegisterName&, const Register::RegisterName&, const Register::RegisterName&, int p_policy);
void addOverflowCheckNoFlag_RegPlusConstant(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, const Register::RegisterName&, int p_constantValue, const Register::RegisterName&, int p_policy);
void addOverflowCheckNoFlag_RegTimesConstant(Instruction_t *p_instruction, const MEDS_InstructionCheckAnnotation& p_annotation, const Register::RegisterName&, int p_constantValue, const Register::RegisterName&, int p_policy);
void addOverflowSaturation(Instruction_t *p_instruction, Register::RegisterName p_reg, const MEDS_InstructionCheckAnnotation& p_annotation, Instruction_t *p_fallthrough);
private:
std::set<VirtualOffset> *m_warnings;
};
......
......@@ -62,6 +62,9 @@ class Transform {
bool isAddSubNonEspInstruction(libIRDB::Instruction_t*);
Register::RegisterName getTargetRegister(libIRDB::Instruction_t*);
void addMovRegisterUnsignedConstant(Instruction_t *p_instr, Register::RegisterName p_regTgt, unsigned p_constant, Instruction_t *p_fallThrough);
void addMovRegisterSignedConstant(Instruction_t *p_instr, Register::RegisterName p_regTgt, int p_constant, Instruction_t *p_fallThrough);
private:
void addTestRegister8(Instruction_t *p_instr, Register::RegisterName, Instruction_t *p_fallThrough);
void addTestRegister16(Instruction_t *p_instr, Register::RegisterName, Instruction_t *p_fallThrough);
......
......@@ -19,11 +19,12 @@ all: env_check ${exes}
# ${PEASOUP_HOME}/tools/ps_link.sh $< -o $@
# gcc -g $< -o $@
gcc $< -o $@
${PEASOUP_HOME}/tools/ps_analyze.sh $@ $@.peasoup --step ilr=off --step concolic=off --step p1transform=off --step isr=off
${PEASOUP_HOME}/tools/ps_analyze.sh $@ $@.peasoup
# ${PEASOUP_HOME}/tools/ps_analyze.sh $@ $@.peasoup --step ilr=off --step concolic=off --step p1transform=off --step isr=off
.c.o:
gcc -O2 -c $<
# gcc -O2 -c $<
gcc -c $<
# ${PEASOUP_HOME}/tools/ps_comp.sh $<
.cpp.o:
......
int main(int argc, char **argv)
{
unsigned a = 2000000000, b = 2000;
......@@ -10,7 +9,7 @@ int main(int argc, char **argv)
if (argc >= 2)
a = (unsigned) atoi(argv[1]) + 1;
if (argc >= 3)
// if (argc >= 3)
b = (unsigned) atoi(argv[2]) + 1;
unsigned d = a * b; // IMUL
......
int main(int argc, char **argv)
{
unsigned a = (unsigned) atoi(argv[1]);
unsigned b = (unsigned) atoi(argv[2]);
unsigned d = a * b;
unsigned a = 0;
unsigned b = 0;
unsigned d;
if (argc >= 2)
a = (unsigned) atoi(argv[1]);
printf("%u\n", d);
if (argc >= 3)
b = (unsigned) atoi(argv[2]);
if (d > 0 && a > 20000 && b > 20000)
printf("hello\n");
// printf("%u * %u = %u\n", a, b, d);
d = a * b;
printf("%u\n", d);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment