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

Subversion Repositories two_dimensional_fast_hartley_transform

[/] [two_dimensional_fast_hartley_transform/] [trunk/] [fht_bfly.v] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 irezki
/**********************************************************************
2
 * File  : fht_8x8_core.v
3
 * Author: Ivan Rezki
4
 * email : irezki@gmail.com
5
 * Topic : RTL Core
6
 *                2-Dimensional Fast Hartley Transform
7
 *
8
 * Function: Fast Hartley Transform ButterFly Unit
9
 *
10
 * RIGHT TO USE: This code example, or any portion thereof, may be
11
 * used and distributed without restriction, provided that this entire
12
 * comment block is included with the example.
13
 *
14
 * DISCLAIMER: THIS CODE EXAMPLE IS PROVIDED "AS IS" WITHOUT WARRANTY
15
 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED
16
 * TO WARRANTIES OF MERCHANTABILITY, FITNESS OR CORRECTNESS. IN NO
17
 * EVENT SHALL THE AUTHOR OR AUTHORS BE LIABLE FOR ANY DAMAGES,
18
 * INCLUDING INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF THE
19
 * USE OF THIS CODE.
20
 **********************************************************************/
21 2 irezki
 
22
module fht_bfly(
23
        rstn,
24
        clk,
25
        valid,
26
        a,
27
        b,
28
        c,
29
        d
30
);
31
 
32
parameter N = 8;
33
 
34
input                   rstn;
35
input                   clk;
36
 
37
input                   valid;
38
 
39
input   [N-1:0]  a; // input
40
input   [N-1:0]  b; // input
41
 
42
output  [N  :0]  c; // additive output
43
output  [N  :0]  d; // subtractive output
44
 
45
reg [N-1:0] a_FF;
46
always @(posedge clk)
47
if              (!rstn) a_FF <= #1 0;
48
else if (valid) a_FF <= #1 a;
49
 
50
reg [N-1:0] b_FF;
51
always @(posedge clk)
52
if              (!rstn) b_FF <= #1 0;
53
else if (valid) b_FF <= #1 b;
54
 
55
assign c = rca_N(a_FF,b_FF);
56
assign d = rca_N(a_FF,twos_complement(b_FF));
57
 
58
// +--------------------------------------------------+ \\
59
// +----------- Function's Description Part ----------+ \\
60
// +--------------------------------------------------+ \\
61
// Full Adder
62
        function [1:0] full_adder;
63
        input a, b, ci;
64
        reg co, s;
65
        begin
66
                s  = (a ^ b ^ ci);
67
                co = (a & b) | (ci & (a ^ b));
68
                full_adder = {co,s};
69
        end
70
        endfunction
71
 
72
// Half Adder, i.e. without carry in
73
        function [1:0] half_adder;
74
        input a, b;
75
        reg co, s;
76
        begin
77
                s  = (a ^ b);
78
                co = (a & b);
79
                half_adder = {co,s};
80
        end
81
        endfunction
82
 
83
// Ripple Carry Adder - rca
84
// Input  vector = N     bits
85
// Output vector = N + 1 bits
86
        function [N:0] rca_N;
87
 
88
//      parameter N = 8;
89
        input [N-1:0] a;
90
        input [N-1:0] b;
91
 
92
        reg [N-1:0] co,sum;
93
 
94
                begin : RCA // RIPPLE_CARRY_ADDER
95
                integer i;
96
                //for (i = 0; i <= N; i = i + 1)
97
                for (i = 0; i < N; i = i + 1)
98
                if (i == 0)
99
                                        {co[i],sum[i]} = half_adder(a[i],b[i]);
100
                                else
101
                                        {co[i],sum[i]} = full_adder(a[i],b[i],co[i-1]);
102
 
103
                rca_N[N-1:0] = sum;
104
                // MSB is a sign bit
105
                rca_N[N] = (a[N-1]==b[N-1]) ? co[N-1] : sum[N-1];
106
                end
107
        endfunction
108
 
109
 
110
        function [N-1:0] twos_complement;
111
        input [N-1:0] a;
112
        reg [N-1:0] ainv;
113
        reg [N:0] plus1;
114
        begin
115
                ainv  = ~a;
116
                plus1 = rca_N(ainv,{{N-1{1'b0}},1'b1});
117
 
118 8 irezki
                // pragma coverage block = off
119
                // synopsys translate_off
120
                // The only problem is absolute minumum negative value
121
                if (a == {1'b1, {N-1{1'b0}}})
122
                        $display("--->>> 2's complement ERROR - absolute minimum negative value: %0b\n\t %m",a);
123
                // synopsys translate_on
124
                // pragma coverage block = on
125 2 irezki
 
126
                twos_complement = plus1[N-1:0];
127
        end
128
        endfunction
129
 
130
endmodule
131 8 irezki
 
132
// Update Log:
133
// 27 Jul. 2011
134
// added pragmas for coverage

powered by: WebSVN 2.1.0

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