From: Tim Wescott on
On 06/03/2010 02: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.

Not quite. It's binary floating point, so the exponent is in powers of
2. If it's IEEE-like, the mantissa will be unsigned with a sign bit
somewhere in the word. I _think_ IEEE exponents are signed 2-s
compliment, but they may be sign-magnitude as well.

Learning a bit about the floating point representation of the machine
would be a good thing.

> 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.

Do you have a way to check this on a real machine, preferably with a
debugger? I can't imagine that's what they mean to do. It would make
far more sense that the conversion is to first calculate where the radix
point* is in the mantissa, make it into an integer + fractional bits,
then truncate or round.

* It's base two, so it's not a decimal point.

--
Tim Wescott
Control system and signal processing consulting
www.wescottdesign.com
From: Raymond Toy on
On 6/6/10 2:05 PM, Tim Wescott wrote:
> On 06/03/2010 02: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.
>
> Not quite. It's binary floating point, so the exponent is in powers of
> 2. If it's IEEE-like, the mantissa will be unsigned with a sign bit
> somewhere in the word. I _think_ IEEE exponents are signed 2-s
> compliment, but they may be sign-magnitude as well.

IEEE exponents are unsigned, but they have a bias so the an exponent
value of the bias represents a true exponent of 0. The mantissa might
also have a hidden 1 bit, as someone else mentioned.

>
> Learning a bit about the floating point representation of the machine
> would be a good thing.
>
>> 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.
>
> Do you have a way to check this on a real machine, preferably with a
> debugger? I can't imagine that's what they mean to do. It would make

I agree with that. If they really meant the mantissa and it's binary
floating point, the only possible values of that instruction are 0, +/-1
and +/- 2 (I think). Hardly useful. The conversion surely takes into
account the exponent and probably does what you would think it would do,
so -2.345e-5 becomes 0 and 5.678e8 is 567800000. (Assuming base 10 for
simplicity).

Ray
From: Jaime Andrés Aranguren Cardona on
On 3 jun, 11:07, "m26k9" <maduranga.liyanage(a)n_o_s_p_a_m.gmail.com>
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.
>
> Cheers.

Hi,

The operand is Fx. For instance:

R1 = FIX F0;

Converts the floating point value stored in F0 to a fixed point value
stored in R1. Say F0 stores the value 123.456; aplying the above
instruction will store the value 123 in R1.

Could not be easier, thanks to SHARCs!

JaaC
From: Albert van der Horst on
In article <g7CdnVzpH6pQ7ZrRnZ2dnUVZ_qednZ2d(a)giganews.com>,
m26k9 <maduranga.liyanage(a)n_o_s_p_a_m.gmail.com> 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.

Start writing the fp numbers as fixed point.
Write those numbers as
- 0.00002345 and 57800000000.0
Truncating towards 0 means leaving off all behind the decimal point.
Towards -infinity means leaving off a .000 or else the highest number
that is still smaller, in those cases:

-1 57800000000

>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.

The second number is too large for 32 bits. This probably results in
the largest 32 bit number.
Write a small test program if the manual leaves that unclear.

>
>Could somebody please explain.
>
>Cheers.

Groetjes Albert

--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert(a)spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

From: m26k9 on
Dear Tim, Ray, Jaac and Albert.

Thank you so much.
I think I got it now.
The SHARC uses IEEE single-precision format.
So what I need to do is to write is as a decimal without an exponent, and
round it to the possible integer?

For example, the value is 2.345e-5, I write it as 0.00002345, which
converted to fixed-point will give zero.
If I had 2.345e+5, then I write 234500, so my fixed-point value is 234500.

Thank you very much for the clarification.

Cheers.