lumag: (Default)
[personal profile] lumag
Я научился (вроде бы) умножать. Разумная критика приветствуется.


module multiply32 (a, b, c);
        input [32 -1:0] a;
        input [32 -1:0] b;
        output [2*32 -1:0] c;

        wire [4*32 -1:0] temp;

        multiply16 part1 (a[16 -1: 0], b[16 -1: 0], temp[32 -1:0]);
        multiply16 part2 (a[16 -1: 0], b[32 -1: 16], temp[2*32 -1:32]);
        multiply16 part3 (a[32 -1: 16], b[16 -1: 0], temp[3*32 -1:2*32]);
        multiply16 part4 (a[32 -1: 16], b[32 -1: 16], temp[4*32 -1:3*32]);

        assign c = {{{temp[4*32 -1:3*32],temp[32 -1:16]} + temp[3*32 -1:2*32] + temp[2*32 -1:32]}, temp[16 -1: 0]};

endmodule

module multiply16 (a, b, c);
        input [16 -1:0] a;
        input [16 -1:0] b;
        output [2*16 -1:0] c;

        wire [4*16 -1:0] temp;

        multiply8 part1 (a[8 -1: 0], b[8 -1: 0], temp[16 -1:0]);
        multiply8 part2 (a[8 -1: 0], b[16 -1: 8], temp[2*16 -1:16]);
        multiply8 part3 (a[16 -1: 8], b[8 -1: 0], temp[3*16 -1:2*16]);
        multiply8 part4 (a[16 -1: 8], b[16 -1: 8], temp[4*16 -1:3*16]);

        assign c = {{{temp[4*16 -1:3*16],temp[16 -1:8]} + temp[3*16 -1:2*16] + temp[2*16 -1:16]}, temp[8 -1: 0]};

endmodule

module multiply8 (a, b, c);
        input [8 -1:0] a;
        input [8 -1:0] b;
        output [2*8 -1:0] c;

        wire [4*8 -1:0] temp;

        multiply4 part1 (a[4 -1: 0], b[4 -1: 0], temp[8 -1:0]);
        multiply4 part2 (a[4 -1: 0], b[8 -1: 4], temp[2*8 -1:8]);
        multiply4 part3 (a[8 -1: 4], b[4 -1: 0], temp[3*8 -1:2*8]);
        multiply4 part4 (a[8 -1: 4], b[8 -1: 4], temp[4*8 -1:3*8]);

        assign c = {{{temp[4*8 -1:3*8],temp[8 -1:4]} + temp[3*8 -1:2*8] + temp[2*8 -1:8]}, temp[4 -1: 0]};

endmodule

module multiply4 (a, b, c);
        input [4 -1:0] a;
        input [4 -1:0] b;
        output [2*4 -1:0] c;

        wire [4*4 -1:0] temp;

        multiply2 part1 (a[2 -1: 0], b[2 -1: 0], temp[4 -1:0]);
        multiply2 part2 (a[2 -1: 0], b[4 -1: 2], temp[2*4 -1:4]);
        multiply2 part3 (a[4 -1: 2], b[2 -1: 0], temp[3*4 -1:2*4]);
        multiply2 part4 (a[4 -1: 2], b[4 -1: 2], temp[4*4 -1:3*4]);

        assign c = {{{temp[4*4 -1:3*4],temp[4 -1:2]} + temp[3*4 -1:2*4] + temp[2*4 -1:4]}, temp[2 -1: 0]};

endmodule

module multiply2(a, b, c);
        input [1:0] a;
        input [1:0] b;
        output [3:0] c;

        assign c[3:1] = (a[0] & b[1]) + (a[1] & b[0]) + {a[1] & b[1], 1’b0};
        assign c[0] = a[0] & b[0];
endmodule


Profile

lumag: (Default)
Dmitry Eremin-Solenikov

March 2016

S M T W T F S
  12345
6789 101112
13141516171819
20212223242526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 25th, 2026 10:46 am
Powered by Dreamwidth Studios