]> git.sesse.net Git - x264/blob - common/x86/cpu-a.asm
Reduce lookahead memory usage, cache misses
[x264] / common / x86 / cpu-a.asm
1 ;*****************************************************************************
2 ;* cpu-a.asm: h264 encoder library
3 ;*****************************************************************************
4 ;* Copyright (C) 2003-2008 x264 project
5 ;*
6 ;* Authors: Laurent Aimar <fenrir@via.ecp.fr>
7 ;*          Loren Merritt <lorenm@u.washington.edu>
8 ;*          Fiona Glaser <fiona@x264.com>
9 ;*
10 ;* This program is free software; you can redistribute it and/or modify
11 ;* it under the terms of the GNU General Public License as published by
12 ;* the Free Software Foundation; either version 2 of the License, or
13 ;* (at your option) any later version.
14 ;*
15 ;* This program is distributed in the hope that it will be useful,
16 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;* GNU General Public License for more details.
19 ;*
20 ;* You should have received a copy of the GNU General Public License
21 ;* along with this program; if not, write to the Free Software
22 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
23 ;*****************************************************************************
24
25 %include "x86inc.asm"
26
27 SECTION .text
28
29 %ifdef ARCH_X86_64
30
31 ;-----------------------------------------------------------------------------
32 ; int x264_cpu_cpuid( int op, int *eax, int *ebx, int *ecx, int *edx )
33 ;-----------------------------------------------------------------------------
34 cglobal x264_cpu_cpuid, 5,7
35     push    rbx
36     mov     r11,   r1
37     mov     r10,   r2
38     movifnidn r9,  r3
39     movifnidn r8,  r4
40     mov     eax,   r0d
41     cpuid
42     mov     [r11], eax
43     mov     [r10], ebx
44     mov     [r9],  ecx
45     mov     [r8],  edx
46     pop     rbx
47     RET
48
49 %else
50
51 ;-----------------------------------------------------------------------------
52 ; int x264_cpu_cpuid_test( void )
53 ; return 0 if unsupported
54 ;-----------------------------------------------------------------------------
55 cglobal x264_cpu_cpuid_test
56     pushfd
57     push    ebx
58     push    ebp
59     push    esi
60     push    edi
61     pushfd
62     pop     eax
63     mov     ebx, eax
64     xor     eax, 0x200000
65     push    eax
66     popfd
67     pushfd
68     pop     eax
69     xor     eax, ebx
70     pop     edi
71     pop     esi
72     pop     ebp
73     pop     ebx
74     popfd
75     ret
76
77 ;-----------------------------------------------------------------------------
78 ; int x264_cpu_cpuid( int op, int *eax, int *ebx, int *ecx, int *edx )
79 ;-----------------------------------------------------------------------------
80 cglobal x264_cpu_cpuid, 0,6
81     mov     eax,    r0m
82     cpuid
83     mov     esi,    r1m
84     mov     [esi],  eax
85     mov     esi,    r2m
86     mov     [esi],  ebx
87     mov     esi,    r3m
88     mov     [esi],  ecx
89     mov     esi,    r4m
90     mov     [esi],  edx
91     RET
92
93 ;-----------------------------------------------------------------------------
94 ; void x264_stack_align( void (*func)(void*), void *arg );
95 ;-----------------------------------------------------------------------------
96 cglobal x264_stack_align
97     push ebp
98     mov  ebp, esp
99     sub  esp, 8
100     and  esp, ~15
101     mov  ecx, [ebp+8]
102     mov  edx, [ebp+12]
103     mov  [esp], edx
104     mov  edx, [ebp+16]
105     mov  [esp+4], edx
106     call ecx
107     leave
108     ret
109
110 %endif
111
112 ;-----------------------------------------------------------------------------
113 ; void x264_emms( void )
114 ;-----------------------------------------------------------------------------
115 cglobal x264_emms
116     emms
117     ret
118
119 ;-----------------------------------------------------------------------------
120 ; void x264_cpu_mask_misalign_sse(void)
121 ;-----------------------------------------------------------------------------
122 cglobal x264_cpu_mask_misalign_sse
123     sub   rsp, 4
124     stmxcsr [rsp]
125     or dword [rsp], 1<<17
126     ldmxcsr [rsp]
127     add   rsp, 4
128     ret