Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
edadma committed Apr 5, 2018
1 parent 55321a2 commit 1bb09c4
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 34 deletions.
2 changes: 1 addition & 1 deletion double2str.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ void
main() {
char a[20];

double2str( 3.4, a );
double2str( 12, a );
println( a );
}
10 changes: 10 additions & 0 deletions src/main/scala/RV32D.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class FP( val rs1: Int, val rs2: Int, val rd: Int, val mode: Int ) extends RType
case 1 => cpu(rd) = boolean2int( cpu.f(rs1) < cpu.f(rs2) )
case 2 => cpu(rd) = boolean2int( cpu.f(rs1) == cpu.f(rs2) )
}
case 0x61 => // FCVT
rs2 match {
case 0 => cpu(rd) = cpu.f(rs1).asInstanceOf[Int]
}
// RV64D
case 0x79 => // FMV.D.X
if (rs2 == 0 && mode == 0)
cpu.f(rd) = ltod( cpu(rs1) )
else
illegal( cpu )
}
}

Expand Down
45 changes: 45 additions & 0 deletions tests/float64.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,46 @@ printb( int b ) {
println( b ? "true" : "false" );
}

char*
double2str( double x, char p[] )
{
int i = 0;
int k = 0;

if (x < 0) {
x = -x;
p[0] = '-';
i++;
k++;
}

while (((int) x) > 0) {
x /= 10;
i++;
}

int n;

p[i] = '.';
x *= 10;
n = (int) x;
x -= n;

while (n > 0) {
if (k == i)
k++;

p[k] = n + '0';
x *= 10;
n = (int) x;
x = x - n;
k++;
}

p[k] = '\0';
return p;
}

void
main() {
double a = 3.4;
Expand All @@ -38,4 +78,9 @@ main() {
printb( a != b );
printb( a * b == 3.4 * 5.6 );
printb( a / b == 3.4 / 5.6 );

// char buf[20];
//
// println( double2str(3.5, buf) );
// println( double2str(-3.5, buf) );
}
90 changes: 57 additions & 33 deletions tests/float64.hex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Hex dump of section '.text':
0x00010080 37010100 ef008014 73500000 00000000 7.......sP......
0x00010080 37010100 ef00402d 73500000 00000000 7.....@-sP......
0x00010090 00000000 00000000 00000000 00000000 ................
0x000100a0 00000000 00000000 00000000 00000000 ................
0x000100b0 00000000 00000000 00000000 00000000 ................
Expand All @@ -18,41 +18,65 @@ Hex dump of section '.text':
0x00010170 13010102 67800000 130101fe 233c1100 ....g.......#<..
0x00010180 23388100 13040102 93070500 2326f4fe #8..........#&..
0x00010190 8327c4fe 9b870700 63880700 b7070100 .'......c.......
0x000101a0 93878736 6f00c000 b7070100 93870737 ...6o..........7
0x000101a0 9387074f 6f00c000 b7070100 9387874f ...Oo..........O
0x000101b0 13850700 eff0dff8 13000000 83308101 .............0..
0x000101c0 03340101 13010102 67800000 130101fd .4......g.......
0x000101d0 23341102 23308102 13040103 b7070100 #4..#0..........
0x000101e0 87b78737 2734f4fe b7070100 87b70738 ...7'4.........8
0x000101f0 2730f4fe b7070100 87b78738 273cf4fc '0.........8'<..
0x00010200 073784fe 873704fe 5377f702 b7070100 .7...7..Sw......
0x00010210 87b70739 d327f7a2 b337f000 93f7f70f ...9.'...7......
0x00010220 9b870700 13850700 eff01ff5 073784fe .............7..
0x00010230 873704fe 5377f70a b7070100 87b78739 .7..Sw.........9
0x00010240 d327f7a2 b337f000 93f7f70f 9b870700 .'...7..........
0x00010250 13850700 eff05ff2 073784fe 873704fe ......_..7...7..
0x00010260 d317f7a2 b337f000 93f7f70f 9b870700 .....7..........
0x00010270 13850700 eff05ff0 073784fe 873704fe ......_..7...7..
0x00010280 d307f7a2 b337f000 93f7f70f 9b870700 .....7..........
0x00010290 13850700 eff05fee 073784fe 873704fe ......_..7...7..
0x000102a0 d397e7a2 b337f000 93f7f70f 9b870700 .....7..........
0x000102b0 13850700 eff05fec 073784fe 873704fe ......_..7...7..
0x000102c0 d387e7a2 b337f000 93f7f70f 9b870700 .....7..........
0x000102d0 13850700 eff05fea 073784fe 873704fe ......_..7...7..
0x000102e0 d327f7a2 93b71700 93f7f70f 9b870700 .'..............
0x000102f0 13850700 eff05fe8 073784fe 873704fe ......_..7...7..
0x00010300 5377f712 b7070100 87b7073a d327f7a2 Sw.........:.'..
0x00010310 b337f000 93f7f70f 9b870700 13850700 .7..............
0x00010320 eff09fe5 073784fe 873704fe 5377f71a .....7...7..Sw..
0x00010330 b7070100 87b7873a d327f7a2 b337f000 .......:.'...7..
0x00010340 93f7f70f 9b870700 13850700 eff0dfe2 ................
0x00010350 13000000 83308102 03340102 13010103 .....0...4......
0x00010360 67800000 g...
0x000101d0 23348102 13040103 273ca4fc 2338a4fc #4......'<..#8..
0x000101e0 232604fe 232404fe 873784fd 530700f2 #&..#$...7..S...
0x000101f0 d397e7a2 638a0702 873784fd d397f722 ....c....7....."
0x00010200 273cf4fc 833704fd 1307d002 2380e700 '<...7......#...
0x00010210 8327c4fe 9b871700 2326f4fe 832784fe .'......#&...'..
0x00010220 9b871700 2324f4fe 6f004002 073784fd ....#$..o.@..7..
0x00010230 b7070100 87b70750 d377f71a 273cf4fc .......P.w..'<..
0x00010240 8327c4fe 9b871700 2326f4fe 873784fd .'......#&...7..
0x00010250 d39707c2 9b870700 e34af0fc 8327c4fe .........J...'..
0x00010260 033704fd b307f700 1307e002 2380e700 .7..........#...
0x00010270 073784fd b7070100 87b70750 d377f712 .7.........P.w..
0x00010280 273cf4fc 873784fd d39707c2 2322f4fe '<...7......#"..
0x00010290 832744fe d38707d2 073784fd d377f70a .'D......7...w..
0x000102a0 273cf4fc 6f004008 032784fe 8327c4fe '<..o.@..'...'..
0x000102b0 1b070700 9b870700 6318f700 832784fe ........c....'..
0x000102c0 9b871700 2324f4fe 832744fe 13f7f70f ....#$...'D.....
0x000102d0 832784fe 833604fd b387f600 1b070703 .'...6..........
0x000102e0 1377f70f 2380e700 073784fd b7070100 .w..#....7......
0x000102f0 87b70750 d377f712 273cf4fc 873784fd ...P.w..'<...7..
0x00010300 d39707c2 2322f4fe 832744fe d38707d2 ....#"...'D.....
0x00010310 073784fd d377f70a 273cf4fc 832784fe .7...w..'<...'..
0x00010320 9b871700 2324f4fe 832744fe 9b870700 ....#$...'D.....
0x00010330 e34cf0f6 832784fe 033704fd b307f700 .L...'...7......
0x00010340 23800700 833704fd 13850700 03348102 #....7.......4..
0x00010350 13010103 67800000 130101fd 23341102 ....g.......#4..
0x00010360 23308102 13040103 b7070100 87b78750 #0.............P
0x00010370 2734f4fe b7070100 87b70751 2730f4fe '4.........Q'0..
0x00010380 b7070100 87b78751 273cf4fc 073784fe .......Q'<...7..
0x00010390 873704fe 5377f702 b7070100 87b70752 .7..Sw.........R
0x000103a0 d327f7a2 b337f000 93f7f70f 9b870700 .'...7..........
0x000103b0 13850700 eff05fdc 073784fe 873704fe ......_..7...7..
0x000103c0 5377f70a b7070100 87b78752 d327f7a2 Sw.........R.'..
0x000103d0 b337f000 93f7f70f 9b870700 13850700 .7..............
0x000103e0 eff09fd9 073784fe 873704fe d317f7a2 .....7...7......
0x000103f0 b337f000 93f7f70f 9b870700 13850700 .7..............
0x00010400 eff09fd7 073784fe 873704fe d307f7a2 .....7...7......
0x00010410 b337f000 93f7f70f 9b870700 13850700 .7..............
0x00010420 eff09fd5 073784fe 873704fe d397e7a2 .....7...7......
0x00010430 b337f000 93f7f70f 9b870700 13850700 .7..............
0x00010440 eff09fd3 073784fe 873704fe d387e7a2 .....7...7......
0x00010450 b337f000 93f7f70f 9b870700 13850700 .7..............
0x00010460 eff09fd1 073784fe 873704fe d327f7a2 .....7...7...'..
0x00010470 93b71700 93f7f70f 9b870700 13850700 ................
0x00010480 eff09fcf 073784fe 873704fe 5377f712 .....7...7..Sw..
0x00010490 b7070100 87b70753 d327f7a2 b337f000 .......S.'...7..
0x000104a0 93f7f70f 9b870700 13850700 eff0dfcc ................
0x000104b0 073784fe 873704fe 5377f71a b7070100 .7...7..Sw......
0x000104c0 87b78753 d327f7a2 b337f000 93f7f70f ...S.'...7......
0x000104d0 9b870700 13850700 eff01fca 13000000 ................
0x000104e0 83308102 03340102 13010103 67800000 .0...4......g...


Hex dump of section '.rodata':
0x00010368 74727565 00000000 66616c73 65000000 true....false...
0x00010378 33333333 33330b40 66666666 66661640 333333.@ffffff.@
0x00010388 33333333 33331f40 00000000 00002240 333333.@......"@
0x00010398 99999999 999901c0 0ad7a370 3d0a3340 ...........p=.3@
0x000103a8 dcb66ddb b66de33f ..m..m.?
0x000104f0 74727565 00000000 66616c73 65000000 true....false...
0x00010500 00000000 00002440 33333333 33330b40 ......$@333333.@
0x00010510 66666666 66661640 33333333 33331f40 ffffff.@333333.@
0x00010520 00000000 00002240 99999999 999901c0 ......"@........
0x00010530 0ad7a370 3d0a3340 dcb66ddb b66de33f ...p=.3@..m..m.?

0 comments on commit 1bb09c4

Please sign in to comment.