Open zu2 opened 4 days ago
In the signed case, this results in better code. use gen_shortcut.
@@ -1393,6 +1428,38 @@
return do_xeqop(n, "xoreq");
case T_HATEQ:
return do_xeqop(n, "xhateq");
+ case T_PLUS:
+ if (s==2 && n->type==CSHORT
+ && r->op == T_CAST && r->type == CSHORT
+ && l->op == T_CAST && l->type == CSHORT
+ && r->right->type == CCHAR
+ && l->right->type == CCHAR ){
+ if (is_simple(r->right)){
+ codegen_lr(l->right);
+ puts("\tclra");
+ op8_on_node(r->right, "add", 0);
+ printf("\tbge X%d\n\tdeca\n",++label);
+ printf("X%d:\n",label);
+ return 1;
+ }
+ }
+ return 0;
+ case T_MINUS:
+ if (s==2 && n->type==CSHORT
+ && r->op == T_CAST && r->type == CSHORT
+ && l->op == T_CAST && l->type == CSHORT
+ && r->right->type == CCHAR
+ && l->right->type == CCHAR ){
+ if (is_simple(r->right)){
+ codegen_lr(l->right);
+ puts("\tclra");
+ op8_on_node(r->right, "sub", 0);
+ printf("\tbge X%d\n\tdeca\n",++label);
+ printf("X%d:\n",label);
+ return 1;
+ }
+ }
+ return 0;
Currently, addition with signed/unsigned char pushes the augend onto the stack, sign-extends the addend, and then calls a helper function.
This patch provides shorter code.
the patch pass this test program.
before
after.
This patch does not shorten the form p - q as memcmp uses. I am looking for a way to do this.