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

Subversion Repositories fir_wishbone

[/] [fir_wishbone/] [trunk/] [hw/] [packages/] [pkg-dsp.vhdl] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 daniel.kho
/* Tauhop Digital Signal Processing package.
2
 
3
        Description
4
        This implements common functions used in digital signal processing.
5
 
6
        To Do:
7
 
8
        Author(s):
9
        - Daniel C.K. Kho, daniel.kho@opencores.org | daniel.kho@tauhop.com
10
 
11
        Copyright© 2014 Authors and Tauhop Solutions. All rights reserved.
12
        This source file may be used and distributed without
13
        restriction provided that this copyright statement is not
14
        removed from the file and that any derivative work contains
15
        the original copyright notice and the associated disclaimer.
16
 
17
        This source file is free software; you can redistribute it
18
        and/or modify it under the terms of the GNU Lesser General
19
        Public License as published by the Free Software Foundation;
20
        either version 2.1 of the License, or (at your option) any
21
        later version.
22
 
23
        This source is distributed in the hope that it will be
24
        useful, but WITHOUT ANY WARRANTY; without even the implied
25
        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
26
        PURPOSE. See the GNU Lesser General Public License for more
27
        details.
28
 
29
        You should have received a copy of the GNU General Public License
30
        along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
 
32
        This notice and disclaimer must be retained as part of this text at all times.
33
 
34
        @dependencies:
35
        @created: Daniel C.K. Kho [daniel.kho@gmail.com] | [daniel.kho@tauhop.com]
36
        @info:
37
        Revision History: @see Mercurial log for full list of changes.
38
*/
39
/* TODO try using generic subprograms to have a single subprogram being
40
        passed generic types.
41
*/
42
library ieee; use ieee.std_logic_1164.all, ieee.numeric_std.all;
43
package dsp_specific is
44
        function clamp(s:unsigned; low,high:unsigned) return unsigned;
45
        function clamp(s:unsigned; low,high:natural) return unsigned;
46
        function clamp(s:signed; low,high:signed) return signed;
47
        function clamp(s:signed; low,high:integer) return signed;
48
 
49
        function max(l,r:unsigned) return unsigned;
50
        function max(l,r:signed) return signed;
51
        function min(l,r:unsigned) return unsigned;
52
        function min(l,r:signed) return signed;
53
end package dsp_specific;
54
 
55
package body dsp_specific is
56
        function clamp(s:unsigned; low,high:unsigned) return unsigned is
57
                variable clamped:unsigned(s'range);
58
        begin
59
                clamped:=low when s<low else high when s>high else s;
60
                return clamped;
61
        end function clamp;
62
 
63
        function clamp(s:unsigned; low,high:natural) return unsigned is begin
64
                return clamp(s,to_unsigned(low,s'length),to_unsigned(high,s'length));
65
        end function clamp;
66
 
67
        function clamp(s:signed; low,high:signed) return signed is
68
                variable clamped:signed(s'range);
69
        begin
70
                clamped:=low when s<low else high when s>high else s;
71
                return clamped;
72
        end function clamp;
73
 
74
        function clamp(s:signed; low,high:integer) return signed is begin
75
                return clamp(s,to_signed(low,s'length),to_signed(high,s'length));
76
        end function clamp;
77
 
78
        function max(l,r:unsigned) return unsigned is begin
79
                /* FIXME support this in next standard. */
80
                --return r when r>l else l;
81
 
82
                if r>l then return r; end if;
83
                return l;
84
        end function max;
85
 
86
        function max(l,r:signed) return signed is begin
87
                --return r when r>l else l;
88
 
89
                if r>l then return r; end if;
90
                return l;
91
        end function max;
92
 
93
        function min(l,r:unsigned) return unsigned is begin
94
                --return r when r<l else l;
95
 
96
                if r<l then return r; end if;
97
                return l;
98
        end function min;
99
 
100
        function min(l,r:signed) return signed is begin
101
                --return r when r<l else l;
102
 
103
                if r<l then return r; end if;
104
                return l;
105
        end function min;
106
end package body dsp_specific;
107
 
108
 
109
library ieee; use ieee.std_logic_1164.all, ieee.numeric_std.all;
110
package dsp_generic is generic(
111
                type T;
112
                --function "+"(l,r:T) return T is <>;
113
                --function "<"(l,r:T) return boolean is <>;
114
                --function ">"(l,r:T) return boolean is <>;
115
                --function ">"(l:T;r:natural) return boolean is <>;
116
                --function clamp(s,low,high:T) return T is <>;
117
                function clamp(s:T; low,high:natural) return T is <>
118
        );
119
 
120
        --function clamp generic(type T) parameter(s:T; low:T; high:T) return T;
121
end package dsp_generic;
122
 
123
package body dsp_generic is end package body dsp_generic;

powered by: WebSVN 2.1.0

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