emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: VIRT_ADDR_VARIES


From: Paul Eggert
Subject: Re: VIRT_ADDR_VARIES
Date: Thu, 10 Nov 2011 08:19:44 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0) Gecko/20110927 Thunderbird/7.0

On 11/10/11 01:29, Andreas Schwab wrote:
>> +  ((uintptr_t) XPNTR (obj) - (uintptr_t) pure <= PURESIZE)
> 
> There is no need for obfuscation, the compiler should find that out by
> itself.

Perhaps it should, but it typically doesn't.  For example, given this:

        #include <inttypes.h>
        #include <stddef.h>
        #define TYPEMASK 7
        #define XPNTR(a) ((a) & ~TYPEMASK)
        #define PURESIZE 1000000

        extern long pure[];

        #define PURE_P1(obj) \
          ((char *) pure <= (char *) XPNTR (obj) \
           && (char *) XPNTR (obj) < (char *) pure + PURESIZE)

        #define PURE_P2(obj) \
          ((uintptr_t) XPNTR (obj) - (uintptr_t) pure <= PURESIZE)

        int pure1 (intptr_t obj) { return PURE_P1 (obj); }
        int pure2 (intptr_t obj) { return PURE_P2 (obj); }

gcc -O2 (x86-64, GCC 4.6.2) generates this for the comparisons of PURE_P1:

                xorl    %eax, %eax
                cmpq    $pure, %rdi
                jb      .L2
                xorl    %eax, %eax
                cmpq    $pure+1000000, %rdi
                setb    %al
        .L2:    rep

and this for PURE_P2:

                xorl    %eax, %eax
                subq    $pure, %rdi
                cmpq    $1000000, %rdi
                setbe   %al

The PURE_P1 version has more instructions, and has a conditional jump.
The PURE_P2 version is nearly as fast as the old code without
VIRT_ADDR_VARIES.  I observed similar savings with the other
compilers I tried (Sun C 5.11 sparcv9 cc -xO4, clang 2.8 x86-64 -O2).
So we should go with PURE_P2.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]