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

Subversion Repositories warp

[/] [warp/] [rtl/] [tmu_edgedivops.v] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 lekernel
/*
2
 * Milkymist VJ SoC
3
 * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
4
 *
5
 * This program is free and excepted software; you can use it, redistribute it
6
 * and/or modify it under the terms of the Exception General Public License as
7
 * published by the Exception License Foundation; either version 2 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
 * FOR A PARTICULAR PURPOSE. See the Exception General Public License for more
13
 * details.
14
 *
15
 * You should have received a copy of the Exception General Public License along
16
 * with this project; if not, write to the Exception License Foundation.
17
 */
18
 
19
module tmu_edgedivops(
20
        input sys_clk,
21
        input sys_rst,
22
 
23
        output busy,
24
 
25
        input pipe_stb_i,
26
        output pipe_ack_o,
27
        input [10:0] A0_S_X,
28
        input [10:0] A0_S_Y,
29
        input [10:0] B0_S_X,
30
        input [10:0] B0_S_Y,
31
        input [10:0] C0_S_X,
32
        input [10:0] C0_S_Y,
33
        input [10:0] A0_D_X,
34
        input [10:0] A0_D_Y,
35
        input [10:0] B0_D_X,
36
        input [10:0] B0_D_Y,
37
        input [10:0] C0_D_X,
38
        input [10:0] C0_D_Y,
39
 
40
        output pipe_stb_o,
41
        input pipe_ack_i,
42
        /* Points pass-through */
43
        output reg [10:0] A_S_X,
44
        output reg [10:0] A_S_Y,
45
        output reg [10:0] A_D_X,
46
        output reg [10:0] A_D_Y,
47
        output reg [10:0] B_D_Y,
48
        output reg [10:0] C_D_Y,
49
 
50
        /* Dividends */
51
        output reg dx1_positive,
52
        output reg [10:0] dx1,
53
        output reg dx2_positive,
54
        output reg [10:0] dx2,
55
        output reg dx3_positive,
56
        output reg [10:0] dx3,
57
 
58
        output reg du1_positive,
59
        output reg [10:0] du1,
60
        output reg du2_positive,
61
        output reg [10:0] du2,
62
        output reg du3_positive,
63
        output reg [10:0] du3,
64
 
65
        output reg dv1_positive,
66
        output reg [10:0] dv1,
67
        output reg dv2_positive,
68
        output reg [10:0] dv2,
69
        output reg dv3_positive,
70
        output reg [10:0] dv3,
71
 
72
        /* Common divisors */
73
        output reg [10:0] divisor1,
74
        output reg [10:0] divisor2,
75
        output reg [10:0] divisor3
76
);
77
 
78
wire en;
79
wire s0_valid;
80
reg s1_valid;
81
 
82
always @(posedge sys_clk) begin
83
        if(sys_rst)
84
                s1_valid = 1'b0;
85
        else if(en)
86
                s1_valid = s0_valid;
87
end
88
 
89
always @(posedge sys_clk) begin
90
        if(en) begin
91
                /* Find signs (whether we will increment or decrement later on) */
92
                dx1_positive = B0_D_X > A0_D_X;
93
                dx2_positive = C0_D_X > A0_D_X;
94
                dx3_positive = C0_D_X > B0_D_X;
95
 
96
                du1_positive = B0_S_X > A0_S_X;
97
                du2_positive = C0_S_X > A0_S_X;
98
                du3_positive = C0_S_X > B0_S_X;
99
 
100
                dv1_positive = B0_S_Y > A0_S_Y;
101
                dv2_positive = C0_S_Y > A0_S_Y;
102
                dv3_positive = C0_S_Y > B0_S_Y;
103
 
104
                /* First edge */
105
                if(dx1_positive)
106
                        dx1 = B0_D_X - A0_D_X;
107
                else
108
                        dx1 = A0_D_X - B0_D_X;
109
                if(du1_positive)
110
                        du1 = B0_S_X - A0_S_X;
111
                else
112
                        du1 = A0_S_X - B0_S_X;
113
                if(dv1_positive)
114
                        dv1 = B0_S_Y - A0_S_Y;
115
                else
116
                        dv1 = A0_S_Y - B0_S_Y;
117
                if(B0_D_Y != A0_D_Y)
118
                        divisor1 = B0_D_Y - A0_D_Y;
119
                else
120
                        divisor1 = 11'd1;
121
 
122
                /* Second edge */
123
                if(C0_D_Y != A0_D_Y) begin
124
                        if(dx2_positive)
125
                                dx2 = C0_D_X - A0_D_X;
126
                        else
127
                                dx2 = A0_D_X - C0_D_X;
128
                        if(du2_positive)
129
                                du2 = C0_S_X - A0_S_X;
130
                        else
131
                                du2 = A0_S_X - C0_S_X;
132
                        if(dv2_positive)
133
                                dv2 = C0_S_Y - A0_S_Y;
134
                        else
135
                                dv2 = A0_S_Y - C0_S_Y;
136
                        divisor2 = C0_D_Y - A0_D_Y;
137
                end else begin
138
                        dx2 = 11'd0;
139
                        du2 = 11'd0;
140
                        dv2 = 11'd0;
141
                        divisor2 = 11'd1;
142
                end
143
 
144
                /* Third edge */
145
                if(C0_D_Y != B0_D_Y) begin
146
                        if(dx3_positive)
147
                                dx3 = C0_D_X - B0_D_X;
148
                        else
149
                                dx3 = B0_D_X - C0_D_X;
150
                        if(du3_positive)
151
                                du3 = C0_S_X - B0_S_X;
152
                        else
153
                                du3 = B0_S_X - C0_S_X;
154
                        if(dv3_positive)
155
                                dv3 = C0_S_Y - B0_S_Y;
156
                        else
157
                                dv3 = B0_S_Y - C0_S_Y;
158
                        divisor3 = C0_D_Y - B0_D_Y;
159
                end else begin
160
                        dx3 = 11'd0;
161
                        du3 = 11'd0;
162
                        dv3 = 11'd0;
163
                        divisor3 = 11'd1;
164
                end
165
        end
166
end
167
 
168
always @(posedge sys_clk) begin
169
        if(en) begin
170
                A_S_X <= A0_S_X;
171
                A_S_Y <= A0_S_Y;
172
                A_D_X <= A0_D_X;
173
                A_D_Y <= A0_D_Y;
174
                B_D_Y <= B0_D_Y;
175
                C_D_Y <= C0_D_Y;
176
        end
177
end
178
 
179
/* Pipeline management */
180
 
181
assign busy = s1_valid;
182
 
183
assign s0_valid = pipe_stb_i;
184
assign pipe_ack_o = pipe_ack_i;
185
 
186
assign en = pipe_ack_i;
187
assign pipe_stb_o = s1_valid;
188
 
189
endmodule

powered by: WebSVN 2.1.0

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