I am interested in working on this issue: __attribute__((interrupt)) trashes MMX registers · Issue #26785 · llvm/llvm-project · GitHub but am unsure of what the best course of action is. The issue states that “Interrupt handler must preserve MMX and X87 states. It shouldn’t be allowed to use MMX nor x87 registers.”
It seems there are two options:
- Preserve the FPU/MMX state if needed by emitting
fsave
andfrstor
(orfxsave
andfxrstor
) instructions as indicated by the Intel software developer manual. However, my understanding is that these instructions are not particularly fast. - Raise an error if an interrupt handler (or any function with its call convention) is compiled with the x87 and/or MMX features enabled. This is GCC’s current behavior.
It may be worth noting that llvm already departs from GCC behavior with SSE instructions, which are disallowed in GCC but handled by llvm. GCC docs state that interrupt handlers should be compiled with -mgeneral-regs-only
, but clang does not require or warn of this to my knowledge.