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

Subversion Repositories 8051

[/] [8051/] [trunk/] [rtl/] [verilog/] [oc8051_multiply.v] - Blame information for rev 46

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

Line No. Rev Author Line
1 2 simont
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// multiply for 8051 Core                                       ////
4
////                                                              ////
5
//// This file is part of the 8051 cores project                  ////
6
//// http://www.opencores.org/cores/8051/                         ////
7
////                                                              ////
8
//// Description                                                  ////
9
//// Implementation of multipication used in alu.v                ////
10
////                                                              ////
11
//// To Do:                                                       ////
12
////  Nothing                                                     ////
13
////                                                              ////
14
//// Author(s):                                                   ////
15
//// - Simon Teran, simont@opencores.org                          ////
16 4 markom
//// - Marko Mlinar, markom@opencores.org                         ////
17 2 simont
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2001 Authors and OPENCORES.ORG                 ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE. See the GNU Lesser General Public License for more  ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45 46 simont
// CVS Revision History
46 2 simont
//
47 46 simont
// $Log: not supported by cvs2svn $
48
//
49 4 markom
// ver: 2 markom
50
// changed to two cycle multiplication, to save resources and
51
// increase speed
52 20 markom
//
53
// ver: 3 markom
54
// changed to four cycle multiplication, to save resources and
55
// increase speed
56 2 simont
 
57
// synopsys translate_off
58
`include "oc8051_timescale.v"
59
// synopsys translate_on
60
 
61
 
62 4 markom
module oc8051_multiply (clk, rst, enable, src1, src2, des1, des2, desOv);
63 2 simont
//
64
// this module is part of alu
65 4 markom
// clk          (in)
66
// rst          (in)
67
// enable       (in)
68 2 simont
// src1         (in)  first operand
69
// src2         (in)  second operand
70
// des1         (out) first result
71
// des2         (out) second result
72
// desOv        (out) Overflow output
73
//
74
 
75 4 markom
input clk, rst, enable;
76 2 simont
input [7:0] src1, src2;
77
output desOv;
78
output [7:0] des1, des2;
79
 
80 4 markom
// wires
81 25 markom
wire [15:0] mul_result1, mul_result, shifted;
82 4 markom
 
83
// real registers
84 20 markom
reg [1:0] cycle;
85 25 markom
reg [15:0] tmp_mul;
86 4 markom
 
87 25 markom
assign mul_result1 = src1 * (cycle == 2'h0 ? src2[7:6]
88
                           : cycle == 2'h1 ? src2[5:4]
89
                           : cycle == 2'h2 ? src2[3:2]
90 20 markom
                           : src2[1:0]);
91 32 simont
 
92 25 markom
assign shifted = (cycle == 2'h0 ? 16'h0 : {tmp_mul[13:0], 2'b00});
93
assign mul_result = mul_result1 + shifted;
94
assign des1 = mul_result[15:8];
95
assign des2 = mul_result[7:0];
96 32 simont
assign desOv = | des1;
97 20 markom
 
98 4 markom
always @(posedge clk or posedge rst)
99 2 simont
begin
100 5 markom
  if (rst) begin
101 25 markom
    cycle <= #1 2'b0;
102
    tmp_mul <= #1 16'b0;
103 5 markom
  end else begin
104 25 markom
    if (enable) cycle <= #1 cycle + 2'b1;
105
    tmp_mul <= #1 mul_result;
106 4 markom
  end
107 2 simont
end
108
 
109
endmodule

powered by: WebSVN 2.1.0

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