1989-06-27 13:16:17 +00:00
|
|
|
/*
|
|
|
|
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Header$ */
|
|
|
|
|
|
|
|
/* #define NOFLOAT for machines without floating point
|
|
|
|
#define ACKFLOAT for machines using the ACK floating point software
|
|
|
|
#define IEEEFLOAT for machines using IEEE floating point format
|
|
|
|
#define OWNFLOAT to use floating point format of machine on which
|
|
|
|
the code generator runs
|
|
|
|
If none of these are defined, PDP-11 format is generated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
}
|
1989-07-11 14:17:34 +00:00
|
|
|
#else /* NOFLOAT */
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#ifndef OWNFLOAT
|
|
|
|
#include <flt_arith.h>
|
|
|
|
#endif /* OWNFLOAT */
|
1989-06-27 13:16:17 +00:00
|
|
|
|
|
|
|
con_float() {
|
|
|
|
int i, j;
|
|
|
|
char *p;
|
|
|
|
#ifdef OWNFLOAT
|
|
|
|
float fl;
|
|
|
|
double f;
|
|
|
|
double atof();
|
1989-07-11 14:17:34 +00:00
|
|
|
#else /* OWNFLOAT */
|
1989-06-27 13:16:17 +00:00
|
|
|
int overflow = 0;
|
1989-07-11 14:17:34 +00:00
|
|
|
flt_arith e;
|
1989-06-27 13:16:17 +00:00
|
|
|
char buf[8];
|
1989-07-11 14:17:34 +00:00
|
|
|
#endif /* OWNFLOAT */
|
1989-06-27 13:16:17 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
#ifdef OWNFLOAT
|
|
|
|
f = atof(str);
|
|
|
|
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);
|
|
|
|
}
|
1989-07-11 14:17:34 +00:00
|
|
|
#else /* OWNFLOAT */
|
|
|
|
flt_str2flt(str, &e);
|
1989-06-27 13:16:17 +00:00
|
|
|
#if IEEEFLOAT+ACKFLOAT
|
|
|
|
if (argval == 4) {
|
|
|
|
#endif
|
1989-07-11 14:17:34 +00:00
|
|
|
e.flt_exp += 127;
|
1989-06-27 13:16:17 +00:00
|
|
|
#ifndef IEEEFLOAT
|
1989-07-11 14:17:34 +00:00
|
|
|
e.flt_exp += 2;
|
1989-06-27 13:16:17 +00:00
|
|
|
#endif
|
1989-07-11 14:17:34 +00:00
|
|
|
if (e.flt_mantissa.flt_h_32 == 0) e.flt_exp = 0;
|
1989-06-27 13:16:17 +00:00
|
|
|
#if IEEEFLOAT+ACKFLOAT
|
1989-07-11 14:17:34 +00:00
|
|
|
if (e.flt_exp >= 255) {
|
1989-06-27 13:16:17 +00:00
|
|
|
overflow = 1;
|
1989-07-11 14:17:34 +00:00
|
|
|
e.flt_exp = 255;
|
|
|
|
e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0;
|
1989-06-27 13:16:17 +00:00
|
|
|
}
|
1989-07-11 14:17:34 +00:00
|
|
|
if (e.flt_exp <= 0) {
|
1989-06-27 13:16:17 +00:00
|
|
|
#if IEEEFLOAT
|
1989-07-11 14:17:34 +00:00
|
|
|
flt_b64_sft(&(e.flt_mantissa), 1);
|
|
|
|
if (e.flt_exp < 0) {
|
|
|
|
flt_b64_sft(&(e.flt_mantissa), -e.flt_exp);
|
|
|
|
e.flt_exp = 0;
|
1989-06-27 13:16:17 +00:00
|
|
|
}
|
|
|
|
#else
|
1989-07-11 14:17:34 +00:00
|
|
|
e.flt_exp = 0;
|
|
|
|
e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0;
|
1989-06-27 13:16:17 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
1989-07-11 14:17:34 +00:00
|
|
|
buf[0] = (e.flt_sign << 7) | (e.flt_exp >> 1);
|
|
|
|
buf[1] = ((e.flt_exp&1) << 7) |
|
|
|
|
((e.flt_mantissa.flt_h_32 & 0x7fffffff) >> 24);
|
|
|
|
buf[2] = e.flt_mantissa.flt_h_32 >> 16;
|
|
|
|
buf[3] = e.flt_mantissa.flt_h_32 >> 8;
|
1989-06-27 13:16:17 +00:00
|
|
|
if (argval == 8) {
|
1989-07-11 14:17:34 +00:00
|
|
|
buf[4] = e.flt_mantissa.flt_h_32;
|
|
|
|
buf[5] = e.flt_mantissa.flt_l_32 >> 24;
|
|
|
|
buf[6] = e.flt_mantissa.flt_l_32 >> 16;
|
|
|
|
buf[7] = e.flt_mantissa.flt_l_32 >> 8;
|
|
|
|
flt_b64_sft(&(e.flt_mantissa), -56);
|
1989-06-27 13:16:17 +00:00
|
|
|
}
|
1989-07-11 14:17:34 +00:00
|
|
|
else flt_b64_sft(&(e.flt_mantissa), -24);
|
1989-06-27 13:16:17 +00:00
|
|
|
#if IEEEFLOAT+ACKFLOAT
|
|
|
|
}
|
|
|
|
else {
|
1989-07-11 14:17:34 +00:00
|
|
|
e.flt_exp += 1023;
|
1989-06-27 13:16:17 +00:00
|
|
|
#ifndef IEEEFLOAT
|
1989-07-11 14:17:34 +00:00
|
|
|
e.flt_exp += 2;
|
1989-06-27 13:16:17 +00:00
|
|
|
#endif
|
1989-07-11 14:17:34 +00:00
|
|
|
if (e.flt_mantissa.flt_h_32 == 0) e.flt_exp = 0;
|
|
|
|
if (e.flt_exp >= 2047) {
|
1989-06-27 13:16:17 +00:00
|
|
|
overflow = 1;
|
1989-07-11 14:17:34 +00:00
|
|
|
e.flt_exp = 2047;
|
|
|
|
e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0;
|
1989-06-27 13:16:17 +00:00
|
|
|
}
|
1989-07-11 14:17:34 +00:00
|
|
|
if (e.flt_exp <= 0) {
|
1989-06-27 13:16:17 +00:00
|
|
|
#if IEEEFLOAT
|
1989-07-11 14:17:34 +00:00
|
|
|
flt_b64_sft(&(e.flt_mantissa), 1);
|
|
|
|
if (e.flt_exp < 0) {
|
|
|
|
flt_b64_sft(&(e.flt_mantissa), -e.flt_exp);
|
|
|
|
e.flt_exp = 0;
|
1989-06-27 13:16:17 +00:00
|
|
|
}
|
|
|
|
#else
|
1989-07-11 14:17:34 +00:00
|
|
|
e.flt_exp = 0;
|
|
|
|
e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0;
|
1989-06-27 13:16:17 +00:00
|
|
|
#endif
|
|
|
|
}
|
1989-07-11 14:17:34 +00:00
|
|
|
buf[0] = (e.flt_sign << 7) | (e.flt_exp >> 4);
|
|
|
|
buf[1] = ((e.flt_exp & 017)<< 4) | ((e.flt_mantissa.flt_h_32 >> 27) & 017);
|
|
|
|
buf[2] = e.flt_mantissa.flt_h_32 >> 19;
|
|
|
|
buf[3] = e.flt_mantissa.flt_h_32 >> 11;
|
|
|
|
buf[4] = e.flt_mantissa.flt_h_32 >> 3;
|
|
|
|
buf[5] = (e.flt_mantissa.flt_h_32 << 5) | ((e.flt_mantissa.flt_l_32 >> 27) & 037);
|
|
|
|
buf[6] = e.flt_mantissa.flt_l_32 >> 19;
|
|
|
|
buf[7] = e.flt_mantissa.flt_l_32 >> 11;
|
|
|
|
flt_b64_sft(&(e.flt_mantissa), -53);
|
1989-06-27 13:16:17 +00:00
|
|
|
}
|
|
|
|
#endif
|
1989-07-11 14:17:34 +00:00
|
|
|
i = argval-1;
|
|
|
|
if (! overflow && (e.flt_mantissa.flt_h_32 & 0x80000000)) for (; i>=0; i--) {
|
1989-06-27 13:16:17 +00:00
|
|
|
if ((buf[i] &0377) != 0377) {
|
|
|
|
buf[i]++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else buf[i] = 0;
|
|
|
|
}
|
|
|
|
if (overflow || i < 0) {
|
|
|
|
fprintf(stderr, "Warning: overflow in floating point constant %s\n", str);
|
|
|
|
}
|
|
|
|
for (i = 0; i < argval; i++) {
|
|
|
|
fprintf(codefile,
|
|
|
|
i != 0 ? ",0%o" : ".data1 0%o",
|
|
|
|
buf[i]&0377);
|
|
|
|
}
|
1989-07-11 14:17:34 +00:00
|
|
|
#endif /* OWNFLOAT */
|
1989-06-27 13:16:17 +00:00
|
|
|
putc('\n', codefile);
|
|
|
|
}
|
1989-07-11 14:17:34 +00:00
|
|
|
#endif /* NOFLOAT */
|