summaryrefslogtreecommitdiff
path: root/genpacksizetables.pl
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2005-01-21 22:15:43 +0000
committerNicholas Clark <nick@ccl4.org>2005-01-21 22:15:43 +0000
commit80a13697042a4d823de61ba24b77aa9d893765d6 (patch)
tree4bba6d03fe49b465c41642e0be1d1ce8ec25abf1 /genpacksizetables.pl
parent78d46eaae9d8413e104f494881b97489e46e1fd4 (diff)
downloadperl-80a13697042a4d823de61ba24b77aa9d893765d6.tar.gz
Shrink a switch() statment by driving the size calculations from the
size table. This requires #ifdef()s in the size table initialiser. Astoundingly this shaves over 6K of the object size with -Os on OS X. I was expecting about 1K (due to shrinking a branch table). Mind you, I'm not going to argue with what I got. :-) p4raw-id: //depot/perl@23854
Diffstat (limited to 'genpacksizetables.pl')
-rwxr-xr-xgenpacksizetables.pl35
1 files changed, 25 insertions, 10 deletions
diff --git a/genpacksizetables.pl b/genpacksizetables.pl
index d7dabc7101..334dece2c3 100755
--- a/genpacksizetables.pl
+++ b/genpacksizetables.pl
@@ -7,11 +7,14 @@ use Encode;
my @lines = grep {!/^#/} <DATA>;
sub addline {
- my ($arrays, $chrmap, $letter, $arrayname, $noone, $nocsum, $size) = @_;
+ my ($arrays, $chrmap, $letter, $arrayname, $noone, $nocsum, $size,
+ $condition) = @_;
my $line = "/* $letter */ $size";
$line .= " | PACK_SIZE_CANNOT_ONLY_ONE" if $noone;
$line .= " | PACK_SIZE_CANNOT_CSUM" if $nocsum;
$line .= ",";
+ # And then the hack
+ $line = [$condition, $line] if $condition;
$arrays->{$arrayname}->[ord $chrmap->{$letter}] = $line;
# print ord $chrmap->{$letter}, " $line\n";
}
@@ -21,16 +24,19 @@ sub output_tables {
my $chrmap = shift;
foreach (@_) {
- my ($letter, $shriek, $noone, $nocsum, $size)
- = /^([A-Za-z])(!?)\t(\S*)\t(\S*)\t(.*)/;
+ my ($letter, $shriek, $noone, $nocsum, $size, $condition)
+ = /^([A-Za-z])(!?)\t(\S*)\t(\S*)\t([^\t\n]+)(?:\t+(.*))?$/;
die "Can't parse '$_'" unless $size;
+ if (defined $condition) {
+ $condition = join " && ", map {"defined($_)"} split ' ', $condition;
+ }
unless ($size =~ s/^=//) {
$size = "sizeof($size)";
}
addline (\%arrays, $chrmap, $letter, $shriek ? 'shrieking' : 'normal',
- $noone, $nocsum, $size);
+ $noone, $nocsum, $size, $condition);
}
my %earliest;
@@ -43,10 +49,19 @@ sub output_tables {
# Remove all the empty elements.
splice @$array, 0, $earliest;
print "unsigned char size_${arrayname}[", scalar @$array, "] = {\n";
- my @lines = map {$_ || "0,"} @$array;
+ my @lines;
+ foreach (@$array) {
+ # There is an assumption here that the last entry isn't conditonal
+ if (ref $_) {
+ push @lines, "#if $_->[0]", " $_->[1]", "#else", " 0,", "#endif";
+ } else {
+ push @lines, $_ ? " $_" : " 0,";
+ }
+ }
# remove the last, annoying, comma
- chop $lines[$#lines];
- print " $_\n" foreach @lines;
+ die "Last entry was a conditional: '$lines[$#lines]'"
+ unless $lines[$#lines] =~ s/,$//;
+ print "$_\n" foreach @lines;
print "};\n";
$earliest{$arrayname} = $earliest;
}
@@ -108,9 +123,9 @@ N! =SIZE32
L =SIZE32
p * * char *
w * char
-q Quad_t
-Q Uquad_t
+q Quad_t HAS_QUAD
+Q Uquad_t HAS_QUAD
f float
d double
F =NVSIZE
-D =LONG_DOUBLESIZE
+D =LONG_DOUBLESIZE HAS_LONG_DOUBLE USE_LONG_DOUBLE