1 /*****************************************************************************
2 * cpu-a.S: arm cpu detection
3 *****************************************************************************
4 * Copyright (C) 2009-2014 x264 project
6 * Authors: David Conrad <lessen42@gmail.com>
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.
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.
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.
22 * This program is also available under a commercial proprietary license.
23 * For more information, contact us at licensing@x264.com.
24 *****************************************************************************/
30 // done in gas because .fpu neon overrides the refusal to assemble
31 // instructions the selected -march/-mcpu doesn't support
32 function x264_cpu_neon_test
37 // return: 0 on success
38 // 1 if counters were already enabled
39 // 9 if lo-res counters were already enabled
40 function x264_cpu_enable_armv7_counter, export=0
41 mrc p15, 0, r2, c9, c12, 0 // read PMNC
45 orr r2, r2, #1 // enable counters
46 bic r2, r2, #8 // full resolution
47 mcreq p15, 0, r2, c9, c12, 0 // write PMNC
48 mov r2, #1 << 31 // enable cycle counter
49 mcr p15, 0, r2, c9, c12, 1 // write CNTENS
53 function x264_cpu_disable_armv7_counter, export=0
54 mrc p15, 0, r0, c9, c12, 0 // read PMNC
55 bic r0, r0, #1 // disable counters
56 mcr p15, 0, r0, c9, c12, 0 // write PMNC
62 mrc p15, 0, \r, c9, c13, 0
65 // return: 0 if transfers neon -> arm transfers take more than 10 cycles
67 function x264_cpu_fast_neon_mrc_test
68 // check for user access to performance counters
69 mrc p15, 0, r0, c9, c14, 0
74 bl x264_cpu_enable_armv7_counter
95 cmpgt r2, #30 << 3 // assume context switch if it took over 30 cycles
100 // disable counters if we enabled them
102 bleq x264_cpu_disable_armv7_counter