# Julia equivalent of C compiler intrinsics?

**URL:** <https://discourse.julialang.org/t/julia-equivalent-of-c-compiler-intrinsics/17278>\
**Category:** General Usage\
**Created:** [November 7, 2018, 9:47pm UTC](https://discourse.julialang.org/t/julia-equivalent-of-c-compiler-intrinsics/17278 "2018-11-07T21:47:44Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [November 7, 2018, 10:24pm UTC](https://discourse.julialang.org/t/julia-equivalent-of-c-compiler-intrinsics/17278/2 "2018-11-07T22:24:38Z")

</div>

`llvmcall` with CPU intrinsics. It is a pain, though. For an example, see [https://discourse.julialang.org/t/compiling-to-branch-table/16599/9](https://discourse.julialang.org/t/compiling-to-branch-table/16599/9) and consider that the `sext` of vector comparison results is essential (this is what x86 does natively) while SIMD.jl uses `zext`. This is why the `pmovmskb`/ `_mm_movemask_epi8` composes well with `pcmpeqb` / `_mm_cmpeq_epi8`, and does not compose with `SIMD.jl` comparison.

The preferred way is to figure out the age old C idiom for whatever you want to do, because llvm was made for clang, and both clang and your processor’s instruction set were made for old C idioms. Hence this will often compile to something good.

The second preferred way is to hope that somebody has written a julia wrapper. Only afterwards one should look whether llvm exposes your intrinsic, under which crazy name and with what crazy calling convention.

Of course llvm only exposes the intrinsic if they have no idiom (in llvm IR!) that reliably compiles to whatever instruction you want, but good luck finding a documentation for that. I passionately hate the llvm docs for processor intrinsics. I often reverse the calling convention from the llvm unit tests; alternatively, compile from C to llvm IR with clang and reverse engineer that.

---

_[View the full topic](https://discourse.julialang.org/t/julia-equivalent-of-c-compiler-intrinsics/17278)._
