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 2

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

Line No. Rev Author Line
1 2 irezki
//
2
// File: fht_8x8_core.v
3
// Author: Ivan Rezki
4
// Topic: RTL Core
5
//                2-Dimensional Fast Hartley Transform
6
//
7
 
8
// Fast Hartley Transform ButterFly Unit
9
 
10
module fht_bfly(
11
        rstn,
12
        clk,
13
        valid,
14
        a,
15
        b,
16
        c,
17
        d
18
);
19
 
20
parameter N = 8;
21
 
22
input                   rstn;
23
input                   clk;
24
 
25
input                   valid;
26
 
27
input   [N-1:0]  a; // input
28
input   [N-1:0]  b; // input
29
 
30
output  [N  :0]  c; // additive output
31
output  [N  :0]  d; // subtractive output
32
 
33
reg [N-1:0] a_FF;
34
always @(posedge clk)
35
if              (!rstn) a_FF <= #1 0;
36
else if (valid) a_FF <= #1 a;
37
 
38
reg [N-1:0] b_FF;
39
always @(posedge clk)
40
if              (!rstn) b_FF <= #1 0;
41
else if (valid) b_FF <= #1 b;
42
 
43
assign c = rca_N(a_FF,b_FF);
44
assign d = rca_N(a_FF,twos_complement(b_FF));
45
 
46
// +--------------------------------------------------+ \\
47
// +----------- Function's Description Part ----------+ \\
48
// +--------------------------------------------------+ \\
49
// Full Adder
50
        function [1:0] full_adder;
51
        input a, b, ci;
52
        reg co, s;
53
        begin
54
                s  = (a ^ b ^ ci);
55
                co = (a & b) | (ci & (a ^ b));
56
                full_adder = {co,s};
57
        end
58
        endfunction
59
 
60
// Half Adder, i.e. without carry in
61
        function [1:0] half_adder;
62
        input a, b;
63
        reg co, s;
64
        begin
65
                s  = (a ^ b);
66
                co = (a & b);
67
                half_adder = {co,s};
68
        end
69
        endfunction
70
 
71
// Ripple Carry Adder - rca
72
// Input  vector = N     bits
73
// Output vector = N + 1 bits
74
        function [N:0] rca_N;
75
 
76
//      parameter N = 8;
77
        input [N-1:0] a;
78
        input [N-1:0] b;
79
 
80
        reg [N-1:0] co,sum;
81
 
82
                begin : RCA // RIPPLE_CARRY_ADDER
83
                integer i;
84
                //for (i = 0; i <= N; i = i + 1)
85
                for (i = 0; i < N; i = i + 1)
86
                if (i == 0)
87
                                        {co[i],sum[i]} = half_adder(a[i],b[i]);
88
                                else
89
                                        {co[i],sum[i]} = full_adder(a[i],b[i],co[i-1]);
90
 
91
                rca_N[N-1:0] = sum;
92
                // MSB is a sign bit
93
                rca_N[N] = (a[N-1]==b[N-1]) ? co[N-1] : sum[N-1];
94
                end
95
        endfunction
96
 
97
 
98
        function [N-1:0] twos_complement;
99
        input [N-1:0] a;
100
        reg [N-1:0] ainv;
101
        reg [N:0] plus1;
102
        begin
103
                ainv  = ~a;
104
                plus1 = rca_N(ainv,{{N-1{1'b0}},1'b1});
105
 
106
        // synopsys translate_off
107
        // The only problem is absolute minumum negative value
108
        if (a == {1'b1, {N-1{1'b0}}}) $display("--->>> 2's complement ERROR - absolute minumum negative value");
109
        // synopsys translate_on
110
 
111
                twos_complement = plus1[N-1:0];
112
        end
113
        endfunction
114
 
115
endmodule

powered by: WebSVN 2.1.0

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