Get subtractions the right way round.

This commit is contained in:
David Given 2016-11-15 20:25:11 +01:00
parent 5e8babf098
commit cc686ded62
2 changed files with 32 additions and 1 deletions

View file

@ -609,7 +609,7 @@ PATTERNS
ALUCC(ADD.I, "addi")
out:(int)reg = SUB.I(left:(int)reg, right:(int)reg)
emit "subf %out, %left, %right"
emit "subf %out, %right, %left"
cost 4;
out:(int)reg = SUB.I(left:(int)reg, right:CONST.I)

View file

@ -0,0 +1,31 @@
#include "test.h"
/* Constants in globals to defeat constant folding. */
int two = 2;
int one = 1;
int zero = 0;
int minusone = -1;
/* Bypasses the CRT, so there's no stdio or BSS initialisation. */
void _m_a_i_n(void)
{
ASSERT((two - one) == 1);
ASSERT((one - two) == -1);
ASSERT((two - 1) == 1);
ASSERT((one - 2) == -1);
ASSERT((2 - one) == 1);
ASSERT((1 - two) == -1);
ASSERT(((unsigned int)two - (unsigned int)one) == 1);
ASSERT(((unsigned int)one - (unsigned int)two) == 0xffffffff);
ASSERT(((unsigned int)two - (unsigned int)1) == 1);
ASSERT(((unsigned int)one - (unsigned int)2) == 0xffffffff);
ASSERT(((unsigned int)2 - (unsigned int)one) == 1);
ASSERT(((unsigned int)1 - (unsigned int)two) == 0xffffffff);
finished();
}