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 4

Go to most recent revision | 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
wire [8:0] mult_constant; // always positive
42
assign mult_constant = 9'd362;
43
 
44
reg [N-1:0] a_FF;
45
always @(posedge clk)
46
if              (!rstn) a_FF <= #1 0;
47
else if (valid) a_FF <= #1 a;
48
 
49
// Convert into 2's complement if (a_FF) is negative
50
wire [N-1:0] b;
51
assign b = a_FF[N-1] ? {~a_FF[N-1:0] + {{N-1{1'b0}},1'b1} } : a_FF[N-1:0];
52
 
53
// Multiply 2 positive numbers 
54
// b[N-2:0] * mult_constant[8:0]
55
// output result mult_wo_sign
56
// N-2+1 - number of (b) bits
57
// 8+1   - number of mult_constant bits
58
// N-2+1+8+1 - number of bits on the output
59
// = N+8 = [N+7:0]
60
wire [N+7:0] mult_wo_sign; // mult without sign
61
assign mult_wo_sign = b[N-2:0]*mult_constant;
62
 
63
// Divide on 256 - [N+7-8:0] = [N-1:0]
64
wire [N-1:0] div256; // divided 256
65
assign div256 = mult_wo_sign >> 8;
66
 
67
assign p = a_FF[N-1] ?
68
                                        {1'b1,{~div256[N-1:0] + {{N-1{1'b0}},1'b1}} } :
69
                                        {1'b0,  div256[N-1:0]}
70
                                        ;
71
endmodule

powered by: WebSVN 2.1.0

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