1 |
15 |
homer.hsin |
/*
|
2 |
|
|
* Copyright 2012, Homer Hsing <homer.hsing@gmail.com>
|
3 |
|
|
*
|
4 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
|
|
* you may not use this file except in compliance with the License.
|
6 |
|
|
* You may obtain a copy of the License at
|
7 |
|
|
*
|
8 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
|
|
*
|
10 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
11 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
|
|
* See the License for the specific language governing permissions and
|
14 |
|
|
* limitations under the License.
|
15 |
|
|
*/
|
16 |
|
|
|
17 |
11 |
homer.hsin |
`timescale 1ns / 1ps
|
18 |
|
|
`define P 20
|
19 |
|
|
|
20 |
|
|
`define M 593 // M is the degree of the irreducible polynomial
|
21 |
|
|
`define WIDTH (2*`M-1) // width for a GF(3^M) element
|
22 |
|
|
`define WIDTH_D0 1187
|
23 |
|
|
|
24 |
|
|
module test_pe;
|
25 |
|
|
|
26 |
|
|
// Inputs
|
27 |
|
|
reg clk;
|
28 |
|
|
reg reset;
|
29 |
|
|
reg [10:0] ctrl;
|
30 |
|
|
reg [`WIDTH_D0:0] d0;
|
31 |
|
|
reg [`WIDTH:0] d1;
|
32 |
|
|
reg [`WIDTH:0] d2;
|
33 |
|
|
reg [`WIDTH:0] wish;
|
34 |
|
|
|
35 |
|
|
// Outputs
|
36 |
|
|
wire [`WIDTH:0] out;
|
37 |
|
|
|
38 |
|
|
// Instantiate the Unit Under Test (UUT)
|
39 |
|
|
PE uut (
|
40 |
|
|
.clk(clk),
|
41 |
|
|
.reset(reset),
|
42 |
|
|
.ctrl(ctrl),
|
43 |
|
|
.d0(d0),
|
44 |
|
|
.d1(d1),
|
45 |
|
|
.d2(d2),
|
46 |
|
|
.out(out)
|
47 |
|
|
);
|
48 |
|
|
|
49 |
|
|
initial begin
|
50 |
|
|
// Initialize Inputs
|
51 |
|
|
clk = 0;
|
52 |
|
|
reset = 0;
|
53 |
|
|
ctrl = 0;
|
54 |
|
|
d0 = 0;
|
55 |
|
|
d1 = 0;
|
56 |
|
|
d2 = 0;
|
57 |
|
|
|
58 |
|
|
// Wait 100 ns for global reset to finish
|
59 |
|
|
#100;
|
60 |
|
|
|
61 |
|
|
// Add stimulus here
|
62 |
|
|
// test mult
|
63 |
|
|
d0 = 1186'h245958540550916859984664a9559916599551944415826a8429555562950a5555a9661855015655694448585615852515916545158595955690a96a566591598660556a61880a410615585525454612010662a4a9116906410014611105015955161455804415166155815941116592650115564164556112804292528419450a45840158a926588250411118055565654556964;
|
64 |
|
|
d1 = 1186'h212291922556595445146a555159a2414515699455212899424869242411a459a6a96954461552562556a11694912451a058440646451050819559181a546891566865542169546869551654262068564119555949915194580525869959a159444051555a01a11509919294620158600555158520569556a514684225201a255a586294585262195922250514115a05542946299;
|
65 |
|
|
d2 = d1;
|
66 |
|
|
wish = 1186'h21a0004a5961412a2068488080020408114aa1aa6296a615418a9a22220948905a4a119849a541100016a14141625a21a906a05024001559086584205a1241804215518688468146052485a40581824a1146915164288a904150960222022aa49555608086151504905a68065906122568a2188a22aa09004451464946201a689926105411588591198551a1085145a6846196910;
|
67 |
|
|
|
68 |
|
|
@(negedge clk);
|
69 |
|
|
reset=1;#`P reset=0;
|
70 |
|
|
ctrl=11'b11111_000000; #`P;
|
71 |
|
|
ctrl=11'b00000_111111; #(198*`P);
|
72 |
|
|
check;
|
73 |
|
|
|
74 |
|
|
// test cubic
|
75 |
|
|
d0 = {6'b10101, 1182'd0};
|
76 |
|
|
d1 = 1186'h198565655595622106a15596a98a5186101959554541466581244585515555665552584505511552650944484555052655692189595619806549462551a56051552069242a6555542014551599866559955466a604511499554654119144668125851211419566a645856592a55865458582952556a916189591194655519664218a5a9a64990415a516a5169865415a912605951;
|
77 |
|
|
d2 = d1;
|
78 |
|
|
wish = 1186'h01a1425a929600890401891a44129844120112246215a566842954a605aaa8aa08588091659481a062a8519a868aa1548569a18a642222490a80aa8026a22501a8492a10555158491155025a84686680984852046a88a1008249008541a550556181952208252029264a0a4151045415450886854129a9658608684901089910281a22a46262a18108451120145a2625904921a96;
|
79 |
|
|
|
80 |
|
|
@(negedge clk);
|
81 |
|
|
reset=1;#`P reset=0;
|
82 |
|
|
ctrl=11'b11111_000000; #`P;
|
83 |
|
|
ctrl=1; #(`P);
|
84 |
|
|
check;
|
85 |
|
|
|
86 |
|
|
// test add
|
87 |
|
|
d0 = {6'b000101, 1182'd0};
|
88 |
|
|
d1 = 1186'h00a6540512a166a914956a65149495511551891946505601545514458a955815a5596918a2195a565906902549a4954419294a5045199954951561555804612a6655256899454941a51a590259466611545a628496596845046015584a4455a5aa69858911112a9666549561252a156559564966195415951a41226620598145a0441915951185246145aa55615556585564965a5;
|
89 |
|
|
d2 = 1186'h219146612691209655566446a585291504580155555689915a555564404562896415518a65915062459564695665590a11465845a6659441a515a50a656a0a809016195545425645a509895161841616a665599585a0115416a8952185954555564146a56025559466a85a098a68584564969965441822018992901511a954664a90555414555114149641a811854525452a65612;
|
90 |
|
|
wish = 1186'h21449a6605425640692892a88959826619a98a6298a61092a2aa69a90a1a8a9219628a9614aaaa8592980452901922422a609695284261954a2a1650816268aa06680281128490865a1416508a0a49240a808859580949991a18aa4900199a0a01aa08624106406a9900206aa05661aa812916985160049694108248010615a82a146269a966160845182801421a98419a5208884;
|
91 |
|
|
|
92 |
|
|
@(negedge clk);
|
93 |
|
|
reset=1;#`P reset=0;
|
94 |
|
|
ctrl=11'b11111_000000; #`P;
|
95 |
|
|
ctrl=11'b10001; #(`P);
|
96 |
|
|
check;
|
97 |
|
|
|
98 |
|
|
// test sub
|
99 |
|
|
d0 = {6'b001001, 1182'd0};
|
100 |
|
|
d1 = 1186'h00a6540512a166a914956a65149495511551891946505601545514458a955815a5596918a2195a565906902549a4954419294a5045199954951561555804612a6655256899454941a51a590259466611545a628496596845046015584a4455a5aa69858911112a9666549561252a156559564966195415951a41226620598145a0441915951185246145aa55615556585564965a5;
|
101 |
|
|
d2 = 1186'h219146612691209655566446a585291504580155555689915a555564404562896415518a65915062459564695665590a11465845a6659441a515a50a656a0a809016195545425645a509895161841616a665599585a0115416a8952185954555564146a56025559466a85a098a68584564969965441822018992901511a954664a90555414555114149641a811854525452a65612;
|
102 |
|
|
wish = 1186'h1215119428104616824206226212a8481105888421099960090082114a5029584144185149480a24146168882642484908a6221a92a405162000885a2699666a9642181654062608001190a12882500aa125152211a95a212184406a85a2105054284214a128950200a84a646a8289202580a0019548269451a2525112a0691265a484818188641059a269a950901166104961296;
|
103 |
|
|
|
104 |
|
|
@(negedge clk);
|
105 |
|
|
reset=1;#`P reset=0;
|
106 |
|
|
ctrl=11'b11111_000000; #`P;
|
107 |
|
|
ctrl=11'b10001; #(`P);
|
108 |
|
|
check;
|
109 |
|
|
|
110 |
|
|
$display("Good!");
|
111 |
|
|
$finish;
|
112 |
|
|
end
|
113 |
|
|
|
114 |
|
|
initial #100 forever #(`P/2) clk = ~clk;
|
115 |
|
|
|
116 |
|
|
task check;
|
117 |
|
|
begin
|
118 |
|
|
if (out !== wish)
|
119 |
|
|
begin $display("E %h %h", out, wish); $finish; end
|
120 |
|
|
end
|
121 |
|
|
endtask
|
122 |
|
|
endmodule
|
123 |
|
|
|