-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SV: Implement some more primitives so RV model builds
- Loading branch information
Showing
15 changed files
with
205 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ediv ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
default Order dec | ||
|
||
$include <arith.sail> | ||
$include <smt.sail> | ||
$include <string.sail> | ||
|
||
function main (() : unit) -> unit = { | ||
assert(ediv_int(7, 5) == 1); | ||
assert(ediv_int(7, -5) == -1); | ||
assert(ediv_int(-7, 5) == -2); | ||
assert(ediv_int(-7, -5) == 2); | ||
assert(ediv_int(12, 3) == 4); | ||
assert(ediv_int(12, -3) == -4); | ||
assert(ediv_int(-12, 3) == -4); | ||
assert(ediv_int(-12, -3) == 4); | ||
|
||
assert(emod_int(7, 5) == 2); | ||
assert(emod_int(7, -5) == 2); | ||
assert(emod_int(-7, 5) == 3); | ||
assert(emod_int(-7, -5) == 3); | ||
assert(emod_int(12, 3) == 0); | ||
assert(emod_int(12, -3) == 0); | ||
assert(emod_int(-12, 3) == 0); | ||
assert(emod_int(-12, -3) == 0); | ||
|
||
print_endline("ediv ok") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ediv from tdiv ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
default Order dec | ||
|
||
$include <arith.sail> | ||
$include <smt.sail> | ||
$include <string.sail> | ||
|
||
val my_ediv_int : (int, int) -> int | ||
|
||
function my_ediv_int(n, m) = { | ||
if n < 0 & m < 0 then { | ||
tdiv_int(abs_int_plain(n) - 1, abs_int_plain(m)) + 1 | ||
} else if n < 0 then { | ||
tdiv_int(n + 1, m) - 1 | ||
} else { | ||
tdiv_int(n, m) | ||
} | ||
} | ||
|
||
val my_emod_int : (int, int) -> int | ||
|
||
function my_emod_int(n, m) = { | ||
n - (m * my_ediv_int(n, m)) | ||
} | ||
|
||
function main (() : unit) -> unit = { | ||
foreach (n from -100 to 100) { | ||
foreach (m from -100 to 100) { | ||
if m != 0 then { | ||
let d = ediv_int(n, m); | ||
let r = emod_int(n, m); | ||
|
||
let my_d = my_ediv_int(n, m); | ||
let my_r = my_emod_int(n, m); | ||
|
||
assert(d == my_d); | ||
assert(r == my_r); | ||
assert(n == m * d + r); | ||
} | ||
} | ||
}; | ||
|
||
print_endline("ediv from tdiv ok") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fdiv ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
default Order dec | ||
|
||
$include <arith.sail> | ||
$include <string.sail> | ||
|
||
function main (() : unit) -> unit = { | ||
assert(fdiv_int(7, 5) == 1); | ||
assert(fdiv_int(7, -5) == -2); | ||
assert(fdiv_int(-7, 5) == -2); | ||
assert(fdiv_int(-7, -5) == 1); | ||
assert(fdiv_int(12, 3) == 4); | ||
assert(fdiv_int(12, -3) == -4); | ||
assert(fdiv_int(-12, 3) == -4); | ||
assert(fdiv_int(-12, -3) == 4); | ||
|
||
assert(fmod_int(7, 5) == 2); | ||
assert(fmod_int(7, -5) == -3); | ||
assert(fmod_int(-7, 5) == 3); | ||
assert(fmod_int(-7, -5) == -2); | ||
assert(fmod_int(12, 3) == 0); | ||
assert(fmod_int(12, -3) == 0); | ||
assert(fmod_int(-12, 3) == 0); | ||
assert(fmod_int(-12, -3) == 0); | ||
|
||
print_endline("fdiv ok") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tdiv ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
default Order dec | ||
|
||
$include <arith.sail> | ||
$include <string.sail> | ||
|
||
function main (() : unit) -> unit = { | ||
assert(tdiv_int(7, 5) == 1); | ||
assert(tdiv_int(7, -5) == -1); | ||
assert(tdiv_int(-7, 5) == -1); | ||
assert(tdiv_int(-7, -5) == 1); | ||
assert(tdiv_int(12, 3) == 4); | ||
assert(tdiv_int(12, -3) == -4); | ||
assert(tdiv_int(-12, 3) == -4); | ||
assert(tdiv_int(-12, -3) == 4); | ||
|
||
assert(tmod_int(7, 5) == 2); | ||
assert(tmod_int(7, -5) == 2); | ||
assert(tmod_int(-7, 5) == -2); | ||
assert(tmod_int(-7, -5) == -2); | ||
assert(tmod_int(12, 3) == 0); | ||
assert(tmod_int(12, -3) == 0); | ||
assert(tmod_int(-12, 3) == 0); | ||
assert(tmod_int(-12, -3) == 0); | ||
|
||
print_endline("tdiv ok") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters