]> git.sesse.net Git - x264/blob - common/arm/cpu-a.S
9ae6b14ee1f0e88fdb6889c4ab60dbf9a741606c
[x264] / common / arm / cpu-a.S
1 /*****************************************************************************
2  * cpu-a.S: arm cpu detection
3  *****************************************************************************
4  * Copyright (C) 2009-2014 x264 project
5  *
6  * Authors: David Conrad <lessen42@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
21  *
22  * This program is also available under a commercial proprietary license.
23  * For more information, contact us at licensing@x264.com.
24  *****************************************************************************/
25
26 #include "asm.S"
27
28 .fpu neon
29 .align 2
30
31 // done in gas because .fpu neon overrides the refusal to assemble
32 // instructions the selected -march/-mcpu doesn't support
33 function x264_cpu_neon_test
34     vadd.i16    q0, q0, q0
35     bx          lr
36 .endfunc
37
38 // return: 0 on success
39 //         1 if counters were already enabled
40 //         9 if lo-res counters were already enabled
41 function x264_cpu_enable_armv7_counter, export=0
42     mrc         p15, 0, r2, c9, c12, 0      // read PMNC
43     ands        r0, r2, #1
44     andne       r0, r2, #9
45
46     orr         r2, r2, #1                  // enable counters
47     bic         r2, r2, #8                  // full resolution
48     mcreq       p15, 0, r2, c9, c12, 0      // write PMNC
49     mov         r2, #1 << 31                // enable cycle counter
50     mcr         p15, 0, r2, c9, c12, 1      // write CNTENS
51     bx          lr
52 .endfunc
53
54 function x264_cpu_disable_armv7_counter, export=0
55     mrc         p15, 0, r0, c9, c12, 0      // read PMNC
56     bic         r0, r0, #1                  // disable counters
57     mcr         p15, 0, r0, c9, c12, 0      // write PMNC
58     bx          lr
59 .endfunc
60
61
62 .macro READ_TIME r
63     mrc         p15, 0, \r, c9, c13, 0
64 .endm
65
66 // return: 0 if transfers neon -> arm transfers take more than 10 cycles
67 //         nonzero otherwise
68 function x264_cpu_fast_neon_mrc_test
69     // check for user access to performance counters
70     mrc         p15, 0, r0, c9, c14, 0
71     cmp         r0, #0
72     bxeq        lr
73
74     push        {r4-r6,lr}
75     bl          x264_cpu_enable_armv7_counter
76     ands        r1, r0, #8
77     mov         r3, #0
78     mov         ip, #4
79     mov         r6, #4
80     moveq       r5, #1
81     movne       r5, #64
82
83 average_loop:
84     mov         r4, r5
85     READ_TIME   r1
86 1:  subs        r4, r4, #1
87 .rept 8
88     vmov.u32    lr, d0[0]
89     add         lr, lr, lr
90 .endr
91     bgt         1b
92     READ_TIME   r2
93
94     subs        r6, r6, #1
95     sub         r2, r2, r1
96     cmpgt       r2, #30 << 3    // assume context switch if it took over 30 cycles
97     addle       r3, r3, r2
98     subsle      ip, ip, #1
99     bgt         average_loop
100
101     // disable counters if we enabled them
102     ands        r0, r0, #1
103     bleq        x264_cpu_disable_armv7_counter
104
105     lsr         r0, r3, #5
106     cmp         r0, #10
107     movgt       r0, #0
108     pop         {r4-r6,pc}
109 .endfunc