Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Logic design, how do I find out the bit-length of numbers?

Status
Not open for further replies.

kel8157

Full Member level 2
Joined
Nov 14, 2007
Messages
131
Helped
5
Reputation
10
Reaction score
3
Trophy points
1,298
Activity points
2,017
Hello!

My design is a large parallel processing unit, which requires to find the
bit-length of signed numbers and dynamic shifting in a single cycle

Here is my code..
Are there any more efficient/fast methods to accomplish these two tasks?
My clock cycle is stingent, and many nested ifs or long case statements
might cause timing issues in later stages.

// Look for bit-length
reg [5:0] bw;
reg [31:0] d0, d1, .. d15;

wire [31:0] d0w, d1w, .. d15w;
wire [31:0] tmpw;
assign d0w = (d0[31]) ? {~d0 + 32'd0} : d0;
..
assign d15w = (d15[31]) ? {~d15 + 32'd0} : d15;
assign tmpw = d0w | d1w | .. d31w;
always @(the list) begin
if(tmpw[31] || tmpw[30] )
bw <= 6'd32;
else if (tmpw[29])
bw <= 6'd30;
else if (tmpw[28])
bw <= 6'd29;
....
end


// dynamic bit-shifting
input [4:0] shift_pos_in;

reg [31:0] din;
reg [31:0] dout;

always @()
case (shift_pos_in)
5'd0: dout <= din;
5'd1: dout <= {din[31], din[31:1]};
5'd2: dout <= {2{din[31]}, din[31:1]};
..

endcase
end

:D
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top