shithub: sl

Download patch

ref: f2a60067b610cdc82921bcfa4e0a6f198af7497e
parent: bdf4d3fe2762e73039908cf7504acc0578d0a697
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Jan 22 16:56:57 EST 2025

smaller binaries by #if-ing the unused stuff

--- a/3rd/mp/mp.h
+++ b/3rd/mp/mp.h
@@ -24,8 +24,6 @@
 #define mpdighi  (((mpdigit)1)<<(Dbits-1))
 #define DIGITS(x) ((int)(x) >= -(Dbits-1) ? ((Dbits - 1 + (x))/Dbits) : 0)
 
-extern	int	dec16(uint8_t*, int, char*, int);
-extern	int	enc16(char*, int, uint8_t*, int);
 extern	mpdigit	dec16chr(int) fl_constfn;
 extern	int	enc16chr(int) fl_constfn;
 
--- a/3rd/mp/mpaux.c
+++ b/3rd/mp/mpaux.c
@@ -184,6 +184,7 @@
 	return 0;
 }
 
+#if 0 // UNUSED
 // k, where n = 2**k * q for odd q
 uint32_t
 mplowbits0(mpint *n)
@@ -212,3 +213,4 @@
 	}
 	return k;
 }
+#endif
--- a/3rd/mp/u16.c
+++ b/3rd/mp/u16.c
@@ -23,47 +23,3 @@
 	o |= between(c, 'a', 'f') & (1+10+(c-'a'));
 	return o-1;
 }
-
-int
-dec16(uint8_t *out, int lim, char *in, int n)
-{
-	int c, w = 0, i = 0;
-	uint8_t *start = out;
-	uint8_t *eout = out + lim;
-
-	while(n-- > 0){
-		c = dec16chr(*in++);
-		if(c < 0)
-			continue;
-		w = (w<<4) + c;
-		i++;
-		if(i == 2){
-			if(out + 1 > eout)
-				goto exhausted;
-			*out++ = w;
-			w = 0;
-			i = 0;
-		}
-	}
-exhausted:
-	return out - start;
-}
-
-int
-enc16(char *out, int lim, uint8_t *in, int n)
-{
-	uint32_t c;
-	char *eout = out + lim;
-	char *start = out;
-
-	while(n-- > 0){
-		c = *in++;
-		if(out + 2 >= eout)
-			goto exhausted;
-		*out++ = enc16chr(c>>4);
-		*out++ = enc16chr(c&15);
-	}
-exhausted:
-	*out = 0;
-	return out - start;
-}
--- a/3rd/mt19937-64.c
+++ b/3rd/mt19937-64.c
@@ -153,13 +153,6 @@
 	return result;
 }
 
-/* generates a random number on [0, 2^63-1]-interval */
-long long
-genrand64_int63(mt19937_64 *context)
-{
-    return (long long)(genrand64_int64(context) >> 1);
-}
-
 /* generates a random number on [0,1]-real-interval */
 double
 genrand64_real1(mt19937_64 *context)
@@ -167,6 +160,7 @@
     return (genrand64_int64(context) >> 11) * (1.0/9007199254740991.0);
 }
 
+#if 0 // UNUSED
 /* generates a random number on [0,1)-real-interval */
 double
 genrand64_real2(mt19937_64 *context)
@@ -180,3 +174,11 @@
 {
 	return ((genrand64_int64(context) >> 12) + 0.5) * (1.0/4503599627370496.0);
 }
+
+/* generates a random number on [0, 2^63-1]-interval */
+long long
+genrand64_int63(mt19937_64 *context)
+{
+    return (long long)(genrand64_int64(context) >> 1);
+}
+#endif
--- a/3rd/tbl.c
+++ b/3rd/tbl.c
@@ -7,6 +7,8 @@
 #include "platform.h"
 #include "tbl.h"
 
+#if 0 // UNUSED
+
 void *
 Tgetl(Tbl *tbl, const char *key, size_t len)
 {
@@ -28,6 +30,21 @@
 }
 
 Tbl *
+Tdel(Tbl *tbl, const char *key)
+{
+	return Tdell(tbl, key, strlen(key));
+}
+
+const char *
+Tnxt(Tbl *tbl, const char *key)
+{
+	void *value = nil;
+	Tnext(tbl, &key, &value);
+	return key;
+}
+#endif
+
+Tbl *
 Tdell(Tbl *tbl, const char *key, size_t len)
 {
 	const char *rkey = nil;
@@ -35,23 +52,9 @@
 	return Tdelkv(tbl, key, len, &rkey, &rval);
 }
 
-Tbl *
-Tdel(Tbl *tbl, const char *key)
-{
-	return Tdell(tbl, key, strlen(key));
-}
-
 bool
 Tnext(Tbl *tbl, const char **pkey, void **pvalue)
 {
 	size_t len = *pkey == nil ? 0 : strlen(*pkey);
 	return Tnextl(tbl, pkey, &len, pvalue);
-}
-
-const char *
-Tnxt(Tbl *tbl, const char *key)
-{
-	void *value = nil;
-	Tnext(tbl, &key, &value);
-	return key;
 }
--- a/equal.c
+++ b/equal.c
@@ -8,11 +8,9 @@
 #define BOUNDED_HASH_BOUND 16384
 
 #if defined(BITS64)
-#define inthash int64hash
-#define MIX(a, b) int64hash((uint64_t)(a) ^ (uint64_t)(b));
-#define doublehash(a) int64hash(a)
+#define MIX(a, b) inthash((value_t)(a) ^ (value_t)(b));
+#define doublehash(a) inthash(a)
 #else
-#define inthash int32hash
 #define MIX(a, b) int64to32hash((uint64_t)(a)<<32 | (uint64_t)(b));
 #define doublehash(a) int64to32hash(a)
 #endif
--- a/hashing.c
+++ b/hashing.c
@@ -19,9 +19,20 @@
 	return i ? i : TOP_BIT;
 }
 
-uint32_t
-int32hash(uint32_t a)
+value_t
+inthash(value_t a)
 {
+#if defined(BITS64)
+	a = (~a) + (a << 21); // a = (a << 21) - a - 1;
+	a = a ^ (a >> 24);
+	a = (a + (a << 3)) + (a << 8); // a * 265
+	a = a ^ (a >> 14);
+	a = (a + (a << 2)) + (a << 4); // a * 21
+	a = a ^ (a >> 28);
+	a = a + (a << 31);
+	return a;
+}
+#else
 	a = (a+0x7ed55d16) + (a<<12);
 	a = (a^0xc761c23c) ^ (a>>19);
 	a = (a+0x165667b1) + (a<<5);
@@ -31,19 +42,6 @@
 	return a;
 }
 
-uint64_t
-int64hash(uint64_t key)
-{
-	key = (~key) + (key << 21); // key = (key << 21) - key - 1;
-	key = key ^ (key >> 24);
-	key = (key + (key << 3)) + (key << 8); // key * 265
-	key = key ^ (key >> 14);
-	key = (key + (key << 2)) + (key << 4); // key * 21
-	key = key ^ (key >> 28);
-	key = key + (key << 31);
-	return key;
-}
-
 uint32_t
 int64to32hash(uint64_t key)
 {
@@ -55,6 +53,7 @@
 	key = key ^ (key >> 22);
 	return (uint32_t)key;
 }
+#endif
 
 uint64_t
 memhash(const char *buf, size_t n)
--- a/hashing.h
+++ b/hashing.h
@@ -1,8 +1,7 @@
 #pragma once
 
 value_t nextipow2(value_t i) fl_constfn;
-uint32_t int32hash(uint32_t a) fl_constfn;
-uint64_t int64hash(uint64_t key) fl_constfn;
+value_t inthash(value_t a) fl_constfn;
 uint32_t int64to32hash(uint64_t key) fl_constfn;
 uint64_t memhash(const char* buf, size_t n);
 uint32_t memhash32(const char* buf, size_t n);
--- a/random.c
+++ b/random.c
@@ -17,12 +17,6 @@
 	return genrand64_int64(&ctx) >> 32;
 }
 
-int64_t
-genrand_int63(void)
-{
-	return genrand64_int63(&ctx);
-}
-
 double
 genrand_double(void)
 {
--- a/random.h
+++ b/random.h
@@ -4,4 +4,3 @@
 double genrand_double(void);
 uint64_t genrand_uint64(void);
 uint32_t genrand_uint32(void);
-int64_t genrand_int63(void);