Pierre Ossman | 2ae181c | 2009-03-09 13:21:27 +0000 | [diff] [blame^] | 1 | ; |
| 2 | ; jsimdcpu.asm - SIMD instruction support check |
| 3 | ; |
| 4 | ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
| 5 | ; |
| 6 | ; Based on |
| 7 | ; x86 SIMD extension for IJG JPEG library |
| 8 | ; Copyright (C) 1999-2006, MIYASAKA Masaru. |
| 9 | ; For conditions of distribution and use, see copyright notice in jsimdext.inc |
| 10 | ; |
| 11 | ; This file should be assembled with NASM (Netwide Assembler), |
| 12 | ; can *not* be assembled with Microsoft's MASM or any compatible |
| 13 | ; assembler (including Borland's Turbo Assembler). |
| 14 | ; NASM is available from http://nasm.sourceforge.net/ or |
| 15 | ; http://sourceforge.net/project/showfiles.php?group_id=6208 |
| 16 | ; |
| 17 | ; [TAB8] |
| 18 | |
| 19 | %include "simd/jsimdext.inc" |
| 20 | |
| 21 | ; -------------------------------------------------------------------------- |
| 22 | SECTION SEG_TEXT |
| 23 | BITS 32 |
| 24 | ; |
| 25 | ; Check if the CPU supports SIMD instructions |
| 26 | ; |
| 27 | ; GLOBAL(unsigned int) |
| 28 | ; jpeg_simd_cpu_support (void) |
| 29 | ; |
| 30 | |
| 31 | align 16 |
| 32 | global EXTN(jpeg_simd_cpu_support) |
| 33 | |
| 34 | EXTN(jpeg_simd_cpu_support): |
| 35 | push ebx |
| 36 | ; push ecx ; need not be preserved |
| 37 | ; push edx ; need not be preserved |
| 38 | ; push esi ; unused |
| 39 | push edi |
| 40 | |
| 41 | xor edi,edi ; simd support flag |
| 42 | |
| 43 | pushfd |
| 44 | pop eax |
| 45 | mov edx,eax |
| 46 | xor eax, 1<<21 ; flip ID bit in EFLAGS |
| 47 | push eax |
| 48 | popfd |
| 49 | pushfd |
| 50 | pop eax |
| 51 | xor eax,edx |
| 52 | jz short .return ; CPUID is not supported |
| 53 | |
| 54 | .return: |
| 55 | mov eax,edi |
| 56 | |
| 57 | pop edi |
| 58 | ; pop esi ; unused |
| 59 | ; pop edx ; need not be preserved |
| 60 | ; pop ecx ; need not be preserved |
| 61 | pop ebx |
| 62 | ret |
| 63 | |