add a dummy function for determining OS support of SSE instructions
[platform/upstream/flac.git] / src / libFLAC / ia32 / cpu_asm.nasm
1 ; libFLAC - Free Lossless Audio Codec library
2 ; Copyright (C) 2001  Josh Coalson
3 ;
4 ; This library is free software; you can redistribute it and/or
5 ; modify it under the terms of the GNU Library General Public
6 ; License as published by the Free Software Foundation; either
7 ; version 2 of the License, or (at your option) any later version.
8 ;
9 ; This library is distributed in the hope that it will be useful,
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 ; Library General Public License for more details.
13 ;
14 ; You should have received a copy of the GNU Library General Public
15 ; License along with this library; if not, write to the
16 ; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 ; Boston, MA  02111-1307, USA.
18
19 %include "nasm.h"
20
21         data_section
22
23 cglobal FLAC__cpu_info_asm_ia32
24 cglobal FLAC__cpu_info_extended_amd_asm_ia32
25 cglobal FLAC__cpu_info_sse_os_asm_ia32
26
27         code_section
28
29 ; **********************************************************************
30 ;
31
32 have_cpuid:
33         pushfd
34         pop     eax
35         mov     edx, eax
36         xor     eax, 0x00200000
37         push    eax
38         popfd
39         pushfd
40         pop     eax
41         cmp     eax, edx
42         jz      .no_cpuid
43         mov     eax, 1
44         jmp     .end
45 .no_cpuid:
46         xor     eax, eax
47 .end:
48         ret
49
50 cident FLAC__cpu_info_asm_ia32
51         push    ebx
52         call    have_cpuid
53         test    eax, eax
54         jz      .no_cpuid
55         mov     eax, 1
56         cpuid
57         mov     eax, edx
58         jmp     .end
59 .no_cpuid:
60         xor     eax, eax
61 .end
62         pop     ebx
63         ret
64
65 cident FLAC__cpu_info_extended_amd_asm_ia32
66         push    ebx
67         call    have_cpuid
68         test    eax, eax
69         jz      .no_cpuid
70         mov     eax, 0x80000000
71         cpuid
72         cmp     eax, 0x80000001
73         jb      .no_cpuid
74         mov     eax, 0x80000001
75         cpuid
76         mov     eax, edx
77         jmp     .end
78 .no_cpuid
79         xor     eax, eax
80 .end
81         pop     ebx
82         ret
83
84 ;WATCHOUT - DO NOT call this function until you have verified CPU support of
85 ;           SSE by inspecting the return value from FLAC__cpu_info_asm_ia32
86 ;NOTE - Since we're not in priv level 0 we can't just check CR4 bits 9 & 10,
87 ;       so right now we just assume there is no OS support.  If you know
88 ;       how to write code to trap a #UD exception in nasm so we can implement
89 ;       this function correctly, let us know!
90 cident FLAC__cpu_info_sse_os_asm_ia32
91         push    ebx
92         mov     eax, 1
93         cpuid
94         mov     eax, 0          ;we would like to 'move eax, cr4'
95         shr     eax, 9
96         and     eax, 3
97         pop     ebx
98         ret
99
100 end