logoalt Hacker News

treydtoday at 2:01 PM2 repliesview on HN

You'd probably also be able to use an intrinsic to avoid the pain of inline asm and make it portable.


Replies

jonhohletoday at 2:30 PM

Intrinsics usually come after new instructions have existed long enough for the higher level pattern across several architectures to establish a common pattern. If specific hardware is being targeted you may need to use those instructions before intrinsics exist.

convolvatrontoday at 3:22 PM

intrinsics are nicer in every way, assuming they exist. but some instructions are inherently non-portable. performance instruction like my popcnt example are good candidates since they can be implemented at varying costs on other architectures. but for systems programming there are control register and mode switch instructions that really aren't. some of those can be put into separate asm routines, but there are some that are poorly suited. segment long jumps on x86 are maybe an example. rdtsc is another one potentially.

its also true that when I unwrap my new spin with fancy new instructions its unlikely to have a robust set of instrinsics around them.

inline asm is a real mess, I always regret tussling with it, but its kind of pragmatically necessary if you're actually working at the metal in a high performance or embedded context unless you're doing the whole thing in assembly.