6 ms·
How does software these days target all the different CPUs with different instructions? If I download, say, debian-11.7.0-amd64-netinst.iso - does it somehow d
by TekMol 3y ago
How does software these days target all the different CPUs with different instructions?
If I download, say, debian-11.7.0-amd64-netinst.iso - does it somehow dynamically adapt to all the different AMD and Intel CPUs and uses the instructions available on the users machine?
- bruce343434 3y agoSoftware compiled to be "portable" uses a reduced subset. You actually have to bully GCC into using the full CPU instruction set with -march=native (you can also put another target CPU arch there). In short, distributed binaries tend to use "least common denominator" instructions. I believe one of the pros touted of Gentoo, where everything is compiled locally, is that all the software uses the CPU to it's fullest potential.
- TekMol 3y agoAfaik, Debian runs on the 386? And I think that came out in the 80s? So all new CPU instructions of the last 40 years are pretty much used by nobody?
- stephen_g 3y agoNo, according to this [1], Debian's i386 architecture dropped support for the 386 and 486 in versions Sarge and Squeeze respectively. Pretty amazing that it did work on the first Pentium (released 1993!) up to 2018. In Debian version after Jessie the Pentium (i586) has been dropped too [2]. Of course, I don't think many people are using i386 builds anymore - most people would have switched to the more modern x86_64 long ago. 1. https://www.debian.org/releases/jessie/i386/ch02s01.html.en https://www.debian.org/releases/jessie/i386/ch02s01.html.en 2. https://www.debian.org/releases/stretch/i386/ch02s01.html.en https://www.debian.org/releases/stretch/i386/ch02s01.html.en
- Arnt 3y agoThe new instructions are used often or seldom depending on whether you count invocations or occurences. There are new instructions that can be used to write a constant-time SHA-256 hash function. A program that contains megabytes of code, more than a million instructions, may reasonably contain only a few of those instructions, because it contains only one or two small hash functions. The instructions are important and effective, but occur only a handful of times among a million instructions.
- pjc50 3y agoThe dirty secret is: yes, many of the new instructions aren't used very often. They only come into play in certain cases: encryption, signal processing, CPU graphics (e.g. paint packages), video/jpeg decoding (when not done on GPU) and so on, most of which are packaged inside libraries which may or may not have multi-CPU implementations.
- rerdavies 3y agoI think the default configuration for GCC x64 is SSE 4.0 instructions enabled, AVX2 instructions enabled, AVX512 and SSE 4.2 disabled. And I think MSVC defaults to processors of a roughly similar age (10 to 15 years old). So instructions in the 40-to-15 year old range get used a lot. If you're running software that's heavily math intensive, or ever gets benchmarked, it's a fairly good bet that they will have either conditionally-installed or conditional-executed code that targets more modern processors.
- Denvercoder9 3y agoThe baseline amd64 System V ABI, which is what Debian targets, only includes SSE and SSE2; not SSE3, SSE4 or AVX2.
- msla 3y agoThe Linux kernel dropped support for the original 80386 in December 2012, with kernel 3.8 Debian dropped support with sarge in 2005 https://en.wikipedia.org/wiki/I386 https://en.wikipedia.org/wiki/I386
- jart 3y agoYou can also dispatch at runtime based on CPUID (x86) or getauxval(AT_HWCAP) for ARM. Also Clang and GCC seem to be moving in the direction of removing -march=native which is sad since grokking all the different microarchitectures isn't easy.
- ZiiS 3y agoLots of speed sensitive programs also ship multiple implementations they can choose at run time so they can more fully utilize a CPU without recompiling.
- another2another 3y agoProbably one of the biggest Bang for your Buck (on Linux) would be to recompile your libc and OpenSSL with -march=native. Then at least all software that depends on those libs (probably the majority) would get some benefit from your local processors extensions.
- lnx01 3y agoCompiler flags. You turn on/off compiler optimisations for target architectures that are aware of all the instruction-set specific hardware level optimisations.
- TekMol 3y agoBut I'm not compiling. And neither are 99.9% of other software users.
- pjmlp 3y agoHence why JITs have some advantages when shipping software, at the cost of a few extra MBs.
- bruce343434 3y agoOnly if the JIT uses the fancy instructions :)
- pjmlp 3y agoMost JVM implementations and the CLR do keep up with fancy instructions. Not all, but surely a few.
- aleden 3y agoIFunc relocations are how glibc dynamically chooses the best memcpy routine to use at runtime based on the CPU. see https://github.com/bminor/glibc/blob/glibc-2.31/sysdeps/x86_64/multiarch/ifunc-memmove.h#L40 https://github.com/bminor/glibc/blob/glibc-2.31/sysdeps/x86_...
- Findecanor 3y agoHere's a article that describes how to use function multi-versioning and indirect functions (ifunc) with GCC and GNU tools: https://lwn.net/Articles/691932/ https://lwn.net/Articles/691932/
- r2vcap 3y agoIn many cases, multiple implementations are included and one is chosen to utilize the best instruction supported by the CPU. Example code: https://source.chromium.org/chromium/chromium/src/+/main:third_party/libyuv/source/scale.cc;drc=d14bd701c83375a982fe9e237a71cc06bef056e7;l=62 https://source.chromium.org/chromium/chromium/src/+/main:thi...
- zX41ZdbW 3y agoRuntime CPU dispatching: https://maksimkita.com/blog/cpu-dispatch-in-clickhouse.html https://maksimkita.com/blog/cpu-dispatch-in-clickhouse.html
- zokier 3y agoThere are several uarch levels defined for x86_64 which include newer instructions than the baseline. Some distros are starting to move to use those higher levels, notably RHEL9 is x86_64-v2. You'll find lots of discussions happening around this topic, for example: https://www.phoronix.com/news/Arch-Linux-x86-64-v3-Port-RFC https://www.phoronix.com/news/Arch-Linux-x86-64-v3-Port-RFC
- ksherlock 3y agoFor a while, submissions to the iOS app store could include bitcode, which was LLVM's intermediate byte code. I don't know if they ever did, but Apple could generate architecture-optimized binaries for their various CPU models. They deprecated that last year, though. .Net ahead-of-time compilation (that is, compiling the .net / clr VM byte code into something your CPU can run directly) could (but apparently doesn't?) do CPU-specific optimizations. The JIT compiler, however does do some CPU-specific optimizations.