Home / Articles / Processor Modes

Processor Modes

Processor Modes

Switching the CPU from one mode to another takes time. It is therefore better practice to group similar kinds of instructions together rather than interleaving them.

The Pentium MMX processor introduced an enhanced instruction set for multimedia support. However, the processor had to switch into a different mode before MMX instructions could execute. Consider this unoptimised code:

main()
{
    int i, j, k;
    someMMX_Instruction1;
    i += j / j * (j - j);
    printf("Enter NO");
    someMMX_Instruction2;
    scanf(...);
    someMMX_Instruction3;
    ...
}

In this code the CPU switches mode on almost every alternate instruction, consuming time unnecessarily. The MMX instructions should be grouped together to minimise mode transitions.

The same principle applies to I/O operations. I/O is handled by the OS, and system calls involve CPU mode switching. The same consideration therefore applies to DMA (Direct Memory Access) and PIC (Programmable Interrupt Controller) calls.

A smart compiler may apply this optimisation automatically, but relying on the compiler is not always a safe assumption.