From: ceriel Date: Wed, 2 Dec 1987 09:04:32 +0000 (+0000) Subject: Added floating point stuff X-Git-Tag: release-5-5~3690 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=9cc60526b76720390d5cf6777a156fade947913e;p=ack.git Added floating point stuff --- diff --git a/mach/m68k2/cg/fppsim.h b/mach/m68k2/cg/fppsim.h index bc077b26f..a7d621e27 100644 --- a/mach/m68k2/cg/fppsim.h +++ b/mach/m68k2/cg/fppsim.h @@ -3,5 +3,4 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -/* #define FPPSIM /* define when using fpp simulator */ -/* #define IEEEFLOAT /* define if it must use IEEE format */ +/* #define NOFLOAT /* define when not using fpp simulator */ diff --git a/mach/m68k2/cg/mach.c b/mach/m68k2/cg/mach.c index 7bc7e9c61..58601dd52 100644 --- a/mach/m68k2/cg/mach.c +++ b/mach/m68k2/cg/mach.c @@ -14,17 +14,6 @@ static char rcsid[] = "$Header$"; #include "fppsim.h" -#ifdef IEEEFLOAT -#include "FP.h" -#include "trp.c" -#include "fcompact.c" -#include "dbl_extract.c" -#ifdef PRT_EXP_DEBUG -#include "prt_extend.c" -#endif -#endif IEEEFLOAT - - con_part(sz,w) register sz; word w; { while (part_size % sz) @@ -50,70 +39,124 @@ con_mult(sz) word sz; { fprintf(codefile,".data4 %s\n",str); } -#ifdef IEEEFLOAT -dbl_adjust(fl) -my_dbl *fl; -{ - EXTEND buf; - - /* special routine to strip SGL_BIAS */ - dbl_extract(fl,&buf); - /* standard routine to add DBL_BIAS */ - fcompact(&buf,fl,sizeof(double)); +#ifdef NOFLOAT +con_float() { + +static int been_here; + if (argval != 4 && argval != 8) + fatal("bad fcon size"); + fputs(".data4\t", codefile); + if (argval == 8) + fputs("0,", codefile); + fputs("0 !dummy float\n", codefile); + if ( !been_here++) + { + fputs("Warning : dummy float-constant(s)\n", stderr); + } } -#endif IEEEFLOAT - -con_float() -{ - register word sz; - register long *l; -#ifdef FPPSIM +#else +#define IEEEFLOAT + +con_float() { + double f; + double atof(); + float fl; + int i; +#ifndef OWNFLOAT + double f1; + double frexp(), modf(); + int j; + int sign = 0; + int fraction[4] ; +#else OWNFLOAT + char *p; +#endif OWNFLOAT + + if (argval!= 4 && argval!= 8) { + fprintf(stderr,"float constant size = %d\n",argval); + fatal("bad fcon size"); + } + fprintf(codefile,"!float %s sz %d\n", str, argval); + f = atof(str); +#ifdef OWNFLOAT + if (argval == 4) { + fl = f; + p = (char *) &fl; + } + else { + p = (char *) &f; + } + fprintf(codefile, ".data1 0%o", *p++ & 0377); + for (i = argval-1; i; i--) { + fprintf(codefile,",0%o", *p++ & 0377); + } +#else OWNFLOAT + f = frexp(f, &i); + if (f < 0) { + f = -f; + sign = 1; + } + if (f == 0) { + if (argval == 8) fprintf(codefile, ".data2 0, 0\n"); + fprintf(codefile, ".data2 0, 0\n"); + return; + } + while (f < 0.5) { + f += f; + i --; + } + f = modf(2 * f, &f1); /* hidden bit */ #ifdef IEEEFLOAT - register my_dbl *md; + if (argval == 4) { #endif IEEEFLOAT - double d, atof(); -#else not FPPSIM - static int been_here; -#endif - - sz = argval; - if (sz!= 4 && sz!= 8) { - char mesg[128]; - sprintf(mesg,"con_float(): bad fcon size %d %ld\nstr: %s\n\0", - sz,sz,str); - fatal(mesg); - } - -#ifdef FPPSIM - d = atof(str); - l = (long *) &d; - + i = (i + 128) & 0377; + fraction[0] = (sign << 15) | (i << 7); + for (j = 6; j>= 0; j--) { + if (f >= 0.5) fraction[0] |= (1 << j); + f = modf(2*f, &f1); + } #ifdef IEEEFLOAT - if (sz == 8) { - /* ATOF() RETURNS THE PROPER FORMAT FOR A FLOAT */ - /* BUT NOT FOR A DOUBLE. CORRECT THE FORMAT. */ - md = (my_dbl *) &d; - dbl_adjust(md); + } + else { + i = (i + 1024) & 03777; + fraction[0] = (sign << 15) | (i << 4); + for (j = 3; j>= 0; j--) { + if (f >= 0.5) fraction[0] |= (1 << j); + f = modf(2*f, &f1); + } } #endif IEEEFLOAT - - while ( sz ) { - fprintf(codefile,"\t.data2 0x%x,0x%x !float test %s\n", - (int)(*l)&0xFFFF,(int)(*l>>16)&0xFFFF,str); - sz -=4 ; - l++; + for (i = 1; i < argval / 2; i++) { + fraction[i] = 0; + for (j = 15; j>= 0; j--) { + if (f >= 0.5) fraction[i] |= (1 << j); + f = modf(2*f, &f1); + } } -#else not FPPSIM - if (! been_here) { - been_here = 1; - fprintf(stderr,"warning: dummy floating constant(s)\n"); + if (f >= 0.5) { + for (i = argval/2 - 1; i >= 0; i--) { + for (j = 0; j < 16; j++) { + if (fraction[i] & (1 << j)) { + fraction[i] &= ~(1 << j); + } + else { + fraction[i] |= (1 << j); + break; + } + } + if (j != 16) break; + } } - while (sz) { - fprintf(codefile,"\t.data4 0 !dummy float\n"); - sz -= 4; + for (i = 0; i < argval/2; i++) { + fprintf(codefile, + i != 0 ? ", 0%o, 0%o" : ".data1 0%o, 0%o", + (fraction[i]>>8)&0377, + fraction[i]&0377); } -#endif +#endif OWNFLOAT + putc('\n', codefile); } +#endif #ifdef REGVARS diff --git a/mach/m68k2/cg/table b/mach/m68k2/cg/table index c67bbc3af..fdb2735c4 100644 --- a/mach/m68k2/cg/table +++ b/mach/m68k2/cg/table @@ -30,7 +30,6 @@ */ #define REGVARS -#include "fppsim.h" EM_WSIZE = 2 EM_PSIZE = 4 @@ -1011,60 +1010,31 @@ adu | | | | adi $1 | sbu | | | | sbi $1 | slu | | | | sli $1 | -#ifdef FPPSIM /* Floating point stuff */ -adf $1==4 | | - remove(ALL) - "jsr .adf4" | | asp 8 lfr 4 | -adf $1==8 | | - remove(ALL) - "jsr .adf8" | | asp 16 lfr 4 loi 8 | -sbf $1==4 | | - remove(ALL) - "jsr .sbf4" | | asp 8 lfr 4 | -sbf $1==8 | | - remove(ALL) - "jsr .sbf8" | | asp 16 lfr 4 loi 8 | -mlf $1==4 | | - remove(ALL) - "jsr .mlf4" | | asp 8 lfr 4 | -mlf $1==8 | | - remove(ALL) - "jsr .mlf8" | | asp 16 lfr 4 loi 8 | -dvf $1==4 | | - remove(ALL) - "jsr .dvf4" | | asp 8 lfr 4 | -dvf $1==8 | | - remove(ALL) - "jsr .dvf8" | | asp 16 lfr 4 loi 8 | -ngf $1==4 | | - remove(ALL) - "jsr .ngf4" | | asp 4 lfr 4 | -ngf $1==8 | | - remove(ALL) - "jsr .ngf8" | | asp 8 lfr 4 loi 8 | -fif $1==4 | | - remove(ALL) - "jsr .fif4" | | asp 8 lfr 4 loi 8 | -fif $1==8 | | - remove(ALL) - "jsr .fif8" | | asp 16 lfr 4 loi 16 | +adf $1==4 | | | | cal ".adf4" asp 4 | +adf $1==8 | | | | cal ".adf8" asp 8 | +sbf $1==4 | | | | cal ".sbf4" asp 4 | +sbf $1==8 | | | | cal ".sbf8" asp 8 | +mlf $1==4 | | | | cal ".mlf4" asp 4 | +mlf $1==8 | | | | cal ".mlf8" asp 8 | +dvf $1==4 | | | | cal ".dvf4" asp 4 | +dvf $1==8 | | | | cal ".dvf8" asp 8 | +ngf $1==4 | | | | cal ".ngf4" | +ngf $1==8 | | | | cal ".ngf8" | +fif $1==4 | | | | cal ".fif4" | +fif $1==8 | | | | cal ".fif8" | fef $1==4 | | remove(ALL) - "jsr .fef4" | | asp 4 lfr 4 loi 8 | + "move.l (sp)+,d0" + "clr.w -(sp)" + "move.l d0,-(sp)" | | cal ".fef4" | fef $1==8 | | remove(ALL) - "jsr .fef8" | | asp 8 lfr 4 loi 12 | -#else not FPPSIM -fef | | | | loc 18 trp | -fif | | | | loc 18 trp | -ngf | | | | loc 18 trp | -adf | | | | loc 18 trp | -sbf | | | | loc 18 trp | -mlf | | | | loc 18 trp | -dvf | | | | loc 18 trp | -#endif FPPSIM - + "move.l (sp)+,d0" + "move.l (sp)+,d1" + "clr.w -(sp)" + "move.l d1,-(sp)" + "move.l d0,-(sp)" | | cal ".fef8" | /* G R O U P VI : P O I N T E R A R I T H M E T I C */ @@ -1373,97 +1343,93 @@ loc loc loc cuu $2 == 1 && $3 == 4 && $1 > 0 && $1 < 128 | | | | ldc $1 | /* Floating point stuff */ -#ifdef FPPSYM -loc loc cif $1==2 && $2==4 | | - remove(ALL) - "move.w #$1,-(sp)" - "jsr .cif4" | | asp 4 lfr 4 | -loc loc cif $1==2 && $2==8 | | - remove(ALL) - "move.w #$1,-(sp)" - "jsr .cif8" | | asp 4 lfr 4 loi 8 | -loc loc cif $1==4 && $2==4 | | - remove(ALL) - "move.w #$1,-(sp)" - "jsr .cif4" | | asp 6 lfr 4 | -loc loc cif $1==4 && $2==8 | | - remove(ALL) - "move.w #$1,-(sp)" - "jsr .cif8" | | asp 6 lfr 4 loi 8 | -loc loc cuf $1==2 && $2==4 | | +/* + * Floating point stuff + * + * Conversion + * + */ + +loc loc cif $1==2 && $2==4 | | | | loc $1 cal ".cif4" | +loc loc cif $1==2 && $2==8 | ANY | remove(ALL) - "move.w #$1,-(sp)" - "jsr .cuf4" | | asp 4 lfr 4 | -loc loc cuf $1==2 && $2==8 | | + "clr.l -(sp)" + "move.w %[1],-(sp)" + | | loc $1 cal ".cif8" | +loc loc cif $1==4 && $2==4 | | | | loc $1 cal ".cif4" asp 2 | +loc loc cif $1==4 && $2==8 | ANY4 | remove(ALL) - "move.w #$1,-(sp)" - "jsr .cuf8" | | asp 4 lfr 4 loi 8 | -loc loc cuf $1==4 && $2==4 | | + "clr.w -(sp)" + "move.l %[1],-(sp)" + | | loc $1 cal ".cif8" | +loc loc cuf $1==2 && $2==4 | | | | loc $1 cal ".cuf4" | +loc loc cuf $1==2 && $2==8 | ANY | remove(ALL) - "move.w #$1,-(sp)" - "jsr .cuf4" | | asp 6 lfr 4 | -loc loc cuf $1==4 && $2==8 | | + "clr.l -(sp)" + "move.w %[1],-(sp)" + | | loc $1 cal ".cuf8" | +loc loc cuf $1==4 && $2==4 | | | | loc $1 cal ".cuf4" asp 2 | +loc loc cuf $1==4 && $2==8 | ANY4 | remove(ALL) - "move.w #$1,-(sp)" - "jsr .cuf8" | | asp 6 lfr 4 loi 8 | + "clr.w -(sp)" + "move.l %[1],-(sp)" + | | loc $1 cal ".cuf8" | loc loc cfi $1==4 && $2==2 | | remove(ALL) "move.w #$1,-(sp)" "move.w #$2,-(sp)" - "jsr .cfi" | | asp 8 lfr 2 | + | | cal ".cfi" asp 6 | loc loc cfi $1==4 && $2==4 | | remove(ALL) "move.w #$1,-(sp)" "move.w #$2,-(sp)" - "jsr .cfi" | | asp 8 lfr 4 | + | | cal ".cfi" asp 4 | loc loc cfi $1==8 && $2==2 | | remove(ALL) "move.w #$1,-(sp)" "move.w #$2,-(sp)" - "jsr .cfi" | | asp 12 lfr 2 | + | | cal ".cfi" asp 10 | loc loc cfi $1==8 && $2==4 | | remove(ALL) "move.w #$1,-(sp)" "move.w #$2,-(sp)" - "jsr .cfi" | | asp 12 lfr 4 | + | | cal ".cfi" asp 8 | loc loc cfu $1==4 && $2==2 | | remove(ALL) "move.w #$1,-(sp)" "move.w #$2,-(sp)" - "jsr .cfu" | | asp 8 lfr 2 | + | | cal ".cfu" asp 6 | loc loc cfu $1==4 && $2==4 | | remove(ALL) "move.w #$1,-(sp)" "move.w #$2,-(sp)" - "jsr .cfu" | | asp 8 lfr 4 | + | | cal ".cfu" asp 4 | loc loc cfu $1==8 && $2==2 | | remove(ALL) "move.w #$1,-(sp)" "move.w #$2,-(sp)" - "jsr .cfu" | | asp 12 lfr 2 | + | | cal ".cfu" asp 10 | loc loc cfu $1==8 && $2==4 | | remove(ALL) "move.w #$1,-(sp)" "move.w #$2,-(sp)" - "jsr .cfu" | | asp 12 lfr 4 | + | | cal ".cfu" asp 8 | loc loc cff $1==8 && $2==4 | | remove(ALL) - "jsr .cff4" | | asp 8 lfr 4 | + | | cal ".cff4" asp 4 | +loc loc cff $1==4 && $2==8 | ANY4 | + remove(ALL) + "clr.l -(sp)" + "move.l %[1],-(sp)" | | cal ".cff8" | loc loc cff $1==4 && $2==8 | | remove(ALL) - "jsr .cff8" | | asp 4 lfr 4 loi 8 | -#else not FPPSIM -cif | | | | loc 18 trp | -cfi | | | | loc 18 trp | -cuf | | | | loc 18 trp | -cfu | | | | loc 18 trp | -cff | | | | loc 18 trp | -#endif FPPSIM - + "move.l (sp),ax" + "clr.l -(sp)" + "move.l ax,(sp)" | | cal ".cff8" | /* G R O U P IX : L O G I C A L */ -and defined($1) && $1 == 2 | ANY DATASCR | +and $1 == 2 | ANY DATASCR | "and %[1],%[2]" setcc(%[2]) erase(%[2]) | %[2] | | (2,2)+%[1] @@ -1492,7 +1458,7 @@ lil and sil $1 == $3 && $2 == 2 && inreg($1) < 2 | DATAREG + IMMEDIATE | /* Note that the contents of an address register may not be used as * operand of a and, or etc. instruction */ -and defined($1) && $1 == 4 | ANY4-ADDREG DATASCR4 | +and $1 == 4 | ANY4-ADDREG DATASCR4 | "and.l %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | (2,3)+%[1] @@ -1512,7 +1478,7 @@ ldl and sdl $1 == $3 && $2 == 4 && inreg($1) < 2 | DATAREG4+EXTENDED4+DOUBLE | lde and sde $1 == $3 && $2 == 4 | DATAREG4+EXTENDED4+DOUBLE | remove(MEM_ALL) "and.l %[1],$1" | | | -and defined($1) && $1 > 4 | STACK | +and $1 > 4 | STACK | allocate(DATAREG4,ADDREG,DATAREG) "move.l #$1/2-1,%[a]" "move.l sp,%[b]" @@ -1523,15 +1489,15 @@ and defined($1) && $1 > 4 | STACK | "dbf %[a],1b" | | | and !defined($1) | DATASCR STACK | allocate(ADDREG,DATAREG) - "move.l sp,%[a]" - "sub.w #1,%[1]" + "lea 0(sp,%[1]),%[a]" "asr #1,%[1]" + "sub.w #1,%[1]" "1:" "move.w (sp)+,%[b]" "and %[b],(%[a])+" "dbf %[1],1b" erase(%[1]) | | | -ior defined($1) && $1 == 2 | ANY DATASCR | +ior $1 == 2 | ANY DATASCR | "or %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | (2,2)+%[1] @@ -1556,7 +1522,7 @@ lil ior sil $1 == $3 && $2 == 2 && inreg($1) < 2 | DATAREG+IMMEDIATE | loe loc ior ste $3 == 2 && $1 == $4 | | remove(MEM_ALL) "or.w #$2,$1" | | | (7,11) -ior defined($1) && $1 == 4 | ANY4-ADDREG DATASCR4 | +ior $1 == 4 | ANY4-ADDREG DATASCR4 | "or.l %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | |(2,3)+%[1] @@ -1576,7 +1542,7 @@ ldl ior sdl $1 == $3 && $2 == 4 && inreg($1) < 2 | DATAREG4+EXTENDED4+DOUBLE | lde ior sde $1 == $3 && $2 == 4 | DATAREG4+EXTENDED4+DOUBLE | remove(MEM_ALL) "or.l %[1],$1" | | | -ior defined($1) && $1 > 4 | STACK | +ior $1 > 4 | STACK | allocate(DATAREG4,ADDREG,DATAREG) "move.l #$1/2-1,%[a]" "move.l sp,%[b]" @@ -1587,15 +1553,15 @@ ior defined($1) && $1 > 4 | STACK | "dbf %[a],1b" | | | ior !defined($1) | DATASCR STACK | allocate(ADDREG,DATAREG) - "move.l sp,%[a]" - "sub.w #1,%[1]" + "lea 0(sp,%[1]),%[a]" "asr #1,%[1]" + "sub.w #1,%[1]" "1:" "move.w (sp)+,%[b]" "or %[b],(%[a])+" "dbf %[1],1b" erase(%[1]) | | | -xor defined($1) && $1 == 2 | DATAREG DATASCR | +xor $1 == 2 | DATAREG DATASCR | "eor %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | (2,2)+%[1] @@ -1623,7 +1589,7 @@ lil xor sil $1 == $3 && $2 == 2 && inreg($1) < 2 | DATAREG+IMMEDIATE | allocate(ADDREG={DISPL4,LB,$1}) remove(MEM_ALL) "eor.w %[1],(%[a])" | | | -xor defined($1) && $1 == 4 | DATAREG4+EXTENDED4 DATASCR4 | +xor $1 == 4 | DATAREG4+EXTENDED4 DATASCR4 | "eor.l %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | (2,3)+%[1] @@ -1643,7 +1609,7 @@ ldl xor sdl $1 == $3 && $2 == 4 && inreg($1) < 2 | DATAREG4+EXTENDED4+DOUBLE | lde xor sde $1 == $3 && $2 == 4 | DATAREG4+EXTENDED4+DOUBLE | remove(MEM_ALL) "eor.l %[1],$1" | | | -xor defined($1) && $1 > 4 | STACK | +xor $1 > 4 | STACK | allocate(DATAREG4,ADDREG,DATAREG) "move.l #$1/2-1,%[a]" "move.l sp,%[b]" @@ -1654,46 +1620,46 @@ xor defined($1) && $1 > 4 | STACK | "dbf %[a],1b" | | | xor !defined($1) | DATASCR STACK | allocate(ADDREG,DATAREG) - "move.l sp,%[a]" - "sub.w #1,%[1]" + "lea 0(sp,%[1]),%[a]" "asr #1,%[1]" + "sub.w #1,%[1]" "1:" "move.w (sp)+,%[b]" "eor %[b],(%[a])+" "dbf %[1],1b" erase(%[1]) | | | -com defined($1) && $1 == 2 | DATASCR | "not %[1]" +com $1 == 2 | DATASCR | "not %[1]" erase(%[1]) setcc(%[1]) | %[1] | | -com defined($1) && $1 == 4 | DATASCR4 | "not.l %[1]" +com $1 == 4 | DATASCR4 | "not.l %[1]" erase(%[1]) setcc(%[1]) | %[1] | | -com defined($1) && $1 > 4 | STACK | allocate(DATAREG4,ADDREG) +com $1 > 4 | STACK | allocate(DATAREG4,ADDREG) "move.l #$1/2-1,%[a]" "move.l sp,%[b]" "1:" "not (%[b])+" "dbf %[a],1b" | | | com !defined($1) | DATASCR STACK | allocate(ADDREG) - "sub.w #1,%[1]" "asr #1,%[1]" + "sub.w #1,%[1]" "move.w sp,%[a]" "1:" "not (%[a])+" "dbf %[1],1b" | | | -rol defined($1) && $1 == 2 | DATAREG DATASCR | +rol $1 == 2 | DATAREG DATASCR | "rol %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | -rol defined($1) && $1 == 4 | DATAREG DATASCR4 | +rol $1 == 4 | DATAREG DATASCR4 | "rol.l %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | -ror defined($1) && $1 == 2 | DATAREG DATASCR | +ror $1 == 2 | DATAREG DATASCR | "ror %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | -ror defined($1) && $1 == 4 | DATAREG DATASCR4 | +ror $1 == 4 | DATAREG DATASCR4 | "ror.l %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | @@ -1842,18 +1808,17 @@ cms !defined($1) | ANY | remove(ALL) cmp | | remove(ALL) "jsr .cmp" | D1 | | -/* floating point */ +/* + * Floating point + * Comparision + */ -#ifdef FPPSIM cmf $1==4 | | remove(ALL) - "jsr .cmf4" | | asp 8 lfr 2 | + | | cal ".cmf4" asp 8 lfr 2 | cmf $1==8 | | remove(ALL) - "jsr .cmf8" | | asp 16 lfr 2 | -#else -cmf | | | | loc 18 trp | -#endif + | | cal ".cmf8" asp 16 lfr 2 | cmi tlt and $1==2 && $3==2 | ANY DATAREG DATASCR | "cmp %[1],%[2]"