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

Subversion Repositories pairing

[/] [pairing/] [trunk/] [rtl/] [f36m.v] - Blame information for rev 5

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

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

powered by: WebSVN 2.1.0

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