flat assembler
Message board for the users of flat assembler.

 Index > Heap > [ARTICLE] Fixed point info and tricks
Author
Borsuc

Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
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

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 ). 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 ). But I might as well be replying tomorrow or today

22 Sep 2006, 14:48
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17272
revolution
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?
22 Sep 2006, 15:22
Borsuc

Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
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.
22 Sep 2006, 18:59
Maverick

Joined: 07 Aug 2006
Posts: 251
Location: Citizen of the Universe
Maverick
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
23 Sep 2006, 07:00
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 17272
revolution
Maverick wrote:
"integral part" or "integer part"?
"Integer" I would expect. "Integral" would have a different meaning.
23 Sep 2006, 07:33
Maverick

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

If it was my native language it would be easier.
23 Sep 2006, 08:02
cod3b453

Joined: 25 Aug 2004
Posts: 619
cod3b453
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
Thanks The_Grey_Beast
23 Sep 2006, 21:52
Tomasz Grysztar
Assembly Artist

Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
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.
23 Sep 2006, 22:20
LocoDelAssembly

Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
 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
23 Sep 2006, 22:38
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
thanks guys, article is linked from Interesting topics now
24 Sep 2006, 09:35

Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Actually FPU is not very slow and FMUL is faster than 2 MOVs+ MUL+DIV. You didn't convince me just yet
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.

Btw, the multiplication and division were nice addition to my brain 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!
25 Sep 2006, 13:29
LocoDelAssembly

Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
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
25 Sep 2006, 14:21
ATV

Joined: 31 Aug 2004
Posts: 109
Location: Finland
ATV
locodelassembly, it shoud be "mov ecx,256" before div to move 8 bits
27 Sep 2006, 11:09
LocoDelAssembly

Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
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)
27 Sep 2006, 14:08
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou can attach files in this forumYou can download files in this forum