What functions are lowered to native instructions?

Every function in Julia is compiled to a sequence of native CPU instructions.

But I guess you are asking what functions compile to a single CPU instruction. That depends mainly on the instruction set of your CPU architecture — if the instruction exists, then LLVM will typically produce it from the most obvious corresponding high-level code. You can find many guides online to the instruction sets of various CPUs (though they are not light reading!).

Alternatively, you can use the @code_native macro to see the compiled code for a given function, and you can decipher this in simple cases to figure out whether a single instruction is produced. For example, in the case you linked:

julia> f(x) = x & (x-1)
f (generic function with 1 method)

julia> @code_native f(3)
	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 12, 0
	.globl	_julia_f_332                    ## -- Begin function julia_f_332
	.p2align	4, 0x90
_julia_f_332:                           ## @julia_f_332
; ┌ @ REPL[10]:1 within `f`
	.cfi_startproc
## %bb.0:                               ## %top
; │┌ @ int.jl:340 within `&`
	blsrq	%rdi, %rax
; │└
	retq
	.cfi_endproc
; └
                                        ## -- End function
.subsections_via_symbols

which tells you that x & (x-1) for x::Int64 is compiled on x86_64 to a single BLSR (reset lowest set bit) instruction.

5 Likes