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?
intrinsic functions
-
- Member
- Posts: 5567
- Joined: Mon Mar 25, 2013 7:01 pm
Re: intrinsic functions
Yes: write them yourself using inline assembler.newosdeveloper2021 wrote:any way to use intrinsic functions like in windows kernel? like __writecr0 and __cpuidex?
In my kernel?
Only if you use Microsoft's compiler.newosdeveloper2021 wrote:EDIT: also can I use microsoft-style inline assembler?
-
- Posts: 15
- Joined: Sat May 01, 2021 8:47 pm
Re: intrinsic functions
Yes: write them yourself using inline assembler.Octocontrabass wrote:newosdeveloper2021 wrote:any way to use intrinsic functions like in windows kernel? like __writecr0 and __cpuidex?
In my kernel?
Can I use immintrin.h or any compiler-specific intrinsic? or would there be some random issue even though it's bare-metal?
Re: intrinsic functions
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.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?
That said, I appear to be in the minority with this opinion, so take it for what it is worth.
Carpe diem!