Description
EDIT: deprecation reason: any eflags manipulation would need to ditch the intrinsics in favor of inline asm to be completely correct because compiler-generated code could use the eflags register in between __{read,write}eflags
calls.
Original comment:
rust-lang/rust#51691 has brought these two intrinsics to my attention, and I believe they should not have been included in stdsimd for two reasons:
- as far as I can tell, they are not officially provided by Intel -- I can't find them in https://software.intel.com/sites/landingpage/IntrinsicsGuide/ -- they're apparently just slipped in sneakily by some compilers (admittedly including icc)
- they are gigantic footguns, I would even go as far as saying they cannot possibly used correctly
To elaborate on the second point: as the OP of the linked rust issue already pointed out, usage of these intrinsics is problematic if compiler-generated code uses the eflags register in between __{read,write}eflags
calls. LLVM does not (and indeed can't really, they way it's architected) provide any way to get anything resembling a guarantee it won't do that. Not for eflags, and not for any other register (except reserved ones which no compiler-generated code touches at all). So these intrinsics are simply impossible to use reliably.
The supported way to manually mess with a register that the compiler wants to use is to have one big inline asm block that does all the manipulation in one go (and declares it as clobbered, if appropriate). rust-lang/rust#51691 mentioned doing that for x86::has_cpuid
, but I'm pretty sure any eflags manipulation would need to ditch the intrinsics in favor of inline asm to be completely correct.
I realize the possibility of miscompiles caused by this is a bit remote, and there's precedent in C compilers, but could we consider at least deprecating these intrinsics seeing as they're not even documented in the intel intrinsics guide? (Of course, I'd be even happier if they were removed entirely -- luckily they aren't stabilized yet.)