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.