Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edadma committed Apr 5, 2018
1 parent 7040af1 commit 3147065
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/RV32I.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class SLTU_MULHU( val rs1: Int, val rs2: Int, val rd: Int ) extends
case 0 =>
cpu(rd) =
if (lcu(cpu(rs1).asInstanceOf[Int], cpu(rs2).asInstanceOf[Int]) < 0) 1 else 0
case 1 => cpu(rd) = ((ulong(cpu(rs1)) * ulong(cpu(rs2))) >> 32).asInstanceOf[Long]
case 1 => cpu(rd) = ((ulong(cpu(rs1)) * ulong(cpu(rs2))) >> 32).longValue
case _ => illegal( cpu )
}
}
Expand All @@ -203,7 +203,7 @@ class SR_DIVU( val rs1: Int, val rs2: Int, val rd: Int ) extends
def apply( cpu: CPU ) =
funct(cpu) match {
case 0 => cpu(rd) = cpu(rs1) >>> (cpu(rs2)&0x3F)
case 1 => cpu(rd) = (ulong(cpu(rs1)) / ulong(cpu(rs2))).asInstanceOf[Long]
case 1 => cpu(rd) = (ulong(cpu(rs1)) / ulong(cpu(rs2))).longValue
case 0x20 => cpu(rd) = cpu(rs1) >> (cpu(rs2)&0x3F)
case _ => illegal( cpu )
}
Expand All @@ -224,7 +224,7 @@ class AND_REMU( val rs1: Int, val rs2: Int, val rd: Int ) extends
def apply( cpu: CPU ) =
funct(cpu) match {
case 0 => cpu(rd) = cpu(rs1) & cpu(rs2)
case 1 => cpu(rd) = (ulong(cpu(rs1)) % ulong(cpu(rs2))).asInstanceOf[Long]
case 1 => cpu(rd) = (ulong(cpu(rs1)) % ulong(cpu(rs2))).longValue
case _ => illegal( cpu )
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/scala/ExamplesNoCompressed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ class ExamplesNoCompressed extends FreeSpec with PropertyChecks with Matchers {
""".trim.stripMargin
}

"int2str64u" in {
Run( "tests/int2str64u.hex" ) shouldBe
"""
|0
|123
|12AB
|2000000000
|20000000000
|F000000000000000
""".trim.stripMargin
}

"armstrong" in {
Run( "tests/armstrong.hex" ) shouldBe
"""
Expand Down
49 changes: 49 additions & 0 deletions tests/int2str64u.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//#include <stdio.h>
//#define out( c ) putchar( c )

void
out( char c ) {
*((char*) 0x20000) = c;
}

void
print( char* s ) {
while (*s)
out( *s++ );
}

void
println( char* s ) {
print( s );
out( '\n' );
}

char*
int2str64u( unsigned long n, int radix, char* buf ) {
char digits[] = "0123456789ABCDEF";
char* p = &buf[33];
unsigned long quo = n;

*p-- = 0;

while (quo >= radix) {
*p-- = digits[(quo%radix)];
quo /= radix;
}

*p = digits[quo];

return p;
}

void
main() {
char buf[34];

println( int2str64u(0, 10, buf) );
println( int2str64u(123, 10, buf) );
println( int2str64u(0x12AB, 16, buf) );
println( int2str64u(2000000000, 10, buf) );
println( int2str64u(20000000000, 10, buf) );
println( int2str64u(0xF000000000000000, 16, buf) );
}
53 changes: 53 additions & 0 deletions tests/int2str64u.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

Hex dump of section '.text':
0x00010080 37010100 ef00c01c 73500000 00000000 7.......sP......
0x00010090 00000000 00000000 00000000 00000000 ................
0x000100a0 00000000 00000000 00000000 00000000 ................
0x000100b0 00000000 00000000 00000000 00000000 ................
0x000100c0 130101fe 233c8100 13040102 93070500 ....#<..........
0x000100d0 a307f4fe b7070200 0347f4fe 2380e700 .........G..#...
0x000100e0 13000000 03348101 13010102 67800000 .....4......g...
0x000100f0 130101fe 233c1100 23388100 13040102 ....#<..#8......
0x00010100 2334a4fe 6f00c001 833784fe 13871700 #4..o....7......
0x00010110 2334e4fe 83c70700 13850700 eff05ffa #4............_.
0x00010120 833784fe 83c70700 e39007fe 13000000 .7..............
0x00010130 83308101 03340101 13010102 67800000 .0...4......g...
0x00010140 130101fe 233c1100 23388100 13040102 ....#<..#8......
0x00010150 2334a4fe 033584fe eff09ff9 1305a000 #4...5..........
0x00010160 eff01ff6 13000000 83308101 03340101 .........0...4..
0x00010170 13010102 67800000 130101fa 233c8104 ....g.......#<..
0x00010180 13040106 233ca4fa 93870500 2334c4fa ....#<......#4..
0x00010190 232af4fa b7070100 03b78734 2334e4fc #*.........4#4..
0x000101a0 13878734 03378700 2338e4fc 93878734 ...4.7..#8.....4
0x000101b0 83c70701 230cf4fc 833784fa 93871702 ....#....7......
0x000101c0 2334f4fe 833784fb 2330f4fe 833784fe #4...7..#0...7..
0x000101d0 1387f7ff 2334e4fe 23800700 6f00c003 ....#4..#...o...
0x000101e0 832744fb 033704fe 3377f702 833784fe .'D..7..3w...7..
0x000101f0 9386f7ff 2334d4fe 930604ff 3387e600 ....#4......3...
0x00010200 034787fd 2380e700 832744fb 033704fe .G..#....'D..7..
0x00010210 b357f702 2330f4fe 832744fb 033704fe .W..#0...'D..7..
0x00010220 e370f7fc 833704fe 130704ff b307f700 .p...7..........
0x00010230 03c787fd 833784fe 2380e700 833784fe .....7..#....7..
0x00010240 13850700 03348105 13010106 67800000 .....4......g...
0x00010250 130101fc 233c1102 23388102 13040104 ....#<..#8......
0x00010260 930784fc 13860700 9305a000 13050000 ................
0x00010270 eff09ff0 93070500 13850700 eff05fec .............._.
0x00010280 930784fc 13860700 9305a000 1305b007 ................
0x00010290 eff09fee 93070500 13850700 eff05fea .............._.
0x000102a0 930784fc 13860700 93050001 b7170000 ................
0x000102b0 1385b72a eff05fec 93070500 13850700 ...*.._.........
0x000102c0 eff01fe8 930784fc 13860700 9305a000 ................
0x000102d0 b7973577 13850740 eff01fea 93070500 ..5w...@........
0x000102e0 13850700 eff0dfe5 930784fc 13860700 ................
0x000102f0 9305a000 b7079500 9387972f 1395b700 .........../....
0x00010300 eff09fe7 93070500 13850700 eff05fe3 .............._.
0x00010310 930784fc 13860700 93050001 9307f0ff ................
0x00010320 1395c703 eff05fe5 93070500 13850700 ......_.........
0x00010330 eff01fe1 13000000 83308103 03340103 .........0...4..
0x00010340 13010104 67800000 ....g...


Hex dump of section '.rodata':
0x00010348 30313233 34353637 38394142 43444546 0123456789ABCDEF
0x00010358 00 .

0 comments on commit 3147065

Please sign in to comment.