SYSTEM.ADDRESS signed (again), DIV, MOD full integer support, ASH and checks support 64 bit ints.

Change (back) to address type being signed.
DIV and MOD fully defined for the full range of integer on both parameters.
_X, _XF, _R and _RF checks upgraded for 64 bit support.
ASH upgraded for 64 bit.
Add div and mod tests to language confidence test.
Enable debuggable C compiler options.
This commit is contained in:
David Brown 2016-09-09 14:47:40 +01:00
parent ebfc60f49d
commit 83aaa70290
8 changed files with 146 additions and 64 deletions

View file

@ -226,6 +226,9 @@ uninstall: configuration
confidence: configuration
@make -f src/tools/make/vishap.make -s confidence
planned-binary-change:
@date >src/test/confidence/planned-binary-change

View file

@ -336,8 +336,7 @@ MODULE Heap;
tag := tagbits + SZA; (* Tag addresses first offset *)
LOOP
SYSTEM.GET(tag, offset); (* Get next ptr field offset *)
IF SYSTEM.BIT(SYSTEM.ADR(offset), SIZE(SYSTEM.ADDRESS)*8 - 1) THEN
(* Sentinel reached: Value is -8*(#fields+1) *)
IF offset < 0 THEN (* Sentinel reached: Value is -8*(#fields+1) *)
SYSTEM.PUT(q - SZA, tag + offset + 1); (* Rotate base ptr into tag *)
IF p = 0 THEN EXIT END ;
n := q; q := p;

View file

@ -21,11 +21,34 @@
// Procedure verions of SYSTEM.H versions used when a multiply accessed
// parameter has side effects.
int64 SYSTEM_XCHK(uint64 i, uint64 ub) {return __X(i, ub);}
int64 SYSTEM_RCHK(uint64 i, uint64 ub) {return __R(i, ub);}
LONGINT SYSTEM_ASH (LONGINT i, LONGINT n) {return __ASH(i, n);}
LONGINT SYSTEM_ABS (LONGINT i) {return __ABS(i);}
double SYSTEM_ABSD(double i) {return __ABS(i);}
LONGINT SYSTEM_ABS (LONGINT i) {return __ABS(i);}
double SYSTEM_ABSD(double i) {return __ABS(i);}
int64 SYSTEM_DIV(int64 x, int64 y)
{
if (x == 0) return 0;
if (x >= 0)
if (y >= 0) {return x/y;}
else {return -((x-y-1)/(-y));}
else
if (y >= 0) {return -((y-x-1)/y);}
else {return (-x)/(-y);}
}
int64 SYSTEM_MOD(int64 x, int64 y)
{
if (x == 0) return 0;
if (x >= 0)
if (y >= 0) {return x % y;}
else {return (y+1) + ((x-1) % (-y));}
else
if (y >= 0) {return (y-1) - ((-x-1) % y);}
else {return -((-x) % (-y));}
}
void SYSTEM_INHERIT(LONGINT *t, LONGINT *t0)
{
@ -57,19 +80,6 @@ void SYSTEM_ENUMR(void *adr, LONGINT *typ, LONGINT size, LONGINT n, void (*P)())
}
}
LONGINT SYSTEM_DIV(uint64 x, uint64 y)
{ if ((int64) x >= 0) return (x / y);
else return -((y - 1 - x) / y);
}
LONGINT SYSTEM_MOD(uint64 x, uint64 y)
{ uint64 m;
if ((int64) x >= 0) return (x % y);
else { m = (-x) % y;
if (m != 0) return (y - m); else return 0;
}
}
LONGINT SYSTEM_ENTIER(double x)
{
LONGINT y;

View file

@ -2,6 +2,8 @@
#define SYSTEM__h
// Temporary while bootstrapping and clearing up SYSTEM.c.
#ifndef LONGINT
#if (__SIZEOF_POINTER__ == 8) || defined(_WIN64)
@ -25,11 +27,14 @@
#if (__SIZEOF_POINTER__ == 8) || defined(_WIN64) || defined(__LP64__)
#if defined(_WIN64)
typedef unsigned long long size_t;
typedef long long address;
#else
typedef unsigned long size_t;
typedef long address;
#endif
#else
typedef unsigned int size_t;
typedef int address;
#endif
#define _SIZE_T_DECLARED // For FreeBSD
@ -59,7 +64,7 @@ typedef unsigned short int uint16;
typedef signed char int8;
typedef unsigned char uint8;
#define address size_t
// The compiler uses 'import' and 'export' which translate to 'extern' and
// nothing respectively.
@ -103,18 +108,40 @@ extern address Platform_OSAllocate (address size);
extern void Platform_OSFree (address addr);
// Assertions and Halts
extern void Platform_Halt(LONGINT x);
extern void Platform_AssertFail(LONGINT x);
#define __HALT(x) Platform_Halt(x)
#define __ASSERT(cond, x) if (!(cond)) Platform_AssertFail((LONGINT)(x))
// Index checking
static inline int64 __XF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-2);} return i;}
#define __X(i, ub) (((uint64)(i)<(uint64)(ub))?i:(__HALT(-2),0))
// Range checking, and checked SHORT and CHR functions
static inline int64 __RF(uint64 i, uint64 ub) {if (i >= ub) {__HALT(-8);} return i;}
#define __R(i, ub) (((uint64)(i)<(uint64)(ub))?i:(__HALT(-8),0))
#define __SHORT(x, ub) ((int)((uLONGINT)(x)+(ub)<(ub)+(ub)?(x):(__HALT(-8),0)))
#define __SHORTF(x, ub) ((int)(__RF((x)+(ub),(ub)+(ub))-(ub)))
#define __CHR(x) ((CHAR)__R(x, 256))
#define __CHRF(x) ((CHAR)__RF(x, 256))
// Run time system routines in SYSTEM.c
extern int64 SYSTEM_XCHK (uint64 i, uint64 ub);
extern int64 SYSTEM_RCHK (uint64 i, uint64 ub);
extern LONGINT SYSTEM_ASH (LONGINT i, LONGINT n);
extern LONGINT SYSTEM_ABS (LONGINT i);
extern double SYSTEM_ABSD (double i);
extern void SYSTEM_INHERIT(LONGINT *t, LONGINT *t0);
extern void SYSTEM_ENUMP (void *adr, LONGINT n, void (*P)());
extern void SYSTEM_ENUMR (void *adr, LONGINT *typ, LONGINT size, LONGINT n, void (*P)());
extern LONGINT SYSTEM_DIV (uint64 x, uint64 y);
extern LONGINT SYSTEM_MOD (uint64 x, uint64 y);
extern LONGINT SYSTEM_ENTIER (double x);
@ -131,7 +158,7 @@ extern LONGINT SYSTEM_ENTIER (double x);
// String comparison
static int __str_cmp(CHAR *x, CHAR *y){
static inline int __str_cmp(CHAR *x, CHAR *y){
LONGINT i = 0;
CHAR ch1, ch2;
do {ch1 = x[i]; ch2 = y[i]; i++;
@ -152,21 +179,12 @@ static int __str_cmp(CHAR *x, CHAR *y){
#define __DEL(x) Platform_OSFree((address)x)
// Index and range checks
#define __X(i, ub) (((uint64)(i)<(uint64)(ub))?i:(__HALT(-2),0))
#define __XF(i, ub) SYSTEM_XCHK((uint64)(i), (uint64)(ub))
#define __R(i, ub) (((uint64)(i)<(uint64)(ub))?i:(__HALT(-8),0))
#define __RF(i, ub) SYSTEM_RCHK((uint64)(i),(uint64)(ub))
/* SYSTEM ops */
#define __VAL(t, x) (*(t*)&(x))
#define __GET(a, x, t) x= *(t*)(address)(a)
#define __GET(a, x, t) x=*(t*)(address)(a)
#define __PUT(a, x, t) *(t*)(address)(a)=x
#define __LSHL(x, n, t) ((t)((u##t)(x)<<(n)))
@ -177,21 +195,28 @@ static int __str_cmp(CHAR *x, CHAR *y){
#define __ROTR(x, n, t) ((t)((u##t)(x)>>(n)|(u##t)(x)<<(8*sizeof(t)-(n))))
#define __ROT(x, n, t) ((n)>=0? __ROTL(x, n, t): __ROTR(x, -(n), t))
#define __ASHL(x, n) ((LONGINT)(x)<<(n))
#define __ASHR(x, n) ((LONGINT)(x)>>(n))
#define __ASHL(x, n) ((int64)(x)<<(n))
#define __ASHR(x, n) ((int64)(x)>>(n))
#define __ASH(x, n) ((n)>=0?__ASHL(x,n):__ASHR(x,-(n)))
#define __ASHF(x, n) SYSTEM_ASH((LONGINT)(x), (LONGINT)(n))
static inline int64 SYSTEM_ASH(int64 x, int64 n) {return __ASH(x,n);}
#define __ASHF(x, n) SYSTEM_ASH((int64)(x), (int64)(n))
#define __BIT(x, n) (*(uint64*)(x)>>(n)&1)
#define __MOVE(s, d, n) memcpy((char*)(address)(d),(char*)(address)(s),n)
#define __SHORT(x, y) ((int)((uLONGINT)(x)+(y)<(y)+(y)?(x):(__HALT(-8),0)))
#define __SHORTF(x, y) ((int)(__RF((x)+(y),(y)+(y))-(y)))
#define __CHR(x) ((CHAR)__R(x, 256))
#define __CHRF(x) ((CHAR)__RF(x, 256))
#define __DIV(x, y) ((x)>=0?(x)/(y):-(((y)-1-(x))/(y)))
#define __DIVF(x, y) SYSTEM_DIV((LONGINT)(x),(LONGINT)(y))
#define __MOD(x, y) ((x)>=0?(x)%(y):__MODF(x,y))
#define __MODF(x, y) SYSTEM_MOD((LONGINT)(x),(LONGINT)(y))
extern int64 SYSTEM_DIV(int64 x, int64 y);
#define __DIVF(x, y) SYSTEM_DIV(x, y)
#define __DIV(x, y) (((x)>0 && (y)>0) ? (x)/(y) : __DIVF(x, y))
extern int64 SYSTEM_MOD(int64 x, int64 y);
#define __MODF(x, y) SYSTEM_MOD(x, y)
#define __MOD(x, y) (((x)>0 && (y)>0) ? (x)%(y) : __MODF(x, y))
#define __ENTIER(x) SYSTEM_ENTIER(x)
#define __ABS(x) (((x)<0)?-(x):(x))
#define __ABSF(x) SYSTEM_ABS((LONGINT)(x))
@ -244,15 +269,6 @@ extern void Heap_FINALL();
#define __FINI Heap_FINALL(); return 0
// Assertions and Halts
extern void Platform_Halt(LONGINT x);
extern void Platform_AssertFail(LONGINT x);
#define __HALT(x) Platform_Halt(x)
#define __ASSERT(cond, x) if (!(cond)) Platform_AssertFail((LONGINT)(x))
// Memory allocation
extern SYSTEM_PTR Heap_NEWBLK (address size);

View file

@ -108,6 +108,59 @@ BEGIN
END
END TestValue;
PROCEDURE side(i: INTEGER): INTEGER; BEGIN RETURN i END side;
PROCEDURE DivMod;
VAR i,j: INTEGER;
BEGIN
j := 2;
i := 4; TestValue(i DIV j, 2, "4 DIV 2"); TestValue(side(i) DIV side(j), 2, "side(4) DIV side(2)");
i := 5; TestValue(i DIV j, 2, "5 DIV 2"); TestValue(side(i) DIV side(j), 2, "side(5) DIV side(2)");
i := 6; TestValue(i DIV j, 3, "6 DIV 2"); TestValue(side(i) DIV side(j), 3, "side(6) DIV side(2)");
i := 7; TestValue(i DIV j, 3, "7 DIV 2"); TestValue(side(i) DIV side(j), 3, "side(7) DIV side(2)");
i := -4; TestValue(i DIV j, -2, "(-4) DIV 2"); TestValue(side(i) DIV side(j), -2, "side(-4) DIV side(2)");
i := -5; TestValue(i DIV j, -3, "(-5) DIV 2"); TestValue(side(i) DIV side(j), -3, "side(-5) DIV side(2)");
i := -6; TestValue(i DIV j, -3, "(-6) DIV 2"); TestValue(side(i) DIV side(j), -3, "side(-6) DIV side(2)");
i := -7; TestValue(i DIV j, -4, "(-7) DIV 2"); TestValue(side(i) DIV side(j), -4, "side(-7) DIV side(2)");
j := -2;
i := 4; TestValue(i DIV j, -2, "4 DIV (-2)"); TestValue(side(i) DIV side(j), -2, "side(4) DIV side(-2)");
i := 5; TestValue(i DIV j, -3, "5 DIV (-2)"); TestValue(side(i) DIV side(j), -3, "side(5) DIV side(-2)");
i := 6; TestValue(i DIV j, -3, "6 DIV (-2)"); TestValue(side(i) DIV side(j), -3, "side(6) DIV side(-2)");
i := 7; TestValue(i DIV j, -4, "7 DIV (-2)"); TestValue(side(i) DIV side(j), -4, "side(7) DIV side(-2)");
i := -4; TestValue(i DIV j, 2, "(-4) DIV (-2)"); TestValue(side(i) DIV side(j), 2, "side(-4) DIV side(-2)");
i := -5; TestValue(i DIV j, 2, "(-5) DIV (-2)"); TestValue(side(i) DIV side(j), 2, "side(-5) DIV side(-2)");
i := -6; TestValue(i DIV j, 3, "(-6) DIV (-2)"); TestValue(side(i) DIV side(j), 3, "side(-6) DIV side(-2)");
i := -7; TestValue(i DIV j, 3, "(-7) DIV (-2)"); TestValue(side(i) DIV side(j), 3, "side(-7) DIV side(-2)");
(* x = (x DIV y) * y + (x MOD y)
=> x MOd y = x - ((x DIV y) * y)
*)
i := 4; j := 3; TestValue(i MOD j, i - ((i DIV j) * j), "4 MOD 3");
i := 5; j := 3; TestValue(i MOD j, i - ((i DIV j) * j), "5 MOD 3");
i := 6; j := 3; TestValue(i MOD j, i - ((i DIV j) * j), "6 MOD 3");
i := 7; j := 3; TestValue(i MOD j, i - ((i DIV j) * j), "7 MOD 3");
i := -4; j := 3; TestValue(i MOD j, i - ((i DIV j) * j), "-4 MOD 3");
i := -5; j := 3; TestValue(i MOD j, i - ((i DIV j) * j), "-5 MOD 3");
i := -6; j := 3; TestValue(i MOD j, i - ((i DIV j) * j), "-6 MOD 3");
i := -7; j := 3; TestValue(i MOD j, i - ((i DIV j) * j), "-7 MOD 3");
i := 4; j := -3; TestValue(i MOD j, i - ((i DIV j) * j), "4 MOD -3");
i := 5; j := -3; TestValue(i MOD j, i - ((i DIV j) * j), "5 MOD -3");
i := 6; j := -3; TestValue(i MOD j, i - ((i DIV j) * j), "6 MOD -3");
i := 7; j := -3; TestValue(i MOD j, i - ((i DIV j) * j), "7 MOD -3");
i := -4; j := -3; TestValue(i MOD j, i - ((i DIV j) * j), "-4 MOD -3");
i := -5; j := -3; TestValue(i MOD j, i - ((i DIV j) * j), "-5 MOD -3");
i := -6; j := -3; TestValue(i MOD j, i - ((i DIV j) * j), "-6 MOD -3");
i := -7; j := -3; TestValue(i MOD j, i - ((i DIV j) * j), "-7 MOD -3");
END DivMod;
PROCEDURE IntSize;
VAR l: LONGINT;
BEGIN
@ -136,6 +189,7 @@ END IntSize;
BEGIN
Shift;
DivMod;
IntSize;
Console.String("Language tests successful."); Console.Ln;
END TestLanguage.

View file

@ -1 +1 @@
b
09 Sep 2016 14:20:47

View file

@ -22,5 +22,5 @@ rm -f *.o *.obj *.exe *.sym *.c *.h result new.asm
# NOTE 2: The cygwin 64 bit build has relocation errors with
# these assembly generation options.
if [ "$COMPILER" = "gcc" -a "$FLAVOUR" != "cygwin.LP64.gcc" ]
then export CFLAGS="-gstabs -g1 -Wa,-acdhln=new.asm"
then export CFLAGS="-gstabs -g1 -Wa,-acdhln=new.asm -Wl,-Map=output.map"
fi

View file

@ -131,20 +131,20 @@ void determineCCompiler() {
#if defined(__MINGW32__)
compiler = "mingw";
if (sizeof (void*) == 4) {
cc = "i686-w64-mingw32-gcc -g";
cc = "i686-w64-mingw32-gcc -g -Og";
} else {
cc = "x86_64-w64-mingw32-gcc -g";
cc = "x86_64-w64-mingw32-gcc -g -Og";
}
#elif defined(__clang__)
compiler = "clang";
cc = "clang -fPIC -g";
cc = "clang -fPIC -g -O1";
#elif defined(__GNUC__)
compiler = "gcc";
if (strncasecmp(os, "cygwin", 6) == 0) {
// Avoid cygwin specific warning that -fPIC is ignored.
cc = "gcc -g";
cc = "gcc -g -Og";
} else {
cc = "gcc -fPIC -g";
cc = "gcc -fPIC -g -Og";
}
#elif defined(_MSC_VER)
compiler = "MSC";