flat assembler
Message board for the users of flat assembler.
Index
> Windows > Java faster than ASM!? Goto page Previous 1, 2, 3, 4, 5 |
Author |
|
itsnobody 14 Feb 2008, 06:36
LocoDelAssembly wrote:
I couldn't get this reciprocal trick to work for dividing by 10...why is that? I get the wrong answer I used 0x1999999A ...what did I do wrong? |
|||
14 Feb 2008, 06:36 |
|
revolution 14 Feb 2008, 07:38
You can't simply change the constant, you also need to change the fixup code that follows.
For div 10 you can do this: Code: mov eax,value mov ecx,0xCCCCCCCD ;ecx=ceil(2^35/10) mul ecx ;edx=value*8/10 shr edx,3 ;edx=quotient, the result |
|||
14 Feb 2008, 07:38 |
|
bitRAKE 14 Feb 2008, 16:13
For the range [0,$7FFFFFFF]:
Code: imul eax,[number],$CCCCCCCD shr eax,1 |
|||
14 Feb 2008, 16:13 |
|
revolution 14 Feb 2008, 16:40
bitRAKE wrote: For the range [0,$7FFFFFFF]: bitRAKE, what are you on about? |
|||
14 Feb 2008, 16:40 |
|
bitRAKE 14 Feb 2008, 17:10
It only works for multiples of ten.
(Let me get some coffee in me and wake up, lol.) |
|||
14 Feb 2008, 17:10 |
|
itsnobody 14 Feb 2008, 22:36
revolution wrote: You can't simply change the constant, you also need to change the fixup code that follows. Thanks Do you have a link on more information about the reciprocal trick? |
|||
14 Feb 2008, 22:36 |
|
revolution 14 Feb 2008, 22:44
itsnobody wrote: Do you have a link on more information about the reciprocal trick? |
|||
14 Feb 2008, 22:44 |
|
itsnobody 14 Feb 2008, 22:52
revolution wrote:
Ok thanks |
|||
14 Feb 2008, 22:52 |
|
Madis731 15 Feb 2008, 06:49
|
|||
15 Feb 2008, 06:49 |
|
itsnobody 17 Feb 2008, 07:52
Madis731 wrote: http://www.azillionmonkeys.com/qed/adiv.html ? Thanks, I made this macro using the formula: Code: macro RECPDIV a,b { ;a/b mov ebx,(0x100000000+(b-1))/b mov eax,a mul ebx } Works for all 32-bit values, it's a LOT faster than regular div, around 8-10 times faster Here's the average results of the speed tests: Java - 2600 milliseconds ASM regular div - 2600 milliseconds ASM reciprocal div - 280 milliseconds Last edited by itsnobody on 17 Feb 2008, 08:56; edited 3 times in total |
|||
17 Feb 2008, 07:52 |
|
revolution 17 Feb 2008, 08:42
itsnobody wrote: I made this macro using the formula: BTW: Why do you have "shr eax,5"? |
|||
17 Feb 2008, 08:42 |
|
itsnobody 17 Feb 2008, 08:53
revolution wrote:
That's right, shr eax, 5 is unnecessary, its edited out now, I don't know how I confused myself to adding that in, must have been thinking about dividing by 2^32 or something As for it failing at a=2147483648, it returns 715,827,883 when the correct integer answer should be 715,827,882 Seems to work for all values less than that though Last edited by itsnobody on 17 Feb 2008, 09:00; edited 1 time in total |
|||
17 Feb 2008, 08:53 |
|
revolution 17 Feb 2008, 08:58
Here is a table for b<=50
Code: b First errored input value 3 2147483648 5 1073741824 6 2147483651 7 1431655770 9 858993461 10 1073741829 11 613566766 12 536870915 13 1073741824 14 429496731 15 306783389 17 268435456 18 306783395 19 330382107 20 1073741839 21 252645140 22 238609315 23 390451587 24 536870927 25 1073741824 26 1073741837 27 858993470 28 178956987 29 330382122 30 306783389 31 159072872 33 148102349 34 268435473 35 178956994 36 134217755 37 143165579 38 134217747 39 252645158 40 178956999 41 1073741824 42 113025485 43 159072866 44 107374211 45 306783404 46 126322577 47 858993478 48 134217743 49 429496759 50 1073741849 |
|||
17 Feb 2008, 08:58 |
|
itsnobody 17 Feb 2008, 09:03
revolution wrote: Here is a table for b<=50 Wow Is there any way to fix these errors using a fixed formula? Or is it not possible to use a fixed formula? |
|||
17 Feb 2008, 09:03 |
|
revolution 17 Feb 2008, 09:10
itsnobody wrote: Is there any way to fix these errors using a fixed formula? Or is it not possible to use a fixed formula? But for b<=50: 7,14,19,21,27,28,31,35,37,38,39,42,45 will all require additional adjustment other than a simple shift. |
|||
17 Feb 2008, 09:10 |
|
itsnobody 17 Feb 2008, 11:41
revolution wrote:
Yeah, I guess I'll have to modify the macro to include the correction errors |
|||
17 Feb 2008, 11:41 |
|
Goto page Previous 1, 2, 3, 4, 5 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.