aboutsummaryrefslogtreecommitdiff
path: root/c67-gen.c
diff options
context:
space:
mode:
authorjiang <30155751@qq.com>2014-04-30 14:24:44 +0800
committerjiang <30155751@qq.com>2014-04-30 14:24:44 +0800
commit9ff288648b23537c205e4dad16002e2b9ca03203 (patch)
tree04168042a0103b0dfde4491e8c664086db990711 /c67-gen.c
parent515169f21bf6c75a3179822e1dd9e006f5ef4412 (diff)
downloadtinycc-9ff288648b23537c205e4dad16002e2b9ca03203.tar.gz
tinycc-9ff288648b23537c205e4dad16002e2b9ca03203.tar.bz2
Restore eda2c756edc4dca004ba217d5bf361235dd9de1f
Diffstat (limited to 'c67-gen.c')
-rw-r--r--c67-gen.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/c67-gen.c b/c67-gen.c
index a26dfaa..209fa7f 100644
--- a/c67-gen.c
+++ b/c67-gen.c
@@ -2102,7 +2102,7 @@ int gtst(int inv, int t)
C67_NOP(5);
t = ind1; //return where we need to patch
- } else { /* VT_JMP || VT_JMPI */
+ } else if (v == VT_JMP || v == VT_JMPI) {
/* && or || optimization */
if ((v & 1) == inv) {
/* insert vtop->c jump list in t */
@@ -2128,6 +2128,37 @@ int gtst(int inv, int t)
t = gjmp(t);
gsym(vtop->c.i);
}
+ } else {
+ if (is_float(vtop->type.t)) {
+ vpushi(0);
+ gen_op(TOK_NE);
+ }
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
+ /* constant jmp optimization */
+ if ((vtop->c.i != 0) != inv)
+ t = gjmp(t);
+ } else {
+ // I think we need to get the value on the stack
+ // into a register, test it, and generate a branch
+ // return the address of the branch, so it can be
+ // later patched
+
+ v = gv(RC_INT); // get value into a reg
+ ind1 = ind;
+ C67_MVKL(C67_A0, t); //r=reg to load, constant
+ C67_MVKH(C67_A0, t); //r=reg to load, constant
+
+ if (v != TREG_EAX && // check if not already in a conditional test reg
+ v != TREG_EDX && v != TREG_ST0 && v != C67_B2) {
+ C67_MV(v, C67_B2);
+ v = C67_B2;
+ }
+
+ C67_IREG_B_REG(inv, v, C67_A0); // [!R] B.S2x A0
+ C67_NOP(5);
+ t = ind1; //return where we need to patch
+ ind1 = ind;
+ }
}
vtop--;
return t;