I think it is fairly obvious by now that what is optimal for one microprocessor may not be optimal for another. You may make the most critical parts of you program in different versions, each optimized for a specific microprocessor and selecting the desired version at run time after detecting which microprocessor the program is running on. If you are using instructions that are not supported by all microprocessors (i.e. conditional moves, FCOMI, MMX and XMM instructions) then you must first check if the program is running on a microprocessor that supports these instructions. The subroutine below checks the type of microprocessor and the features supported.
; define CPUID instruction if not known by assembler: CPUID MACRO DB 0FH, 0A2H ENDM ; C++ prototype: ; extern "C" long int DetectProcessor (void); ; return value: ; bits 8-11 = family (5 for PPlain and PMMX, 6 for PPro, PII and PIII) ; bit 0 = floating point instructions supported ; bit 15 = conditional move and FCOMI instructions supported ; bit 23 = MMX instructions supported ; bit 25 = XMM instructions supported _DetectProcessor PROC NEAR PUBLIC _DetectProcessor PUSH EBX PUSH ESI PUSH EDI PUSH EBP ; detect if CPUID instruction supported by microprocessor: PUSHFD POP EAX MOV EBX, EAX XOR EAX, 1 SHL 21 ; check if CPUID bit can toggle PUSH EAX POPFD PUSHFD POP EAX XOR EAX, EBX AND EAX, 1 SHL 21 JZ SHORT DPEND ; CPUID instruction not supported XOR EAX, EAX CPUID ; get number of CPUID functions TEST EAX, EAX JZ SHORT DPEND ; CPUID function 1 not supported MOV EAX, 1 CPUID ; get family and features AND EAX, 000000F00H ; family AND EDX, 0FFFFF0FFH ; features flags OR EAX, EDX ; combine bits DPEND: POP EBP POP EDI POP ESI POP EBX RET _DetectProcessor ENDP
Note that some operating systems do not allow XMM instructions. Information on how to check for operating system support of XMM instructions can be found in Intel's application note AP-900: "Identifying support for Streaming SIMD Extensions in the Processor and Operating System". More information on microprocessor identification can be found in Intel's application note AP-485: "Intel Processor Identification and the CPUID Instruction".
To code the conditional move, MMX, XMM instructions etc. on an assembler that doesn't have these instructions use the macros at www.agner.org/assem/macros.zip