4 ms·
Generating arrays at compile-time in C++ with lambdas
- dataflow 3y agoI'm surprised to see this. The bitset approach has all the cache lines it needs inside the instruction cache. The lookup table requires loading another cache line and evicting an existing one as a result of that. Whether that's an optimization or pessimization is hardly obvious; it depends entirely on the access patterns and workload.
- muragekibicho 3y agoTotally unrelated! You submission history is quite interesting! I wish HN let us follow users like you!
- dataflow 3y agoThat means a lot :) thank you!
- lwwch 3y agoIt’s been a while, but usually you do this because a lot of simd instructions operate more easily on lookup tables like this. You can mask, compare, compute, etc. on multiple lanes at the same time against a lookup table. The u8 value you’d produce into each component of a simd vector would be used as a shuffle mask or a gather offset to use the table.
- sfpotter 3y agoSame thing in C99: static const uint8_t table[256] = { ['\0'] = 1, ['a'] = 1, ['/'] = 1, ['\\'] = 1, }; bool get_table_value(char c) { return table[(uint8_t)c]; }
- spacechild1 3y agoThis is also valid C++, so the example in the article does seem rather contrived.
- extraduder_ire 3y agoI wonder if this is common enough that compilers will eventually convert one form into the other when doing whole program optimization. Like ripping out a duff's device you put in your code, because it knows what you're getting at.