The function to do the same for a byte is... what? 3 or 4 lines long in C? I guess it takes a couple of temp variables, though, which may dissuade some devs.
The function to do the same for a byte is... what? 3 or 4 lines long in C? I guess it takes a couple of temp variables, though, which may dissuade some devs.
auto is_upper= (x > '@') & (x < '[');
return is_upper ? x+32 : x;
Which boils down to add, add, cmp, cmov on x86. It might save some cache traffic, but the cache traffic is less code since it's only a mov. The version that's code instead of lookups probably exacerbates register pressure problems in large programs? I don't have good intuition for which would be more efficient in practice.I dunno, it's ridiculously a benefit to the code by my instinct. While lookup table looks pretty bad.
I mean, I'm not skilled enough in those ISA extensions to stick my neck out. It's not totally obvious to me that there is not some shuffle or permute facility that can load 64 bytes at a time from LUTs.
You are talking about vgather and/or vscatter, which are well known to be very slow AVX2 or AVX512 instructions.
Maybe a future CPU will make these instructions high performance. But no modern 2023-era CPU has a high-speed vgather.
Like: the vgather does one-at-a-time slow. You basically lose parallelism even if the vgather instruction describes what you want to do, it's not an effective parallel operation today (and may never be)
--------
Pshufb as a 4-bit LUT is an exception and is effectively a high speed (but very very small) lookup table. Like every cycle 64 bytes at a time fast.
You are limited by the 16-byte lookup size (aka the size of an SSE register), maybe a bit bigger if there are new instructions I dunno about.
By using SIMD instructions like AVX2 you can do 32 characters in parallel. With AVX512, 64.
Pretty easy to write something way faster by not using a LUT.
In fact, I'm pretty sure that Unicode cannot be solved with a lookup table due to its variable length, but maybe you can prove me wrong? (Assuming UTF8 here)
Unicode does have a limited space, but it cannot be stored practically in single table. It currently runs up to 0x323AF, a bit over 200k, and most of the characters of course don't have a lower/uppercase mapping. The implementations I've seen do a few comparisons and then delegate to a table.
But: horses for courses. If you have to normalize a lot of Latin-1 text (such transform case, or strip diacritics), you can probably write some vector instructions that runs circles around a simple LUT. But it's not going to be as easy.
TIFFNoBitRevTable[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, ... 0xFF }
Maybe PSHUFB/VTBL to reverse each nibble and then put the reversed nibbles together would be wayyy faster?I'm guessing portability matters here, and there is not much commercial pressure to actually optimise this TIFF library?
The most used one is probably sin() on CPUs without hardware math