News for hackers. Stuff that matters.
Re:Parsing JSON faster with Intel AVX-512 by loeg on Thursday May 26, 2022 @03:21PM (#31522355)
GCC has offered Function Multiversioning for about a decade now (GCC ~4.8 or 4.9). GCC 6's resolver apparently uses CPUID to resolve the ifunc once at program start: https://lwn.net/Articles/691932/ .

Clang added it in 7.0.0: https://releases.llvm.org/7.0.0/tools/clang/docs/AttributeRe...

A nice presentation on it: https://llvm.org/devmtg/2014-10/Slides/Christopher-Function%...

Re:Parsing JSON faster with Intel AVX-512 by indygreg2 on Thursday May 26, 2022 @05:15PM (#31523454)
While this IFUNC feature does exist and it is useful, when I performed binary analysis on every package in Ubuntu in January, I found that only ~11 distinct packages have IFUNCs. It certainly looks like this ELF feature is not really used much [in open source] outside of GNU toolchain-level software!

https://gregoryszorc.com/blog/2022/01/09/bulk-analyze-linux-...

Re:Parsing JSON faster with Intel AVX-512 by burntsushi on Thursday May 26, 2022 @08:57PM (#31525025)
Do note that IFUNC is a convenience. You don't actually need to use IFUNCs to write target specific code that dispatches dynamically at runtime.

For example, ripgrep's dependencies dispatch dynamically at runtime by querying CPUID, but nothing uses GCC's "IFUNC" thingy. So it's likely that much more software is utilizing target specific code than not. Still, it's probably less than one would like.

(I think this is less of a response to you and more of a response to this entire thread. It seems like some folks are conflating "IFUNC" with "all forms of dynamic dispatching based on CPUID.")

Re:Parsing JSON faster with Intel AVX-512 by TkTech on Thursday May 26, 2022 @05:40PM (#31523681)
I've wanted to use them many times in the past, but the limited support on other compilers (looking at you MSVC) always made it a non-starter. If I have to support some other method of feature detection anyways, there's no point.
Re:Parsing JSON faster with Intel AVX-512 by arthur2e5 on Thursday May 26, 2022 @08:19PM (#31524811)
The way ifunc (well, actually language-level FMV) works in GCC and clang is that the input source code, not the command-line switches, specifies what ISA extensions to build for on a candidate function. This naturally means that packagers and other vendors are not using it as much as you hope: they would need to have a separate patch to add these attributes for each architecture and that’s just not maintainable.

Even Intel’s Clear Linux does not bother to patch individual libraries. They just use the glibc library multi-versioning feature to load from different directories depending on the cpuid.

In my opinion, GCC and Clang could make the whole thing more ergonomic. Ideally you declare a function as "interesting for multi-versioning" in the source using an attribute, then in the command line define what -march's to actually clone for. Kinda like ICC’s /Qax. (On second thought preprocessor defs are sufficient, duh.)

Re:Parsing JSON faster with Intel AVX-512 by jeffbee on Thursday May 26, 2022 @07:57PM (#31524687)
The use of ifunc in libc, openssl, and zlib covers just about everything people want from it. You want that optimized memcpy, you only need it in one place.
Re:Parsing JSON faster with Intel AVX-512 by matheusmoreira on Friday May 27, 2022 @01:21AM (#31526244)
This is interesting. It looks like the multiversioned functions are resolved by the dynamic linker or loader. What happens if the binary uses static linking? Is there a way to resolve the functions generated by GCC ourselves? Can we specify their symbols?