OLD | NEW |
| (Empty) |
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 3 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. If not, see http://www.gnu.org/licenses/. | |
19 | |
20 | |
21 # Usage: cd $(builddir)/mpn | |
22 # $(srcdir)/x86/t-zdisp2.pl | |
23 # | |
24 # Grep for any "0(reg...)" addressing modes coming out of the x86 .asm | |
25 # files. Additive expressions like "12+4-16" are recognised too. | |
26 # | |
27 # Old gas doesn't preserve the "0" displacement, so if it's wanted then | |
28 # Zdisp ought to be used to give explicit .byte sequences. See | |
29 # mpn/x86/README. | |
30 # | |
31 # No output means everything is ok. All the asm files are put through m4 in | |
32 # PIC and non-PIC modes, and in each multi-function form, all of which can | |
33 # take a while to run. | |
34 # | |
35 # This program is only meant for use during development. | |
36 | |
37 use strict; | |
38 use File::Find; | |
39 use File::Basename; | |
40 use Getopt::Std; | |
41 | |
42 my %opt; | |
43 getopts('t', \%opt); | |
44 | |
45 | |
46 my $srcdir; | |
47 open IN, '<Makefile' or die; | |
48 while (<IN>) { | |
49 if (/^srcdir[ \t]*=[ \t]*(.*)/) { | |
50 $srcdir = $1; | |
51 last; | |
52 } | |
53 } | |
54 close IN or die; | |
55 defined $srcdir or die "Cannot find \$srcdir in Makefile\n"; | |
56 | |
57 my $filecount = 0; | |
58 | |
59 my $tempfile = 't-zdisp2.tmp'; | |
60 open KARA, ">$tempfile" or die; | |
61 close KARA or die; | |
62 | |
63 find({ wanted => \&process, preprocess => \&process_mparam, no_chdir => 1 }, | |
64 "$srcdir/x86"); | |
65 | |
66 sub process { | |
67 if (/gmp-mparam.h$/) { | |
68 process_mparam($_); | |
69 } elsif (/\.asm$/) { | |
70 process_asm($_); | |
71 } | |
72 } | |
73 | |
74 # Ensure we're using the right SQR_KARATSUBA_THRESHOLD for the part of the | |
75 # tree being processed. | |
76 sub process_mparam { | |
77 my $file = "$File::Find::dir/gmp-mparam.h"; | |
78 if (-f $file) { | |
79 print "$file\n" if $opt{'t'}; | |
80 open MPARAM, "<$file" or die; | |
81 while (<MPARAM>) { | |
82 if (/^#define SQR_KARATSUBA_THRESHOLD[ \t]*([0-9][0-9]*)/) { | |
83 open KARA, ">$tempfile" or die; | |
84 print KARA "define(\`SQR_KARATSUBA_THRESHOLD',$1)\n\n"; | |
85 print "define(\`SQR_KARATSUBA_THRESHOLD',$1)\n" if $opt{'t'}; | |
86 close KARA or die; | |
87 last; | |
88 } | |
89 } | |
90 close MPARAM or die; | |
91 } | |
92 return @_; | |
93 } | |
94 | |
95 sub process_asm { | |
96 my ($file) = @_; | |
97 my $base = basename ($file, '.asm'); | |
98 | |
99 my @funs; | |
100 if ($base eq 'aors_n') { @funs = qw(add_n sub_n); } | |
101 elsif ($base eq 'aorsmul_1') { @funs = qw(addmul_1 submul_1); } | |
102 elsif ($base eq 'popham') { @funs = qw(popcount hamdist); } | |
103 elsif ($base eq 'logops_n') { @funs = qw(and_n andn_n nand_n ior_n iorn_n nio
r_n xor_n xnor_n); } | |
104 elsif ($base eq 'lorrshift') { @funs = qw(lshift rshift); } | |
105 else { @funs = ($base); } | |
106 | |
107 foreach my $fun (@funs) { | |
108 foreach my $pic ('', ' -DPIC') { | |
109 my $header = "$file: 0: $pic\n"; | |
110 $filecount++; | |
111 | |
112 my $m4 = "m4 -DHAVE_HOST_CPU_athlon -DOPERATION_$fun $pic ../config.m4 $te
mpfile $file"; | |
113 print "$m4\n" if $opt{'t'}; | |
114 | |
115 open IN, "$m4 |" or die; | |
116 while (<IN>) { | |
117 next unless /([0-9+-][0-9 \t+-]*)\(%/; | |
118 my $pat=$1; | |
119 $pat = eval($pat); | |
120 next if ($pat != 0); | |
121 print "$header$_"; | |
122 $header=''; | |
123 } | |
124 close IN or die; | |
125 } | |
126 } | |
127 } | |
128 | |
129 unlink($tempfile); | |
130 print "total $filecount processed\n"; | |
131 exit 0; | |
132 | |
133 | |
134 # Local variables: | |
135 # perl-indent-level: 2 | |
136 # End: | |
OLD | NEW |