Monday, April 6, 2009

Something about Fix point logic

Something about Fix point logic

I am writing this topic because this topic is some cofused one but easy to understand.
ok so without wasting time i will directly jump to the topic.

If we have given the job of writing a real value(real values are values having points in them, u must have known this)
than its is very easy, huh!
write two point five. you write 2.5

Fix point and floating point are two types of representation for real values.
Floating point gives you higher range .
When a number is stored in processor it is stored in processor register.
The register length is of some bits and in case of ARM it is 32 bits.
So the number we store is get store in these 32 bits.
like if u write 17d(d for decimal) it will store as 10001 with leading bits as all zeroes.

Forget all representation you know . You are given job of writing 17.5.
How you will do it?
Now you will say i will fix 4 bits from these 32 bits for fractional bits and rest all for integer portions.
than you can write it as 10001.1000 with all leading bits zero
This is what you say fix point as you fix the fractional bits as 4 places.
The problem is precision here. The precision is pow(2,-4)
So it is you who decide how much number to fix for fractional part and how much for integer part.
That is programmer .
If my number table(or say range of numbers i am dealing with) is like .625 to 457878.5 than i am done with this allotment.
As both range ( pow(2,28) for unsigned or pow(2,27) for signed) and prcision are satisfied , i am happy man.
You can say it is Q28.4 or in short Q4. The usual standard saying in industry is Q27.4 so adopt it.

Now their is another representation system also . It is floating point system.
As the name seems it is the fractional thing which you can float.
like 250*pow(10,1) or 2.50*pow(10,3) .
The system use to represent is IEEE754 which in short can be said as 1+8+23 for single precision numbers.
So a 32 bit number can be represented by this notation.
You can read the old slides or google it for how to represent any number in this format.

Now the point is why on earth the fix point is preferred.
It is because if the core of the processor is fix point core than the compiler has to emulate the float variable in
your code to fix point.(It write fix point version for that section).
Floating point core needs complex logic and thus use more silicon and thus more costly.
Nowadays core for floats are also available but its selection depends on lot or factors.
Like difference in notation of ARM11F or ARM11 is that the former have floating point accelarator.
So you must use fix point notation if your core is ARM11 only.

(Note:- for people who will try to implement this theory ,note that you will see benefits in speed only if
you change the logic of code instead of calling fix point library function all the time for calculation
as the fucntion calling will make it ineffiecient. You can do practical with using profilers.)

Apologies for writing it in without figures and not giving practical examples for it but this blog
might solve some confusion .
I will clarify more with example in next blog if time permits.

No comments:

Post a Comment