From: David Laight <david.laight.linux@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Kuan-Wei Chiu <visitorckw@gmail.com>,
Guan-Chun Wu <409411716@gms.tku.edu.tw>,
Andrew Morton <akpm@linux-foundation.org>,
ebiggers@kernel.org, tytso@mit.edu, jaegeuk@kernel.org,
xiubli@redhat.com, idryomov@gmail.com, kbusch@kernel.org,
axboe@kernel.dk, hch@lst.de, sagi@grimberg.me,
home7438072@gmail.com, linux-nvme@lists.infradead.org,
linux-fscrypt@vger.kernel.org, ceph-devel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 0/6] lib/base64: add generic encoder/decoder, migrate users
Date: Wed, 5 Nov 2025 14:38:20 +0000 [thread overview]
Message-ID: <20251105143820.11558ca8@pumpkin> (raw)
In-Reply-To: <aQtbmWLqtFXvT8Bc@smile.fi.intel.com>
On Wed, 5 Nov 2025 16:13:45 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Wed, Nov 05, 2025 at 09:48:27AM +0000, David Laight wrote:
> > On Tue, 4 Nov 2025 11:48:57 +0200
> > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > > On Tue, Nov 04, 2025 at 09:03:26AM +0000, David Laight wrote:
> > > > On Mon, 3 Nov 2025 19:07:24 +0800
> > > > Kuan-Wei Chiu <visitorckw@gmail.com> wrote:
> > > > > On Mon, Nov 03, 2025 at 11:24:35AM +0100, Andy Shevchenko wrote:
>
...
> > How about this one?
>
> Better than previous one(s) but quite cryptic to understand. Will need a
> comment explaining the logic behind, if we go this way.
My first version (of this version) had all three character ranges in the define:
so:
#define INIT_1(v, ch_62, ch_63) \
[ v ] = (v) >= '0' && (v) <= '9' ? (v) - '0' \
: (v) >= 'A' && (v) <= 'Z' ? (v) - 'A' + 10 \
: (v) >= 'a' && (v) <= 'z' ? (v) - 'a' + 36 \
: (v) == ch_62 ? 62 : (v) == ch_63 ? 63 : -1
Perhaps less cryptic - even if the .i line will be rather longer.
It could be replicated for all 256 bytes, but I think the range
initialisers are reasonable for the non-printable ranges.
I did wonder if the encode and decode lookup tables count be interleaved
and both initialisers generated from the same #define.
But I can't think of a way of generating 'x' and "X" from a #define parameter.
(I don't think "X"[0] is constant enough...)
David
>
> > #define INIT_1(v, ch_lo, ch_hi, off, ch_62, ch_63) \
> > [ v ] = ((v) >= ch_lo && (v) <= ch_hi) ? (v) - ch_lo + off \
> > : (v) == ch_62 ? 62 : (v) == ch_63 ? 63 : -1
> > #define INIT_2(v, ...) INIT_1(v, __VA_ARGS__), INIT_1((v) + 1, __VA_ARGS__)
> > #define INIT_4(v, ...) INIT_2(v, __VA_ARGS__), INIT_2((v) + 2, __VA_ARGS__)
> > #define INIT_8(v, ...) INIT_4(v, __VA_ARGS__), INIT_4((v) + 4, __VA_ARGS__)
> > #define INIT_16(v, ...) INIT_8(v, __VA_ARGS__), INIT_8((v) + 8, __VA_ARGS__)
> > #define INIT_32(v, ...) INIT_16(v, __VA_ARGS__), INIT_16((v) + 16, __VA_ARGS__)
> >
> > #define BASE64_REV_INIT(ch_62, ch_63) { \
> > [ 0 ... 0x1f ] = -1, \
> > INIT_32(0x20, '0', '9', 0, ch_62, ch_63), \
> > INIT_32(0x40, 'A', 'Z', 10, ch_62, ch_63), \
> > INIT_32(0x60, 'a', 'z', 26, ch_62, ch_63), \
> > [ 0x80 ... 0xff ] = -1 }
> >
> > which gets the pre-processor to do all the work.
> > ch_62 and ch_63 can be any printable characters.
> >
> > Note that the #define names are all in a .c file - so don't need any
> > kind of namespace protection.
>
> > They can also all be #undef after the initialiser.
>
> Yes, that's too.
>
> > > Moreover this table is basically a dup of the strings in the first array.
> > > Which already makes an unnecessary duplication.
> >
> > That is what the self tests are for.
> >
> > > That's why I prefer to
> > > see a script (one source of data) to generate the header or something like
> > > this to have the tables and strings robust against typos.
> >
> > We have to differ on that one.
> > Especially in cases (like this) where generating that data is reasonably trivial.
> >
> > > The above is simply an unreadable mess.
>
next prev parent reply other threads:[~2025-11-05 14:38 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-29 10:17 [PATCH v4 0/6] lib/base64: add generic encoder/decoder, migrate users Guan-Chun Wu
2025-10-29 10:20 ` [PATCH v4 1/6] lib/base64: Add support for multiple variants Guan-Chun Wu
2025-10-29 10:20 ` [PATCH v4 2/6] lib/base64: Optimize base64_decode() with reverse lookup tables Guan-Chun Wu
2025-10-29 10:21 ` [PATCH v4 3/6] lib/base64: rework encode/decode for speed and stricter validation Guan-Chun Wu
2025-10-29 10:21 ` [PATCH v4 4/6] lib: add KUnit tests for base64 encoding/decoding Guan-Chun Wu
2025-10-29 10:21 ` [PATCH v4 5/6] fscrypt: replace local base64url helpers with lib/base64 Guan-Chun Wu
2025-10-29 10:22 ` [PATCH v4 6/6] ceph: replace local base64 " Guan-Chun Wu
2025-11-01 4:09 ` [PATCH v4 0/6] lib/base64: add generic encoder/decoder, migrate users Andrew Morton
2025-11-03 10:24 ` Andy Shevchenko
2025-11-03 11:07 ` Kuan-Wei Chiu
2025-11-03 13:22 ` David Laight
2025-11-03 14:41 ` Andy Shevchenko
2025-11-03 18:16 ` Andy Shevchenko
2025-11-03 19:29 ` David Laight
2025-11-03 19:37 ` Andy Shevchenko
2025-11-03 22:32 ` David Laight
2025-11-04 8:21 ` Andy Shevchenko
2025-11-04 1:27 ` Andrew Morton
2025-11-04 8:22 ` Andy Shevchenko
2025-11-04 9:03 ` David Laight
2025-11-04 9:48 ` Andy Shevchenko
2025-11-05 9:48 ` David Laight
2025-11-05 14:13 ` Andy Shevchenko
2025-11-05 14:38 ` David Laight [this message]
2025-11-09 12:36 ` Guan-Chun Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251105143820.11558ca8@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=409411716@gms.tku.edu.tw \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@intel.com \
--cc=axboe@kernel.dk \
--cc=ceph-devel@vger.kernel.org \
--cc=ebiggers@kernel.org \
--cc=hch@lst.de \
--cc=home7438072@gmail.com \
--cc=idryomov@gmail.com \
--cc=jaegeuk@kernel.org \
--cc=kbusch@kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=tytso@mit.edu \
--cc=visitorckw@gmail.com \
--cc=xiubli@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox