From ed34e06d2debea89daafa75192f422f149fbeea0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 17 Jan 1989 11:05:02 +0000 Subject: [PATCH] Added floating point, fixed LPB --- mach/i86/ce/EM_table | 121 +++++++++++++++++++++++++++++++++++- mach/i86/ce/mach.c | 143 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 263 insertions(+), 1 deletion(-) diff --git a/mach/i86/ce/EM_table b/mach/i86/ce/EM_table index eb5017fd1..30833b7a5 100644 --- a/mach/i86/ce/EM_table +++ b/mach/i86/ce/EM_table @@ -381,6 +381,62 @@ C_sru /* */ /******************************************************************************/ +C_adf + $1 == 4 ==> "call .adf4"; + "pop bx"; + "pop bx". + $1 == 8 ==> "call .adf8"; + "add sp,8". + default ==> arg_error("C_adf", $1). + +C_sbf + $1 == 4 ==> "call .sbf4"; + "pop bx"; + "pop bx". + $1 == 8 ==> "call .sbf8"; + "add sp,8". + default ==> arg_error("C_sbf", $1). + +C_mlf + $1 == 4 ==> "call .mlf4"; + "pop bx"; + "pop bx". + $1 == 8 ==> "call .mlf8"; + "add sp,8". + default ==> arg_error("C_mlf", $1). + +C_dvf + $1 == 4 ==> "call .dvf4"; + "pop bx"; + "pop bx". + $1 == 8 ==> "call .dvf8"; + "add sp,8". + default ==> arg_error("C_dvf", $1). + +C_fif + $1 == 4 ==> "call .fif4". + $1 == 8 ==> "call .fif8". + default ==> arg_error("C_fif", $1). + +C_fef + $1 == 4 ==> "pop ax"; + "pop bx"; + "push bx"; + "push bx"; + "push ax"; + "call .fef4". + $1 == 8 ==> "pop ax"; + "pop bx"; + "pop cx"; + "pop dx"; + "push dx"; + "push dx"; + "push cx"; + "push bx"; + "push ax"; + "call .fef8". + default ==> arg_error("C_fef", $1). + /******************************************************************************/ /* */ /* Group 6 : Pointer arithmetic */ @@ -489,6 +545,8 @@ C_zer default ==> arg_error( "C_zer", $1). +C_zrf ==> C_zer($1). + C_zer_narg ==> "pop cx"; "sar cx, 1"; "xor ax, ax"; @@ -517,6 +575,54 @@ C_cuu ==> "pop cx"; "call .cuu"; "push ax". +C_cif ==> "call .cif". + +C_cuf ==> "call .cuf". + +C_cfi ==> "call .cfi"; + "pop bx"; + "pop cx"; + "cmp bx,4"; + "je 1f"; + "add sp,cx"; + "push ax"; + "jmp 2f"; + "1:add cx,4"; + "add sp,cx"; + "2:". + +C_cfu ==> "call .cfu"; + "pop bx"; + "pop cx"; + "cmp bx,4"; + "je 1f"; + "add sp,cx"; + "push ax"; + "jmp 2f"; + "1:add cx,4"; + "add sp,cx"; + "2:". + +C_cff ==> "pop ax"; + "pop bx"; + "cmp ax,bx"; + "je 1f"; + "cmp ax,4"; + "je 2f"; + "pop cx"; + "pop bx"; + "xor ax,ax"; + "push ax"; + "push ax"; + "push bx"; + "push cx"; + "call .cff8"; + "jmp 1f"; + "2: call .cff4"; + "pop bx"; + "pop bx"; + "1:". + /******************************************************************************/ /* */ /* Group 9 : Logical */ @@ -767,6 +873,15 @@ C_cmp ==> "pop bx"; "1: dec ax"; "2: push ax". +C_cmf + $1 == 4 ==> "call .cmf4"; + "add sp,8"; + "push ax". + $1 == 8 ==> "call .cmf8"; + "add sp,16"; + "push ax". + default ==> arg_error("C_cmf", $1). + C_tlt ==> "pop ax"; "xor bx, bx"; "test ax, ax"; @@ -1054,7 +1169,9 @@ C_lor default ==> arg_error( "C_lor", $1). -C_lpb ==> "add bp, 4". +C_lpb ==> "pop ax"; + "add ax,4"; + "push ax". C_mon ==> "pop ax"; "call .mon". @@ -1117,6 +1234,8 @@ C_trp ==> "pop ax"; $2 == 4 ==> gen4( (FOUR_BYTES) atol( $1)). default ==> arg_error( "..ucon", $1). +..fcon ==> con_float($1, $2). + /******************************************************************************/ /* */ /* Extra-routines */ diff --git a/mach/i86/ce/mach.c b/mach/i86/ce/mach.c index 437af6484..53f49ca88 100644 --- a/mach/i86/ce/mach.c +++ b/mach/i86/ce/mach.c @@ -15,3 +15,146 @@ int val; { return( val >= -128 && val <= 127); } + +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++) + { + fprint(STDERR, "Warning : dummy float-constant(s)\n"); + } +#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 +}