develooper Front page | perl.perl5.porters | Postings from March 2008

[patch] optimize IS_NUM_COMPARE

From:
Jim Cromie
Date:
March 17, 2008 08:06
Subject:
[patch] optimize IS_NUM_COMPARE
Message ID:
47DE88DA.1070102@gmail.com

heres a re-spin of a micro-optimization of the OP_IS_NUMCOMPARE
macro defined and used in op.c:Perl_ck_bitop.
Patch is on top of diff.opcode-comments I sent yesterday.

patch generates the macro-def in opcode.pl, and writes
it to opnames.h, as is already done with 3 other OP_IS_* macros.

Curiously, this doesnt shrink the object built with gcc -O2,
so I built with -O0 too.  Objdump output gives some insight
into (one aspect of) gcc's optimizer.

IOW, patch makes us (very slightly) less dependent upon
the compiler's optimization.


[jimc@harpo op-is-num]$ size {.,../blead}/op.o
   text    data     bss     dec     hex filename
 126390       0       0  126390   1edb6 ./op.o
 126390       0       0  126390   1edb6 ../blead/op.o




objdump of patched code

    {
        const OP * const left = cBINOPo->op_first;
        const OP * const right = left->op_sibling;
     797:       8b 4a 04                mov    0x4(%edx),%ecx
        if ((OP_IS_NUMCOMPARE(left->op_type) &&
     79a:       66 05 ba 01             add    $0x1ba,%ax
     79e:       66 25 ff 01             and    $0x1ff,%ax
     7a2:       66 83 f8 0d             cmp    $0xd,%ax
     7a6:       77 06                   ja     7ae <Perl_ck_bitop+0x6e>
     7a8:       f6 42 12 08             testb  $0x8,0x12(%edx)
     7ac:       74 18                   je     7c6 <Perl_ck_bitop+0x86>
     7ae:       0f b7 41 10             movzwl 0x10(%ecx),%eax
     7b2:       66 05 ba 01             add    $0x1ba,%ax
     7b6:       66 25 ff 01             and    $0x1ff,%ax
     7ba:       66 83 f8 0d             cmp    $0xd,%ax
     7be:       77 c0                   ja     780 <Perl_ck_bitop+0x40>
     7c0:       f6 41 12 08             testb  $0x8,0x12(%ecx)
     7c4:       75 ba                   jne    780 <Perl_ck_bitop+0x40>
                (left->op_flags & OPf_PARENS) == 0) ||


objdump of blead code, compiled w gcc -O2

     797:       8b 4a 04                mov    0x4(%edx),%ecx
        if ((OP_IS_NUMCOMPARE(left->op_type) &&
     79a:       66 25 ff 01             and    $0x1ff,%ax
     79e:       83 e8 46                sub    $0x46,%eax
     7a1:       66 83 f8 0d             cmp    $0xd,%ax
     7a5:       77 06                   ja     7ad <Perl_ck_bitop+0x6d>
     7a7:       f6 42 12 08             testb  $0x8,0x12(%edx)
     7ab:       74 17                   je     7c4 <Perl_ck_bitop+0x84>
     7ad:       0f b7 41 10             movzwl 0x10(%ecx),%eax
     7b1:       66 25 ff 01             and    $0x1ff,%ax
     7b5:       83 e8 46                sub    $0x46,%eax
     7b8:       66 83 f8 0d             cmp    $0xd,%ax
     7bc:       77 c2                   ja     780 <Perl_ck_bitop+0x40>
     7be:       f6 41 12 08             testb  $0x8,0x12(%ecx)
     7c2:       75 bc                   jne    780 <Perl_ck_bitop+0x40>
                (left->op_flags & OPf_PARENS) == 0) ||


object with gcc -O0

        if ((OP_IS_NUMCOMPARE(left->op_type) &&
   15c97:       8b 45 f8                mov    -0x8(%ebp),%eax
   15c9a:       0f b7 40 10             movzwl 0x10(%eax),%eax
   15c9e:       66 25 ff 01             and    $0x1ff,%ax
   15ca2:       66 83 f8 46             cmp    $0x46,%ax
   15ca6:       0f 84 f1 00 00 00       je     15d9d <Perl_ck_bitop+0x1a4>
   15cac:       8b 45 f8                mov    -0x8(%ebp),%eax
   15caf:       0f b7 40 10             movzwl 0x10(%eax),%eax
   15cb3:       66 25 ff 01             and    $0x1ff,%ax
   15cb7:       66 83 f8 47             cmp    $0x47,%ax
   15cbb:       0f 84 dc 00 00 00       je     15d9d <Perl_ck_bitop+0x1a4>
   15cc1:       8b 45 f8                mov    -0x8(%ebp),%eax
   15cc4:       0f b7 40 10             movzwl 0x10(%eax),%eax
   15cc8:       66 25 ff 01             and    $0x1ff,%ax
   15ccc:       66 83 f8 48             cmp    $0x48,%ax
   15cd0:       0f 84 c7 00 00 00       je     15d9d <Perl_ck_bitop+0x1a4>
   15cd6:       8b 45 f8                mov    -0x8(%ebp),%eax
   15cd9:       0f b7 40 10             movzwl 0x10(%eax),%eax
   15cdd:       66 25 ff 01             and    $0x1ff,%ax
   15ce1:       66 83 f8 49             cmp    $0x49,%ax
   15ce5:       0f 84 b2 00 00 00       je     15d9d <Perl_ck_bitop+0x1a4>
   15ceb:       8b 45 f8                mov    -0x8(%ebp),%eax
   15cee:       0f b7 40 10             movzwl 0x10(%eax),%eax
   15cf2:       66 25 ff 01             and    $0x1ff,%ax
   15cf6:       66 83 f8 4a             cmp    $0x4a,%ax
   15cfa:       0f 84 9d 00 00 00       je     15d9d <Perl_ck_bitop+0x1a4>
   15d00:       8b 45 f8                mov    -0x8(%ebp),%eax
   15d03:       0f b7 40 10             movzwl 0x10(%eax),%eax
   15d07:       66 25 ff 01             and    $0x1ff,%ax
   15d0b:       66 83 f8 4b             cmp    $0x4b,%ax
   15d0f:       0f 84 88 00 00 00       je     15d9d <Perl_ck_bitop+0x1a4>
   15d15:       8b 45 f8                mov    -0x8(%ebp),%eax
   15d18:       0f b7 40 10             movzwl 0x10(%eax),%eax
   15d1c:       66 25 ff 01             and    $0x1ff,%ax
   15d20:       66 83 f8 4c             cmp    $0x4c,%ax
   15d24:       74 77                   je     15d9d <Perl_ck_bitop+0x1a4>
   15d26:       8b 45 f8                mov    -0x8(%ebp),%eax
   15d29:       0f b7 40 10             movzwl 0x10(%eax),%eax
   15d2d:       66 25 ff 01             and    $0x1ff,%ax
   15d31:       66 83 f8 4d             cmp    $0x4d,%ax
   15d35:       74 66                   je     15d9d <Perl_ck_bitop+0x1a4>
   15d37:       8b 45 f8                mov    -0x8(%ebp),%eax
   15d3a:       0f b7 40 10             movzwl 0x10(%eax),%eax
   15d3e:       66 25 ff 01             and    $0x1ff,%ax
   15d42:       66 83 f8 4e             cmp    $0x4e,%ax
   15d46:       74 55                   je     15d9d <Perl_ck_bitop+0x1a4>
   15d48:       8b 45 f8                mov    -0x8(%ebp),%eax
   15d4b:       0f b7 40 10             movzwl 0x10(%eax),%eax
   15d4f:       66 25 ff 01             and    $0x1ff,%ax
   15d53:       66 83 f8 4f             cmp    $0x4f,%ax
   15d57:       74 44                   je     15d9d <Perl_ck_bitop+0x1a4>
   15d59:       8b 45 f8                mov    -0x8(%ebp),%eax
...





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About