What do you mean by a "long instruction"? All CPU instructions are atomic, they take the smallest unit of time possible (from the perspective of the processor). Or did I miss something in class? :)
–
JakobJan 25 '11 at 14:09

@Jakob: what about modern superscalar processors though, where you may have > 100 instructions "in flight" on any given clock cycle ? Do all these instructions need to complete before the interrupt can be serviced ?
–
Paul RJan 25 '11 at 14:30

@Jakob: According to Intel Manual different instructions takes different amaount of time (cycles)
–
Tichomir MitkovJan 25 '11 at 15:14

2 Answers
2

From a programmer's point of view, either a specific instruction is retired, and all its side effects committed to registers/memory or it isn't (and it's as if the instruction wasn't executed at all). The whole point of instruction retirement is to guarantee a coherent view of the program state at the point of external events, such as interrupts.

That's notably why instructions retire in order, so that external observers can still look at the architectural state of the CPU as if it was executing sequentially instructions.

There are exceptions to this, notably the REP-string class of instructions.

I believe this is what you asked about, but if it is not, then let me ask you: how would you observe that an instruction was "partially" executed from anywhere ?

As far as I know, it depends on the processor and the instruction. More specifically, it depends whether and when the processor samples for pending interrupts. If the processor only looks for pending interrupts after completing the current instruction, then clearly nothing will interrupt an instruction in the middle. However, if a long instruction is executing, it might be beneficial (latency-wise) to sample for interrupts several times during the instruction's execution. There is a downside to this -- in this case, you would have to restore all changes that were made to registers and flags as a result of the instruction's partial execution, because after the interrupt completes you would have to go back and reissue that instruction.