flat assembler
Message board for the users of flat assembler.

flat assembler > Heap > [ARTICLE] Fixed point info and tricks

Author
Thread Post new topic Reply to topic
Borsuc



Joined: 29 Dec 2005
Posts: 2468
Location: Bucharest, Romania
There has been some time since I was on the net, and I decided to write an article which I hope will make you understand fixed point, the difference between it and floating point, and how both are just "emulations" of 'real' numbers.

I see some people get confused at the "multiplication by the reciprocal" in integer arithmetic. Don't worry, that's actually a fixed point trick. I hope the article explains it well enough. But of course the list is much longer -- fixed point is certainly low-level math-oriented, but math is still math Smile

Of course the article might contain errors (especially in the floating point info). Thanks to revolution for explaining float a while back (I looked so dumb back then Razz). That's why I post it here, so feedback is appreciated.

If you know of any other forums or places I should post the article before it's finished (i.e for corrections, etc.) let me know. However as I previously stated it may take a while for me to get on the net, so please don't be frustrated if I don't reply within days (or even weeks Sad ). But I might as well be replying tomorrow or today Wink


Description:
Download
Filename: Fixed point info and tricks.txt
Filesize: 24.06 KB
Downloaded: 599 Time(s)

Post 22 Sep 2006, 14:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15974
Location: Qo'noS
A good effort overall. I got a little confused when you mentioned fractions (ie. "4/7", "1/2" etc.), but then I realised you meant the fractional component of the number (the part after the binary/decimal point). Perhaps you can reword those parts a little?
Post 22 Sep 2006, 15:22
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2468
Location: Bucharest, Romania
Oh yes, sorry.. I am usually typing very fast and I think ahead, so I wanted to skip that "fractional part" faster with just "fraction" (sorry if this doesn't make sense). Now I realize it's wrong, thanks for the observation. I'll fix it.

My aim was to make a relatively simple but comprehensive article on fixed point, without too much math terms involved, but still explaining the math behind. Any other feedback is welcome.
Post 22 Sep 2006, 18:59
View user's profile Send private message Reply with quote
Maverick



Joined: 07 Aug 2006
Posts: 251
Location: Citizen of the Universe
revolution wrote:
A good effort overall. I got a little confused when you mentioned fractions (ie. "4/7", "1/2" etc.), but then I realised you meant the fractional component of the number (the part after the binary/decimal point). Perhaps you can reword those parts a little?

I always called it "fractional part" too. By the way, do you think that the part on the left of the point should be called "integral part" or "integer part"? I'm used to call it "integral part", but I'm not 100% sure that's the correct wording.

_________________
Greets,
Fabio
Post 23 Sep 2006, 07:00
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15974
Location: Qo'noS
Maverick wrote:
"integral part" or "integer part"?
"Integer" I would expect. "Integral" would have a different meaning.
Post 23 Sep 2006, 07:33
View user's profile Send private message Visit poster's website Reply with quote
Maverick



Joined: 07 Aug 2006
Posts: 251
Location: Citizen of the Universe
That was my fear. However, in plain English, why not "Fraction part" then?

If it was my native language it would be easier. Wink
Post 23 Sep 2006, 08:02
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 620
The_Grey_Beast wrote:
...
r = (color1 * (color2+1)) >> 8
...
I used that method a little while back in my alpha blend function but the "+1" didn't occur to me... at least I know now Laughing
Thanks The_Grey_Beast
Post 23 Sep 2006, 21:52
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6927
Location: Kraków, Poland
A very nice explanation for "multiplication by the reciprocal", perhaps the clearest one. However, just for completeness, I'd like to note that this trick may be interpreted not only as a fixed-point application, but also explained according to the 2-adic field theory (see the discussion I once participated in on the other board). You know, the p-adic numbers are my research topic, that's why I'm promoting them perhaps too frequently. Wink
Post 23 Sep 2006, 22:20
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4634
Location: Argentina
[edit] Edited last code because ADC doesn't work in that case [/edit]
[edit2] ATV has pointed me a mistake about DIV but I completely removed all the post because the article multiplies a 8.8 number so there is no need to take advantage of the 64-bit produced result [/edit2]


Last edited by LocoDelAssembly on 27 Sep 2006, 14:06; edited 2 times in total
Post 23 Sep 2006, 22:38
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7109
Location: Slovakia
thanks guys, article is linked from Interesting topics now
Post 24 Sep 2006, 09:35
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2146
Location: Estonia
Actually FPU is not very slow and FMUL is faster than 2 MOVs+ MUL+DIV. You didn't convince me just yet Smile
If you think you can beat SSE+FPU with simple integer arithmetic, then I would say SSE is 4 to 8 times faster.

Yeah, I see your point on making use of all the bits, but I only switch from int to float just when it isn't possible any other way. That is usually when FSINCOS and FSQRT are involved. All other algorithms can be made with ints and I think there is no middle ground.

You can think of a number to be fixed point, but to me its just another int, that I'm using in some very tricky way. Smile

Btw, the multiplication and division were nice addition to my brain Wink but until I can't use them, its just a thought floating around in my mind.

Anyway, I do not feel wasting my time reading your article. It was in well-formed English and great reading. Thank you!
Post 25 Sep 2006, 13:29
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4634
Location: Argentina
Quote:
In x86 assembly this can be written a lot faster (note that I assume we have a 8.8 fractional number which cannot overflow a 32-bit register; otherwise you'd have to use the "edx" register too)


Sorry Embarassed
Post 25 Sep 2006, 14:21
View user's profile Send private message Reply with quote
ATV



Joined: 31 Aug 2004
Posts: 109
Location: Finland
locodelassembly, it shoud be "mov ecx,256" before div to move 8 bits
Post 27 Sep 2006, 11:09
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4634
Location: Argentina
Thanks, I removed the post now because it was enterely wrong anyway (because the article uses 8.8 fixed point in the example so EDX is not needed here)
Post 27 Sep 2006, 14:08
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.