[cairo] [patch] Accelerate CAIRO_BITSWAP8 on 64 bit machines

Petr Kobalíček kobalicek.petr at gmail.com
Tue May 29 03:31:34 PDT 2012


Hi Xing,

there is nothing to verify, sizeof(long) varies across operating
systems / platforms, so please never make assumption that sizeof(long)
== sizeof(void*); it's wrong and it caused a lot of bugs in software.

Under 64-bit windows, sizeof(long) is always 4.

You can use sizeof(void*) or, which is better,
sizeof(intptr_t/uintptr_t) as suggested in earlier post. It's also
possible to write the macro without #if conditional, but it will be
probably harder to read.

Best regards
Petr Kobalicek

On Tue, May 29, 2012 at 11:37 AM, Xing, Dongsheng
<dongsheng.xing at intel.com> wrote:
>> > From: Chris Wilson
>> > Sent: Tuesday, May 29, 2012 3:25 PM
>> > To: Xing, Dongsheng; cairo at cairographics.org
>> > Subject: Re: [cairo] [patch] Accelerate CAIRO_BITSWAP8 on 64 bit
>> > machines
>> >
>> > > On Tue, 29 May 2012 02:03:58 +0000, "Xing, Dongsheng" wrote:
>> > > > Hi, CAIRO_BITSWAP8 costs seven operations on a 32 bit machine,
>> > > > but it can be done with only four operations on 64 bit machines.
>> > > > This patch accelerates CAIRO_BITSWAP8 on 64 bit machines.
>> > >
>> > > This doesn't apply to master. Care to resend?
>>
>> It justs means that the parent of this patch is not known upstream and by my repository so git can not reconstruct the right patch for me.
>> > > A more appropriate test here would be that "SIZEOF_LONG_LONG >= 8" as that is the condition used in the macro.
>>
>> > I think SIZEOF_LONG >= 8 is better. Because sizeof(long long)==8 on a 32 bit machine. And SIZEOF_LONG is the length of a native processor word.
>> Ok, if we can use SIZEOF_LONG here, wouuld 0x80200802LU suffice?
>> -Chris
>
> Sorry. My last email is interpreted WRONG by the mail server. Hence I send the mail again.
>
> To Chris: Yes, 0x80200802LU is suffice. The patch has been modified accordingly. The patch is now known upstream.
>
> To Zhigang: I am installing Visual Studio Express 2011 64bits on Windows. I will verify whether sizeof(long)==4 on Windows 64.
>
> Best regards,
> Dongsheng
>
> Signed-off-by: Dongsheng Xing <dongsheng.xing at intel.com>
> ---
>  src/cairoint.h |    4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/src/cairoint.h b/src/cairoint.h index 2c9f2dd..96e2c1f 100644
> --- a/src/cairoint.h
> +++ b/src/cairoint.h
> @@ -169,7 +169,11 @@ do {                                       \
>  * Devised by Sean Anderson, July 13, 2001.
>  * Source: http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits
>  */
> +#if (SIZEOF_LONG >= 8)
> +#define CAIRO_BITSWAP8(c) ((((c) * 0x80200802LU & 0x884422110LU) *
> +0x101010101LU) >> 32) #else
>  #define CAIRO_BITSWAP8(c) ((((c) * 0x0802LU & 0x22110LU) | ((c) * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16)
> +#endif
>
>  /* Return the number of 1 bits in mask.
>  *
> --
> 1.7.9.5
>
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list