diff --git a/tgt-vvp/eval_real.c b/tgt-vvp/eval_real.c index 8a7dda0f2..54768be5b 100644 --- a/tgt-vvp/eval_real.c +++ b/tgt-vvp/eval_real.c @@ -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; diff --git a/vvp/opcodes.txt b/vvp/opcodes.txt index f3a266569..f8ba97f10 100644 --- a/vvp/opcodes.txt +++ b/vvp/opcodes.txt @@ -492,7 +492,7 @@ is removed from the before calculating the real value. If ==0x3fff and == 0, the value is +inf. If ==0x7fff and == 0, the value is -inf. -If --0x3fff and != 0, the value is NaN. +If ==0x3fff and != 0, the value is NaN. * %mod , , * %mod/s , , diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 65425ff84..05344f160 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -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;