diff --git a/doc/harp_iset.tex b/doc/harp_iset.tex index 8a2134e4..f913efc8 100644 --- a/doc/harp_iset.tex +++ b/doc/harp_iset.tex @@ -314,8 +314,8 @@ format, which can be fixed point or floating point. \begin{tabular}{cl} \textbf{Instruction}&\textbf{Description}\\ \hline -\texttt{itof} \%dest, \%src&Integer to floating point.\\ -\texttt{ftoi} \%dest, \%src&Floating point to integer.\\ +\texttt{itof} \%dest, \%src&Signed integer to floating point.\\ +\texttt{ftoi} \%dest, \%src&Floating point to signed integer.\\ \texttt{fneg} \%dest, \%src&Negate (complement sign bit).\\ \texttt{fadd} \%dest, \%src1, \%src2&Floating point add.\\ \texttt{fsub} \%dest, \%src1, \%src2&Floating point subtract.\\ diff --git a/src/instruction.cpp b/src/instruction.cpp index 86f10695..0bd037ab 100644 --- a/src/instruction.cpp +++ b/src/instruction.cpp @@ -291,7 +291,7 @@ void Instruction::executeOn(Core &c) { c.pc = c.shadowPc; } break; - case ITOF: reg[rdest] = Float(double(reg[rsrc[0]]), wordSz); + case ITOF: reg[rdest] = Float(double(Word_s(reg[rsrc[0]])), wordSz); break; case FTOI: reg[rdest] = Word_s(double(Float(reg[rsrc[0]], wordSz))); reg[rdest].trunc(wordSz); diff --git a/src/unit_test/float_test.cpp b/src/unit_test/float_test.cpp index 8d5169a1..f432fd7b 100644 --- a/src/unit_test/float_test.cpp +++ b/src/unit_test/float_test.cpp @@ -24,6 +24,10 @@ int main() { for (unsigned i = 0; i < 2; i++) { int n = rand() - RAND_MAX/2; double d = n * 0.0000001; + + // Sometimes do negative numbers. + if (rand() & 1) d = -d; + try_val(d, sz); }