# 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:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 8, 2018, 8:19pm UTC](https://discourse.julialang.org/t/julia-equivalent-of-c-compiler-intrinsics/17278/21 "2018-11-08T20:19:29Z")

</div>

> [@yuyichao](#):
>
> generic intrinsics

What are “generic intrinsics”?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [November 8, 2018, 8:22pm UTC](https://discourse.julialang.org/t/julia-equivalent-of-c-compiler-intrinsics/17278/22 "2018-11-08T20:22:13Z")

</div>

I mean the platform agnostic ones. Basically the ones in [LLVM Language Reference Manual — LLVM 16.0.0git documentation](https://llvm.org/docs/LangRef.html). `llvm.fma` would be the simplest example but there’s now also loads of masked store/load and what’s not in there… AFAICT, they abstract some functions that doesn’t exist in C as builtin operators but are supported in hardware on multiple platforms and this makes it easier to optimize for all platforms. Or in another word, anything that doesn’t have an arch name in the name…

---

<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 8, 2018, 8:24pm UTC](https://discourse.julialang.org/t/julia-equivalent-of-c-compiler-intrinsics/17278/23 "2018-11-08T20:24:37Z")

</div>

The llvm langref is really really bad for explaining how to use the machine-specific IR calls correctly and contains no entry at all for things that have no builtin because a recognized idiom exists. In contrast, the intel docs are really good, provide a nice API and compose splendidly with Agner Fog’s tables for performance details.

So, which header file in clang should I read exactly, such that I can grep for the intel `_mm_something` name and see what to do?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [November 8, 2018, 8:31pm UTC](https://discourse.julialang.org/t/julia-equivalent-of-c-compiler-intrinsics/17278/24 "2018-11-08T20:31:25Z")

</div>

> [@foobar\_lv2](#):
>
> The llvm langref is really really bad for explaining how to use the machine-specific IR calls correctly and contains no entry at all for things that have no builtin because a recognized idiom exists.

I don’t disagree. I also didn’t write it (not that I can do better) and I’ve had the same frustration… I don’t think it’s ever meant to be a user manual for someone that want to write llvm IR (which isn’t really meant to be hand written anyway…) but just a reference of what can be done and you’ll have to refer to either the implementation or the corresponding C function to learn more about them. FWIW, they can’t give you any performance model at this level since it’s really platform dependent…

I totally agree that the mapping between C and LLVM code is a mess, and that’s probably a big part why both gcc and clang implement the intel intrinsics (the C-API) in C instead…

> [@foobar\_lv2](#):
>
> splendidly with Agner Fog’s tables for performance details.

This isn’t strictly true though. The compilers these days are smart enough to not give you the exact instruction you asked for…

> [@foobar\_lv2](#):
>
> So, which header file in clang should I read exactly, such that I can grep for the intel `_mm_something` name and see what to do?

I never remember where they are exactly but since the header name is know I just always look for the file directly. `locate immintrin.h` shows that my clang 5 headers are in `/usr/lib/clang/5.0.1/include`.

[Previous page](https://discourse.julialang.org/t/julia-equivalent-of-c-compiler-intrinsics/17278.md?page=1)
