From 1a7d027beedcdfab1abcee755162d51f9ccfdb36 Mon Sep 17 00:00:00 2001 From: Minero Aoki Date: Sun, 31 May 2009 18:57:00 +0000 Subject: [PATCH] r5009@macbookpro: aamine | 2009-06-01 03:56:40 +0900 * net/loveruby/cflat/sysdep/x86/CodeGenerator.java (Bin): optimize more patterns. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4271 1b9489fe-b721-0410-924e-b54b9192deb8 --- ChangeLog | 5 +++ .../cflat/sysdep/x86/CodeGenerator.java | 41 ++++++++++++++----- test/test_cbc.sh | 22 ++++++---- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf272da..fea8a1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Jun 1 03:55:41 2009 Minero Aoki + + * net/loveruby/cflat/sysdep/x86/CodeGenerator.java (Bin): optimize + more patterns. + Sun May 31 22:32:29 2009 Minero Aoki * net/loveruby/cflat/sysdep/x86/CodeGenerator.java: refactoring: diff --git a/net/loveruby/cflat/sysdep/x86/CodeGenerator.java b/net/loveruby/cflat/sysdep/x86/CodeGenerator.java index 3c9977c..c7306bc 100644 --- a/net/loveruby/cflat/sysdep/x86/CodeGenerator.java +++ b/net/loveruby/cflat/sysdep/x86/CodeGenerator.java @@ -767,30 +767,49 @@ public class CodeGenerator // #@@range/Bin{ public Void visit(Bin node) { - Operand right = null; - if (!doesSpillRegister(node.op()) && node.right().isConstant()){ + Op op = node.op(); + Type t = node.type(); + if (node.right().isConstant() + && !doesRequireRegisterOperand(op)) { compile(node.left()); - right = node.right().asmValue(); + compileBinaryOp(op, ax(t), node.right().asmValue()); + } + else if (node.right().isConstant()) { + compile(node.left()); + loadConstant(node.right(), cx()); + compileBinaryOp(op, ax(t), cx(t)); } else if (node.right().isVar()) { compile(node.left()); - loadVariable(((Var)node.right()), cx()); - right = cx(node.type()); + loadVariable((Var)node.right(), cx(t)); + compileBinaryOp(op, ax(t), cx(t)); + } + else if (node.right().isAddr()) { + compile(node.left()); + loadAddress(node.right().getEntityForce(), cx(t)); + compileBinaryOp(op, ax(t), cx(t)); + } + else if (node.left().isConstant() + || node.left().isVar() + || node.left().isAddr()) { + compile(node.right()); + as.mov(ax(), cx()); + compile(node.left()); + compileBinaryOp(op, ax(t), cx(t)); } else { compile(node.right()); as.virtualPush(ax()); compile(node.left()); as.virtualPop(cx()); - right = cx(node.type()); + compileBinaryOp(op, ax(t), cx(t)); } - compileBinaryOp(node.op(), ax(node.type()), right); return null; } // #@@} - // #@@range/doesSpillRegister{ - private boolean doesSpillRegister(Op op) { + // #@@range/doesRequireRegisterOperand{ + private boolean doesRequireRegisterOperand(Op op) { switch (op) { case S_DIV: case U_DIV: @@ -875,7 +894,7 @@ public class CodeGenerator default: throw new Error("unknown binary operator: " + op); } - as.movzb(al(), left); + as.movzx(al(), left); } // #@@} } @@ -896,7 +915,7 @@ public class CodeGenerator case NOT: as.test(ax(src), ax(src)); as.sete(al()); - as.movzb(al(), ax(dest)); + as.movzx(al(), ax(dest)); break; case S_CAST: as.movsx(ax(src), ax(dest)); diff --git a/test/test_cbc.sh b/test/test_cbc.sh index f78574d..ce62b56 100644 --- a/test/test_cbc.sh +++ b/test/test_cbc.sh @@ -341,14 +341,20 @@ assert_stat() { assert_out() { msg="$1"; shift - assert_compile_success "$1.cb" && - assert_stdout "$msg" "$@" && - assert_compile_success -O "$1.cb" && - assert_stdout "$msg" "$@" && - assert_compile_success -fPIC "$1.cb" && - assert_stdout "$msg" "$@" && - assert_compile_success -O -fPIC "$1.cb" && - assert_stdout "$msg" "$@" + if [ -n "$SHUNIT_FAST" ] + then + assert_compile_success "$1.cb" && + assert_stdout "$msg" "$@" + else + assert_compile_success "$1.cb" && + assert_stdout "$msg" "$@" && + assert_compile_success -O "$1.cb" && + assert_stdout "$msg" "$@" && + assert_compile_success -fPIC "$1.cb" && + assert_stdout "$msg" "$@" && + assert_compile_success -O -fPIC "$1.cb" && + assert_stdout "$msg" "$@" + fi } assert_ok() {