aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Hutt <timothy.hutt@codasip.com>2024-07-09 20:24:14 +0100
committerGitHub <noreply@github.com>2024-07-09 20:24:14 +0100
commitb6cdb537ed012db550c3b50754241b86280843f2 (patch)
treeb192e7404ee3ba10f0b00a1770b4006e1e363c16
parent809337eb0db5de41928c7d9ad90c20f786107a41 (diff)
downloadsail-riscv-b6cdb537ed012db550c3b50754241b86280843f2.zip
sail-riscv-b6cdb537ed012db550c3b50754241b86280843f2.tar.gz
sail-riscv-b6cdb537ed012db550c3b50754241b86280843f2.tar.bz2
Use bool <-> bit mappings from riscv_types.sail
Use these mappings and change the other functions to be aliases of them.
-rw-r--r--model/prelude.sail26
-rw-r--r--model/riscv_types.sail10
2 files changed, 18 insertions, 18 deletions
diff --git a/model/prelude.sail b/model/prelude.sail
index ae1cafc..45d49c0 100644
--- a/model/prelude.sail
+++ b/model/prelude.sail
@@ -99,18 +99,28 @@ overload zeros = {zeros_implicit}
val ones : forall 'n, 'n >= 0 . implicit('n) -> bits('n)
function ones (n) = sail_ones (n)
-val bool_to_bit : bool -> bit
-function bool_to_bit x = if x then bitone else bitzero
+mapping bool_bit : bool <-> bit = {
+ true <-> bitone,
+ false <-> bitzero,
+}
-val bool_to_bits : bool -> bits(1)
-function bool_to_bits x = [bool_to_bit(x)]
+mapping bool_bits : bool <-> bits(1) = {
+ true <-> 0b1,
+ false <-> 0b0,
+}
-val bit_to_bool : bit -> bool
-function bit_to_bool b = match b {
- bitone => true,
- bitzero => false
+mapping bool_not_bits : bool <-> bits(1) = {
+ true <-> 0b0,
+ false <-> 0b1,
}
+// These aliases make the conversion direction a bit clearer.
+function bool_to_bit(x : bool) -> bit = bool_bit(x)
+function bit_to_bool(x : bit) -> bool = bool_bit(x)
+function bool_to_bits(x : bool) -> bits(1) = bool_bits(x)
+function bits_to_bool(x : bits(1)) -> bool = bool_bits(x)
+
+
val to_bits : forall 'l, 'l >= 0.(int('l), int) -> bits('l)
function to_bits (l, n) = get_slice_int(l, n, 0)
diff --git a/model/riscv_types.sail b/model/riscv_types.sail
index 61e0089..f6e2d1c 100644
--- a/model/riscv_types.sail
+++ b/model/riscv_types.sail
@@ -356,16 +356,6 @@ enum extop_zbb = {RISCV_SEXTB, RISCV_SEXTH, RISCV_ZEXTH}
enum zicondop = {RISCV_CZERO_EQZ, RISCV_CZERO_NEZ}
-mapping bool_bits : bool <-> bits(1) = {
- true <-> 0b1,
- false <-> 0b0
-}
-
-mapping bool_not_bits : bool <-> bits(1) = {
- true <-> 0b0,
- false <-> 0b1
-}
-
// Get the bit encoding of word_width.
mapping size_enc : word_width <-> bits(2) = {
BYTE <-> 0b00,