LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

logical shift in FPGA

I have to use logical shift to fixed point number to avoid division operation..in LabVIEW FPGA. 

I used logical shift available in Numeric palette. But it is working for +ve numbers numbers

 

for-ve inputs , I have to negate the inputs and give to logical shift and  again i need to negate the o/p..

In this way only, I am getting results..

Is there any other simple way to do this?

 

I tried with i32 in FPGA .But same issue is there .

0 Kudos
Message 1 of 12
(2,174 Views)

Logical shift has no real meaning for non-integers, and little meaning for signed integers.

 

The bits will simply be shifted. So a sign bit will be dropped, if it's true.

 

Why not divide by 2? That is the same as a shift of -1.

 

Shift FPGA.png

0 Kudos
Message 2 of 12
(2,163 Views)

Division node consumes more resources in FPGA compared to this logical shift.

Can we do shifting preserving the sign bit?

0 Kudos
Message 3 of 12
(2,158 Views)

If I remember correctly, a logical shift (with a constant shift amount) is free on an FPGA (just some routing gymnastics).  A Divide is extremely expensive.  So I understand trying to work around the divide.  But unless you are inside of a Single Cycle Timed Loop, I think it will just be easier to do the divide.  In other words, optimize only when you need to.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 12
(2,131 Views)

Thinking about it a little more, I think this will be the simplest route while being really cheap to the hardware.  Do a Rotate Left With Carry in order to get the MSb and then a Rotate Right With Carry using the original value and the carry out from the rotate left.  I am not sure how this works with the 2's compliment formats, but my quick spot checking does seem to work.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 12
(2,125 Views)

This helps if it is a constant shift of 1 or a division of 2.

 But the amount of Shift is a control for me. 

0 Kudos
Message 6 of 12
(2,117 Views)

Then use Scale By Power Of 2.

0 Kudos
Message 7 of 12
(2,108 Views)

A logical shift is a "logical" shift meaning it does not account for any complement arithmetic use. That is also the reason why it is extremely cheap when translated to hardware logic. Two complements arithmetic is more complex and does require some extra logic to handle negative integer numbers (and is potentially even more complex for fixed point arithmetics).

 

There is potentially some way to make it less complex than a division but it won't be a single node. While for positive numbers it can remain a simple logical shift, for negative numbers however, either detected by the method as crossrulz showed or with a smaller than 0 node, it will involve two shifts and using a boolean OR operation.

 

Arithmetic shift.png

 

Scale by Power of 2 as mentioned by Wiebe does basically this.

Rolf Kalbermatter
My Blog
Message 8 of 12
(2,106 Views)

In integers, this logic is working.

But for FXP point shifting, we cant use boolean nodes.

 

Do we need to convert them to integers, then shift and again to FXP?

and 

Does negate nodes consume more resources compared to the logical shift?

 

0 Kudos
Message 9 of 12
(2,098 Views)

Yes you need to convert the FXP to an integer and back. And that does cost some resources for sure if the FXP is not 32 bit word length.

 

Negate and logical shift are fundamentally different operations. Why do you try to compare them?

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 12
(2,093 Views)