Imported Upstream version 1.5.3
[platform/upstream/libjpeg-turbo.git] / simd / jsimdcpu.asm
1 ;
2 ; jsimdcpu.asm - SIMD instruction support check
3 ;
4 ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5 ;
6 ; Based on the x86 SIMD extension for IJG JPEG library
7 ; Copyright (C) 1999-2006, MIYASAKA Masaru.
8 ; For conditions of distribution and use, see copyright notice in jsimdext.inc
9 ;
10 ; This file should be assembled with NASM (Netwide Assembler),
11 ; can *not* be assembled with Microsoft's MASM or any compatible
12 ; assembler (including Borland's Turbo Assembler).
13 ; NASM is available from http://nasm.sourceforge.net/ or
14 ; http://sourceforge.net/project/showfiles.php?group_id=6208
15 ;
16 ; [TAB8]
17
18 %include "jsimdext.inc"
19
20 ; --------------------------------------------------------------------------
21         SECTION SEG_TEXT
22         BITS    32
23 ;
24 ; Check if the CPU supports SIMD instructions
25 ;
26 ; GLOBAL(unsigned int)
27 ; jpeg_simd_cpu_support (void)
28 ;
29
30         align   16
31         global  EXTN(jpeg_simd_cpu_support)
32
33 EXTN(jpeg_simd_cpu_support):
34         push    ebx
35 ;       push    ecx             ; need not be preserved
36 ;       push    edx             ; need not be preserved
37 ;       push    esi             ; unused
38         push    edi
39
40         xor     edi,edi                 ; simd support flag
41
42         pushfd
43         pop     eax
44         mov     edx,eax
45         xor     eax, 1<<21              ; flip ID bit in EFLAGS
46         push    eax
47         popfd
48         pushfd
49         pop     eax
50         xor     eax,edx
51         jz      short .return           ; CPUID is not supported
52
53         ; Check for MMX instruction support
54         xor     eax,eax
55         cpuid
56         test    eax,eax
57         jz      short .return
58
59         xor     eax,eax
60         inc     eax
61         cpuid
62         mov     eax,edx                 ; eax = Standard feature flags
63
64         test    eax, 1<<23              ; bit23:MMX
65         jz      short .no_mmx
66         or      edi, byte JSIMD_MMX
67 .no_mmx:
68         test    eax, 1<<25              ; bit25:SSE
69         jz      short .no_sse
70         or      edi, byte JSIMD_SSE
71 .no_sse:
72         test    eax, 1<<26              ; bit26:SSE2
73         jz      short .no_sse2
74         or      edi, byte JSIMD_SSE2
75 .no_sse2:
76
77         ; Check for 3DNow! instruction support
78         mov     eax, 0x80000000
79         cpuid
80         cmp     eax, 0x80000000
81         jbe     short .return
82
83         mov     eax, 0x80000001
84         cpuid
85         mov     eax,edx                 ; eax = Extended feature flags
86
87         test    eax, 1<<31              ; bit31:3DNow!(vendor independent)
88         jz      short .no_3dnow
89         or      edi, byte JSIMD_3DNOW
90 .no_3dnow:
91
92 .return:
93         mov     eax,edi
94
95         pop     edi
96 ;       pop     esi             ; unused
97 ;       pop     edx             ; need not be preserved
98 ;       pop     ecx             ; need not be preserved
99         pop     ebx
100         ret
101
102 ; For some reason, the OS X linker does not honor the request to align the
103 ; segment unless we do this.
104         align   16