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

Subversion Repositories m1_core

[/] [m1_core/] [trunk/] [hdl/] [rtl/] [m1_core/] [m1_mul.v] - Blame information for rev 64

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 33 fafa1971
/*
2 64 albert.wat
 * M1 Multiplier
3 33 fafa1971
 *
4
 * Simple RTL-level Multiplier with Alternating Bit Protocol (ABP) interface.
5
 */
6
 
7
// 32-bit * 32-bit Integer Multiplier (this version is not optimized and always takes 32 cycles)
8
module m1_mul(
9
    input        sys_reset_i,      // System Reset
10
    input        sys_clock_i,      // System Clock
11
    input[31:0]  a_i,              // Operand A
12
    input[31:0]  b_i,              // Operand B
13
    input        signed_i,         // If multiplication is signed
14
    output reg[63:0] product_o,    // Product of multiplication
15
    input        abp_req_i,        // ABP Request
16
    output reg   abp_ack_o         // ABP Acknowledgement
17
  );
18
 
19
 
20
  // Registers
21
  reg[63:0]    a_latched;        // Latched 'a' input
22
  reg[31:0]    b_latched;        // Latched 'b' input
23
  reg[63:0]    product_tmp;      // Temporary result
24
  reg          negative_output;  // If output is negative
25
  reg[5:0]     count;            // Downward counter (32->0)
26
  reg          abp_last;         // Level of last ABP request
27
 
28
  // Sequential logic
29
  always @(posedge sys_clock_i) begin
30
 
31
    // Initialization
32
    if(sys_reset_i) begin
33
 
34
      product_o = 0;
35
      abp_ack_o = 0;
36
      negative_output = 0;
37
      count = 6'd0;
38
      abp_last = 0;
39
 
40
    // New request
41
    end else if(abp_req_i!=abp_last) begin
42
 
43
      abp_last = abp_req_i;     // Latch level of ABP request
44
      count  = 6'd32;           // Start counter
45
      product_tmp = 0;          // Initialize result
46
      a_latched = (!signed_i || !a_i[31]) ? { 32'd0, a_i } : { 32'd0, (~a_i+1'b1) };
47
      b_latched = (!signed_i || !b_i[31]) ? b_i : (~b_i + 1'b1);
48
      negative_output = signed_i && (a_i[31] ^ b_i[31]);
49
      product_o = (!negative_output) ? product_tmp : (~product_tmp+1);  // Degugging only
50
 
51
    // Calculating
52
    end else if(count>0) begin
53
 
54
      count = count-1;
55
      if(b_latched[0]==1) product_tmp = product_tmp + a_latched;
56
      a_latched = a_latched << 1;
57
      b_latched = b_latched >> 1;
58
      product_o = (!negative_output) ? product_tmp : (~product_tmp + 1);  // Debugging only
59
 
60
    // Return the result
61
    end else if(count==0) begin
62
 
63
      abp_ack_o = abp_req_i;    // Return the result
64
      product_o = (!negative_output) ? product_tmp : (~product_tmp + 1);
65
 
66
    end
67
 
68
  end
69
 
70
endmodule
71
 

powered by: WebSVN 2.1.0

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