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