Added floating point support

This commit is contained in:
ceriel 1988-09-14 14:06:31 +00:00
parent eaaa335e50
commit 091f3dbebf
2 changed files with 228 additions and 22 deletions

View file

@ -228,52 +228,52 @@ C_sru
/******************************************************************************/
C_adf
$1 == 4 ==> C_cal( "adf4");
C_asp( (arith) 4).
$1 == 8 ==> C_cal( "adf8");
C_asp( (arith) 8).
$1 == 4 ==> "jsr (.adf4)";
"tst.l (sp)+".
$1 == 8 ==> "jsr (.adf8)";
"lea (8, sp), sp".
default ==> arg_error( "adf", $1).
C_sbf
$1 == 4 ==> C_cal( "sbf4");
C_asp( (arith) 4).
$1 == 8 ==> C_cal( "sbf8");
C_asp( (arith) 8).
$1 == 4 ==> "jsr (.sbf4)";
"tst.l (sp)+".
$1 == 8 ==> "jsr (.sbf8)";
"lea (8, sp), sp".
default ==> arg_error( "sbf", $1).
C_mlf
$1 == 4 ==> C_cal( "mlf4");
C_asp( (arith) 4).
$1 == 8 ==> C_cal( "mlf8");
C_asp( (arith) 8).
$1 == 4 ==> "jsr (.mlf4)";
"tst.l (sp)+".
$1 == 8 ==> "jsr (.mlf8)";
"lea (8, sp), sp".
default ==> arg_error( "mlf", $1).
C_dvf
$1 == 4 ==> C_cal( "dvf4");
C_asp( (arith) 4).
$1 == 8 ==> C_cal( "dvf8");
C_asp( (arith) 8).
$1 == 4 ==> "jsr (.dvf4)";
"tst.l (sp)+".
$1 == 8 ==> "jsr (.dvf8)";
"lea (8, sp), sp".
default ==> arg_error( "dvf", $1).
C_ngf
$1 == 4 ==> C_cal( "ngf4").
$1 == 8 ==> C_cal( "ngf8").
$1 == 4 ==> "jsr (.ngf4)".
$1 == 8 ==> "jsr (.ngf8)".
default ==> arg_error( "ngf", $1).
C_fif
$1 == 4 ==> C_cal( "fif4").
$1 == 8 ==> C_cal( "fif8").
$1 == 4 ==> "jsr (.fif4)".
$1 == 8 ==> "jsr (.fif8)".
default ==> arg_error( "fif", $1).
C_fef
$1 == 4 ==> C_dup( (arith) 4);
C_cal( "fef4").
"jsr (.fef4)".
$1 == 8 ==> "move.l (sp)+, d0";
"move.l (sp)+, d1";
"move.l d0, -(sp)";
"move.l d1, -(sp)";
"move.l d0, -(sp)";
C_cal( "fef8").
"jsr (.fef8)".
default ==> arg_error( "fef", $1).
/******************************************************************************/
@ -361,6 +361,58 @@ C_ciu ==> C_cuu().
C_cui ==> C_cuu().
C_cfi ==> "jsr (.cfi)";
"move.l (4, sp), d0";
"cmp.l #4, d0";
"beq 1f";
"tst.l (sp)+";
"1:";
"lea (8, sp), sp".
C_cfu ==> "jsr (.cfu)";
"move.l (4, sp), d0";
"cmp.l #4, d0";
"beq 1f";
"tst.l (sp)+";
"1:";
"lea (8, sp), sp".
C_cff ==> "move.l (sp)+, d0";
"move.l (sp)+, d1";
"cmp.l d0, d1";
"beq 1f";
"cmp.l #4, d0";
"bne 2f";
"jsr (.cff4)";
"add.l #4, sp";
"bra 1f";
"2:";
"move.l (sp), d0";
"clr.l (sp)";
"move.l d0,-(sp)";
"jsr (.cff8)";
"1:".
C_cif ==> "move.l (sp)+, d0";
"cmp.l #4, d0";
"bne 1f";
"jsr (.cif4)";
"add.l #4, sp";
"bra 2f";
"1:";
"jsr (.cif8)";
"2:".
C_cuf ==> "move.l (sp)+, d0";
"cmp.l #4, d0";
"bne 1f";
"jsr (.cuf4)";
"add.l #4, sp";
"bra 2f";
"1:";
"jsr (.cuf8)";
"2:".
/******************************************************************************/
/* */
/* Group 9 : Logical */
@ -574,6 +626,15 @@ C_tgt ==> "move.l (sp)+, d0";
"clr.l (sp)";
"1:".
C_cmf
$1 == 4 ==> "jsr (.cmf4)";
"tst.l (sp)+";
"move.l d0,(sp)".
$1 == 8 ==> "jsr (.cmf8)";
"lea (12,sp), sp";
"move.l d0,(sp)".
default ==> arg_error("cmf", $1).
/******************************************************************************/
/* */
/* Group 13 : Branch */
@ -795,6 +856,8 @@ C_trp ==> "jsr (.trp)".
$2 == 4 ==> gen4( (FOUR_BYTES) atol( $1)).
default ==> arg_error( "icon", $2).
..fcon ==> con_float($1, $2).
/*****************************************************************************/
prolog ==> .

View file

@ -22,3 +22,146 @@ char *filename;
return( 1);
}
*/
con_float(str, argval)
char *str;
int argval;
{
#ifdef NOFLOAT
static int been_here;
if (argval != 4 && argval != 8)
arg_error("fcon", argval);
if (argval == 8)
gen4((FOUR_BYTES) 0);
gen4((FOUR_BYTES) 0);
if ( !been_here++)
{
fputs("Warning : dummy float-constant(s)\n", stderr);
}
#else
#define IEEEFLOAT
double f;
double atof();
int i;
int j;
double frexp();
#ifndef OWNFLOAT
int sign = 0;
int fraction[4] ;
#else OWNFLOAT
float fl;
char *p;
#endif OWNFLOAT
if (argval!= 4 && argval!= 8) {
arg_error("fcon", argval);
argval = 8;
}
f = atof(str);
if (f == 0) {
if (argval == 8) gen4((FOUR_BYTES) 0);
gen4((FOUR_BYTES) 0);
return;
}
#ifdef OWNFLOAT
if (argval == 4) {
/* careful: avoid overflow */
double ldexp();
f = frexp(f, &i);
fl = f;
fl = frexp(fl,&j);
if (i+j > 127) {
/* overflow situation */
gen1(f<0?0377:0177);
gen1(0377);
gen1(0377);
gen1(0377);
return;
}
if (i+j < -127) {
/* underflow situation */
gen1(f<0?0200:0);
gen1(0200);
gen1(0);
gen1(0);
return;
}
fl = ldexp(fl, i+j);
p = (char *) &fl;
}
else {
p = (char *) &f;
}
gen1(*p++&0377);
for (i = argval-1; i; i--) {
gen1(*p++&0377);
}
#else OWNFLOAT
f = frexp(f, &i);
if (f < 0) {
f = -f;
sign = 1;
}
while (f < 0.5) {
f += f;
i --;
}
f = 2*f - 1.0; /* hidden bit */
#ifdef IEEEFLOAT
if (argval == 4) {
#endif IEEEFLOAT
i = (i + 128) & 0377;
fraction[0] = (sign << 15) | (i << 7);
for (j = 6; j>= 0; j--) {
f *= 2;
if (f >= 1.0) {
f -= 1.0;
fraction[0] |= (1 << j);
}
}
#ifdef IEEEFLOAT
}
else {
i = (i + 1024) & 03777;
fraction[0] = (sign << 15) | (i << 4);
for (j = 3; j>= 0; j--) {
f *= 2;
if (f >= 1.0) {
fraction[0] |= (1 << j);
f -= 1.0;
}
}
}
#endif IEEEFLOAT
for (i = 1; i < argval / 2; i++) {
fraction[i] = 0;
for (j = 15; j>= 0; j--) {
f *= 2;
if (f >= 1.0) {
fraction[i] |= (1 << j);
f -= 1.0;
}
}
}
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;
}
}
for (i = 0; i < argval/2; i++) {
gen1((fraction[i]>>8)&0377);
gen1(fraction[i]&0377);
}
#endif OWNFLOAT
#endif
}