Was never specified, but itof/ftoi should be signed. (issue #4)

This commit is contained in:
chad
2014-10-08 17:06:04 -04:00
parent 65c9aeadc5
commit 54adca00e3
3 changed files with 7 additions and 3 deletions

View File

@@ -314,8 +314,8 @@ format, which can be fixed point or floating point.
\begin{tabular}{cl} \begin{tabular}{cl}
\textbf{Instruction}&\textbf{Description}\\ \textbf{Instruction}&\textbf{Description}\\
\hline \hline
\texttt{itof} \%dest, \%src&Integer to floating point.\\ \texttt{itof} \%dest, \%src&Signed integer to floating point.\\
\texttt{ftoi} \%dest, \%src&Floating point to integer.\\ \texttt{ftoi} \%dest, \%src&Floating point to signed integer.\\
\texttt{fneg} \%dest, \%src&Negate (complement sign bit).\\ \texttt{fneg} \%dest, \%src&Negate (complement sign bit).\\
\texttt{fadd} \%dest, \%src1, \%src2&Floating point add.\\ \texttt{fadd} \%dest, \%src1, \%src2&Floating point add.\\
\texttt{fsub} \%dest, \%src1, \%src2&Floating point subtract.\\ \texttt{fsub} \%dest, \%src1, \%src2&Floating point subtract.\\

View File

@@ -291,7 +291,7 @@ void Instruction::executeOn(Core &c) {
c.pc = c.shadowPc; c.pc = c.shadowPc;
} }
break; break;
case ITOF: reg[rdest] = Float(double(reg[rsrc[0]]), wordSz); case ITOF: reg[rdest] = Float(double(Word_s(reg[rsrc[0]])), wordSz);
break; break;
case FTOI: reg[rdest] = Word_s(double(Float(reg[rsrc[0]], wordSz))); case FTOI: reg[rdest] = Word_s(double(Float(reg[rsrc[0]], wordSz)));
reg[rdest].trunc(wordSz); reg[rdest].trunc(wordSz);

View File

@@ -24,6 +24,10 @@ int main() {
for (unsigned i = 0; i < 2; i++) { for (unsigned i = 0; i < 2; i++) {
int n = rand() - RAND_MAX/2; int n = rand() - RAND_MAX/2;
double d = n * 0.0000001; double d = n * 0.0000001;
// Sometimes do negative numbers.
if (rand() & 1) d = -d;
try_val(d, sz); try_val(d, sz);
} }