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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [rtl/] [8051/] [oc8051_divide.v] - Blame information for rev 36

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// divide for 8051 Core                                         ////
4
////                                                              ////
5
//// This file is part of the 8051 cores project                  ////
6
////  http://www.opencores.org/cores/oms8051mini/                 ////
7
////                                                              ////
8
//// Description                                                  ////
9
//// Four cycle implementation of division used in alu.v          ////
10
////                                                              ////
11
//// To Do:                                                       ////
12
////  check if compiler does proper optimizations of the code     ////
13
////                                                              ////
14
//// Author(s):                                                   ////
15
////      - Simon Teran, simont@opencores.org                     ////
16
////      - Marko Mlinar, markom@opencores.org                    ////
17
////      - Dinesh Annayya, dinesha@opencores.org                 ////
18
////                                                              ////
19
//////////////////////////////////////////////////////////////////////
20 25 dinesha
////   v0.0 - Dinesh A, 5th Jan 2017
21
////        1. Active edge of reset changed from High to Low
22
//////////////////////////////////////////////////////////////////////
23 2 dinesha
////                                                              ////
24
//// Copyright (C) 2001 Authors and OPENCORES.ORG                 ////
25
////                                                              ////
26
//// This source file may be used and distributed without         ////
27
//// restriction provided that this copyright statement is not    ////
28
//// removed from the file and that any derivative work contains  ////
29
//// the original copyright notice and the associated disclaimer. ////
30
////                                                              ////
31
//// This source file is free software; you can redistribute it   ////
32
//// and/or modify it under the terms of the GNU Lesser General   ////
33
//// Public License as published by the Free Software Foundation; ////
34
//// either version 2.1 of the License, or (at your option) any   ////
35
//// later version.                                               ////
36
////                                                              ////
37
//// This source is distributed in the hope that it will be       ////
38
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
39
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
40
//// PURPOSE. See the GNU Lesser General Public License for more  ////
41
//// details.                                                     ////
42
////                                                              ////
43
//// You should have received a copy of the GNU Lesser General    ////
44
//// Public License along with this source; if not, download it   ////
45
//// from http://www.opencores.org/lgpl.shtml                     ////
46
////                                                              ////
47
//////////////////////////////////////////////////////////////////////
48
//
49
// CVS Revision History
50
//
51
// $Log: not supported by cvs2svn $
52
// Revision 1.8  2002/09/30 17:15:31  simont
53
// prepared header
54
//
55
//
56
 
57
 
58 25 dinesha
module oc8051_divide (clk, resetn, enable, src1, src2, des1, des2, desOv);
59 2 dinesha
//
60
// this module is part of alu
61
// clk          (in)
62 25 dinesha
// resetn       (in)
63 2 dinesha
// enable       (in)  starts divison
64
// src1         (in)  first operand
65
// src2         (in)  second operand
66
// des1         (out) first result
67
// des2         (out) second result
68
// desOv        (out) Overflow output
69
//
70
 
71 25 dinesha
input clk, resetn, enable;
72 2 dinesha
input [7:0] src1, src2;
73
output desOv;
74
output [7:0] des1, des2;
75
 
76
// wires
77
wire desOv;
78
wire div0, div1;
79
wire [7:0] rem0, rem1, rem2;
80
wire [8:0] sub0, sub1;
81
wire [15:0] cmp0, cmp1;
82
wire [7:0] div_out, rem_out;
83
 
84
// real registers
85
reg [1:0] cycle;
86
reg [5:0] tmp_div;
87
reg [7:0] tmp_rem;
88
 
89
// The main logic
90
assign cmp1 = src2 << ({2'h3 - cycle, 1'b0} + 3'h1);
91
assign cmp0 = src2 << ({2'h3 - cycle, 1'b0} + 3'h0);
92
 
93
assign rem2 = cycle != 0 ? tmp_rem : src1;
94
 
95
assign sub1 = {1'b0, rem2} - {1'b0, cmp1[7:0]};
96
assign div1 = |cmp1[15:8] ? 1'b0 : !sub1[8];
97
assign rem1 = div1 ? sub1[7:0] : rem2[7:0];
98
 
99
assign sub0 = {1'b0, rem1} - {1'b0, cmp0[7:0]};
100
assign div0 = |cmp0[15:8] ? 1'b0 : !sub0[8];
101
assign rem0 = div0 ? sub0[7:0] : rem1[7:0];
102
 
103
//
104
// in clock cycle 0 we first calculate two MSB bits, ...
105
// till finally in clock cycle 3 we calculate two LSB bits
106
assign div_out = {tmp_div, div1, div0};
107
assign rem_out = rem0;
108
assign desOv = src2 == 8'h0;
109
 
110
//
111
// divider works in four clock cycles -- 0, 1, 2 and 3
112 25 dinesha
always @(posedge clk or negedge resetn)
113 2 dinesha
begin
114 25 dinesha
  if (resetn == 1'b0) begin
115 36 dinesha
    cycle <= 2'b0;
116
    tmp_div <= 6'h0;
117
    tmp_rem <= 8'h0;
118 2 dinesha
  end else begin
119 36 dinesha
    if (enable) cycle <= cycle + 2'b1;
120
    tmp_div <= div_out[5:0];
121
    tmp_rem <= rem_out;
122 2 dinesha
  end
123
end
124
 
125
//
126
// assign outputs
127
assign des1 = rem_out;
128
assign des2 = div_out;
129
 
130
endmodule

powered by: WebSVN 2.1.0

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