]> git.sesse.net Git - x264/blob - common/arm/cpu-a.S
Faster chroma CBP handling
[x264] / common / arm / cpu-a.S
1 /*****************************************************************************
2  * cpu-a.S: h264 encoder library
3  *****************************************************************************
4  * Copyright (C) 2009 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
23 #include "asm.S"
24
25 .fpu neon
26 .align
27
28 // done in gas because .fpu neon overrides the refusal to assemble
29 // instructions the selected -march/-mcpu doesn't support
30 function x264_cpu_neon_test
31     vadd.i16    q0, q0, q0
32     bx          lr
33 .endfunc
34
35 // return: 0 on success
36 //         1 if counters were already enabled
37 //         9 if lo-res counters were already enabled
38 function x264_cpu_enable_armv7_counter
39     mrc         p15, 0, r2, c9, c12, 0      // read PMNC
40     ands        r0, r2, #1
41     andne       r0, r2, #9
42
43     orr         r2, r2, #1                  // enable counters
44     bic         r2, r2, #8                  // full resolution
45     mcreq       p15, 0, r2, c9, c12, 0      // write PMNC
46     mov         r2, #1 << 31                // enable cycle counter
47     mcr         p15, 0, r2, c9, c12, 1      // write CNTENS
48     bx          lr
49 .endfunc
50
51 function x264_cpu_disable_armv7_counter
52     mrc         p15, 0, r0, c9, c12, 0      // read PMNC
53     bic         r0, r0, #1                  // disable counters
54     mcr         p15, 0, r0, c9, c12, 0      // write PMNC
55     bx          lr
56 .endfunc
57
58
59 .macro READ_TIME r
60     mrc         p15, 0, \r, c9, c13, 0
61 .endm
62
63 // return: 0 if transfers neon -> arm transfers take more than 10 cycles
64 //         nonzero otherwise
65 function x264_cpu_fast_neon_mrc_test
66     // check for user access to performance counters
67     mrc         p15, 0, r0, c9, c14, 0
68     cmp         r0, #0
69     bxeq        lr
70
71     push        {r4-r6,lr}
72     bl          x264_cpu_enable_armv7_counter
73     ands        r1, r0, #8
74     mov         r3, #0
75     mov         ip, #4
76     mov         r6, #4
77     moveq       r5, #1
78     movne       r5, #64
79
80 average_loop:
81     mov         r4, r5
82     READ_TIME   r1
83 1:  subs        r4, r4, #1
84 .rept 8
85     vmov.u32    lr, d0[0]
86     add         lr, lr, lr
87 .endr
88     bgt         1b
89     READ_TIME   r2
90
91     subs        r6, r6, #1
92     sub         r2, r2, r1
93     cmpgt       r2, #30 << 3    // assume context switch if it took over 30 cycles
94     addle       r3, r3, r2
95     subles      ip, ip, #1
96     bgt         average_loop
97
98     // disable counters if we enabled them
99     ands        r0, r0, #1
100     bleq        x264_cpu_disable_armv7_counter
101
102     lsr         r0, r3, #5
103     cmp         r0, #10
104     movgt       r0, #0
105     pop         {r4-r6,pc}
106 .endfunc