Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Assembly x86 > Re: Binary roun...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 4603 of 4729
Post > Topic >>

Re: Binary rounding problem in 3DNow!

by kuratkull <spamtrap@[EMAIL PROTECTED] > Apr 4, 2008 at 06:12 AM

On Apr 3, 12:47 pm, kuratkull  <spamt...@[EMAIL PROTECTED]
> wrote:
> Hello all you happy people :)
>
> I have experience with C, Python and CLisp, but ASM is very new to me.
> So I am doing the very-fast-prime-search(which is almost a must when
> learning a new language), and I succeeded with a rather slow version
> using idivl, at first. I profiled my code and decided that the idivl
> could be replaced with the AMD 3DNow! instructions.
>
> The first failure is with %ecx = 3 and %edx=9.
> The rounding to int, just before the debug, should round the 1/3*9 to
> 3, but because of the binary representation of the float, it rounds it
> down to 2.
> Is there a way around it?
>
>      MOVD    %ecx, %MM0       /* divisor */
>      PI2FD   %MM0, %MM0      /* divisor to float */
>      MOVQ    %MM0, %MM2     /* copy of divisor */
>      PFRCP   %MM0, %MM0    /* 1/divisor */
>      MOVD    %edx, %MM1       /* prime candidate */
>      PI2FD   %MM1, %MM1      /* prime. to float */
>      MOVQ    %MM1, %MM3     /* copy of prime. */
>      PFMUL   %MM0, %MM1    /* 1/divisor * prime. */
>      PF2ID   %MM1, %MM1      /* answer to int ...*/
>      MOVQ    %MM1, %MM4     /* DEBUG for viewing value */
>      PI2FD   %MM1, %MM1      /* ... and back to float */
>      PFMUL   %MM1, %MM2    /*  int(1/divisor*prime) * divisor */
>      PFCMPEQ %MM2, %MM3  /*if the %MM2 and the prime candidate are
> equal, then != prime */
>      MOVD %MM3, %eax
>
> I know the code is rather ugly, but remember I'm still new, and I am
> currently trying to make it work first :)
>
> Every answer(even if it's just for saying "You're fckd!") is
> appreciated.
>
> Thanks,
> kuratkull

PLEASE DONT ANSWER TO THIS THREAD, I DOUBLED BY MISTAKE, the correct
topic is:
http://groups.google.com/group/comp.lang.asm.x86/browse_thread/thread/6ca6fd909eb8195f#

Sorry again!
 




 2 Posts in Topic:
Binary rounding problem in 3DNow!
kuratkull <spamtrap@[  2008-04-03 02:47:22 
Re: Binary rounding problem in 3DNow!
kuratkull <spamtrap@[  2008-04-04 06:12:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:08:12 CDT 2008.