A bad try implementing overflow detection in C2 (2) (original) (raw)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
diff --git a/src/cpu/x86/vm/x86_64.ad b/src/cpu/x86/vm/x86_64.ad |
---|
--- a/src/cpu/x86/vm/x86_64.ad |
+++ b/src/cpu/x86/vm/x86_64.ad |
@@ -10627,6 +10627,45 @@ |
ins_pipe(pipe_jcc); |
%} |
+instruct addI_ovf(rRegI dst, rRegI src, rFlagsReg cr) |
+%{ |
+ effect(DEF cr, USE dst, USE src); |
+ |
+ format %{ "addl dst,dst, dst,src\t# int with overflow check" %} |
+ opcode(0x03); |
+ ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src)); |
+ ins_pipe(ialu_reg_reg); |
+%} |
+ |
+instruct jmpOvf(rFlagsReg cr, label labl) |
+%{ |
+ effect(USE labl, USE cr); |
+ |
+ format %{ "jo $labl" %} |
+ size(6); |
+ ins_encode %{ |
+ Label* L = labllabllabl$label; |
+ __ jcc(Assembler::overflow, *L, false); // Always long jump |
+ %} |
+ ins_pipe(pipe_jcc); |
+%} |
+ |
+// Jump Direct on Add Overflow |
+instruct jmpAddOverflow(cmpOp cop, rRegI dst, rRegI src, rRegI sum, immI0 zero, label labl) |
+%{ |
+ predicate( n->in(1)->as_Bool()->_test._test == BoolTest::lt && |
+ n->in(2)->in(1)->in(1)->in(2) == n->in(2)->in(1)->in(2)->in(2) |
+ ); |
+ match(If cop (CmpI (AndI (XorI dst (AddI dst src)) (XorI src sum)) zero)); |
+ |
+ ins_cost(300); |
+ expand %{ |
+ rFlagsReg cr; |
+ addI_ovf(dst, src, cr); |
+ jmpOvf(cr, labl); |
+ %} |
+%} |
+ |
// Jump Direct Conditional - Label defines a relative address from Jcc+1 |
instruct jmpLoopEnd(cmpOp cop, rFlagsReg cr, label labl) |
%{ |
@@ -10828,6 +10867,20 @@ |
ins_short_branch(1); |
%} |
+instruct jmpOvf_short(rFlagsReg cr, label labl) |
+%{ |
+ effect(USE labl, USE cr); |
+ |
+ format %{ "jo,s $labl" %} |
+ size(2); |
+ ins_encode %{ |
+ Label* L = labllabllabl$label; |
+ __ jccb(Assembler::overflow, *L); |
+ %} |
+ ins_pipe(pipe_jcc); |
+ ins_short_branch(1); |
+%} |
+ |
// Jump Direct Conditional - Label defines a relative address from Jcc+1 |
instruct jmpLoopEnd_short(cmpOp cop, rFlagsReg cr, label labl) %{ |
match(CountedLoopEnd cop cr); |