Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Some compilers have a dynamic dispatch for this; you run the "cpuinfo" instruction and check for capability bits, and then dispatch to the version you can support. Some dynamic linkers can even link different versions of a function depending on the CPU capabilities -- gcc has a special __attribute__((__target__()) pragma for this.


GCC's method is called ifunc https://sourceware.org/glibc/wiki/GNU_IFUNC

The upside is your program may get updated, accelerated routines if it is dynamically linked to a library that you update. The downside is the calls are always indirect via the PLT, which isn't very efficient. It is suitable for things like block encryption and compression where the function entry latency is not very large compared to how long the function runs. It is not very suitable for calls that may be extremely short, like memcmp.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: