Support binary and octal floating-point
[nasm.git] / float.c
blob7e99f96cbd91055ae648407cc71631d77c2a7ddb
1 /* float.c floating-point constant support for the Netwide Assembler
3 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4 * Julian Hall. All rights reserved. The software is
5 * redistributable under the licence given in the file "Licence"
6 * distributed in the NASM archive.
8 * initial version 13/ix/96 by Simon Tatham
9 */
11 #include "compiler.h"
13 #include <ctype.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <inttypes.h>
19 #include "nasm.h"
20 #include "float.h"
23 * -----------------
24 * local variables
25 * -----------------
27 static efunc error;
28 static bool daz = false; /* denormals as zero */
29 static enum float_round rc = FLOAT_RC_NEAR; /* rounding control */
32 * -----------
33 * constants
34 * -----------
37 /* 112 bits + 64 bits for accuracy + 16 bits for rounding */
38 #define MANT_WORDS 12
40 /* 52 digits fit in 176 bits because 10^53 > 2^176 > 10^52 */
41 #define MANT_DIGITS 52
43 /* the format and the argument list depend on MANT_WORDS */
44 #define MANT_FMT "%04x%04x_%04x%04x_%04x%04x_%04x%04x_%04x%04x_%04x%04x"
45 #define MANT_ARG SOME_ARG(mant, 0)
47 #define SOME_ARG(a,i) (a)[(i)+0], (a)[(i)+1], (a)[(i)+2], (a)[(i)+3], \
48 (a)[(i)+4], (a)[(i)+5], (a)[(i)+6], (a)[(i)+7], (a)[(i)+8], \
49 (a)[(i)+9], (a)[(i)+10], (a)[(i)+11]
52 * ---------------------------------------------------------------------------
53 * emit a printf()-like debug message... but only if DEBUG_FLOAT was defined
54 * ---------------------------------------------------------------------------
57 #ifdef DEBUG_FLOAT
58 #define dprintf(x) printf x
59 #else /* */
60 #define dprintf(x) do { } while (0)
61 #endif /* */
64 * ---------------------------------------------------------------------------
65 * multiply
66 * ---------------------------------------------------------------------------
68 static int float_multiply(uint16_t * to, uint16_t * from)
70 uint32_t temp[MANT_WORDS * 2];
71 int32_t i, j;
74 * guaranteed that top bit of 'from' is set -- so we only have
75 * to worry about _one_ bit shift to the left
77 dprintf(("%s=" MANT_FMT "\n", "mul1", SOME_ARG(to, 0)));
78 dprintf(("%s=" MANT_FMT "\n", "mul2", SOME_ARG(from, 0)));
80 memset(temp, 0, sizeof temp);
82 for (i = 0; i < MANT_WORDS; i++) {
83 for (j = 0; j < MANT_WORDS; j++) {
84 uint32_t n;
85 n = (uint32_t) to[i] * (uint32_t) from[j];
86 temp[i + j] += n >> 16;
87 temp[i + j + 1] += n & 0xFFFF;
91 for (i = MANT_WORDS * 2; --i;) {
92 temp[i - 1] += temp[i] >> 16;
93 temp[i] &= 0xFFFF;
96 dprintf(("%s=" MANT_FMT "_" MANT_FMT "\n", "temp", SOME_ARG(temp, 0),
97 SOME_ARG(temp, MANT_WORDS)));
99 if (temp[0] & 0x8000) {
100 for (i = 0; i < MANT_WORDS; i++) {
101 to[i] = temp[i] & 0xFFFF;
103 dprintf(("%s=" MANT_FMT " (%i)\n", "prod", SOME_ARG(to, 0), 0));
104 return 0;
105 } else {
106 for (i = 0; i < MANT_WORDS; i++) {
107 to[i] = (temp[i] << 1) + !!(temp[i + 1] & 0x8000);
109 dprintf(("%s=" MANT_FMT " (%i)\n", "prod", SOME_ARG(to, 0), -1));
110 return -1;
115 * ---------------------------------------------------------------------------
116 * read an exponent; returns INT32_MAX on error
117 * ---------------------------------------------------------------------------
119 static int32_t read_exponent(const char *string, int32_t max)
121 int32_t i = 0;
122 bool neg = false;
124 if (*string == '+') {
125 string++;
126 } else if (*string == '-') {
127 neg = true;
128 string++;
130 while (*string) {
131 if (*string >= '0' && *string <= '9') {
132 i = (i * 10) + (*string - '0');
135 * To ensure that underflows and overflows are
136 * handled properly we must avoid wraparounds of
137 * the signed integer value that is used to hold
138 * the exponent. Therefore we cap the exponent at
139 * +/-5000, which is slightly more/less than
140 * what's required for normal and denormal numbers
141 * in single, double, and extended precision, but
142 * sufficient to avoid signed integer wraparound.
144 if (i > max)
145 i = max;
146 } else if (*string == '_') {
147 /* do nothing */
148 } else {
149 error(ERR_NONFATAL,
150 "invalid character in floating-point constant %s: '%c'",
151 "exponent", *string);
152 return INT32_MAX;
154 string++;
157 return neg ? -i : i;
161 * ---------------------------------------------------------------------------
162 * convert
163 * ---------------------------------------------------------------------------
165 static bool ieee_flconvert(const char *string, uint16_t * mant,
166 int32_t * exponent)
168 char digits[MANT_DIGITS];
169 char *p, *q, *r;
170 uint16_t mult[MANT_WORDS], bit;
171 uint16_t *m;
172 int32_t tenpwr, twopwr;
173 int32_t extratwos;
174 bool started, seendot, warned;
175 p = digits;
176 tenpwr = 0;
177 started = seendot = false;
178 warned = (pass0 != 1);
179 while (*string && *string != 'E' && *string != 'e') {
180 if (*string == '.') {
181 if (!seendot) {
182 seendot = true;
183 } else {
184 error(ERR_NONFATAL,
185 "too many periods in floating-point constant");
186 return false;
188 } else if (*string >= '0' && *string <= '9') {
189 if (*string == '0' && !started) {
190 if (seendot) {
191 tenpwr--;
193 } else {
194 started = true;
195 if (p < digits + sizeof(digits)) {
196 *p++ = *string - '0';
197 } else {
198 if (!warned) {
199 error(ERR_WARNING|ERR_WARN_FL_TOOLONG,
200 "floating-point constant significand contains "
201 "more than %i digits", MANT_DIGITS);
202 warned = true;
205 if (!seendot) {
206 tenpwr++;
209 } else if (*string == '_') {
210 /* do nothing */
211 } else {
212 error(ERR_NONFATAL,
213 "invalid character in floating-point constant %s: '%c'",
214 "significand", *string);
215 return false;
217 string++;
220 if (*string) {
221 int32_t e;
223 string++; /* eat the E */
224 e = read_exponent(string, 5000);
225 if (e == INT32_MAX)
226 return false;
227 tenpwr += e;
231 * At this point, the memory interval [digits,p) contains a
232 * series of decimal digits zzzzzzz, such that our number X
233 * satisfies X = 0.zzzzzzz * 10^tenpwr.
235 q = digits;
236 dprintf(("X = 0."));
237 while (q < p) {
238 dprintf(("%c", *q + '0'));
239 q++;
241 dprintf((" * 10^%i\n", tenpwr));
244 * Now convert [digits,p) to our internal representation.
246 bit = 0x8000;
247 for (m = mant; m < mant + MANT_WORDS; m++) {
248 *m = 0;
250 m = mant;
251 q = digits;
252 started = false;
253 twopwr = 0;
254 while (m < mant + MANT_WORDS) {
255 uint16_t carry = 0;
256 while (p > q && !p[-1]) {
257 p--;
259 if (p <= q) {
260 break;
262 for (r = p; r-- > q;) {
263 int32_t i;
264 i = 2 * *r + carry;
265 if (i >= 10) {
266 carry = 1;
267 i -= 10;
268 } else {
269 carry = 0;
271 *r = i;
273 if (carry) {
274 *m |= bit;
275 started = true;
277 if (started) {
278 if (bit == 1) {
279 bit = 0x8000;
280 m++;
281 } else {
282 bit >>= 1;
284 } else {
285 twopwr--;
288 twopwr += tenpwr;
291 * At this point, the 'mant' array contains the first frac-
292 * tional places of a base-2^16 real number which when mul-
293 * tiplied by 2^twopwr and 5^tenpwr gives X.
295 dprintf(("X = " MANT_FMT " * 2^%i * 5^%i\n", MANT_ARG, twopwr,
296 tenpwr));
299 * Now multiply 'mant' by 5^tenpwr.
301 if (tenpwr < 0) { /* mult = 5^-1 = 0.2 */
302 for (m = mult; m < mult + MANT_WORDS - 1; m++) {
303 *m = 0xCCCC;
305 mult[MANT_WORDS - 1] = 0xCCCD;
306 extratwos = -2;
307 tenpwr = -tenpwr;
310 * If tenpwr was 1000...000b, then it becomes 1000...000b. See
311 * the "ANSI C" comment below for more details on that case.
313 * Because we already truncated tenpwr to +5000...-5000 inside
314 * the exponent parsing code, this shouldn't happen though.
316 } else if (tenpwr > 0) { /* mult = 5^+1 = 5.0 */
317 mult[0] = 0xA000;
318 for (m = mult + 1; m < mult + MANT_WORDS; m++) {
319 *m = 0;
321 extratwos = 3;
322 } else {
323 extratwos = 0;
325 while (tenpwr) {
326 dprintf(("loop=" MANT_FMT " * 2^%i * 5^%i (%i)\n", MANT_ARG,
327 twopwr, tenpwr, extratwos));
328 if (tenpwr & 1) {
329 dprintf(("mant*mult\n"));
330 twopwr += extratwos + float_multiply(mant, mult);
332 dprintf(("mult*mult\n"));
333 extratwos = extratwos * 2 + float_multiply(mult, mult);
334 tenpwr >>= 1;
337 * In ANSI C, the result of right-shifting a signed integer is
338 * considered implementation-specific. To ensure that the loop
339 * terminates even if tenpwr was 1000...000b to begin with, we
340 * manually clear the MSB, in case a 1 was shifted in.
342 * Because we already truncated tenpwr to +5000...-5000 inside
343 * the exponent parsing code, this shouldn't matter; neverthe-
344 * less it is the right thing to do here.
346 tenpwr &= (uint32_t) - 1 >> 1;
350 * At this point, the 'mant' array contains the first frac-
351 * tional places of a base-2^16 real number in [0.5,1) that
352 * when multiplied by 2^twopwr gives X. Or it contains zero
353 * of course. We are done.
355 *exponent = twopwr;
356 return true;
360 * ---------------------------------------------------------------------------
361 * round a mantissa off after i words
362 * ---------------------------------------------------------------------------
365 #define ROUND_COLLECT_BITS \
366 for (j = i; j < MANT_WORDS; j++) { \
367 m = m | mant[j]; \
370 #define ROUND_ABS_DOWN \
371 for (j = i; j < MANT_WORDS; j++) { \
372 mant[j] = 0x0000; \
375 #define ROUND_ABS_UP \
376 do { \
377 ++mant[--i]; \
378 mant[i] &= 0xFFFF; \
379 } while (i > 0 && !mant[i]); \
380 return (!i && !mant[i]);
382 static bool ieee_round(int sign, uint16_t * mant, int32_t i)
384 uint16_t m = 0;
385 int32_t j;
386 if ((sign == 0x0000) || (sign == 0x8000)) {
387 if (rc == FLOAT_RC_NEAR) {
388 if (mant[i] & 0x8000) {
389 mant[i] &= 0x7FFF;
390 ROUND_COLLECT_BITS;
391 mant[i] |= 0x8000;
392 if (m) {
393 ROUND_ABS_UP;
394 } else {
395 if (mant[i - 1] & 1) {
396 ROUND_ABS_UP;
397 } else {
398 ROUND_ABS_DOWN;
401 } else {
402 ROUND_ABS_DOWN;
404 } else if (((sign == 0x0000) && (rc == FLOAT_RC_DOWN))
405 || ((sign == 0x8000) && (rc == FLOAT_RC_UP))) {
406 ROUND_COLLECT_BITS;
407 if (m) {
408 ROUND_ABS_DOWN;
410 } else if (((sign == 0x0000) && (rc == FLOAT_RC_UP))
411 || ((sign == 0x8000) && (rc == FLOAT_RC_DOWN))) {
412 ROUND_COLLECT_BITS;
413 if (m) {
414 ROUND_ABS_UP;
416 } else if (rc == FLOAT_RC_ZERO) {
417 ROUND_ABS_DOWN;
418 } else {
419 error(ERR_PANIC, "float_round() can't handle rc=%i", rc);
421 } else {
422 error(ERR_PANIC, "float_round() can't handle sign=%i", sign);
424 return false;
427 /* Returns a value >= 16 if not a valid hex digit */
428 static unsigned int hexval(char c)
430 unsigned int v = (unsigned char) c;
432 if (v >= '0' && v <= '9')
433 return v - '0';
434 else
435 return (v|0x20) - 'a' + 10;
438 /* Handle floating-point numbers with radix 2^bits and binary exponent */
439 static bool ieee_flconvert_bin(const char *string, int bits,
440 uint16_t * mant, int32_t * exponent)
442 static const int log2tbl[16] =
443 { -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 };
444 uint16_t mult[MANT_WORDS + 1], *mp;
445 int ms;
446 int32_t twopwr;
447 bool seendot, seendigit;
448 unsigned char c;
449 int radix = 1 << bits;
450 unsigned int v;
452 twopwr = 0;
453 seendot = seendigit = false;
454 ms = 0;
455 mp = NULL;
457 memset(mult, 0, sizeof mult);
459 while ((c = *string++) != '\0') {
460 if (c == '.') {
461 if (!seendot)
462 seendot = true;
463 else {
464 error(ERR_NONFATAL,
465 "too many periods in floating-point constant");
466 return false;
468 } else if ((v = hexval(c)) < (unsigned int)radix) {
469 if (!seendigit && v) {
470 int l = log2tbl[v];
472 seendigit = 1;
473 mp = mult;
474 ms = 15-l;
476 twopwr = seendot ? twopwr-bits+l : l+1-bits;
479 if (seendigit) {
480 if (ms <= 0) {
481 *mp |= v >> -ms;
482 mp++;
483 if (mp > &mult[MANT_WORDS])
484 mp = &mult[MANT_WORDS]; /* Guard slot */
485 ms += 16;
487 *mp |= v << ms;
488 ms -= bits;
490 if (!seendot)
491 twopwr += bits;
492 } else {
493 if (seendot)
494 twopwr -= bits;
496 } else if (c == 'p' || c == 'P') {
497 int32_t e;
498 e = read_exponent(string, 20000);
499 if (e == INT32_MAX)
500 return false;
501 twopwr += e;
502 break;
503 } else if (c == '_') {
504 /* ignore */
505 } else {
506 error(ERR_NONFATAL,
507 "floating-point constant: `%c' is invalid character", c);
508 return false;
512 if (!seendigit) {
513 memset(mant, 0, 2 * MANT_WORDS); /* Zero */
514 *exponent = 0;
515 } else {
516 memcpy(mant, mult, 2 * MANT_WORDS);
517 *exponent = twopwr;
520 return true;
524 * Shift a mantissa to the right by i bits.
526 static void ieee_shr(uint16_t * mant, int i)
528 uint16_t n, m;
529 int j = 0;
530 int sr, sl, offs;
532 sr = i%16; sl = 16-sr;
533 offs = i/16;
535 if (sr == 0) {
536 if (offs)
537 for (j = MANT_WORDS-1; j >= offs; j--)
538 mant[j] = mant[j-offs];
539 } else {
540 n = mant[MANT_WORDS-1-offs] >> sr;
541 for (j = MANT_WORDS-1; j > offs; j--) {
542 m = mant[j-offs-1];
543 mant[j] = (m << sl) | n;
544 n = m >> sr;
546 mant[j--] = n;
548 while (j >= 0)
549 mant[j--] = 0;
552 #if defined(__i386__) || defined(__x86_64__)
553 #define put(a,b) (*(uint16_t *)(a) = (b))
554 #else
555 #define put(a,b) (((a)[0] = (b)), ((a)[1] = (b) >> 8))
556 #endif
558 /* Set a bit, using *bigendian* bit numbering (0 = MSB) */
559 static void set_bit(uint16_t *mant, int bit)
561 mant[bit >> 4] |= 1 << (~bit & 15);
564 /* Test a single bit */
565 static int test_bit(const uint16_t *mant, int bit)
567 return (mant[bit >> 4] >> (~bit & 15)) & 1;
570 /* Report if the mantissa value is all zero */
571 static bool is_zero(const uint16_t *mant)
573 int i;
575 for (i = 0; i < MANT_WORDS; i++)
576 if (mant[i])
577 return false;
579 return true;
582 /* Produce standard IEEE formats, with implicit or explicit integer
583 bit; this makes the following assumptions:
585 - the sign bit is the MSB, followed by the exponent,
586 followed by the integer bit if present.
587 - the sign bit plus exponent fit in 16 bits.
588 - the exponent bias is 2^(n-1)-1 for an n-bit exponent */
590 struct ieee_format {
591 int words;
592 int mantissa; /* Fractional bits in the mantissa */
593 int explicit; /* Explicit integer */
594 int exponent; /* Bits in the exponent */
598 * The 16- and 128-bit formats are expected to be in IEEE 754r.
599 * AMD SSE5 uses the 16-bit format.
601 * The 32- and 64-bit formats are the original IEEE 754 formats.
603 * The 80-bit format is x87-specific, but widely used.
605 static const struct ieee_format ieee_16 = { 1, 10, 0, 5 };
606 static const struct ieee_format ieee_32 = { 2, 23, 0, 8 };
607 static const struct ieee_format ieee_64 = { 4, 52, 0, 11 };
608 static const struct ieee_format ieee_80 = { 5, 63, 1, 15 };
609 static const struct ieee_format ieee_128 = { 8, 112, 0, 15 };
611 /* Types of values we can generate */
612 enum floats {
613 FL_ZERO,
614 FL_DENORMAL,
615 FL_NORMAL,
616 FL_INFINITY,
617 FL_QNAN,
618 FL_SNAN
621 static int to_float(const char *str, int sign, uint8_t * result,
622 const struct ieee_format *fmt)
624 uint16_t mant[MANT_WORDS], *mp;
625 int32_t exponent = 0;
626 int32_t expmax = 1 << (fmt->exponent - 1);
627 uint16_t one_mask = 0x8000 >> ((fmt->exponent+fmt->explicit) % 16);
628 int one_pos = (fmt->exponent+fmt->explicit)/16;
629 int i;
630 int shift;
631 enum floats type;
632 bool ok;
634 sign = (sign < 0 ? 0x8000 : 0);
636 if (str[0] == '_') {
637 /* Special tokens */
639 switch (str[2]) {
640 case 'n': /* __nan__ */
641 case 'N':
642 case 'q': /* __qnan__ */
643 case 'Q':
644 type = FL_QNAN;
645 break;
646 case 's': /* __snan__ */
647 case 'S':
648 type = FL_SNAN;
649 break;
650 case 'i': /* __infinity__ */
651 case 'I':
652 type = FL_INFINITY;
653 break;
654 default:
655 error(ERR_NONFATAL,
656 "internal error: unknown FP constant token `%s'\n", str);
657 type = FL_QNAN;
658 break;
660 } else {
661 if (str[0] == '0') {
662 switch (str[1]) {
663 case 'x': case 'X':
664 case 'h': case 'H':
665 ok = ieee_flconvert_bin(str+2, 4, mant, &exponent);
666 break;
667 case 'o': case 'O':
668 case 'q': case 'Q':
669 ok = ieee_flconvert_bin(str+2, 3, mant, &exponent);
670 break;
671 case 'b': case 'B':
672 case 'y': case 'Y':
673 ok = ieee_flconvert_bin(str+2, 1, mant, &exponent);
674 break;
675 case 'd': case 'D':
676 case 't': case 'T':
677 ok = ieee_flconvert(str+2, mant, &exponent);
678 break;
679 case '0': case '1': case '2': case '3': case '4':
680 case '5': case '6': case '7': case '8': case '9':
681 case '\0':
682 /* Leading zero was just a zero */
683 ok = ieee_flconvert(str, mant, &exponent);
684 break;
685 default:
686 error(ERR_NONFATAL,
687 "floating-point constant: invalid radix `%c'", str[1]);
688 ok = false;
689 break;
691 } else if (str[0] == '$') {
692 ok = ieee_flconvert_bin(str+1, 4, mant, &exponent);
693 } else {
694 ok = ieee_flconvert(str, mant, &exponent);
697 if (!ok) {
698 type = FL_QNAN;
699 } else if (mant[0] & 0x8000) {
701 * Non-zero.
703 exponent--;
704 if (exponent >= 2 - expmax && exponent <= expmax) {
705 type = FL_NORMAL;
706 } else if (exponent < 2 - expmax &&
707 exponent >= 2 - expmax - fmt->mantissa) {
708 type = FL_DENORMAL;
709 } else if (exponent > 0) {
710 if (pass0 == 1)
711 error(ERR_WARNING|ERR_WARN_FL_OVERFLOW,
712 "overflow in floating-point constant");
713 type = FL_INFINITY;
714 } else {
715 /* underflow */
716 if (pass0 == 1)
717 error(ERR_WARNING|ERR_WARN_FL_UNDERFLOW,
718 "underflow in floating-point constant");
719 type = FL_ZERO;
721 } else {
722 /* Zero */
723 type = FL_ZERO;
727 switch (type) {
728 case FL_ZERO:
729 zero:
730 memset(mant, 0, sizeof mant);
731 break;
733 case FL_DENORMAL:
735 shift = -(exponent + expmax - 2 - fmt->exponent)
736 + fmt->explicit;
737 ieee_shr(mant, shift);
738 ieee_round(sign, mant, fmt->words);
739 if (mant[one_pos] & one_mask) {
740 /* One's position is set, we rounded up into normal range */
741 exponent = 1;
742 if (!fmt->explicit)
743 mant[one_pos] &= ~one_mask; /* remove explicit one */
744 mant[0] |= exponent << (15 - fmt->exponent);
745 } else {
746 if (daz || is_zero(mant)) {
747 /* Flush denormals to zero */
748 if (pass0 == 1)
749 error(ERR_WARNING|ERR_WARN_FL_UNDERFLOW,
750 "underflow in floating-point constant");
751 goto zero;
752 } else {
753 if (pass0 == 1)
754 error(ERR_WARNING|ERR_WARN_FL_DENORM,
755 "denormal floating-point constant");
758 break;
761 case FL_NORMAL:
762 exponent += expmax - 1;
763 ieee_shr(mant, fmt->exponent+fmt->explicit);
764 ieee_round(sign, mant, fmt->words);
765 /* did we scale up by one? */
766 if (test_bit(mant, fmt->exponent+fmt->explicit-1)) {
767 ieee_shr(mant, 1);
768 exponent++;
769 if (exponent >= (expmax << 1)-1) {
770 if (pass0 == 1)
771 error(ERR_WARNING|ERR_WARN_FL_OVERFLOW,
772 "overflow in floating-point constant");
773 type = FL_INFINITY;
774 goto overflow;
778 if (!fmt->explicit)
779 mant[one_pos] &= ~one_mask; /* remove explicit one */
780 mant[0] |= exponent << (15 - fmt->exponent);
781 break;
783 case FL_INFINITY:
784 case FL_QNAN:
785 case FL_SNAN:
786 overflow:
787 memset(mant, 0, sizeof mant);
788 mant[0] = ((1 << fmt->exponent)-1) << (15 - fmt->exponent);
789 if (fmt->explicit)
790 mant[one_pos] |= one_mask;
791 if (type == FL_QNAN)
792 set_bit(mant, fmt->exponent+fmt->explicit+1);
793 else if (type == FL_SNAN)
794 set_bit(mant, fmt->exponent+fmt->explicit+fmt->mantissa);
795 break;
798 mant[0] |= sign;
800 for (mp = &mant[fmt->words], i = 0; i < fmt->words; i++) {
801 uint16_t m = *--mp;
802 put(result, m);
803 result += 2;
806 return 1; /* success */
809 int float_const(const char *number, int32_t sign, uint8_t * result,
810 int bytes, efunc err)
812 error = err;
814 switch (bytes) {
815 case 2:
816 return to_float(number, sign, result, &ieee_16);
817 case 4:
818 return to_float(number, sign, result, &ieee_32);
819 case 8:
820 return to_float(number, sign, result, &ieee_64);
821 case 10:
822 return to_float(number, sign, result, &ieee_80);
823 case 16:
824 return to_float(number, sign, result, &ieee_128);
825 default:
826 error(ERR_PANIC, "strange value %d passed to float_const", bytes);
827 return 0;
831 /* Set floating-point options */
832 int float_option(const char *option)
834 if (!nasm_stricmp(option, "daz")) {
835 daz = true;
836 return 0;
837 } else if (!nasm_stricmp(option, "nodaz")) {
838 daz = false;
839 return 0;
840 } else if (!nasm_stricmp(option, "near")) {
841 rc = FLOAT_RC_NEAR;
842 return 0;
843 } else if (!nasm_stricmp(option, "down")) {
844 rc = FLOAT_RC_DOWN;
845 return 0;
846 } else if (!nasm_stricmp(option, "up")) {
847 rc = FLOAT_RC_UP;
848 return 0;
849 } else if (!nasm_stricmp(option, "zero")) {
850 rc = FLOAT_RC_ZERO;
851 return 0;
852 } else if (!nasm_stricmp(option, "default")) {
853 rc = FLOAT_RC_NEAR;
854 daz = false;
855 return 0;
856 } else {
857 return -1; /* Unknown option */