Handle NaN constant in the code generator and fix loadi/wr NaN bug.

This patch fixes a bug in %loadi/wr regarding NaN values. It also
fixes the code generator to correctly output a NaN value.
This commit is contained in:
Cary R 2008-08-28 18:11:55 -07:00 committed by Stephen Williams
parent 1ca8241b88
commit 2d3cd7cb9a
3 changed files with 11 additions and 4 deletions

View File

@ -206,13 +206,19 @@ static int draw_realnum_real(ivl_expr_t exp)
/* Handle the special case that the value is +-inf. */
if (isinf(value)) {
if (value > 0)
fprintf(vvp_out, " %%loadi/wr %d, 0, %d; load=+inf\n",
fprintf(vvp_out, " %%loadi/wr %d, 0, %d; load=+inf\n",
res, 0x3fff);
else
fprintf(vvp_out, " %%loadi/wr %d, 0, %d; load=-inf\n",
fprintf(vvp_out, " %%loadi/wr %d, 0, %d; load=-inf\n",
res, 0x7fff);
return res;
}
/* Handle the special case that the value is NaN. */
if (value != value) {
fprintf(vvp_out, " %%loadi/wr %d, 1, %d; load=NaN\n",
res, 0x3fff);
return res;
}
if (value < 0) {
sign = 0x4000;

View File

@ -492,7 +492,7 @@ is removed from the <exp> before calculating the real value.
If <exp>==0x3fff and <mant> == 0, the value is +inf.
If <exp>==0x7fff and <mant> == 0, the value is -inf.
If <exp>--0x3fff and <mant> != 0, the value is NaN.
If <exp>==0x3fff and <mant> != 0, the value is NaN.
* %mod <bit-l>, <bit-r>, <wid>
* %mod/s <bit-l>, <bit-r>, <wid>

View File

@ -2663,8 +2663,9 @@ bool of_LOADI_WR(vthread_t thr, vvp_code_t cp)
return true;
}
// Detect NaN
if ( (exp&0x3fff) == 0x3fff ) {
if (exp==0x3fff && cp->number!=0) {
thr->words[idx].w_real = nan("");
return true;
}
double sign = (exp & 0x4000)? -1.0 : 1.0;