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/] [signed_mult_const_asic.v] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 irezki
/**********************************************************************
2
 * File  : signed_mult_const_asic.v
3
 * Author: Ivan Rezki
4
 * email : irezki@gmail.com
5
 * Topic : RTL Core
6
 *                2-Dimensional Fast Hartley Transform
7
 *
8
 *
9
 * Function: Signed Multiplier - constant sqrt(2) = 1.41421
10
 * 1.41421*a = (256*1.41421)*a/256 = 362.03776*a/256 = 362*a/256
11
 * product = 362*a/2^8
12
 *
13
 * RIGHT TO USE: This code example, or any portion thereof, may be
14
 * used and distributed without restriction, provided that this entire
15
 * comment block is included with the example.
16
 *
17
 * DISCLAIMER: THIS CODE EXAMPLE IS PROVIDED "AS IS" WITHOUT WARRANTY
18
 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED
19
 * TO WARRANTIES OF MERCHANTABILITY, FITNESS OR CORRECTNESS. IN NO
20
 * EVENT SHALL THE AUTHOR OR AUTHORS BE LIABLE FOR ANY DAMAGES,
21
 * INCLUDING INCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF THE
22
 * USE OF THIS CODE.
23
 **********************************************************************/
24 2 irezki
 
25
module signed_mult_const_asic (
26
        rstn,
27
        clk,
28
        valid,
29
        a,
30
        p
31
);
32
 
33
parameter               N = 8;
34
input                   rstn;
35
input                   clk;
36
input                   valid;
37
input  [N-1:0] a; // variable - positive/negative
38
output [N  :0] p; // product output
39
 
40
// FHT constant
41 7 irezki
//wire [8:0] mult_constant; // always positive
42
//assign mult_constant = 9'd362;
43
parameter mult_constant = 9'd362;
44 2 irezki
 
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
// Convert into 2's complement if (a_FF) is negative
51
wire [N-1:0] b;
52
assign b = a_FF[N-1] ? {~a_FF[N-1:0] + {{N-1{1'b0}},1'b1} } : a_FF[N-1:0];
53
 
54
// Multiply 2 positive numbers 
55
// b[N-2:0] * mult_constant[8:0]
56
// output result mult_wo_sign
57
// N-2+1 - number of (b) bits
58
// 8+1   - number of mult_constant bits
59
// N-2+1+8+1 - number of bits on the output
60
// = N+8 = [N+7:0]
61
wire [N+7:0] mult_wo_sign; // mult without sign
62
assign mult_wo_sign = b[N-2:0]*mult_constant;
63
 
64 7 irezki
// Divided by 256 - [N+7-8:0] = [N-1:0]
65 2 irezki
wire [N-1:0] div256; // divided 256
66
assign div256 = mult_wo_sign >> 8;
67
 
68
assign p = a_FF[N-1] ?
69
                                        {1'b1,{~div256[N-1:0] + {{N-1{1'b0}},1'b1}} } :
70
                                        {1'b0,  div256[N-1:0]}
71
                                        ;
72
endmodule
73 7 irezki
 
74
// Update Log:
75
// 27 Jul. 2011
76
// wire [8:0] mult_constant replaced by parameter

powered by: WebSVN 2.1.0

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