How are modern processor instructions exposed to userland?

Steve O'Hara-Smith steve at
Wed Jun 19 10:04:22 UTC 2019

On Wed, 19 Jun 2019 11:58:23 +0530
Mayuresh Kathe <mayuresh at> wrote:

> Hello,
> I have been wondering about this, and couldn't find an answer on the Web 
> because I didn't know what to search for.
> Let's think about the AVX-512 instruction introduced with the latest 
> Intel Core i9 Skylake-X processor.
> I wanted to know how one could use such capabilities via regular C.

	The usual way that processor features get exposed is by being used
in the implementation of low level routines. Depending on the application
there may be run or compile time detection of CPU and choice of
implementation (mplayer/mencoder offers both in its build).

> There should be some way, someone working on the FreeBSD core who would 
> expose that instruction capability to the userland via libc, right?

	Not necessarily libc and not usually the instruction directly, but
if it is worthwhile some functions may grow implementation versions based
on the new instruction to be used when that CPU is available.

	Other approaches are used sometimes, for example the hardware
crypto engine in some processors is exposed via a device with a fallback
software implementation in the kernel. Kernel code and a user/kernel
interface will be needed whenever the instruction is privileged.

	The principle is the same the new feature is used to conditionally
implement an API for which there are fallback implementations for CPUs
without the new feature. The fine details vary feature by feature.

> If my assumption is correct, may I know who does that? And, how do they 
> go about doing it?

	Either by writing assembler that implements entry points with the C
calling conventions or using the C extensions that allow embedded assembler.

> Obviously, knowledge of x86-64 assembler would be a must, so would 
> knowledge of C89; right?


Steve O'Hara-Smith <steve at>

More information about the freebsd-questions mailing list