shithub: rgbds

Download patch

ref: c24cab6d1d1735fc305712a4e95996c10023b45d
parent: 0cbe6abbd5855dae13e79cde17f972b6ced623f1
author: Antonio Niño Díaz <[email protected]>
date: Sun Dec 31 08:09:08 EST 2017

Use NOT operator to complement bits instead of XOR

The previous way of doing it relied on the variable being 32-bit wide.

Signed-off-by: Antonio Niño Díaz <[email protected]>

--- a/src/asm/asmy.y
+++ b/src/asm/asmy.y
@@ -1220,7 +1220,7 @@
 					}
 				|	T_OP_ADD const %prec NEG		{ $$ = +$2; }
 				|	T_OP_SUB const %prec NEG		{ $$ = -$2; }
-				|	T_OP_NOT const %prec NEG		{ $$ = 0xFFFFFFFF^$2; }
+				|	T_OP_NOT const %prec NEG		{ $$ = ~$2; }
 				|	T_OP_ROUND '(' const ')'		{ $$ = math_Round($3); }
 				|	T_OP_CEIL '(' const ')'			{ $$ = math_Ceil($3); }
 				|	T_OP_FLOOR '(' const ')'		{ $$ = math_Floor($3); }
--- a/src/asm/rpn.c
+++ b/src/asm/rpn.c
@@ -362,6 +362,6 @@
 rpn_UNNOT(struct Expression * expr, struct Expression * src)
 {
 	*expr = *src;
-	expr->nVal = expr->nVal ^ 0xFFFFFFFF;
+	expr->nVal = ~expr->nVal;
 	pushbyte(expr, RPN_UNNOT);
 }
--- a/src/link/patch.c
+++ b/src/link/patch.c
@@ -128,7 +128,7 @@
 			rpnpush(rpnpop() ^ rpnpop());
 			break;
 		case RPN_UNNOT:
-			rpnpush(rpnpop() ^ 0xFFFFFFFF);
+			rpnpush(~rpnpop());
 			break;
 		case RPN_LOGAND:
 			rpnpush(rpnpop() && rpnpop());