intrinsic functions

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
newosdeveloper2021
Posts: 15
Joined: Sat May 01, 2021 8:47 pm

intrinsic functions

Post by newosdeveloper2021 »

any way to use intrinsic functions like in windows kernel? like __writecr0 and __cpuidex?
In my kernel?

EDIT: also can I use microsoft-style inline assembler?
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: intrinsic functions

Post by Octocontrabass »

newosdeveloper2021 wrote:any way to use intrinsic functions like in windows kernel? like __writecr0 and __cpuidex?
In my kernel?
Yes: write them yourself using inline assembler.
newosdeveloper2021 wrote:EDIT: also can I use microsoft-style inline assembler?
Only if you use Microsoft's compiler.
newosdeveloper2021
Posts: 15
Joined: Sat May 01, 2021 8:47 pm

Re: intrinsic functions

Post by newosdeveloper2021 »

Octocontrabass wrote:
newosdeveloper2021 wrote:any way to use intrinsic functions like in windows kernel? like __writecr0 and __cpuidex?
In my kernel?
Yes: write them yourself using inline assembler.

Can I use immintrin.h or any compiler-specific intrinsic? or would there be some random issue even though it's bare-metal?
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: intrinsic functions

Post by nullplan »

newosdeveloper2021 wrote:Yes: write them yourself using inline assembler.

Can I use immintrin.h or any compiler-specific intrinsic? or would there be some random issue even though it's bare-metal?
You can use compiler-internal headers (like immintrin.h) in freestanding mode. And I would highly recommend using those over trying to write the inline assembler yourself. Inline assembler for control instructions is non-trivial, and I would recommend if you must write those yourself, then please use a normal external function for those. The problem is that it is not always easy, telling the compiler about all the things that your snippet can do. An external function call has well-defined characteristics you can rely on. Inline assembler is hard to get right and impossible to test: What works today may not work tomorrow.

That said, I appear to be in the minority with this opinion, so take it for what it is worth.
Carpe diem!
Post Reply