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 += -= on char produces inefficient code for large numbers. #164

Open
zu2 opened this issue Nov 16, 2024 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@zu2
Copy link

zu2 commented Nov 16, 2024

--- ../Fuzix-Compiler-Kit/be-codegen-6800.c	2024-11-13 00:32:04
+++ be-codegen-6800.c	2024-11-16 21:25:36
@@ -1350,15 +1416,17 @@
 		}
 		return 0;
 	case T_PLUSEQ:
-		if (s == 1 && memop_const(n, "inc", nr, 2))
+		v = r->value;
+		if (s == 1 && v<2+optsize && memop_const(n, "inc", nr, 2))
 			return 1;
-		if (s == 2 && add_to_node(n, 1, 1))
+		if (s <= 2 && add_to_node(n, 1, 1))
 			return 1;
 		return do_xeqop(n, "xpluseq");
 	case T_MINUSEQ:
-		if (s == 1 && memop_const(n, "dec", nr, 2))
+		v = r->value;
+		if (s == 1 && v<2+optsize && memop_const(n, "dec", nr, 2))
 			return 1;
-		if (s == 2 && add_to_node(n, -1, 1))
+		if (s <= 2 && add_to_node(n, -1, 1))
 			return 1;
 		return do_xeqop(n, "xminuseq");
 	case T_PLUSPLUS:

test program:

int
sub(unsigned char x,unsigned char y)
{
	x += 10;
	y -= 10;
	return x+y;
}

int
main(int argc, char **argv)
{
	unsigned char x,y;

	x = 100;
	y = 50;

	if (sub(x,y)!=150)
		return 1;

	return 0;
}

before

_sub:
;:rewritten:
;T_PLUSEQ v0 t8 f6 NORETURN, UCHAR
;    T_ARGUMENT v0 t9 f1  UCHAR	x
;    T_CONSTANT va t8 f900 BYTETAIL, UCHAR
;make local ptr off 2, rlim 252 noff 2
	tsx
	inc 2,x
	inc 2,x
	inc 2,x
	inc 2,x
	inc 2,x
	inc 2,x
	inc 2,x
	inc 2,x
	inc 2,x
	inc 2,x
;
;:rewritten:
;T_MINUSEQ v0 t8 f6 NORETURN, UCHAR
;    T_ARGUMENT v1 t9 f1  UCHAR	y
;    T_CONSTANT va t8 f900 BYTETAIL, UCHAR
;make local ptr off 3, rlim 252 noff 3
	dec 3,x
	dec 3,x
	dec 3,x
	dec 3,x
	dec 3,x
	dec 3,x
	dec 3,x
	dec 3,x
	dec 3,x
	dec 3,x

after

_sub:
;:rewritten:
;T_PLUSEQ v0 t8 f6 NORETURN, UCHAR
;    T_ARGUMENT v0 t9 f1  UCHAR	x
;    T_CONSTANT va t8 f900 BYTETAIL, UCHAR
;make local ptr off 2, rlim 252 noff 2
	tsx
	ldb 2,x
	addb #10
	stb 2,x
;
;:rewritten:
;T_MINUSEQ v0 t8 f6 NORETURN, UCHAR
;    T_ARGUMENT v1 t9 f1  UCHAR	y
;    T_CONSTANT va t8 f900 BYTETAIL, UCHAR
;make local ptr off 3, rlim 252 noff 3
	ldb 3,x
	addb #246
	stb 3,x
@EtchedPixels EtchedPixels added bug Something isn't working enhancement New feature or request labels Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants