DSPRelated.com
Forums

problem with 32 bit multiplication built-in function on blackfin

Started by Marko Kanadi March 16, 2009
Hello everyone,

I am Marko Kanadi from DSP research group of Institut Teknologi Bandung
I am new to Blackfin (BF561EZ).
I have a problem with 32x32 bit multiplication built-in function on Blackfin, which is the mult_fr1x32x32.
Underwritten is my code :

fract32 x[2]={0,0}; //mixtures
fract32 test=0;

x[0]=(fract32)(iChannel0LeftIn); //integer to fract32 conversion
x[1]=(fract32)(iChannel0RightIn); //integer to fract32 conversion

test = mult_fr1x32x32(x[0],x[1]);

But when I checked the 'Expressions', it gave me:
Name : iChannel0LeftIn ; Value : 3643392 ; Type : int
Name : iChannel0RightIn ; Value : 6985728 ; Type : int
Name : x[0] ; Value : 3643392 ; Type : long
Name : x[1] ; Value : 6985728 ; Type : long
Name : test ; Value : 11851 ; Type : int

If you checked the value of 'test', it shows the it gives the certainly wrong value. What has happened here? Can anyone give me any clue of what I'm doing wrong?

I also have another question, how can a variable with type 'fract32' has a value bigger than 1? What I understand is that the value of fract32 is in the range of -1
Thank you before.

________________________________

Regards,
Marko Kanadi

________________________________
Hello Marko,

Marko Kanadi wrote:
> Hello everyone,
>
> I am Marko Kanadi from DSP research group of Institut Teknologi Bandung
> I am new to Blackfin (BF561EZ).
> I have a problem with 32x32 bit multiplication built-in function on
> Blackfin, which is the mult_fr1x32x32.
> Underwritten is my code :
>
> fract32 x[2]={0,0}; //mixtures
> fract32 test=0;
>
> x[0]=(fract32)(iChannel0LeftIn); //integer to fract32 conversion
> x[1]=(fract32)(iChannel0RightIn); //integer to fract32 conversion
>
> test = mult_fr1x32x32(x[0],x[1]);
>
> But when I checked the 'Expressions', it gave me:
> Name : iChannel0LeftIn ; Value : 3643392 ; Type : int
> Name : iChannel0RightIn ; Value : 6985728 ; Type : int
> Name : x[0] ; Value : 3643392 ; Type : long
> Name : x[1] ; Value : 6985728 ; Type : long
> Name : test ; Value : 11851 ; Type : int
>
> If you checked the value of 'test', it shows the it gives the certainly
> wrong value. What has happened here? Can anyone give me any clue of what
> I'm doing wrong?

It looks OK to me. The result of 32 bit fractional multiply should be
normalised by dividing by 2^31 (shifting right 31 places).

> I also have another question, how can a variable with type 'fract32' has
> a value bigger than 1? What I understand is that the value of fract32
> is in the range of -1

The range is actually -1 <= x <= 1-2^(-31). You can't represent numbers
bigger than this directly in fract32, but what you can do is do
something like floating point arithmetic and have a fixed (at compile
time) static exponent and treat the fract32 as an unnormalised mantissa.

When you multiply two mantissae (fract32s) the exponent of the result
is just the sum of the two exponents (which is again statically
determined).

When you add you do it like floating point, arithmetic shift the
mantissa whichever number has the lower exponent down to align it with
the mantissa of the other number. The exponent of the result is just the
larger of the two input exponents (again statically determined). You
need to make sure everything is scaled correctly to avoid
clipping/overflow, but with 32 bits to play with that usually isn't too
much of a problem.

This is probably quite a bit cheaper than full floating point and you
can use cpp macros to help you keep track of the exponents at each stage
of your calculation.

HTH

Regards
--
Adrian Hey
Marko,

The value you got is correct. The int value of 3643392 is about 0.00169 in
fract32. The int value 6985728 is 0.00325 in fract32. To convert the int
to fract32, divide by 2^31. The answer represented as an int is the 11851
value that you got (about 5.5e-6 in fract32). i.e. 0.00169 * 0.00325 5.5e-6.

Fixed point numbers can be represented as integer or fractional types. Any
32 bit number can be represented as an integer (i.e. 32.0, where 32 bits
have weights that are positive powers of two and 0 fractional bits) or as a
fractional (i.e. 1.31, where the MSB is a sign bit and the remaining 31 bits
are fractional bits, or bit weights with negative powers of two). The bit
weight scheme for a number is determined by the position of the binary
point.

The range for fract is -1<= x < 1. This is the case whether you are
working with 8, 16, 32 bit, or any size fixed point number. Only the
precision changes. Contrast this with integer where the range is +127/-128,
+/-32K, and +/- 2e9, respectively for the same three number sizes.

Best regards,

George Kadziolka

Kaztek Systems

www.kaztek.com

From: a... [mailto:a...] On Behalf Of Marko
Kanadi
Sent: Monday, March 16, 2009 10:15 PM
To: adsp Blackfin yahoogroups
Subject: [adsp] problem with 32 bit multiplication built-in function on
blackfin

Hello everyone,

I am Marko Kanadi from DSP research group of Institut Teknologi Bandung
I am new to Blackfin (BF561EZ).
I have a problem with 32x32 bit multiplication built-in function on
Blackfin, which is the mult_fr1x32x32.
Underwritten is my code :

fract32 x[2]={0,0}; //mixtures
fract32 test=0;

x[0]=(fract32)(iChannel0LeftIn); //integer to fract32 conversion
x[1]=(fract32)(iChannel0RightIn); //integer to fract32 conversion

test = mult_fr1x32x32(x[0],x[1]);

But when I checked the 'Expressions', it gave me:
Name : iChannel0LeftIn ; Value : 3643392 ; Type : int
Name : iChannel0RightIn ; Value : 6985728 ; Type : int
Name : x[0] ; Value : 3643392 ; Type : long
Name : x[1] ; Value : 6985728 ; Type : long
Name : test ; Value : 11851 ; Type : int

If you checked the value of 'test', it shows the it gives the certainly
wrong value. What has happened here? Can anyone give me any clue of what I'm
doing wrong?

I also have another question, how can a variable with type 'fract32' has a
value bigger than 1? What I understand is that the value of fract32 is in
the range of -1
Thank you before.

_____

Regards,
Marko Kanadi

_____