public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] base64: Unroll the tables initialisers
@ 2025-11-03 19:05 Andy Shevchenko
  2025-11-03 19:17 ` Andy Shevchenko
  2025-11-03 22:18 ` David Laight
  0 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-03 19:05 UTC (permalink / raw)
  To: Andrew Morton, Guan-Chun Wu, Kuan-Wei Chiu, linux-kernel
  Cc: David Laight, Andy Shevchenko

Currently the initialisers of the tables have duplicate indices.
This prevents from building with `make W=1`.

To address the issue, unroll the table initialisers with generated
arrays by the following Python excerpt:

CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

def gen_table(ch62, ch63):
    table = [ 0xff ] * 256
    for idx, char in enumerate(CHARS):
        table[ord(char)] = idx
    table[ord(ch62)] = 62
    table[ord(ch63)] = 63

    for i in range(0, len(table), 8):
        print (f"\t{', '.join(f"0x{c:02x}" for c in table[i:i+8])},\t/* {i:-3d} - {i+7:-3d} */")

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/base64.c | 115 +++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 102 insertions(+), 13 deletions(-)

diff --git a/lib/base64.c b/lib/base64.c
index bcdbd411d63b..0a7c15c5c1b6 100644
--- a/lib/base64.c
+++ b/lib/base64.c
@@ -21,20 +21,109 @@ static const char base64_tables[][65] = {
 	[BASE64_IMAP] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,",
 };
 
-#define BASE64_REV_INIT(ch_62, ch_63) { \
-	[0 ... 255] = -1, \
-	['A'] =  0,  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, \
-	['a'] = 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, \
-	['0'] = 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, \
-	[ch_62] = 62, [ch_63] = 63, \
-}
-
 static const s8 base64_rev_maps[][256] = {
-	[BASE64_STD] = BASE64_REV_INIT('+', '/'),
-	[BASE64_URLSAFE] = BASE64_REV_INIT('-', '_'),
-	[BASE64_IMAP] = BASE64_REV_INIT('+', ',')
+	[BASE64_STD] = {
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   0 -   7 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   8 -  15 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  16 -  23 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  24 -  31 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  32 -  39 */
+		0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f,	/*  40 -  47 */
+		0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,	/*  48 -  55 */
+		0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  56 -  63 */
+		0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,	/*  64 -  71 */
+		0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,	/*  72 -  79 */
+		0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,	/*  80 -  87 */
+		0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  88 -  95 */
+		0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,	/*  96 - 103 */
+		0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,	/* 104 - 111 */
+		0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,	/* 112 - 119 */
+		0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 120 - 127 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 128 - 135 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 136 - 143 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 144 - 151 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 152 - 159 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 160 - 167 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 168 - 175 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 176 - 183 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 184 - 191 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 192 - 199 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 200 - 207 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 208 - 215 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 216 - 223 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 224 - 231 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 232 - 239 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 240 - 247 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 248 - 255 */
+	},
+	[BASE64_URLSAFE] = {
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   0 -   7 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   8 -  15 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  16 -  23 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  24 -  31 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  32 -  39 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff,	/*  40 -  47 */
+		0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,	/*  48 -  55 */
+		0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  56 -  63 */
+		0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,	/*  64 -  71 */
+		0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,	/*  72 -  79 */
+		0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,	/*  80 -  87 */
+		0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0x3f,	/*  88 -  95 */
+		0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,	/*  96 - 103 */
+		0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,	/* 104 - 111 */
+		0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,	/* 112 - 119 */
+		0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 120 - 127 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 128 - 135 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 136 - 143 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 144 - 151 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 152 - 159 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 160 - 167 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 168 - 175 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 176 - 183 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 184 - 191 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 192 - 199 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 200 - 207 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 208 - 215 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 216 - 223 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 224 - 231 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 232 - 239 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 240 - 247 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 248 - 255 */
+	},
+	[BASE64_IMAP] = {
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   0 -   7 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   8 -  15 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  16 -  23 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  24 -  31 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  32 -  39 */
+		0xff, 0xff, 0xff, 0x3e, 0x3f, 0xff, 0xff, 0xff,	/*  40 -  47 */
+		0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,	/*  48 -  55 */
+		0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  56 -  63 */
+		0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,	/*  64 -  71 */
+		0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,	/*  72 -  79 */
+		0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,	/*  80 -  87 */
+		0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  88 -  95 */
+		0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,	/*  96 - 103 */
+		0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,	/* 104 - 111 */
+		0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,	/* 112 - 119 */
+		0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 120 - 127 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 128 - 135 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 136 - 143 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 144 - 151 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 152 - 159 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 160 - 167 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 168 - 175 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 176 - 183 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 184 - 191 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 192 - 199 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 200 - 207 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 208 - 215 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 216 - 223 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 224 - 231 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 232 - 239 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 240 - 247 */
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 248 - 255 */
+	},
 };
 /**
  * base64_encode() - Base64-encode some binary data
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/1] base64: Unroll the tables initialisers
  2025-11-03 19:05 [PATCH v1 1/1] base64: Unroll the tables initialisers Andy Shevchenko
@ 2025-11-03 19:17 ` Andy Shevchenko
  2025-11-03 22:18 ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-03 19:17 UTC (permalink / raw)
  To: Andrew Morton, Guan-Chun Wu, Kuan-Wei Chiu, linux-kernel; +Cc: David Laight

On Mon, Nov 03, 2025 at 08:05:10PM +0100, Andy Shevchenko wrote:
> Currently the initialisers of the tables have duplicate indices.
> This prevents from building with `make W=1`.
> 
> To address the issue, unroll the table initialisers with generated
> arrays by the following Python excerpt:
> 
> CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
> 
> def gen_table(ch62, ch63):
>     table = [ 0xff ] * 256
>     for idx, char in enumerate(CHARS):
>         table[ord(char)] = idx
>     table[ord(ch62)] = 62
>     table[ord(ch63)] = 63
> 
>     for i in range(0, len(table), 8):
>         print (f"\t{', '.join(f"0x{c:02x}" for c in table[i:i+8])},\t/* {i:-3d} - {i+7:-3d} */")

I haven't added a Fixes tag as the idea to fold this to the initial
contribution.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/1] base64: Unroll the tables initialisers
  2025-11-03 19:05 [PATCH v1 1/1] base64: Unroll the tables initialisers Andy Shevchenko
  2025-11-03 19:17 ` Andy Shevchenko
@ 2025-11-03 22:18 ` David Laight
  2025-11-04  8:18   ` Andy Shevchenko
  1 sibling, 1 reply; 6+ messages in thread
From: David Laight @ 2025-11-03 22:18 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Andrew Morton, Guan-Chun Wu, Kuan-Wei Chiu, linux-kernel

On Mon,  3 Nov 2025 20:05:10 +0100
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Currently the initialisers of the tables have duplicate indices.
> This prevents from building with `make W=1`.
> 
> To address the issue, unroll the table initialisers with generated
> arrays by the following Python excerpt:
> 
> CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
> 
> def gen_table(ch62, ch63):
>     table = [ 0xff ] * 256
>     for idx, char in enumerate(CHARS):
>         table[ord(char)] = idx
>     table[ord(ch62)] = 62
>     table[ord(ch63)] = 63
> 
>     for i in range(0, len(table), 8):
>         print (f"\t{', '.join(f"0x{c:02x}" for c in table[i:i+8])},\t/* {i:-3d} - {i+7:-3d} */")
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  lib/base64.c | 115 +++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 102 insertions(+), 13 deletions(-)
> 
> diff --git a/lib/base64.c b/lib/base64.c
> index bcdbd411d63b..0a7c15c5c1b6 100644
> --- a/lib/base64.c
> +++ b/lib/base64.c
> @@ -21,20 +21,109 @@ static const char base64_tables[][65] = {
>  	[BASE64_IMAP] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,",
>  };
>  
> -#define BASE64_REV_INIT(ch_62, ch_63) { \
> -	[0 ... 255] = -1, \
> -	['A'] =  0,  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, \
> -	['a'] = 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, \
> -	['0'] = 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, \
> -	[ch_62] = 62, [ch_63] = 63, \
> -}
> -
>  static const s8 base64_rev_maps[][256] = {
> -	[BASE64_STD] = BASE64_REV_INIT('+', '/'),
> -	[BASE64_URLSAFE] = BASE64_REV_INIT('-', '_'),
> -	[BASE64_IMAP] = BASE64_REV_INIT('+', ',')
> +	[BASE64_STD] = {
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   0 -   7 */

You need to use -1 not 0xff.

> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   8 -  15 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  16 -  23 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  24 -  31 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  32 -  39 */

Nothing wrong with [ 0 ... 39 ] = -1,

> +		0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f,	/*  40 -  47 */
> +		0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,	/*  48 -  55 */
> +		0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  56 -  63 */
> +		0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,	/*  64 -  71 */
> +		0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,	/*  72 -  79 */
> +		0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,	/*  80 -  87 */
> +		0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  88 -  95 */
> +		0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,	/*  96 - 103 */
> +		0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,	/* 104 - 111 */
> +		0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,	/* 112 - 119 */
> +		0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 120 - 127 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 128 - 135 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 136 - 143 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 144 - 151 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 152 - 159 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 160 - 167 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 168 - 175 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 176 - 183 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 184 - 191 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 192 - 199 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 200 - 207 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 208 - 215 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 216 - 223 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 224 - 231 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 232 - 239 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 240 - 247 */
> +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 248 - 255 */
> +	},
...

This is impenetrable crap...

	David


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/1] base64: Unroll the tables initialisers
  2025-11-03 22:18 ` David Laight
@ 2025-11-04  8:18   ` Andy Shevchenko
  2025-11-04  9:07     ` David Laight
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-04  8:18 UTC (permalink / raw)
  To: David Laight; +Cc: Andrew Morton, Guan-Chun Wu, Kuan-Wei Chiu, linux-kernel

On Mon, Nov 03, 2025 at 10:18:57PM +0000, David Laight wrote:
> On Mon,  3 Nov 2025 20:05:10 +0100
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > Currently the initialisers of the tables have duplicate indices.
> > This prevents from building with `make W=1`.
> > 
> > To address the issue, unroll the table initialisers with generated
> > arrays by the following Python excerpt:
> > 
> > CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
> > 
> > def gen_table(ch62, ch63):
> >     table = [ 0xff ] * 256
> >     for idx, char in enumerate(CHARS):
> >         table[ord(char)] = idx
> >     table[ord(ch62)] = 62
> >     table[ord(ch63)] = 63
> > 
> >     for i in range(0, len(table), 8):
> >         print (f"\t{', '.join(f"0x{c:02x}" for c in table[i:i+8])},\t/* {i:-3d} - {i+7:-3d} */")

...

> > +	[BASE64_STD] = {
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   0 -   7 */
> 
> You need to use -1 not 0xff.

Whu? The s8 type is pretty much 8-bit, care to explain the point?

> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   8 -  15 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  16 -  23 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  24 -  31 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  32 -  39 */
> 
> Nothing wrong with [ 0 ... 39 ] = -1,

Have you tried? It's unreadable if we use ranges.

> > +		0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f,	/*  40 -  47 */
> > +		0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,	/*  48 -  55 */
> > +		0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  56 -  63 */
> > +		0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,	/*  64 -  71 */
> > +		0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,	/*  72 -  79 */
> > +		0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,	/*  80 -  87 */
> > +		0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff,	/*  88 -  95 */
> > +		0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,	/*  96 - 103 */
> > +		0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,	/* 104 - 111 */
> > +		0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,	/* 112 - 119 */
> > +		0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 120 - 127 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 128 - 135 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 136 - 143 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 144 - 151 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 152 - 159 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 160 - 167 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 168 - 175 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 176 - 183 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 184 - 191 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 192 - 199 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 200 - 207 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 208 - 215 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 216 - 223 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 224 - 231 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 232 - 239 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 240 - 247 */
> > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/* 248 - 255 */
> > +	},

...

> This is impenetrable crap...

Send your version for the review, please, we still have a build issue here.
But I definitely do not like current state of affairs.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/1] base64: Unroll the tables initialisers
  2025-11-04  8:18   ` Andy Shevchenko
@ 2025-11-04  9:07     ` David Laight
  2025-11-04  9:44       ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: David Laight @ 2025-11-04  9:07 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Andrew Morton, Guan-Chun Wu, Kuan-Wei Chiu, linux-kernel

On Tue, 4 Nov 2025 10:18:39 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Mon, Nov 03, 2025 at 10:18:57PM +0000, David Laight wrote:
..
> > > +	[BASE64_STD] = {
> > > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   0 -   7 */  
> > 
> > You need to use -1 not 0xff.  
> 
> Whu? The s8 type is pretty much 8-bit, care to explain the point?

I think it is clang that complains that the value is out of range.

	David



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/1] base64: Unroll the tables initialisers
  2025-11-04  9:07     ` David Laight
@ 2025-11-04  9:44       ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-04  9:44 UTC (permalink / raw)
  To: David Laight; +Cc: Andrew Morton, Guan-Chun Wu, Kuan-Wei Chiu, linux-kernel

On Tue, Nov 04, 2025 at 09:07:40AM +0000, David Laight wrote:
> On Tue, 4 Nov 2025 10:18:39 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > On Mon, Nov 03, 2025 at 10:18:57PM +0000, David Laight wrote:

...

> > > > +	[BASE64_STD] = {
> > > > +		0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,	/*   0 -   7 */  
> > > 
> > > You need to use -1 not 0xff.  
> > 
> > Whu? The s8 type is pretty much 8-bit, care to explain the point?
> 
> I think it is clang that complains that the value is out of range.

I use clang on daily basis to compile kernel and I definitely compiled
the proposal I sent. So, no, not this one.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-04  9:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03 19:05 [PATCH v1 1/1] base64: Unroll the tables initialisers Andy Shevchenko
2025-11-03 19:17 ` Andy Shevchenko
2025-11-03 22:18 ` David Laight
2025-11-04  8:18   ` Andy Shevchenko
2025-11-04  9:07     ` David Laight
2025-11-04  9:44       ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox