Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

be-codegen-6800.c gen_shortcut() long value assignment. #154

Open
zu2 opened this issue Nov 2, 2024 · 0 comments
Open

be-codegen-6800.c gen_shortcut() long value assignment. #154

zu2 opened this issue Nov 2, 2024 · 0 comments

Comments

@zu2
Copy link

zu2 commented Nov 2, 2024

I tried assigning a long value using gen_shortcut().It seems to work in a simple test.

--- ../Fuzix-Compiler-Kit/be-codegen-6800.c	2024-11-02 08:28:02
+++ be-codegen-6800.c	2024-11-02 14:42:14
@@ -1152,7 +1152,7 @@
 	struct node *r = n->right;
 	unsigned s = get_size(n->type);
 	unsigned nr = n->flags & NORETURN;
-	unsigned v;
+	unsigned v,vl,vr;
 
 	/* Don't generate unreachable code */
 	if (unreachable)
@@ -1283,7 +1283,25 @@
 					load_d_const(r->value);
 					op16d_on_ptr("st", "st", v + 2);
 					load_d_const(r->value >> 16);
+					op16d_on_ptr("st", "st", v);
+					invalidate_work();
+					return 1;
+				}
+			}
+			if (n->op == T_EQ && nr && s == 4 &&  l->op == T_LOCAL
+			&&  r->op == T_DEREF && r->right->op == T_LOCAL) {
+				vl = l->value;
+				vr = r->right->value;
+				printf("; T_EQ && T_LOCAL v=%d, vl=%d, vr=%d\n",v,vl,vr);
+				if(vl<252 && vr<252){
+					v  += load_x_with(l, 0);
+					vr = load_x_with(r->right, 0);
+					printf("; T_EQ make direct load/store v=%d, vr=%d\n",v,vr);
+					op16d_on_ptr("ld", "ld", vr + 2);
+					op16d_on_ptr("st", "st", v + 2);
+					op16d_on_ptr("ld", "ld", vr);
 					op16d_on_ptr("st", "st", v);
+					invalidate_work();
 					return 1;
 				}
 			}
@@ -1330,10 +1348,29 @@
 		}
 		return 0;
 	case T_PLUSEQ:
 		if (s == 1 && memop_const(n, "inc", nr, 2))
 			return 1;
 		if (s == 2 && add_to_node(n, 1, 1))
 			return 1;
+		if (s == 4 && nr && l->op == T_LOCAL && r->op == T_DEREF && r->right->op == T_LOCAL) {
+			v = n->value;
+			vl = l->value;
+			vr = r->right->value;
+			printf("; T_PLUSEQ && T_LOCAL v=%d, vl=%d, vr=%d\n",v,vl,vr);
+			if(vl<254 && vr<254){	// both offset < 254
+				vl = v + load_x_with(l, 0);
+				vr = load_x_with(r->right, 0);
+				printf("; T_PLUSEQ make direct load/add/store v=%d, vl=%d, vr=%d\n",v,vl,vr);
+				op16d_on_ptr("ld", "ld", vl + 2);
+				op16d_on_ptr("add", "adc", vr + 2);
+				op16d_on_ptr("st", "st", vl + 2);
+				op16d_on_ptr("ld", "ld", vl);
+				op16d_on_ptr("adc", "adc", vr);
+				op16d_on_ptr("st", "st", vl);
+				invalidate_work();
+				return 1;
+			}
+		}
 		return do_xeqop(n, "xpluseq");
 	case T_MINUSEQ:
 		if (s == 1 && memop_const(n, "dec", nr, 2))

sample program:

int
main(int argc, char **argv)
{
	long a = 1;
	unsigned long b = 100;
	long c;

	c = a;
	c += b;

	return !(c==a+b);
}

It compiles like this.

; T_EQ/EQPLUS v=0
; T_EQ && T_LOCAL v=0, vl=8, vr=0
;make local ptr off 8, rlim 252 noff 8
;make local ptr off 0, rlim 252 noff 0
; T_EQ make direct load/store v=8, vr=0
        ldb 3,x
        lda 2,x
        stb 11,x
        sta 10,x
        ldb 1,x
        lda 0,x
        stb 9,x
        sta 8,x
;
; T_PLUSEQ && T_LOCAL v=0, vl=8, vr=4
;make local ptr off 8, rlim 252 noff 8
;make local ptr off 4, rlim 252 noff 4
; T_PLUSEQ make direct load/add/store v=0, vl=8, vr=4
        ldb 11,x
        lda 10,x
        addb 7,x
        adca 6,x
        stb 11,x
        sta 10,x
        ldb 9,x
        lda 8,x
        adcb 5,x
        adca 4,x
        stb 9,x
        sta 8,x

I think there is an error in the code because I don't fully understand how to use load_x_with and make_local_ptr.

It seems possible to compile global variables and other calculations this way, but simply adding them would make the program size enormous. I'm thinking of a way to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant