04-16-2021 08:06 AM
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 .
04-16-2021 08:22 AM
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.
04-16-2021 08:28 AM
Division node consumes more resources in FPGA compared to this logical shift.
Can we do shifting preserving the sign bit?
04-16-2021 09:12 AM
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.
04-16-2021 09:31 AM - edited 04-16-2021 09:32 AM
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.
04-16-2021 09:54 AM
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.
04-16-2021 10:26 AM
Then use Scale By Power Of 2.
04-16-2021 10:30 AM - edited 04-16-2021 10:33 AM
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.
Scale by Power of 2 as mentioned by Wiebe does basically this.
04-16-2021 11:19 AM
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?
04-16-2021 11:47 AM
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?