mirror of https://github.com/aamine/cbc
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
This commit is contained in:
parent
694aa209f3
commit
1a7d027bee
|
|
@ -1,3 +1,8 @@
|
|||
Mon Jun 1 03:55:41 2009 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* net/loveruby/cflat/sysdep/x86/CodeGenerator.java (Bin): optimize
|
||||
more patterns.
|
||||
|
||||
Sun May 31 22:32:29 2009 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* net/loveruby/cflat/sysdep/x86/CodeGenerator.java: refactoring:
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue