16. Polyphonyの紹介:
Q: 言語として Python のすべてをカバーしていますか?
A: いいえ、Python のサブセットになります。
Python
Polyphony
(is a subset of Python)
Function
Class
List(Fixed size)
Tuple
For/While
If/Else
...
String
Dictionary
Set
Builtin funcs
...
Python のすべてをカバーしているわけではない
16
17. Python の関数を Verilog にする
from polyphony import testbench
def fib(n):
if n <= 0: return 0
if n == 1: return 1
r0 = 0
r1 = 1
for i in range(n-1):
prev_r1 = r1
r1 = r0 + r1
r0 = prev_r1
return r1
@testbench
def test():
expect = [0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610]
for i in range(len(expect)):
result = fib(i)
assert expect[i] == result
print(i, "=>", result)
test()
フィボナッチ数列
module fib
(
input wire clk,
input wire rst,
input wire fib_ready,
input wire fib_accept,
output reg fib_valid,
input wire signed [31:0] fib_in_n,
output reg signed [31:0] fib_out_0
);
中略
//signals:
wire cond565;
wire cond566;
中略
always @(posedge clk) begin
if (rst) begin
fib_out_0 <= 0;
i2 <= 0;
n <= 0;
r02 <= 0;
r12 <= 0;
fib_state <= fib_b1_INIT;
end else begin //if (rst)
中略
endcase
end
end
endmodule
17
Python の関数
テスト
Verilog HDL
18. どの辺が HDL 記述と違うか?
Polyphony (Python) Verilog-HDL
def a_b():
a = 3
b = 4
c = a + b
print(c)
出力結果は 7
a = 3;
b = 4;
c <= a + b;
$display("%d", c);
出力結果は x(不定)
18
19. どの辺が MyHDL 記述と違うか?
Polyphony (Python) MyHDL
def a_b():
a = 3
b = 4
c = a + b
print(c)
出力結果は 7
def a_b(clock, start, done, reset):
a = Signal(intbv(0)[7:])
b = Signal(intbv(0)[7:])
c = Signal(intbv(0)[7:])
@always_seq(clock.posedge, reset=reset)
def logic():
if reset:
a.next = 3
b.next = 4
else:
while True:
if start:
c.next = a + b
done.next = True
return logic
出力結果は7?
19
nextという
特別な
キーワード
42. pipeline のサポート
42
def pipelined_unroll01(xs, ys):
s = 0
for i in pipelined(unroll(range(8), 2)):
x = xs[i] + 1
if x < 0:
s = s + x
else:
s = s - x
ys[i] = x
#print(x)
return s
unroll
pipelined
コード例は、組み込みでよくみるような、レジスタのアドレスと書き込みデータの羅列になっています。AXI lite の Master の記述が出来るので、極端な話、CPU なしで動作可能なシステムが作れてしまいます。ツールにもよるのですが、ハードとソフトの IDE を行ったり来たりする必要がなくなります。