OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:56 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: intrinsic functions
PostPosted: Mon May 24, 2021 8:13 am 
Offline

Joined: Sat May 01, 2021 8:47 pm
Posts: 15
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?


Top
 Profile  
 
 Post subject: Re: intrinsic functions
PostPosted: Mon May 24, 2021 9:18 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
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.


Top
 Profile  
 
 Post subject: Re: intrinsic functions
PostPosted: Mon May 24, 2021 10:23 am 
Offline

Joined: Sat May 01, 2021 8:47 pm
Posts: 15
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?


Top
 Profile  
 
 Post subject: Re: intrinsic functions
PostPosted: Mon May 24, 2021 10:35 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 56 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group