OpenCores
URL https://opencores.org/ocsvn/tiny_tate_bilinear_pairing/tiny_tate_bilinear_pairing/trunk

Subversion Repositories tiny_tate_bilinear_pairing

[/] [tiny_tate_bilinear_pairing/] [trunk/] [group_size_is_151_bits/] [testbench/] [test_pairing.v] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
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 5 homer.hsin
`timescale 1ns / 1ps
18
`define P 20 // clock period 
19
 
20
module test_pairing;
21
 
22
        // Inputs
23
        reg clk;
24
        reg reset;
25
        reg sel;
26
        reg [5:0] addr;
27
        reg w;
28
    reg update;
29
    reg ready;
30
    reg i;
31
 
32
        // Outputs
33
        wire done;
34
    wire o;
35
 
36
    // Buffers
37
        reg [197:0] out;
38
 
39
        // Instantiate the Unit Under Test (UUT)
40
        pairing uut (
41
        .clk(clk),
42
        .reset(reset),
43
        .sel(sel),
44
        .addr(addr),
45
        .w(w),
46
        .update(update),
47
        .ready(ready),
48
        .i(i),
49
        .o(o),
50
        .done(done)
51
        );
52
 
53
        initial begin
54
                // Initialize Inputs
55
                clk = 0;
56
                reset = 0;
57
                sel = 0;
58
                addr = 0;
59
                w = 0;
60
        update = 0;
61
        ready = 0;
62
        i = 0;
63
        out = 0;
64
 
65
                // Wait 100 ns for global reset to finish
66
                #100;
67
 
68
                // Add stimulus here
69
        /* keep FSM silent */
70
        reset = 1;
71
            /* init xp, yp, xq, yq */
72 14 homer.hsin
            write(3, 194'h21181940120548aa020568aa65a5989609251595a89a44598);
73
            write(5, 194'h0a905590506a8a845592a09644a2095291422910a968a5048);
74
            write(6, 194'h21181940120548aa020568aa65a5989609251595a89a44598);
75
            write(7, 194'h0a905590506a8a845592a09644a2095291422910a968a5048);
76 5 homer.hsin
            /* read back. uncomment me if error happens */
77
            /* read(3);
78
            $display("xp = %h", out);
79
            read(5);
80
            $display("yp = %h", out);
81
            read(6);
82
            $display("xq = %h", out);
83
            read(7);
84
            $display("yq = %h", out);*/
85
        reset = 0;
86
 
87
        sel = 0; w = 0;
88
        @(posedge done);
89
        @(negedge clk);
90
            read(9);
91 14 homer.hsin
            check(194'h09a49266428495042842965645266a2164a1268408a669866);
92 5 homer.hsin
            read(10);
93 14 homer.hsin
            check(194'h204446152452400968480544296829199a169a2562a908520);
94 5 homer.hsin
            read(11);
95 14 homer.hsin
            check(194'h1699142918666651a156954a80544689590a5094624610281);
96 5 homer.hsin
            read(12);
97 14 homer.hsin
            check(194'h2461998924145511611291626a4a295888569280285884661);
98 5 homer.hsin
            read(13);
99 14 homer.hsin
            check(194'h1040525045a404150a1881aa91a99156660a1658a090a1091);
100 5 homer.hsin
            read(14);
101 14 homer.hsin
            check(194'h2400a94249694808254880924a06494816081900811198925);
102 5 homer.hsin
            $display("Good");
103
        $finish;
104
        end
105
 
106
    initial #100 forever #(`P/2) clk = ~clk;
107
 
108
    task write;
109
        input [5:0] adr;
110
        input [197:0] dat;
111
        integer j;
112
        begin
113
            sel = 1;
114
            w = 0;
115
            addr = adr;
116
            update = 1;
117
            #`P;
118
            update = 0;
119
            ready = 1;
120
            for(j=0;j<198;j=j+1)
121
               begin
122
               i = dat[j];
123
               #`P;
124
               end
125
            ready = 0;
126
            w = 1; #`P; w = 0;
127
        end
128
    endtask
129
 
130
    task read;
131
        input [5:0] adr;
132
        integer j;
133
        begin
134
            sel = 1;
135
            w = 0;
136
            addr = adr;
137
            #`P;
138
            update = 1;
139
            #`P;
140
            update = 0;
141
            out = 0;
142
            ready = 1;
143
            for(j=0;j<198;j=j+1)
144
               begin
145
               out = {o, out[197:1]};
146
               #`P;
147
               end
148
        end
149
    endtask
150
 
151
    task check;
152
        input [197:0] wish;
153
        begin
154
            if (out !== wish)
155
                begin $display("Error!"); $finish; end
156
        end
157
    endtask
158
endmodule
159
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.