File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 34
34
is a context manager (under which conditional assignements can be made), and "otherwise",
35
35
which is an instance that stands in for a 'fall through' case. The details of how these
36
36
should be used, and the difference between normal assignments and condtional assignments,
37
- described in more detail in the state machine example from in prytl/examples.
37
+ described in more detail in the state machine example in examples/example3-statemachine.py.
38
+
39
+ There are instances where you might want a wirevector to be set to a certain value in all
40
+ but certain with blocks. For example, say you have a processor with a PC register that is
41
+ normally updated to PC + 1 after each cycle, except when the current instruction is
42
+ a branch or jump. You could represent that as follows::
43
+
44
+ pc = pyrtl.Register(32)
45
+ instr = pyrtl.WireVector(32)
46
+ res = pyrtl.WireVector(32)
47
+
48
+ op = instr[:7]
49
+ ADD = 0b0110011
50
+ JMP = 0b1101111
51
+
52
+ with conditional_assignment(
53
+ defaults={
54
+ pc: pc + 1,
55
+ res: 0
56
+ }
57
+ ):
58
+ with op == ADD:
59
+ res |= instr[15:20] + instr[20:25]
60
+ # pc will be updated to pc + 1
61
+ with op == JMP:
62
+ pc.next |= pc + instr[7:]
63
+ # res will be set to 0
38
64
39
65
In addition to the conditional context, there is a helper function "currently_under_condition"
40
66
which will test if the code where it is called is currently elaborating hardware
Original file line number Diff line number Diff line change @@ -133,7 +133,8 @@ def test_default_value_for_wires(self):
133
133
r1 : r1 + 2 ,
134
134
r2 : 6 ,
135
135
o : 3
136
- }):
136
+ }
137
+ ):
137
138
with i < 2 :
138
139
r1 .next |= r1 + 1
139
140
# r2 will be updated to 6
You can’t perform that action at this time.
0 commit comments