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

Subversion Repositories pairing

[/] [pairing/] [trunk/] [rtl/] [f32m.v] - Blame information for rev 21

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 3 homer.xing
// out = (v0 & l0) | (v1 & l1) | (v2 & l2) | ... | (v5 & l5)
4
module f32m_mux6(v0, v1, v2, v3, v4, v5, l0, l1, l2, l3, l4, l5, out);
5
    input l0, l1, l2, l3, l4, l5;
6
    input [`W2:0] v0, v1, v2, v3, v4, v5;
7
    output [`W2:0] out;
8
    f3m_mux6
9
        ins1 (v0[`WIDTH:0], v1[`WIDTH:0], v2[`WIDTH:0],
10
              v3[`WIDTH:0], v4[`WIDTH:0], v5[`WIDTH:0],
11
              l0, l1, l2, l3, l4, l5,
12
              out[`WIDTH:0]),
13
        ins2 (v0[`W2:`WIDTH+1], v1[`W2:`WIDTH+1], v2[`W2:`WIDTH+1],
14
              v3[`W2:`WIDTH+1], v4[`W2:`WIDTH+1], v5[`W2:`WIDTH+1],
15
              l0, l1, l2, l3, l4, l5,
16
              out[`W2:`WIDTH+1]);
17
endmodule
18
 
19 2 homer.xing
// C == A+B in GF(3^{2M})
20
module f32m_add(a, b, c);
21
    input [`W2:0] a, b;
22
    output [`W2:0] c;
23 3 homer.xing
    f3m_add
24
        a1 (a[`W2:`WIDTH+1], b[`W2:`WIDTH+1], c[`W2:`WIDTH+1]),
25
        a2 (a[`WIDTH:0], b[`WIDTH:0], c[`WIDTH:0]);
26 2 homer.xing
endmodule
27
 
28 3 homer.xing
// C = a0 + a1 + a2 in GF(3^{2M})
29
module f32m_add3(a0, a1, a2, c);
30
    input [`W2:0] a0, a1, a2;
31
    output [`W2:0] c;
32
    wire [`W2:0] t;
33
    f32m_add
34
        ins1 (a0, a1, t), // t == a0+a1
35
        ins2 (t, a2, c);  // c == t+a2 == a0+a1+a2
36
endmodule
37
 
38
// C = a0 + a1 + a2 + a3 in GF(3^{2M})
39
module f32m_add4(a0, a1, a2, a3, c);
40
    input [`W2:0] a0, a1, a2, a3;
41
    output [`W2:0] c;
42
    wire [`W2:0] t1, t2;
43
    f32m_add
44
        ins1 (a0, a1, t1), // t1 == a0+a1
45
        ins2 (a2, a3, t2), // t2 == a2+a3
46
        ins3 (t1, t2, c);  // c == t1+t2 == a0+a1+a2+a3
47
endmodule
48
 
49
// c == -a in GF(3^{2M})
50
module f32m_neg(a, c);
51
    input [`W2:0] a;
52
    output [`W2:0] c;
53
    f3m_neg
54
        n1 (a[`W2:`WIDTH+1], c[`W2:`WIDTH+1]),
55
        n2 (a[`WIDTH:0], c[`WIDTH:0]);
56
endmodule
57
 
58 2 homer.xing
// C == A-B in GF(3^{2M})
59
module f32m_sub(a, b, c);
60
    input [`W2:0] a, b;
61
    output [`W2:0] c;
62 3 homer.xing
    f3m_sub
63
        s1 (a[`W2:`WIDTH+1], b[`W2:`WIDTH+1], c[`W2:`WIDTH+1]),
64
        s2 (a[`WIDTH:0], b[`WIDTH:0], c[`WIDTH:0]);
65 2 homer.xing
endmodule
66
 
67
// C == A*B in GF(3^{2M})
68
module f32m_mult(clk, reset, a, b, c, done);
69
    input reset, clk;
70
    input [`W2:0] a, b;
71
    output reg [`W2:0] c;
72
    output reg done;
73 7 homer.xing
    wire [`WIDTH:0] a0,a1,b0,b1,c0,c1,
74
                    v1,v2,v3,v4,v5,v6;
75 2 homer.xing
    reg mult_reset;
76 7 homer.xing
    wire mult_done, p;
77 2 homer.xing
 
78
    assign {a1,a0} = a;
79
    assign {b1,b0} = b;
80
 
81
    f3m_add
82
        ins1 (a0, a1, v1), // v1 == a0 + a1
83
        ins2 (b0, b1, v2), // v2 == b0 + b1
84
        ins3 (v3, v4, v6); // v6 == v3 + v4 = a0*b0 + a1*b1
85
    f3m_sub
86
        ins7 (v5, v6, c1), // c1 == v5 - v6 = (a0+a1) * (b0+b1) - (a0*b0 + a1*b1)
87
        ins8 (v3, v4, c0); // c0 == a0*b0 - a1*b1
88
    // v3 == a0 * b0
89
    // v4 == a1 * b1
90
    // v5 == v1 * v2 = (a0+a1) * (b0+b1)
91 7 homer.xing
    f3m_mult3
92
        ins9 (clk, mult_reset, a0, b0, v3, a1, b1, v4, v1, v2, v5, mult_done);
93 2 homer.xing
    func6
94 8 homer.xing
        ins10 (clk, reset, mult_done, p);
95 2 homer.xing
 
96
    always @ (posedge clk)
97 7 homer.xing
        mult_reset <= reset;
98 2 homer.xing
 
99
    always @ (posedge clk)
100 7 homer.xing
        if (reset)
101
            done <= 0;
102
        else if (p)
103
          begin
104
            done <= 1; c <= {c1, c0};
105
          end
106 2 homer.xing
endmodule
107
 
108
// C == A^3 in GF(3^{2m})
109
module f32m_cubic(clk, a, c);
110
    input clk;
111
    input [`W2:0] a;
112
    output reg [`W2:0] c;
113
    wire [`WIDTH:0] a0,a1,c0,c1,v;
114
    assign {a1,a0} = a;
115
    f3m_cubic
116
        ins1 (a0, c0), // c0 == a0^3
117
        ins2 (a1, v);  // v == a1^3
118
    f3m_neg
119
        ins3 (v, c1);  // c1 == -v == - a1^3
120
    always @ (posedge clk)
121
        c <= {c1,c0};
122
endmodule

powered by: WebSVN 2.1.0

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