summary refs log tree commit diff
path: root/fold.c
diff options
context:
space:
mode:
authorEyal Sawady <ecs@d2evs.net>2022-01-17 22:00:48 +0000
committerQuentin Carbonneaux <quentin@c9x.me>2022-01-23 11:43:59 +0100
commite91d12158122b23271ff49de8977c92fef7f3908 (patch)
treeea5051ef69ae917f23249fe7a6adc8569deb3718 /fold.c
parent367c8215d99054892740ad74c690b106c45ebf60 (diff)
downloadroux-e91d12158122b23271ff49de8977c92fef7f3908.tar.gz
Add a negation instruction
Necessary for floating-point negation, because
`%result = sub 0, %operand` doesn't give the correct sign for 0/-0.
Diffstat (limited to 'fold.c')
-rw-r--r--fold.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/fold.c b/fold.c
index 348e532..9923f75 100644
--- a/fold.c
+++ b/fold.c
@@ -368,6 +368,7 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr)
 	switch (op) {
 	case Oadd:  x = l.u + r.u; break;
 	case Osub:  x = l.u - r.u; break;
+	case Oneg:  x = -l.u; break;
 	case Odiv:  x = w ? l.s / r.s : (int32_t)l.s / (int32_t)r.s; break;
 	case Orem:  x = w ? l.s % r.s : (int32_t)l.s % (int32_t)r.s; break;
 	case Oudiv: x = w ? l.u / r.u : (uint32_t)l.u / (uint32_t)r.u; break;
@@ -464,6 +465,7 @@ foldflt(Con *res, int op, int w, Con *cl, Con *cr)
 		switch (op) {
 		case Oadd: xd = ld + rd; break;
 		case Osub: xd = ld - rd; break;
+		case Oneg: xd = -ld; break;
 		case Odiv: xd = ld / rd; break;
 		case Omul: xd = ld * rd; break;
 		case Oswtof: xd = (int32_t)cl->bits.i; break;
@@ -480,6 +482,7 @@ foldflt(Con *res, int op, int w, Con *cl, Con *cr)
 		switch (op) {
 		case Oadd: xs = ls + rs; break;
 		case Osub: xs = ls - rs; break;
+		case Oneg: xs = -ls; break;
 		case Odiv: xs = ls / rs; break;
 		case Omul: xs = ls * rs; break;
 		case Oswtof: xs = (int32_t)cl->bits.i; break;