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


|