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

Subversion Repositories pairing

[/] [pairing/] [trunk/] [rtl/] [f33m.v] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 homer.xing
`include "inc.v"
2
 
3
// c == a+b in GF(3^{3*M})
4
module f33m_add(a, b, c);
5
    input [`W3:0] a,b;
6
    output [`W3:0] c;
7
    wire [`WIDTH:0] a0,a1,a2,b0,b1,b2,c0,c1,c2;
8
    assign {a2,a1,a0} = a;
9
    assign {b2,b1,b0} = b;
10
    assign c = {c2,c1,c0};
11
    f3m_add
12
        ins1 (a0,b0,c0),
13
        ins2 (a1,b1,c1),
14
        ins3 (a2,b2,c2);
15
endmodule
16
 
17
// c == a-b in GF(3^{3*M})
18
module f33m_sub(a, b, c);
19
    input [`W3:0] a,b;
20
    output [`W3:0] c;
21
    wire [`WIDTH:0] a0,a1,a2,b0,b1,b2,c0,c1,c2;
22
    assign {a2,a1,a0} = a;
23
    assign {b2,b1,b0} = b;
24
    assign c = {c2,c1,c0};
25
    f3m_sub
26
        ins1 (a0,b0,c0),
27
        ins2 (a1,b1,c1),
28
        ins3 (a2,b2,c2);
29
endmodule
30
 
31
// c == a*b in GF(3^{3*M})
32
module f33m_mult(clk, reset, a, b, c, done);
33
    input clk, reset;
34
    input [`W3:0] a, b;
35
    output reg [`W3:0] c;
36
    output reg done;
37
 
38
    reg [`WIDTH:0] x0, x1, x2, x3, x4, x5;
39
    wire [`WIDTH:0]  a0, a1, a2,
40
                     b0, b1, b2,
41
                     c0, c1, c2,
42
                     v1, v2, v3, v4, v5, v6,
43
                     nx0, nx2, nx5,
44
                     d0, d1, d2, d3, d4;
45
    reg [6:0] K;
46
    wire e0, e1, e2,
47
         e3, e4, e5,
48
         mult_done, p, rst;
49
    wire [`WIDTH:0] in0, in1;
50
    wire [`WIDTH:0] o;
51
    reg mult_reset, delay1, delay2;
52
 
53
    assign {e0,e1,e2,e3,e4,e5} = K[6:1];
54
    assign {a2,a1,a0} = a;
55
    assign {b2,b1,b0} = b;
56
    assign d4 = x0;
57
    assign d0 = x5;
58
    assign rst = delay2;
59
 
60
    f3m_mux6
61
        ins1 (a2,v1,a1,v3,v5,a0,e0,e1,e2,e3,e4,e5,in0), // $in0$ is the first input
62
        ins2 (b2,v2,b1,v4,v6,b0,e0,e1,e2,e3,e4,e5,in1); // $in1$ is the second input
63
    f3m_mult
64
        ins3 (clk, mult_reset, in0, in1, o, mult_done); // o == in0 * in1
65
    func6
66
        ins4 (clk, mult_done, p);
67
    f3m_add
68
        ins5 (a1, a2, v1), // v1 == a1+a2
69
        ins6 (b1, b2, v2), // v2 == b1+b2
70
        ins7 (a0, a2, v3), // v3 == a0+a2
71
        ins8 (b0, b2, v4), // v4 == b0+b2
72
        ins9 (a0, a1, v5), // v5 == a0+a1
73
        ins10 (b0, b1, v6), // v6 == b0+b1
74
        ins11 (d0, d3, c0), // c0 == d0+d3
75
        ins12 (d2, d4, c2); // c2 == d2+d4
76
    f3m_neg
77
        ins13 (x0, nx0), // nx0 == -x0
78
        ins14 (x2, nx2), // nx2 == -x2
79
        ins15 (x5, nx5); // nx5 == -x5
80
    f3m_add3
81
        ins16 (x1, nx0, nx2, d3), // d3 == x1-x0-x2
82
        ins17 (x4, nx2, nx5, d1), // d1 == x4-x2-x5
83
        ins18 (d1, d3, d4, c1); // c1 == d1+d3+d4
84
    f3m_add4
85
        ins19 (x3, x2, nx0, nx5, d2); // d2 == x3+x2-x0-x5
86
 
87
    always @ (posedge clk)
88
      begin
89
        if (reset) K <= 7'b1000000;
90
        else if (p) K <= {1'b0,K[6:1]};
91
      end
92
 
93
    always @ (posedge clk)
94
      begin
95
        if (e0) x0 <= o; // x0 == a2*b2
96
        if (e1) x1 <= o; // x1 == (a2+a1)*(b2+b1)
97
        if (e2) x2 <= o; // x2 == a1*b1
98
        if (e3) x3 <= o; // x3 == (a2+a0)*(b2+b0)
99
        if (e4) x4 <= o; // x4 == (a1+a0)*(b1+b0)
100
        if (e5) x5 <= o; // x5 == a0*b0
101
      end
102
 
103
    always @ (posedge clk)
104
      begin
105
        if (reset) done <= 0;
106
        else if (K[0])
107
          begin
108
            done <= 1; c <= {c2,c1,c0};
109
          end
110
      end
111
 
112
    always @ (posedge clk)
113
      begin
114
        if (rst) mult_reset <= 1;
115
        else if (mult_done) mult_reset <= 1;
116
        else mult_reset <= 0;
117
      end
118
 
119
    always @ (posedge clk)
120
      begin
121
        delay2 <= delay1; delay1 <= reset;
122
      end
123
endmodule
124
 
125 6 homer.xing
// c == a^{-1} in GF(3^{3*M})
126
 
127
 

powered by: WebSVN 2.1.0

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