From: m26k9 on
Hello,

I am sure this is a pretty simple question, but I am having some ambiguity.
I need to confirm what is happening exactly. Any information is really
appreciated.

So this is a Sharc DSP I am working with. Question is pretty simple.

Rn = FIX Fx;

FIX description from the manual is as follows:
"Converts the floating-point operand in Fx to a twos-complement 32-bit
fixed-point integer result. If the MODE1 register TRUNC bit=1, the FIX
operation truncates the mantissa towards –Infinity. If the TRUNC bit=0,
the FIX operation rounds the mantissa towards the nearest integer. The
TRUNC operation always truncates toward 0. Note that the TRUNC bit
does not influence operation of the TRUNC instruction."


Now the problem is, what is the "floating point OPERAND"?
The mantissa is always a fractional value with one digit left to the
decimal point. For example, the floating point will be something like
-2.345*(10-5) or 5.678*(10+8), and the mantissa will be 2.345 or 5.678.
Now, when it says the mantissa towards -inifinity or nearest integer, that
means the fixed-point value will be -2 or 5 (according to the above example
values)? Which definitely cannot be the case since we have 32-bits.

Could somebody please explain.

Cheers.
From: Jerry Avins on
On 6/3/2010 5:07 AM, m26k9 wrote:
> Hello,
>
> I am sure this is a pretty simple question, but I am having some ambiguity.
> I need to confirm what is happening exactly. Any information is really
> appreciated.
>
> So this is a Sharc DSP I am working with. Question is pretty simple.
>
> Rn = FIX Fx;
>
> FIX description from the manual is as follows:
> "Converts the floating-point operand in Fx to a twos-complement 32-bit
> fixed-point integer result. If the MODE1 register TRUNC bit=1, the FIX
> operation truncates the mantissa towards –Infinity. If the TRUNC bit=0,
> the FIX operation rounds the mantissa towards the nearest integer. The
> TRUNC operation always truncates toward 0. Note that the TRUNC bit
> does not influence operation of the TRUNC instruction."
>
>
> Now the problem is, what is the "floating point OPERAND"?
> The mantissa is always a fractional value with one digit left to the
> decimal point. For example, the floating point will be something like
> -2.345*(10-5) or 5.678*(10+8), and the mantissa will be 2.345 or 5.678.
> Now, when it says the mantissa towards -inifinity or nearest integer, that
> means the fixed-point value will be -2 or 5 (according to the above example
> values)? Which definitely cannot be the case since we have 32-bits.
>
> Could somebody please explain.

Your best bet is trying it and examining the result. My guesses are

"operand" is the entire number, which you can consider as a whole in any
base/ Instead of considering the individual bits, Base 10 will make
thinking easier. So 2.644e2 converts to 264.4, which has some binary
representation. (Work it out.) Then apply the truncate/round rules to
the result. The difference between truncating and rounding is either 1 or 0.

Jerry
--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
From: m26k9 on

>
>Your best bet is trying it and examining the result. My guesses are
>
>"operand" is the entire number, which you can consider as a whole in any
>base/ Instead of considering the individual bits, Base 10 will make
>thinking easier. So 2.644e2 converts to 264.4, which has some binary
>representation. (Work it out.) Then apply the truncate/round rules to
>the result. The difference between truncating and rounding is either 1 or
0.
>
>Jerry

Thank you Jerry.
Unfortunately I'm just starting out with assembly and am given the task of
finding the algorithm of someone else's code. Unfortunately I have
experience nor the time to carry this out. I need to understand how a
floating-point value will be converted to a "signed integer fixed-point"
value to go through the code and report what is happening. I guess it
depends on the DSP I am using too.

Thank you again.
From: glen herrmannsfeldt on
m26k9 <maduranga.liyanage(a)n_o_s_p_a_m.gmail.com> wrote:
(snip)

> Unfortunately I'm just starting out with assembly and am given the task of
> finding the algorithm of someone else's code. Unfortunately I have
> experience nor the time to carry this out. I need to understand how a
> floating-point value will be converted to a "signed integer fixed-point"
> value to go through the code and report what is happening. I guess it
> depends on the DSP I am using too.

It depends on the DSP and the needed range. It is somewhat easier
if you don't need all the bits in the floating point value, as
would be the case with 32 bit float and 16 bit int.

For unsigned 16 bit fixed to 32 bit float, store the int into
the low half of a 32 bit word with the appropriate exponent,
then load it as a floating point value. If there is no
'hidden one', all you need to do is normalize the result,
which adding zero will do on many machines. If there is
a hidden one, then subtract the value with the same exponent
as use previously with all the other bits zero, which will
then normalize the result.

For twos complement, invert the high bit first, which results
in an unsigned value 32768 higher than the original value.
Convert as above, and subtract 32768.

For 32 bit float to 16 bit int, pretty much reverse the above,
though you should check that the value is in range first.

-- glen
From: m26k9 on
>m26k9 <maduranga.liyanage(a)n_o_s_p_a_m.gmail.com> wrote:
>(snip)
>
>> Unfortunately I'm just starting out with assembly and am given the task
of
>> finding the algorithm of someone else's code. Unfortunately I have
>> experience nor the time to carry this out. I need to understand how a
>> floating-point value will be converted to a "signed integer
fixed-point"
>> value to go through the code and report what is happening. I guess it
>> depends on the DSP I am using too.
>
>It depends on the DSP and the needed range. It is somewhat easier
>if you don't need all the bits in the floating point value, as
>would be the case with 32 bit float and 16 bit int.
>
>For unsigned 16 bit fixed to 32 bit float, store the int into
>the low half of a 32 bit word with the appropriate exponent,
>then load it as a floating point value. If there is no
>'hidden one', all you need to do is normalize the result,
>which adding zero will do on many machines. If there is
>a hidden one, then subtract the value with the same exponent
>as use previously with all the other bits zero, which will
>then normalize the result.
>
>For twos complement, invert the high bit first, which results
>in an unsigned value 32768 higher than the original value.
>Convert as above, and subtract 32768.
>
>For 32 bit float to 16 bit int, pretty much reverse the above,
>though you should check that the value is in range first.
>
>-- glen
>

Thank you very much Glen.
I think it is what I needed to know. I will go through your explanation
again and see thourouhly.
And also thank you for that part on inverting the MSB. There was a line
which did that and I wasn't sure what it was supposed to do.

Thank you heaps.