首页 随笔 乐走天涯 程序资料 评论中心 Tag 论坛 其他资源 搜索 联系我 关于 RSS

27.10 Detecting processor type (All processors)


日期: 2000-04-03 14:00 | 联系我 | 关注我: Telegram, Twitter

27.10 Detecting processor type (All processors)

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

标签: MMX 优化

 文章评论
目前没有任何评论.

↓ 快抢占第1楼,发表你的评论和意见 ↓

发表你的评论
如果你想针对此文发表评论, 请填写下列表单:
姓名: * 必填 (Twitter 用户可输入以 @ 开头的用户名, Steemit 用户可输入 @@ 开头的用户名)
E-mail: 可选 (不会被公开。如果我回复了你的评论,你将会收到邮件通知)
反垃圾广告: 为了防止广告机器人自动发贴, 请计算下列表达式的值:
9 x 4 + 3 = * 必填
评论内容:
* 必填
你可以使用下列标签修饰文字:
[b] 文字 [/b]: 加粗文字
[quote] 文字 [/quote]: 引用文字

 
首页 随笔 乐走天涯 猎户星 Google Earth 程序资料 程序生活 评论 Tag 论坛 资源 搜索 联系 关于 隐私声明 版权声明 订阅邮件

程序员小辉 建站于 1997 ◇ 做一名最好的开发者是我不变的理想。
Copyright © XiaoHui.com; 保留所有权利。