Clang-format before editing.

This commit is contained in:
David Given 2018-09-10 22:42:30 +02:00
parent 976fa0efca
commit 9733454d8e

View file

@ -5,7 +5,7 @@
/* $Id$ */ /* $Id$ */
/* /*
#define CODE_GENERATOR for code generator #define CODE_GENERATOR for code generator
#define CODE_EXPANDER for code expander #define CODE_EXPANDER for code expander
@ -20,9 +20,9 @@
Unfortunately, the IEEE standard does not define the byte-order. Unfortunately, the IEEE standard does not define the byte-order.
depends on the #defines depends on the #defines
FL_MSL_AT_LOW_ADDRESS 1 if most significant long is at low address FL_MSL_AT_LOW_ADDRESS 1 if most significant long is at low address
FL_MSW_AT_LOW_ADDRESS 1 if most significant word is at low address FL_MSW_AT_LOW_ADDRESS 1 if most significant word is at low address
FL_MSB_AT_LOW_ADDRESS 1 if most significant byte is at low address FL_MSB_AT_LOW_ADDRESS 1 if most significant byte is at low address
*/ */
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
#define USE_FLT #define USE_FLT
@ -37,47 +37,57 @@
#define FL_MSB_AT_LOW_ADDRESS 0 #define FL_MSB_AT_LOW_ADDRESS 0
#endif #endif
#define I0 ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \ #define I0 \
+ (FL_MSB_AT_LOW_ADDRESS ? 0 : 1)) ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \
#define I1 ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \ + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0)) #define I1 \
#define I2 ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \ ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \
+ (FL_MSB_AT_LOW_ADDRESS ? 0 : 1)) + (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
#define I3 ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \ #define I2 \
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0)) ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \
#define I4 ((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \ + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
+ (FL_MSB_AT_LOW_ADDRESS ? 0 : 1)) #define I3 \
#define I5 ((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \ ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0)) + (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
#define I6 ((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \ #define I4 \
+ (FL_MSB_AT_LOW_ADDRESS ? 0 : 1)) ((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \
#define I7 ((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \ + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0)) #define I5 \
((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
#define I6 \
((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \
+ (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
#define I7 \
((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \
+ (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
#ifndef USE_FLT #ifndef USE_FLT
static int static int float_cst(str, sz, buf) char *str, *buf;
float_cst(str, sz, buf) int sz;
char *str, *buf;
int sz;
{ {
int i; int i;
char *p; char* p;
float fl; float fl;
double f; double f;
double atof(); double atof();
if (sz!= 4 && sz!= 8) { if (sz != 4 && sz != 8)
{
return 1; return 1;
} }
f = atof(str); f = atof(str);
if (sz == 4) { if (sz == 4)
{
fl = f; fl = f;
p = (char *) &fl; p = (char*)&fl;
} }
else { else
p = (char *) &f; {
p = (char*)&f;
} }
for (i = sz; i; i--) { for (i = sz; i; i--)
{
*buf++ = *p++; *buf++ = *p++;
} }
return 0; return 0;
@ -87,89 +97,105 @@ float_cst(str, sz, buf)
#include <ctype.h> #include <ctype.h>
#include <flt_arith.h> #include <flt_arith.h>
int int float_cst(str, sz, buf) char *str, *buf;
float_cst(str, sz, buf) int sz;
char *str, *buf;
int sz;
{ {
int overflow = 0; int overflow = 0;
flt_arith e; flt_arith e;
if (sz!= 4 && sz!= 8) { if (sz != 4 && sz != 8)
{
return 1; return 1;
} }
flt_str2flt(str, &e); flt_str2flt(str, &e);
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
if (sz == 4) { if (sz == 4)
{
#endif #endif
#ifdef PDPFLOAT #ifdef PDPFLOAT
e.flt_exp += 129; e.flt_exp += 129;
#else #else
e.flt_exp += 127; e.flt_exp += 127;
#endif #endif
if (e.flt_mantissa.flt_h_32 == 0) e.flt_exp = 0; if (e.flt_mantissa.flt_h_32 == 0)
e.flt_exp = 0;
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
if (e.flt_mantissa.flt_h_32 & 0x80) { if (e.flt_mantissa.flt_h_32 & 0x80)
{
/* rounding */ /* rounding */
if ((e.flt_mantissa.flt_h_32 & 0xffffff00) == 0xffffff00) { if ((e.flt_mantissa.flt_h_32 & 0xffffff00) == 0xffffff00)
{
e.flt_exp++; e.flt_exp++;
e.flt_mantissa.flt_h_32 = 0x80000000; e.flt_mantissa.flt_h_32 = 0x80000000;
} }
else { else
{
e.flt_mantissa.flt_h_32 += 0x80; e.flt_mantissa.flt_h_32 += 0x80;
} }
} }
if (e.flt_exp >= 255) { if (e.flt_exp >= 255)
{
overflow = 1; overflow = 1;
e.flt_exp = 255; e.flt_exp = 255;
e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0; e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0;
} }
if (e.flt_exp <= 0) { if (e.flt_exp <= 0)
{
flt_b64_sft(&(e.flt_mantissa), 1); flt_b64_sft(&(e.flt_mantissa), 1);
if (e.flt_exp < 0) { if (e.flt_exp < 0)
{
flt_b64_sft(&(e.flt_mantissa), -e.flt_exp); flt_b64_sft(&(e.flt_mantissa), -e.flt_exp);
e.flt_exp = 0; e.flt_exp = 0;
} }
} }
#endif #endif
#ifndef IEEEFLOAT #ifndef IEEEFLOAT
if (sz == 4 && (e.flt_mantissa.flt_h_32 & 0x80)) { if (sz == 4 && (e.flt_mantissa.flt_h_32 & 0x80))
{
/* rounding */ /* rounding */
if ((e.flt_mantissa.flt_h_32 & 0xffffff00) == 0xffffff00) { if ((e.flt_mantissa.flt_h_32 & 0xffffff00) == 0xffffff00)
{
e.flt_exp++; e.flt_exp++;
e.flt_mantissa.flt_h_32 = 0x80000000; e.flt_mantissa.flt_h_32 = 0x80000000;
} }
else { else
{
e.flt_mantissa.flt_h_32 += 0x80; e.flt_mantissa.flt_h_32 += 0x80;
} }
} }
if (sz == 8 && (e.flt_mantissa.flt_l_32 & 0x80)) { if (sz == 8 && (e.flt_mantissa.flt_l_32 & 0x80))
{
/* rounding */ /* rounding */
if ((e.flt_mantissa.flt_l_32 & 0xffffff00) == 0xffffff00) { if ((e.flt_mantissa.flt_l_32 & 0xffffff00) == 0xffffff00)
{
e.flt_mantissa.flt_l_32 = 0; e.flt_mantissa.flt_l_32 = 0;
if (e.flt_mantissa.flt_h_32 == 0xffffffff) { if (e.flt_mantissa.flt_h_32 == 0xffffffff)
{
e.flt_exp++; e.flt_exp++;
e.flt_mantissa.flt_h_32 = 0x80000000; e.flt_mantissa.flt_h_32 = 0x80000000;
} }
else e.flt_mantissa.flt_h_32++; else
e.flt_mantissa.flt_h_32++;
} }
else { else
{
e.flt_mantissa.flt_l_32 += 0x80; e.flt_mantissa.flt_l_32 += 0x80;
} }
} }
if (e.flt_exp > 255) { if (e.flt_exp > 255)
{
overflow = 1; overflow = 1;
e.flt_exp = 255; e.flt_exp = 255;
e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0xffffffff; e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0xffffffff;
} }
#endif #endif
buf[I0] = (e.flt_sign << 7) | (e.flt_exp >> 1); buf[I0] = (e.flt_sign << 7) | (e.flt_exp >> 1);
buf[I1] = ((e.flt_exp&1) << 7) | buf[I1] = ((e.flt_exp & 1) << 7) | ((e.flt_mantissa.flt_h_32 & 0x7fffffff) >> 24);
((e.flt_mantissa.flt_h_32 & 0x7fffffff) >> 24);
buf[I2] = e.flt_mantissa.flt_h_32 >> 16; buf[I2] = e.flt_mantissa.flt_h_32 >> 16;
buf[I3] = e.flt_mantissa.flt_h_32 >> 8; buf[I3] = e.flt_mantissa.flt_h_32 >> 8;
#ifndef IEEEFLOAT #ifndef IEEEFLOAT
if (sz == 8) { if (sz == 8)
{
buf[I4] = e.flt_mantissa.flt_h_32; buf[I4] = e.flt_mantissa.flt_h_32;
buf[I5] = e.flt_mantissa.flt_l_32 >> 24; buf[I5] = e.flt_mantissa.flt_l_32 >> 24;
buf[I6] = e.flt_mantissa.flt_l_32 >> 16; buf[I6] = e.flt_mantissa.flt_l_32 >> 16;
@ -181,37 +207,47 @@ float_cst(str, sz, buf)
flt_b64_sft(&(e.flt_mantissa), -24); flt_b64_sft(&(e.flt_mantissa), -24);
#ifdef IEEEFLOAT #ifdef IEEEFLOAT
} }
else { else
{
e.flt_exp += 1023; e.flt_exp += 1023;
if (e.flt_mantissa.flt_h_32 == 0) e.flt_exp = 0; if (e.flt_mantissa.flt_h_32 == 0)
if (e.flt_mantissa.flt_l_32 & 0x400) { e.flt_exp = 0;
if (e.flt_mantissa.flt_l_32 & 0x400)
{
/* rounding */ /* rounding */
if ((e.flt_mantissa.flt_l_32 & 0xfffff800) == 0xfffff800) { if ((e.flt_mantissa.flt_l_32 & 0xfffff800) == 0xfffff800)
{
e.flt_mantissa.flt_l_32 = 0; e.flt_mantissa.flt_l_32 = 0;
if (e.flt_mantissa.flt_h_32 == 0xffffffff) { if (e.flt_mantissa.flt_h_32 == 0xffffffff)
{
e.flt_exp++; e.flt_exp++;
e.flt_mantissa.flt_h_32 = 0x80000000; e.flt_mantissa.flt_h_32 = 0x80000000;
} }
else e.flt_mantissa.flt_h_32++; else
e.flt_mantissa.flt_h_32++;
} }
else { else
{
e.flt_mantissa.flt_l_32 += 0x400; e.flt_mantissa.flt_l_32 += 0x400;
} }
} }
if (e.flt_exp >= 2047) { if (e.flt_exp >= 2047)
{
overflow = 1; overflow = 1;
e.flt_exp = 2047; e.flt_exp = 2047;
e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0; e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0;
} }
if (e.flt_exp <= 0) { if (e.flt_exp <= 0)
{
flt_b64_sft(&(e.flt_mantissa), 1); flt_b64_sft(&(e.flt_mantissa), 1);
if (e.flt_exp < 0) { if (e.flt_exp < 0)
{
flt_b64_sft(&(e.flt_mantissa), -e.flt_exp); flt_b64_sft(&(e.flt_mantissa), -e.flt_exp);
e.flt_exp = 0; e.flt_exp = 0;
} }
} }
buf[I0] = (e.flt_sign << 7) | (e.flt_exp >> 4); buf[I0] = (e.flt_sign << 7) | (e.flt_exp >> 4);
buf[I1] = ((e.flt_exp & 017)<< 4) | ((e.flt_mantissa.flt_h_32 >> 27) & 017); buf[I1] = ((e.flt_exp & 017) << 4) | ((e.flt_mantissa.flt_h_32 >> 27) & 017);
buf[I2] = e.flt_mantissa.flt_h_32 >> 19; buf[I2] = e.flt_mantissa.flt_h_32 >> 19;
buf[I3] = e.flt_mantissa.flt_h_32 >> 11; buf[I3] = e.flt_mantissa.flt_h_32 >> 11;
buf[I4] = e.flt_mantissa.flt_h_32 >> 3; buf[I4] = e.flt_mantissa.flt_h_32 >> 3;
@ -221,15 +257,17 @@ float_cst(str, sz, buf)
flt_b64_sft(&(e.flt_mantissa), -53); flt_b64_sft(&(e.flt_mantissa), -53);
} }
#endif #endif
#if ! FL_MSL_AT_LOW_ADDRESS #if !FL_MSL_AT_LOW_ADDRESS
if (sz == 4) { if (sz == 4)
{
buf[I4] = buf[I0]; buf[I4] = buf[I0];
buf[I5] = buf[I1]; buf[I5] = buf[I1];
buf[I6] = buf[I2]; buf[I6] = buf[I2];
buf[I7] = buf[I3]; buf[I7] = buf[I3];
} }
#endif #endif
if (overflow) { if (overflow)
{
return 2; return 2;
} }
return 0; return 0;
@ -243,16 +281,19 @@ con_float()
int rval = float_cst(str, (int)argval, buf); int rval = float_cst(str, (int)argval, buf);
int i; int i;
if (rval == 1) { if (rval == 1)
fprintf(stderr,"float constant size = %d\n",(int)argval); {
fprintf(stderr, "float constant size = %d\n", (int)argval);
fatal("bad fcon size"); fatal("bad fcon size");
} }
fprintf(codefile,"!float %s sz %d\n", str, (int)argval); fprintf(codefile, "!float %s sz %d\n", str, (int)argval);
if (rval == 2) { if (rval == 2)
{
fprintf(stderr, "Warning: overflow in floating point constant %s\n", str); fprintf(stderr, "Warning: overflow in floating point constant %s\n", str);
} }
fprintf(codefile, ".data1 0%o", buf[0] & 0377); fprintf(codefile, ".data1 0%o", buf[0] & 0377);
for (i = 1; i < (int)argval; i++) { for (i = 1; i < (int)argval; i++)
{
fprintf(codefile, ",0%o", buf[i] & 0377); fprintf(codefile, ",0%o", buf[i] & 0377);
} }
putc('\n', codefile); putc('\n', codefile);
@ -260,19 +301,20 @@ con_float()
#endif /* CODE_GENERATOR */ #endif /* CODE_GENERATOR */
#ifdef CODE_EXPANDER #ifdef CODE_EXPANDER
con_float(str, argval) con_float(str, argval) char* str;
char *str; arith argval;
arith argval;
{ {
char buf[8]; char buf[8];
int rval = float_cst(str, (int)argval, buf); int rval = float_cst(str, (int)argval, buf);
int i; int i;
if (rval == 1) { if (rval == 1)
{
argval = 8; argval = 8;
rval = float_cst(str, 8, buf); rval = float_cst(str, 8, buf);
} }
for (i = 0; i < (int)argval; i++) { for (i = 0; i < (int)argval; i++)
{
gen1(buf[i]); gen1(buf[i]);
} }
} }