2 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 See the copyright notice in the ACK home directory, in the file "Copyright".
6 /* $Id: con_float,v 2.11 1994/06/24 12:53:35 ceriel Exp $ */
9 #define CODE_GENERATOR for code generator
10 #define CODE_EXPANDER for code expander
12 #define IEEEFLOAT for machines using IEEE floating point format
13 #define PDPFLOAT for machines using the PDP-11 floating point format
14 If none of these are defined, the format of the machine on which the
15 code generator runs is used.
16 Returns 1 if sz has an illegal value, 2 in case of overflow,
17 and 0 if all went well.
18 If neither IEEEFLOAT nor PDPFLOAT are defined, the return value is not
21 Unfortunately, the IEEE standard does not define the byte-order.
22 depends on the #defines
23 FL_MSL_AT_LOW_ADDRESS 1 if most significant long is at low address
24 FL_MSW_AT_LOW_ADDRESS 1 if most significant word is at low address
25 FL_MSB_AT_LOW_ADDRESS 1 if most significant byte is at low address
32 #undef FL_MSL_AT_LOW_ADDRESS
33 #define FL_MSL_AT_LOW_ADDRESS 1
34 #undef FL_MSW_AT_LOW_ADDRESS
35 #define FL_MSW_AT_LOW_ADDRESS 1
36 #undef FL_MSB_AT_LOW_ADDRESS
37 #define FL_MSB_AT_LOW_ADDRESS 0
40 #define I0 ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \
41 + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
42 #define I1 ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \
43 + (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
44 #define I2 ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \
45 + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
46 #define I3 ((FL_MSL_AT_LOW_ADDRESS ? 0 : 4) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \
47 + (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
48 #define I4 ((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \
49 + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
50 #define I5 ((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 0 : 2) \
51 + (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
52 #define I6 ((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \
53 + (FL_MSB_AT_LOW_ADDRESS ? 0 : 1))
54 #define I7 ((FL_MSL_AT_LOW_ADDRESS ? 4 : 0) + (FL_MSW_AT_LOW_ADDRESS ? 2 : 0) \
55 + (FL_MSB_AT_LOW_ADDRESS ? 1 : 0))
59 float_cst(str, sz, buf)
69 if (sz!= 4 && sz!= 8) {
80 for (i = sz; i; i--) {
88 #include <flt_arith.h>
91 float_cst(str, sz, buf)
98 if (sz!= 4 && sz!= 8) {
101 flt_str2flt(str, &e);
110 if (e.flt_mantissa.flt_h_32 == 0) e.flt_exp = 0;
112 if (e.flt_mantissa.flt_h_32 & 0x80) {
114 if ((e.flt_mantissa.flt_h_32 & 0xffffff00) == 0xffffff00) {
116 e.flt_mantissa.flt_h_32 = 0x80000000;
119 e.flt_mantissa.flt_h_32 += 0x80;
122 if (e.flt_exp >= 255) {
125 e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0;
127 if (e.flt_exp <= 0) {
128 flt_b64_sft(&(e.flt_mantissa), 1);
130 flt_b64_sft(&(e.flt_mantissa), -e.flt_exp);
136 if (sz == 4 && (e.flt_mantissa.flt_h_32 & 0x80)) {
138 if ((e.flt_mantissa.flt_h_32 & 0xffffff00) == 0xffffff00) {
140 e.flt_mantissa.flt_h_32 = 0x80000000;
143 e.flt_mantissa.flt_h_32 += 0x80;
146 if (sz == 8 && (e.flt_mantissa.flt_l_32 & 0x80)) {
148 if ((e.flt_mantissa.flt_l_32 & 0xffffff00) == 0xffffff00) {
149 e.flt_mantissa.flt_l_32 = 0;
150 if (e.flt_mantissa.flt_h_32 == 0xffffffff) {
152 e.flt_mantissa.flt_h_32 = 0x80000000;
154 else e.flt_mantissa.flt_h_32++;
157 e.flt_mantissa.flt_l_32 += 0x80;
160 if (e.flt_exp > 255) {
163 e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0xffffffff;
166 buf[I0] = (e.flt_sign << 7) | (e.flt_exp >> 1);
167 buf[I1] = ((e.flt_exp&1) << 7) |
168 ((e.flt_mantissa.flt_h_32 & 0x7fffffff) >> 24);
169 buf[I2] = e.flt_mantissa.flt_h_32 >> 16;
170 buf[I3] = e.flt_mantissa.flt_h_32 >> 8;
173 buf[I4] = e.flt_mantissa.flt_h_32;
174 buf[I5] = e.flt_mantissa.flt_l_32 >> 24;
175 buf[I6] = e.flt_mantissa.flt_l_32 >> 16;
176 buf[I7] = e.flt_mantissa.flt_l_32 >> 8;
177 flt_b64_sft(&(e.flt_mantissa), -56);
181 flt_b64_sft(&(e.flt_mantissa), -24);
186 if (e.flt_mantissa.flt_h_32 == 0) e.flt_exp = 0;
187 if (e.flt_mantissa.flt_l_32 & 0x400) {
189 if ((e.flt_mantissa.flt_l_32 & 0xfffff800) == 0xfffff800) {
190 e.flt_mantissa.flt_l_32 = 0;
191 if (e.flt_mantissa.flt_h_32 == 0xffffffff) {
193 e.flt_mantissa.flt_h_32 = 0x80000000;
195 else e.flt_mantissa.flt_h_32++;
198 e.flt_mantissa.flt_l_32 += 0x400;
201 if (e.flt_exp >= 2047) {
204 e.flt_mantissa.flt_h_32 = e.flt_mantissa.flt_l_32 = 0;
206 if (e.flt_exp <= 0) {
207 flt_b64_sft(&(e.flt_mantissa), 1);
209 flt_b64_sft(&(e.flt_mantissa), -e.flt_exp);
213 buf[I0] = (e.flt_sign << 7) | (e.flt_exp >> 4);
214 buf[I1] = ((e.flt_exp & 017)<< 4) | ((e.flt_mantissa.flt_h_32 >> 27) & 017);
215 buf[I2] = e.flt_mantissa.flt_h_32 >> 19;
216 buf[I3] = e.flt_mantissa.flt_h_32 >> 11;
217 buf[I4] = e.flt_mantissa.flt_h_32 >> 3;
218 buf[I5] = (e.flt_mantissa.flt_h_32 << 5) | ((e.flt_mantissa.flt_l_32 >> 27) & 037);
219 buf[I6] = e.flt_mantissa.flt_l_32 >> 19;
220 buf[I7] = e.flt_mantissa.flt_l_32 >> 11;
221 flt_b64_sft(&(e.flt_mantissa), -53);
224 #if ! FL_MSL_AT_LOW_ADDRESS
239 #ifdef CODE_GENERATOR
243 int rval = float_cst(str, (int)argval, buf);
247 fprintf(stderr,"float constant size = %d\n",(int)argval);
248 fatal("bad fcon size");
250 fprintf(codefile,"!float %s sz %d\n", str, (int)argval);
252 fprintf(stderr, "Warning: overflow in floating point constant %s\n", str);
254 fprintf(codefile, ".data1 0%o", buf[0] & 0377);
255 for (i = 1; i < (int)argval; i++) {
256 fprintf(codefile, ",0%o", buf[i] & 0377);
258 putc('\n', codefile);
260 #endif /* CODE_GENERATOR */
263 con_float(str, argval)
268 int rval = float_cst(str, (int)argval, buf);
273 rval = float_cst(str, 8, buf);
275 for (i = 0; i < (int)argval; i++) {
279 #endif /* CODE_EXPANDER */