summaryrefslogtreecommitdiff
path: root/generate_uudmap.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2009-05-20 08:30:48 +0200
committerNicholas Clark <nick@ccl4.org>2009-05-20 10:50:04 +0200
commitefa50c51e3301a2ca8be765fedfdae78eff1615b (patch)
treeef032fdb284883023b030a999bb925240c7d24be /generate_uudmap.c
parent869053c868a03539389422a7a28502818825a940 (diff)
downloadperl-efa50c51e3301a2ca8be765fedfdae78eff1615b.tar.gz
Replace run-time on-demand initialisation of PL_bitcount with a constant table.
(The table is 256 bytes; the run-time initialisation code is larger than this!) Adapt generate_uudmap.c to generate the initalisation block for PL_bitcount, writing the code to bitcount.h, using the same approach as uudmap.h. To preserve binary compatibility: for MULTIPLICITY: keep Ibitcount in the interpreter structure, but remove all the macros that access it. PL_bitcount is a new symbol in the object file, which won't clash with anything as that name wasn't used before. otherwise: keep PL_bitcount as a char *, but initialise it at compile time to a new constant array PL_bitcount array. Remove the code that attempts to Safefree() it at interpreter destruction time.
Diffstat (limited to 'generate_uudmap.c')
-rw-r--r--generate_uudmap.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/generate_uudmap.c b/generate_uudmap.c
index 27b142a64c..2c3e24a267 100644
--- a/generate_uudmap.c
+++ b/generate_uudmap.c
@@ -1,3 +1,8 @@
+/* Originally this program just generated uudmap.h
+ However, when we later wanted to generate bitcount.h, it was easier to
+ refactor it and keep the same name, than either alternative - rename it,
+ or duplicate all of the Makefile logic for a second program. */
+
#include <stdio.h>
#include <stdlib.h>
/* If it turns out that we need to make this conditional on config.sh derived
@@ -45,12 +50,14 @@ typedef unsigned char U8;
/* This will ensure it is all zeros. */
static char PL_uudmap[256];
+static char PL_bitcount[256];
int main(int argc, char **argv) {
size_t i;
+ int bits;
- if (argc < 2 || argv[1][0] == '\0') {
- fprintf(stderr, "Usage: %s uudemap.h\n", argv[0]);
+ if (argc < 3 || argv[1][0] == '\0' || argv[2][0] == '\0') {
+ fprintf(stderr, "Usage: %s uudemap.h bitcount.h\n", argv[0]);
return 1;
}
@@ -64,6 +71,19 @@ int main(int argc, char **argv) {
output_block_to_file(argv[0], argv[1], PL_uudmap, sizeof(PL_uudmap));
+ for (bits = 1; bits < 256; bits++) {
+ if (bits & 1) PL_bitcount[bits]++;
+ if (bits & 2) PL_bitcount[bits]++;
+ if (bits & 4) PL_bitcount[bits]++;
+ if (bits & 8) PL_bitcount[bits]++;
+ if (bits & 16) PL_bitcount[bits]++;
+ if (bits & 32) PL_bitcount[bits]++;
+ if (bits & 64) PL_bitcount[bits]++;
+ if (bits & 128) PL_bitcount[bits]++;
+ }
+
+ output_block_to_file(argv[0], argv[2], PL_bitcount, sizeof(PL_bitcount));
+
return 0;
}