[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ft-devel] FT_MulFix assembly
From: |
Miles Bader |
Subject: |
Re: [ft-devel] FT_MulFix assembly |
Date: |
Tue, 07 Sep 2010 18:34:01 +0900 |
James Cloos <address@hidden> writes:
>>> The C version does away-from-zero rounding.
>
> MB> Do you have test cases that show this? I tried using random inputs,
> MB> but even up to billions of iterations, I can't seem to find a set of
> MB> inputs where my function yields different results from yours.
>
> The C version saves the two signs, takes the absolute values,
> multiplies, scales and then sets the sign.
>
> When I tested, I used dd(1) to generate a quarter-gig file from urandom
> (I used a fixed file so that it would be reproducable), mmap(2)ed that
> to an int[], and went through two at a time. The C and my initial asm
> versions produced different results whenever the second int was -1 (ie
> 0xFFFFFFFF) and the first matched: (a > 0 && (a & 0xFFFF == 0x8000)).
>
> In other words, multiplying something like 7.5 by -1/65536.
>
> An example of that test's output was:
>
> 7AFA8000, FFFFFFFF, FFFF8505, FFFF8506, 0
>
> In that example, FFFF8505 is what the C version generates.
Hm, are you sure that's not backwards? When I tried the git C version[*],
as well as your most recent FT_MulFix_x86_64, it returned 0xFFFF8506...
The following C version:
typedef signed int FT_Int;
typedef signed long FT_Long;
typedef signed long FT_Int64; /* on x86-64 */
FT_Long
FT_MulFix_C_new( FT_Long a,
FT_Long b )
{
return (((FT_Int64)a * (FT_Int64)b) + 0x8000) >> 16;
}
... generates this code:
imulq %rsi, %rdi
leaq 32768(%rdi), %rax
sarq $16, %rax
It seems to yield exactly the same results as the offical C version[*],
both for your test case:
$ ./t 0x7AFA8000 0xFFFFFFFF
0x7afa8000 x 0xffffffff =>
C: 0x7fff8506
C_new: 0x7fff8506
asm: 0x7fff8506
... and also for <billions of random inputs>.
Is there something I'm missing...?
[*] Fetched from:
http://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/src/base/ftcalc.c
Thanks,
-Miles
--
Liberty, n. One of imagination's most precious possessions.
- Re: [ft-devel] FT_MulFix assembly, James Cloos, 2010/09/05
- Re: [ft-devel] FT_MulFix assembly, Graham Asher, 2010/09/06
- Re: [ft-devel] FT_MulFix assembly, Miles Bader, 2010/09/06
- Re: [ft-devel] FT_MulFix assembly, Miles Bader, 2010/09/06
- Re: [ft-devel] FT_MulFix assembly, Miles Bader, 2010/09/06
- Re: [ft-devel] FT_MulFix assembly, James Cloos, 2010/09/06
- Re: [ft-devel] FT_MulFix assembly, Miles Bader, 2010/09/06
- Re: [ft-devel] FT_MulFix assembly, James Cloos, 2010/09/07
- Re: [ft-devel] FT_MulFix assembly,
Miles Bader <=
- Re: [ft-devel] FT_MulFix assembly, James Cloos, 2010/09/07
- Re: [ft-devel] FT_MulFix assembly, Miles Bader, 2010/09/07
- Re: [ft-devel] FT_MulFix assembly, James Cloos, 2010/09/18
- Re: [ft-devel] FT_MulFix assembly, Werner LEMBERG, 2010/09/19