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