Blame mpn/x86/t-zdisp2.pl

Packit 5c3484
#!/usr/bin/perl -w
Packit 5c3484
#
Packit 5c3484
# Copyright 2001, 2002 Free Software Foundation, Inc.
Packit 5c3484
#
Packit 5c3484
#  This file is part of the GNU MP Library.
Packit 5c3484
#
Packit 5c3484
#  The GNU MP Library is free software; you can redistribute it and/or modify
Packit 5c3484
#  it under the terms of either:
Packit 5c3484
#
Packit 5c3484
#    * the GNU Lesser General Public License as published by the Free
Packit 5c3484
#      Software Foundation; either version 3 of the License, or (at your
Packit 5c3484
#      option) any later version.
Packit 5c3484
#
Packit 5c3484
#  or
Packit 5c3484
#
Packit 5c3484
#    * the GNU General Public License as published by the Free Software
Packit 5c3484
#      Foundation; either version 2 of the License, or (at your option) any
Packit 5c3484
#      later version.
Packit 5c3484
#
Packit 5c3484
#  or both in parallel, as here.
Packit 5c3484
#
Packit 5c3484
#  The GNU MP Library is distributed in the hope that it will be useful, but
Packit 5c3484
#  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit 5c3484
#  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit 5c3484
#  for more details.
Packit 5c3484
#
Packit 5c3484
#  You should have received copies of the GNU General Public License and the
Packit 5c3484
#  GNU Lesser General Public License along with the GNU MP Library.  If not,
Packit 5c3484
#  see https://www.gnu.org/licenses/.
Packit 5c3484
Packit 5c3484
Packit 5c3484
# Usage: cd $(builddir)/mpn
Packit 5c3484
#        $(srcdir)/x86/t-zdisp2.pl
Packit 5c3484
#
Packit 5c3484
# Grep for any "0(reg...)" addressing modes coming out of the x86 .asm
Packit 5c3484
# files.  Additive expressions like "12+4-16" are recognised too.
Packit 5c3484
#
Packit 5c3484
# Old gas doesn't preserve the "0" displacement, so if it's wanted then
Packit 5c3484
# Zdisp ought to be used to give explicit .byte sequences.  See
Packit 5c3484
# mpn/x86/README.
Packit 5c3484
#
Packit 5c3484
# No output means everything is ok.  All the asm files are put through m4 in
Packit 5c3484
# PIC and non-PIC modes, and in each multi-function form, all of which can
Packit 5c3484
# take a while to run.
Packit 5c3484
#
Packit 5c3484
# This program is only meant for use during development.
Packit 5c3484
Packit 5c3484
use strict;
Packit 5c3484
use File::Find;
Packit 5c3484
use File::Basename;
Packit 5c3484
use Getopt::Std;
Packit 5c3484
Packit 5c3484
my %opt;
Packit 5c3484
getopts('t', \%opt);
Packit 5c3484
Packit 5c3484
Packit 5c3484
my $srcdir;
Packit 5c3484
open IN, '
Packit 5c3484
while (<IN>) {
Packit 5c3484
  if (/^srcdir[ \t]*=[ \t]*(.*)/) {
Packit 5c3484
    $srcdir = $1;
Packit 5c3484
    last;
Packit 5c3484
  }
Packit 5c3484
}
Packit 5c3484
close IN or die;
Packit 5c3484
defined $srcdir or die "Cannot find \$srcdir in Makefile\n";
Packit 5c3484
Packit 5c3484
my $filecount = 0;
Packit 5c3484
Packit 5c3484
my $tempfile = 't-zdisp2.tmp';
Packit 5c3484
open KARA, ">$tempfile" or die;
Packit 5c3484
close KARA or die;
Packit 5c3484
Packit 5c3484
find({ wanted => \&process, preprocess => \&process_mparam, no_chdir => 1 },
Packit 5c3484
     "$srcdir/x86");
Packit 5c3484
Packit 5c3484
sub process {
Packit 5c3484
  if (/gmp-mparam.h$/) {
Packit 5c3484
    process_mparam($_);
Packit 5c3484
  } elsif (/\.asm$/) {
Packit 5c3484
    process_asm($_);
Packit 5c3484
  }
Packit 5c3484
}
Packit 5c3484
Packit 5c3484
# Ensure we're using the right SQR_TOOM2_THRESHOLD for the part of the
Packit 5c3484
# tree being processed.
Packit 5c3484
sub process_mparam {
Packit 5c3484
  my $file = "$File::Find::dir/gmp-mparam.h";
Packit 5c3484
  if (-f $file) {
Packit 5c3484
    print "$file\n" if $opt{'t'};
Packit 5c3484
    open MPARAM, "<$file" or die;
Packit 5c3484
    while (<MPARAM>) {
Packit 5c3484
      if (/^#define SQR_TOOM2_THRESHOLD[ \t]*([0-9][0-9]*)/) {
Packit 5c3484
        open KARA, ">$tempfile" or die;
Packit 5c3484
        print KARA "define(\`SQR_TOOM2_THRESHOLD',$1)\n\n";
Packit 5c3484
        print "define(\`SQR_TOOM2_THRESHOLD',$1)\n" if $opt{'t'};
Packit 5c3484
        close KARA or die;
Packit 5c3484
        last;
Packit 5c3484
      }
Packit 5c3484
    }
Packit 5c3484
    close MPARAM or die;
Packit 5c3484
  }
Packit 5c3484
  return @_;
Packit 5c3484
}
Packit 5c3484
Packit 5c3484
sub process_asm {
Packit 5c3484
  my ($file) = @_;
Packit 5c3484
  my $base = basename ($file, '.asm');
Packit 5c3484
Packit 5c3484
  my @funs;
Packit 5c3484
  if    ($base eq 'aors_n')    { @funs = qw(add_n sub_n); }
Packit 5c3484
  elsif ($base eq 'aorsmul_1') { @funs = qw(addmul_1 submul_1); }
Packit 5c3484
  elsif ($base eq 'popham')    { @funs = qw(popcount hamdist); }
Packit 5c3484
  elsif ($base eq 'logops_n')  { @funs = qw(and_n andn_n nand_n ior_n iorn_n nior_n xor_n xnor_n); }
Packit 5c3484
  elsif ($base eq 'lorrshift') { @funs = qw(lshift rshift); }
Packit 5c3484
  else                         { @funs = ($base); }
Packit 5c3484
Packit 5c3484
  foreach my $fun (@funs) {
Packit 5c3484
    foreach my $pic ('', ' -DPIC') {
Packit 5c3484
      my $header = "$file: 0: $pic\n";
Packit 5c3484
      $filecount++;
Packit 5c3484
Packit 5c3484
      my $m4 = "m4 -DHAVE_HOST_CPU_athlon -DOPERATION_$fun $pic ../config.m4 $tempfile $file";
Packit 5c3484
      print "$m4\n" if $opt{'t'};
Packit 5c3484
Packit 5c3484
      open IN, "$m4 |" or die;
Packit 5c3484
      while (<IN>) {
Packit 5c3484
        next unless /([0-9+-][0-9 \t+-]*)\(%/;
Packit 5c3484
        my $pat=$1;
Packit 5c3484
        $pat = eval($pat);
Packit 5c3484
        next if ($pat != 0);
Packit 5c3484
        print "$header$_";
Packit 5c3484
        $header='';
Packit 5c3484
      }
Packit 5c3484
      close IN or die;
Packit 5c3484
    }
Packit 5c3484
  }
Packit 5c3484
}
Packit 5c3484
Packit 5c3484
unlink($tempfile);
Packit 5c3484
print "total $filecount processed\n";
Packit 5c3484
exit 0;
Packit 5c3484
Packit 5c3484
Packit 5c3484
# Local variables:
Packit 5c3484
# perl-indent-level: 2
Packit 5c3484
# End: