[BACK]Return to t-zdisp2.pl CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpn / x86

Annotation of OpenXM_contrib/gmp/mpn/x86/t-zdisp2.pl, Revision 1.1.1.1

1.1       ohara       1: #!/usr/bin/perl -w
                      2: #
                      3: # Copyright 2001, 2002 Free Software Foundation, Inc.
                      4: #
                      5: # This file is part of the GNU MP Library.
                      6: #
                      7: # The GNU MP Library is free software; you can redistribute it and/or modify
                      8: # it under the terms of the GNU Lesser General Public License as published
                      9: # by the Free Software Foundation; either version 2.1 of the License, or (at
                     10: # your option) any later version.
                     11: #
                     12: # The GNU MP Library is distributed in the hope that it will be useful, but
                     13: # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     14: # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
                     15: # License for more details.
                     16: #
                     17: # You should have received a copy of the GNU Lesser General Public License
                     18: # along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
                     19: # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     20: # MA 02111-1307, USA.
                     21:
                     22:
                     23: # Usage: cd $(builddir)/mpn
                     24: #        $(srcdir)/x86/t-zdisp2.pl
                     25: #
                     26: # Grep for any "0(reg...)" addressing modes coming out of the x86 .asm
                     27: # files.  Additive expressions like "12+4-16" are recognised too.
                     28: #
                     29: # Old gas doesn't preserve the "0" displacement, so if it's wanted then
                     30: # Zdisp ought to be used to give explicit .byte sequences.  See
                     31: # mpn/x86/README.
                     32: #
                     33: # No output means everything is ok.  All the asm files are put through m4 in
                     34: # PIC and non-PIC modes, and in each multi-function form, all of which can
                     35: # take a while to run.
                     36: #
                     37: # This program is only meant for use during development.
                     38:
                     39: use strict;
                     40: use File::Find;
                     41: use File::Basename;
                     42: use Getopt::Std;
                     43:
                     44: my %opt;
                     45: getopts('t', \%opt);
                     46:
                     47:
                     48: my $srcdir;
                     49: open IN, '<Makefile' or die;
                     50: while (<IN>) {
                     51:   if (/^srcdir[ \t]*=[ \t]*(.*)/) {
                     52:     $srcdir = $1;
                     53:     last;
                     54:   }
                     55: }
                     56: close IN or die;
                     57: defined $srcdir or die "Cannot find \$srcdir in Makefile\n";
                     58:
                     59: my $filecount = 0;
                     60:
                     61: my $tempfile = 't-zdisp2.tmp';
                     62: open KARA, ">$tempfile" or die;
                     63: close KARA or die;
                     64:
                     65: find({ wanted => \&process, preprocess => \&process_mparam, no_chdir => 1 },
                     66:      "$srcdir/x86");
                     67:
                     68: sub process {
                     69:   if (/gmp-mparam.h$/) {
                     70:     process_mparam($_);
                     71:   } elsif (/\.asm$/) {
                     72:     process_asm($_);
                     73:   }
                     74: }
                     75:
                     76: # Ensure we're using the right SQR_KARATSUBA_THRESHOLD for the part of the
                     77: # tree being processed.
                     78: sub process_mparam {
                     79:   my $file = "$File::Find::dir/gmp-mparam.h";
                     80:   if (-f $file) {
                     81:     print "$file\n" if $opt{'t'};
                     82:     open MPARAM, "<$file" or die;
                     83:     while (<MPARAM>) {
                     84:       if (/^#define SQR_KARATSUBA_THRESHOLD[ \t]*([0-9][0-9]*)/) {
                     85:         open KARA, ">$tempfile" or die;
                     86:         print KARA "define(\`SQR_KARATSUBA_THRESHOLD',$1)\n\n";
                     87:         print "define(\`SQR_KARATSUBA_THRESHOLD',$1)\n" if $opt{'t'};
                     88:         close KARA or die;
                     89:         last;
                     90:       }
                     91:     }
                     92:     close MPARAM or die;
                     93:   }
                     94:   return @_;
                     95: }
                     96:
                     97: sub process_asm {
                     98:   my ($file) = @_;
                     99:   my $base = basename ($file, '.asm');
                    100:
                    101:   my @funs;
                    102:   if    ($base eq 'aors_n')    { @funs = qw(add_n sub_n); }
                    103:   elsif ($base eq 'aorsmul_1') { @funs = qw(addmul_1 submul_1); }
                    104:   elsif ($base eq 'popham')    { @funs = qw(popcount hamdist); }
                    105:   elsif ($base eq 'logops_n')  { @funs = qw(and_n andn_n nand_n ior_n iorn_n nior_n xor_n xnor_n); }
                    106:   elsif ($base eq 'lorrshift') { @funs = qw(lshift rshift); }
                    107:   else                         { @funs = ($base); }
                    108:
                    109:   foreach my $fun (@funs) {
                    110:     foreach my $pic ('', ' -DPIC') {
                    111:       my $header = "$file: 0: $pic\n";
                    112:       $filecount++;
                    113:
                    114:       my $m4 = "m4 -DHAVE_HOST_CPU_athlon -DOPERATION_$fun $pic ../config.m4 $tempfile $file";
                    115:       print "$m4\n" if $opt{'t'};
                    116:
                    117:       open IN, "$m4 |" or die;
                    118:       while (<IN>) {
                    119:         next unless /([0-9+-][0-9 \t+-]*)\(%/;
                    120:         my $pat=$1;
                    121:         $pat = eval($pat);
                    122:         next if ($pat != 0);
                    123:         print "$header$_";
                    124:         $header='';
                    125:       }
                    126:       close IN or die;
                    127:     }
                    128:   }
                    129: }
                    130:
                    131: unlink($tempfile);
                    132: print "total $filecount processed\n";
                    133: exit 0;
                    134:
                    135:
                    136: # Local variables:
                    137: # perl-indent-level: 2
                    138: # End:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>