[cairo] _cairo_color_compute_shorts fails with FPU set to
single precision
Behdad Esfahbod
behdad at behdad.org
Wed Aug 30 01:08:27 PDT 2006
On Wed, 2006-08-30 at 09:56 +0200, Alexander Larsson wrote:
> On Wed, 2006-08-30 at 03:45 -0400, Behdad Esfahbod wrote:
>
> > Or better yet, use what Ali suggests. Or even without a branch:
> >
> > int32_t i;
> > i = f * 65536.0;
> > i -= i == 65536;
>
> Are you sure this doesn't generate a branch in the assembly? It might be
> able to use a cmov to avoid it, but maybe not.
It's using the comparison result in the subtract AFAIU:
convert:
pushl %ebp
xorl %edx, %edx
movl %esp, %ebp
subl $8, %esp
fnstcw -2(%ebp)
flds .LC0
fmull 8(%ebp)
movzwl -2(%ebp), %eax
movb $12, %ah
movw %ax, -4(%ebp)
fldcw -4(%ebp)
fistpl -8(%ebp)
fldcw -2(%ebp)
movl -8(%ebp), %eax
leave
cmpl $65536, %eax
sete %dl
subl %edx, %eax
ret
(gcc -O2)
int
convert (double d)
{
int i;
i = d * 65536.0;
i -= i == 65536;
return i;
}
Carl, while you are at it, it may be good to think about what to do
about NANs in color computations. Catching NAN in all color entry
points for example if we're not doing already.
--
behdad
http://behdad.org/
"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
-- Dan Bern, "New American Language"
More information about the cairo
mailing list