From 5053f2a183e02fadae48814c6bd297d752a4903c Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 14 May 1987 14:58:21 +0000 Subject: [PATCH] generate code for ACK assembler, including floats --- mach/pdp/cg/mach.c | 44 +++++++++++++++++++++++++++++++++++--------- mach/pdp/cg/mach.h | 2 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/mach/pdp/cg/mach.c b/mach/pdp/cg/mach.c index 37d4bf5ee..b15dbfc93 100644 --- a/mach/pdp/cg/mach.c +++ b/mach/pdp/cg/mach.c @@ -50,24 +50,50 @@ con_mult(sz) word sz; { * The next function is difficult to do when not running on a PDP 11 or VAX * The strategy followed is to assume the code generator is running on a PDP 11 * unless the ACK_ASS define is on. - * In the last case floating point constants are simply not handled */ con_float() { #ifdef ACK_ASS - static int been_here; + double f, f1; + double atof(), frexp(), modf(); + int i, j; + int sign = 0; + int fraction ; if (argval != 4 && argval != 8) fatal("bad fcon size"); - fprintf(codefile,".data4\t"); - if (argval == 8) - fprintf(codefile,"F_DUM,"); - fprintf(codefile,"F_DUM\n"); - if ( !been_here++) - fprintf(stderr,"Warning : dummy float-constant(s)\n"); + f = atof(str); + f = frexp(f, &i); + if (f < 0) { + f = -f; + sign = 1; + } + while (f < 0.5) { + f += f; + i --; + } + f = modf(2 * f, &f1); /* hidden bit */ + i = (i + 128) & 0377; + fraction = (sign << 15) | (i << 7); + for (j = 6; j>= 0; j--) { + if (f >= 0.5) fraction |= (1 << j); + f = modf(2*f, &f1); + } + fprintf(codefile, ".data2 0%o", fraction); + for (i = argval / 2 - 1; i; i--) { + fraction = 0; + for (j = 15; j>= 0; j--) { + if (f >= 0.5) fraction |= (1 << j); + f = modf(2*f, &f1); + } + fprintf(codefile, ", 0%o", fraction); + } + putc('\n', codefile); #else double f; - register short *p,i; + double atof(); + int i; + short *p; if (argval != 4 && argval != 8) fatal("bad fcon size"); diff --git a/mach/pdp/cg/mach.h b/mach/pdp/cg/mach.h index 64bddd106..4c2395f18 100644 --- a/mach/pdp/cg/mach.h +++ b/mach/pdp/cg/mach.h @@ -8,7 +8,7 @@ * or for the standard UNIX V7 assembler. * If on code is generated for the ACK assembler. */ -/* #define ACK_ASS /* code for ACK assembler */ +#define ACK_ASS /* code for ACK assembler */ #ifdef ACK_ASS #define COMMENTCHAR '!' -- 2.34.1