Skip to content

Commit 994135f

Browse files
committed
librtl: add bufifs and fix strings
1 parent 4a7c900 commit 994135f

File tree

9 files changed

+389
-221
lines changed

9 files changed

+389
-221
lines changed

ODIN_II/SRC/ast_elaborate.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ ast_node_t* build_hierarchy(ast_node_t* node, ast_node_t* parent, int index, sc_
597597
if (!(node_is_constant(node->children[0]))) {
598598
error_message(AST, node->loc,
599599
"%s", "Replication constant must be a constant expression");
600-
} else if (node->children[0]->types.vnumber->is_dont_care_string()) {
600+
} else if (node->children[0]->types.vnumber->has_unknown()) {
601601
error_message(AST, node->loc,
602602
"%s", "Replication constant cannot contain x or z");
603603
}
@@ -1326,7 +1326,7 @@ ast_node_t* finalize_ast(ast_node_t* node, ast_node_t* parent, sc_hierarchy* loc
13261326
if (!(node_is_constant(node->children[0]))) {
13271327
error_message(AST, node->loc,
13281328
"%s", "Replication constant must be a constant expression");
1329-
} else if (node->children[0]->types.vnumber->is_dont_care_string()) {
1329+
} else if (node->children[0]->types.vnumber->has_unknown()) {
13301330
error_message(AST, node->loc,
13311331
"%s", "Replication constant cannot contain x or z");
13321332
}
@@ -1700,12 +1700,12 @@ ast_node_t* finalize_ast(ast_node_t* node, ast_node_t* parent, sc_hierarchy* loc
17001700
case RANGE_REF: {
17011701
bool is_constant_ref = node_is_constant(node->children[0]);
17021702
if (is_constant_ref) {
1703-
is_constant_ref = is_constant_ref && !(node->children[0]->types.vnumber->is_dont_care_string());
1703+
is_constant_ref = is_constant_ref && !(node->children[0]->types.vnumber->has_unknown());
17041704
}
17051705

17061706
is_constant_ref = is_constant_ref && node_is_constant(node->children[1]);
17071707
if (is_constant_ref) {
1708-
is_constant_ref = is_constant_ref && !(node->children[1]->types.vnumber->is_dont_care_string());
1708+
is_constant_ref = is_constant_ref && !(node->children[1]->types.vnumber->has_unknown());
17091709
}
17101710

17111711
if (!is_constant_ref) {
@@ -1721,13 +1721,13 @@ ast_node_t* finalize_ast(ast_node_t* node, ast_node_t* parent, sc_hierarchy* loc
17211721
case ARRAY_REF: {
17221722
bool is_constant_ref = node_is_constant(node->children[0]);
17231723
if (is_constant_ref) {
1724-
is_constant_ref = is_constant_ref && !(node->children[0]->types.vnumber->is_dont_care_string());
1724+
is_constant_ref = is_constant_ref && !(node->children[0]->types.vnumber->has_unknown());
17251725
}
17261726

17271727
if (node->num_children == 2) {
17281728
is_constant_ref = is_constant_ref && node_is_constant(node->children[1]);
17291729
if (is_constant_ref) {
1730-
is_constant_ref = is_constant_ref && !(node->children[1]->types.vnumber->is_dont_care_string());
1730+
is_constant_ref = is_constant_ref && !(node->children[1]->types.vnumber->has_unknown());
17311731
}
17321732
}
17331733

ODIN_II/SRC/ast_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ void c_display(ast_node_t* node) {
13891389
* but we will just assume, the programmer should know to use a string
13901390
* and internally both are just numbers
13911391
*/
1392-
std::string format_str = node->children[0]->types.vnumber->to_printable();
1392+
std::string format_str = node->children[0]->types.vnumber->to_vstring('s');
13931393
ast_node_t* argv_nodes = node->children[1];
13941394
long argc_node = 0;
13951395
while (!format_str.empty()) {

libs/librtlnumber/main.cpp

Lines changed: 40 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,25 @@ inline static std::string _bad_ops(std::string test, const char* FUNCT, int LINE
2626
*
2727
* This is used for testing purposes only, unused in ODIN as the input is already preprocessed
2828
*/
29-
3029
static std::string arithmetic(std::string op, std::string a_in) {
3130
VNumber a(a_in);
3231
VNumber result;
3332

34-
if (op == "to_unsigned") {
33+
if (op == "is_true") {
34+
result = VNumber(V_TRUE(a));
35+
} else if (op == "is_false") {
36+
result = VNumber(V_FALSE(a));
37+
} else if (op == "is_unk") {
38+
result = VNumber(V_UNK(a));
39+
} else if (op == "is_x") {
40+
result = VNumber(V_IS_X(a));
41+
} else if (op == "is_z") {
42+
result = VNumber(V_IS_Z(a));
43+
} else if (op == "is_unsigned") {
44+
result = VNumber(V_IS_UNSIGNED(a));
45+
} else if (op == "is_signed") {
46+
result = VNumber(V_IS_SIGNED(a));
47+
} else if (op == "to_unsigned") {
3548
result = V_UNSIGNED(a);
3649
} else if (op == "to_signed") {
3750
result = V_SIGNED(a);
@@ -59,7 +72,7 @@ static std::string arithmetic(std::string op, std::string a_in) {
5972
bad_ops(op);
6073
}
6174

62-
return result.to_full_string();
75+
return result.to_verilog_bitstring();
6376
}
6477

6578
static std::string arithmetic(std::string a_in, std::string op, std::string b_in) {
@@ -123,7 +136,7 @@ static std::string arithmetic(std::string a_in, std::string op, std::string b_in
123136
bad_ops(op);
124137
}
125138

126-
return result.to_full_string();
139+
return result.to_verilog_bitstring();
127140
}
128141

129142
int main(int argc, char** argv) {
@@ -137,88 +150,45 @@ int main(int argc, char** argv) {
137150
ERR_MSG("Not Enough Arguments: " << std::to_string(argc - 1));
138151

139152
return -1;
140-
} else if (argc == 3 && input[1] == "is_true") {
141-
VNumber input_2(input[2]);
142-
143-
if (V_TRUE(input_2)) {
144-
result = "pass";
145-
} else {
146-
result = "fail";
147-
}
148-
} else if (argc == 3 && input[1] == "is_false") {
149-
VNumber input_2(input[2]);
150-
151-
if (V_FALSE(input_2)) {
152-
result = "pass";
153-
} else {
154-
result = "fail";
155-
}
156-
} else if (argc == 3 && input[1] == "is_unk") {
157-
VNumber input_2(input[2]);
158-
159-
if (V_UNK(input_2)) {
160-
result = "pass";
161-
} else {
162-
result = "fail";
163-
}
164-
} else if (argc == 3 && input[1] == "is_x") {
165-
VNumber input_2(input[2]);
166-
167-
if (V_IS_X(input_2)) {
168-
result = "pass";
169-
} else {
170-
result = "fail";
171-
}
172-
} else if (argc == 3 && input[1] == "is_z") {
173-
VNumber input_2(input[2]);
174-
175-
if (V_IS_Z(input_2)) {
176-
result = "pass";
177-
} else {
178-
result = "fail";
179-
}
180-
} else if (argc == 3 && input[1] == "is_unsigned") {
181-
VNumber input_2(input[2]);
182-
183-
if (V_IS_UNSIGNED(input_2)) {
184-
result = "pass";
185-
} else {
186-
result = "fail";
187-
}
188-
} else if (argc == 3 && input[1] == "is_signed") {
189-
VNumber input_2(input[2]);
190-
191-
if (V_IS_SIGNED(input_2)) {
192-
result = "pass";
193-
} else {
194-
result = "fail";
195-
}
196-
} else if (argc == 3 && input[1] == "display") {
197-
VNumber input_2(input[2]);
198-
199-
result = V_STRING(input_2);
200153
} else if (argc == 3) {
201154
result = arithmetic(input[1], input[2]);
155+
} else if (argc == 4 && input[1] == "display") {
156+
VNumber a(input[3]);
157+
result = V_STRING(a, input[2][0]);
158+
} else if (argc == 4 && input[1] == "bufif0") {
159+
VNumber bus(input[2]);
160+
VNumber trigger(input[3]);
161+
result = V_BITWISE_BUFIF0(bus, trigger).to_verilog_bitstring();
162+
} else if (argc == 4 && input[1] == "bufif1") {
163+
VNumber bus(input[2]);
164+
VNumber trigger(input[3]);
165+
result = V_BITWISE_BUFIF1(bus, trigger).to_verilog_bitstring();
166+
} else if (argc == 4 && input[1] == "notif0") {
167+
VNumber bus(input[2]);
168+
VNumber trigger(input[3]);
169+
result = V_BITWISE_NOTIF0(bus, trigger).to_verilog_bitstring();
170+
} else if (argc == 4 && input[1] == "notif1") {
171+
VNumber bus(input[2]);
172+
VNumber trigger(input[3]);
173+
result = V_BITWISE_NOTIF1(bus, trigger).to_verilog_bitstring();
202174
} else if (argc == 4) {
203175
result = arithmetic(input[1], input[2], input[3]);
204-
205176
} else if (argc == 6 && (input[2] == "?" && input[4] == ":")) {
206177
VNumber a(input[1]);
207178
VNumber b(input[3]);
208179
VNumber c(input[5]);
209180

210-
result = V_TERNARY(a, b, c).to_full_string();
211-
} else if (argc == 6 && (input[1] == "{" && input[3] == "," && input[5] == "}")) // the pipe symbol is a hack since our test handle uses csv.
212-
{
181+
result = V_TERNARY(a, b, c).to_verilog_bitstring();
182+
} else if (argc == 6 && (input[1] == "{" && input[3] == "," && input[5] == "}")) {
213183
VNumber a(input[2]);
214184
VNumber b(input[4]);
215185

216-
result = V_CONCAT({a, b}).to_full_string();
186+
result = V_CONCAT({a, b}).to_verilog_bitstring();
217187
} else if (argc == 7 && (input[1] == "{" && input[3] == "{" && input[5] == "}" && input[6] == "}")) {
218188
VNumber n_times(input[2]);
219189
VNumber replicant(input[4]);
220190

221-
result = V_REPLICATE(replicant, n_times).to_full_string();
191+
result = V_REPLICATE(replicant, n_times).to_verilog_bitstring();
222192
} else {
223193
ERR_MSG("invalid Arguments: " << std::to_string(argc - 1));
224194
return -1;

libs/librtlnumber/regression_tests/basic_regression_tests.csv

Lines changed: 92 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,61 @@
88
#####################
99

1010
# truth test
11-
simple_true, is_true, 1'b1, pass
12-
simple_fail, is_true, 1'b0, fail
13-
decimal_true, is_true, 1, pass
14-
decimal_fail, is_true, 0, fail
15-
complex_true, is_true, 3'b1xz, pass
16-
complex_fail, is_true, 3'b0xz, fail
17-
unknown_x, is_true, 1'bx, fail
18-
unknown_z, is_true, 1'bz, fail
19-
large_number_pass, is_true, 128'h8000_0000_0000_0000, pass
11+
simple_true, is_true, 1'b1, 1'b1
12+
simple_fail, is_true, 1'b0, 1'b0
13+
decimal_true, is_true, 1, 1'b1
14+
decimal_fail, is_true, 0, 1'b0
15+
complex_true, is_true, 3'b1xz, 1'b1
16+
complex_fail, is_true, 3'b0xz, 1'b0
17+
unknown_x, is_true, 1'bx, 1'b0
18+
unknown_z, is_true, 1'bz, 1'b0
19+
large_number_pass, is_true, 128'h8000_0000_0000_0000, 1'b1
2020

2121
# type test
22-
simple_x_pass, is_x, 1'bx, pass
23-
simple_x_fail, is_x, 1'b1, fail
24-
complex_x_pass, is_x, 4'bxxxx, pass
25-
complex_x_fail, is_x, 4'bzxxx, fail
26-
simple_z_pass, is_z, 1'bz, pass
27-
simple_z_fail, is_z, 1'b1, fail
28-
complex_z_pass, is_z, 4'bzzzz, pass
29-
complex_z_fail, is_z, 4'bxzzz, fail
30-
simple_unk_x_pass, is_unk, 2'bx1, pass
31-
simple_unk_z_pass, is_unk, 2'bz1, pass
32-
simple_unk_fail, is_unk, 2'b10, fail
22+
simple_x_pass, is_x, 1'bx, 1'b1
23+
simple_x_fail, is_x, 1'b1, 1'b0
24+
complex_x_pass, is_x, 4'bxxxx, 1'b1
25+
complex_x_fail, is_x, 4'bzxxx, 1'b0
26+
simple_z_pass, is_z, 1'bz, 1'b1
27+
simple_z_fail, is_z, 1'b1, 1'b0
28+
complex_z_pass, is_z, 4'bzzzz, 1'b1
29+
complex_z_fail, is_z, 4'bxzzz, 1'b0
30+
simple_unk_x_pass, is_unk, 2'bx1, 1'b1
31+
simple_unk_z_pass, is_unk, 2'bz1, 1'b1
32+
simple_unk_fail, is_unk, 2'b10, 1'b0
3333

3434
# sign test
35-
simple_is_unsigned_pass, is_unsigned, 2'b11, pass
36-
simple_is_unsigned_fail, is_unsigned, 2'sb11, fail
37-
simple_is_signed_pass, is_signed, 2'b11, fail
38-
simple_is_signed_fail, is_signed, 2'sb11, pass
35+
simple_is_unsigned_pass, is_unsigned, 2'b11, 1'b1
36+
simple_is_unsigned_fail, is_unsigned, 2'sb11, 1'b0
37+
simple_is_signed_pass, is_signed, 2'b11, 1'b0
38+
simple_is_signed_fail, is_signed, 2'sb11, 1'b1
3939

4040
# type conversion test
4141
simple_is_unsigned_1, to_unsigned, 2'b11, 2'b11
4242
simple_is_unsigned_2, to_unsigned, 2'sb11, 2'b11
4343
simple_is_signed_1, to_signed, 2'b11, 2'sb11
4444
simple_is_signed_2, to_signed, 2'sb11, 2'sb11
4545

46+
# string display
47+
simple_string_b, display, b, 64'd18446744073709551615, 1111111111111111111111111111111111111111111111111111111111111111
48+
simple_string_B, display, B, 65'd18446744073709551616, 10000000000000000000000000000000000000000000000000000000000000000
49+
simple_string_u, display, u, 1'bz, 1'b0 # todo, figure out the real result for this
50+
simple_string_U, display, U, 1'bx, 1'b0 # todo, figure out the real result for this
51+
simple_string_z, display, z, 1'bz, z
52+
simple_string_Z, display, Z, 1'bx, X
53+
simple_string_s, display, s, "hello world", hello world
54+
simple_string_S, display, S, "hello world", hello world
55+
simple_string_o, display, o, 64'd18446744073709551615, 1777777777777777777777
56+
simple_string_O, display, O, 65'd18446744073709551616, 2000000000000000000000
57+
simple_string_h, display, h, 64'd18446744073709551615, ffffffffffffffff
58+
simple_string_H, display, H, 64'd18446744073709551614, FFFFFFFFFFFFFFFE
59+
simple_string_d, display, d, 265663, 265663
60+
simple_string_D, display, D, 265663, 265663
61+
simple_string_c, display, c, "hello world", h
62+
simple_string_C, display, C, "world", w
63+
4664
# string test
47-
simple_string, display, "hello world", hello world
65+
simple_string, display, s, "hello world", hello world
4866
string_compare_pass, "hello world", ==, "hello world", 1'b1
4967
string_compare_fail, "hello world", ==, "hello", 1'b0
5068
string_ne_pass, "hello world", !=, "hello", 1'b1
@@ -77,6 +95,55 @@ simple_decimal_plus, 6, +, 1, 7
7795
simple_decimal_shift_right, 6, >>>, 1, 3
7896
simple_decimal_shift_left, 6, <<<, 1, 12
7997

98+
#################
99+
# tristate
100+
101+
# single bit trigger
102+
# ======
103+
104+
# bufif0
105+
bufif0_on, bufif0, 4'b10xz, 1'b0, 4'b10xx
106+
bufif0_off, bufif0, 4'b10xz, 1'b1, 4'bzzzz
107+
bufif0_dc, bufif0, 4'b10xz, 1'bx, 4'bxxxx
108+
bufif0_hihz, bufif0, 4'b10xz, 1'bz, 4'bxxxx
109+
110+
# bufif1
111+
bufif1_on, bufif1, 4'b10xz, 1'b1, 4'b10xx
112+
bufif1_off, bufif1, 4'b10xz, 1'b0, 4'bzzzz
113+
bufif1_dc, bufif1, 4'b10xz, 1'bx, 4'bxxxx
114+
bufif1_hihz, bufif1, 4'b10xz, 1'bz, 4'bxxxx
115+
116+
# notif0
117+
notif0_on, notif0, 4'b10xz, 1'b0, 4'b01xx
118+
notif0_off, notif0, 4'b10xz, 1'b1, 4'bzzzz
119+
notif0_dc, notif0, 4'b10xz, 1'bx, 4'bxxxx
120+
notif0_hihz, notif0, 4'b10xz, 1'bz, 4'bxxxx
121+
122+
# notif1
123+
notif1_on, notif1, 4'b10xz, 1'b1, 4'b01xx
124+
notif1_off, notif1, 4'b10xz, 1'b0, 4'bzzzz
125+
notif1_dc, notif1, 4'b10xz, 1'bx, 4'bxxxx
126+
notif1_hihz, notif1, 4'b10xz, 1'bz, 4'bxxxx
127+
128+
# wide trigger
129+
# ======
130+
131+
# bufif0
132+
bufif0_upper, bufif0, 4'b10xz, 4'b1100, 4'bzzxx
133+
bufif0_lower, bufif0, 4'b10xz, 4'b0011, 4'b10zz
134+
135+
# bufif1
136+
bufif1_upper, bufif1, 4'b10xz, 4'b1100, 4'b10zz
137+
bufif1_lower, bufif1, 4'b10xz, 4'b0011, 4'bzzxx
138+
139+
# notif0
140+
notif0_upper, notif0, 4'b10xz, 4'b1100, 4'bzzxx
141+
notif0_lower, notif0, 4'b10xz, 4'b0011, 4'b01zz
142+
143+
# notif1
144+
notif1_upper, notif1, 4'b10xz, 4'b1100, 4'b01zz
145+
notif1_lower, notif1, 4'b10xz, 4'b0011, 4'bzzxx
146+
80147

81148
# Reduction
82149
Reduction-and, &, 4'b1010, 1'b0

0 commit comments

Comments
 (0)