Mercurial > libavutil.hg
comparison arm/intreadwrite.h @ 728:1fa3820b1a84 libavutil
ARM asm for AV_RN*()
ARMv6 and later support unaligned loads and stores for single
word/halfword but not double/multiple. GCC is ignorant of this and
will always use bytewise accesses for unaligned data. Casting to an
int32_t pointer is dangerous since a load/store double or multiple
instruction might be used (this happens with some code in FFmpeg).
Implementing the AV_[RW]* macros with inline asm using only supported
instructions gives fast and safe unaligned accesses. ARM RVCT does
the right thing with generic code.
This gives an overall speedup of up to 10%.
author | mru |
---|---|
date | Sat, 18 Apr 2009 00:00:28 +0000 |
parents | |
children | 2d52bcf3e4e6 |
comparison
equal
deleted
inserted
replaced
727:98b64f65be0d | 728:1fa3820b1a84 |
---|---|
1 /* | |
2 * This file is part of FFmpeg. | |
3 * | |
4 * FFmpeg is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Lesser General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2.1 of the License, or (at your option) any later version. | |
8 * | |
9 * FFmpeg 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 * Lesser General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Lesser General Public | |
15 * License along with FFmpeg; if not, write to the Free Software | |
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 */ | |
18 | |
19 #ifndef AVUTIL_ARM_INTREADWRITE_H | |
20 #define AVUTIL_ARM_INTREADWRITE_H | |
21 | |
22 #include <stdint.h> | |
23 #include "config.h" | |
24 | |
25 #if HAVE_FAST_UNALIGNED && HAVE_INLINE_ASM | |
26 | |
27 #define AV_RN16 AV_RN16 | |
28 static inline uint16_t AV_RN16(const void *p) | |
29 { | |
30 uint16_t v; | |
31 __asm__ ("ldrh %0, %1" : "=r"(v) : "m"(*(const uint16_t *)p)); | |
32 return v; | |
33 } | |
34 | |
35 #define AV_WN16 AV_WN16 | |
36 static inline void AV_WN16(void *p, uint16_t v) | |
37 { | |
38 __asm__ ("strh %1, %0" : "=m"(*(uint16_t *)p) : "r"(v)); | |
39 } | |
40 | |
41 #define AV_RN32 AV_RN32 | |
42 static inline uint32_t AV_RN32(const void *p) | |
43 { | |
44 uint32_t v; | |
45 __asm__ ("ldr %0, %1" : "=r"(v) : "m"(*(const uint32_t *)p)); | |
46 return v; | |
47 } | |
48 | |
49 #define AV_WN32 AV_WN32 | |
50 static inline void AV_WN32(void *p, uint32_t v) | |
51 { | |
52 __asm__ ("str %1, %0" : "=m"(*(uint32_t *)p) : "r"(v)); | |
53 } | |
54 | |
55 #define AV_RN64 AV_RN64 | |
56 static inline uint64_t AV_RN64(const void *p) | |
57 { | |
58 union { uint64_t v; uint32_t hl[2]; } v; | |
59 __asm__ ("ldr %0, %2 \n\t" | |
60 "ldr %1, %3 \n\t" | |
61 : "=r"(v.hl[0]), "=r"(v.hl[1]) | |
62 : "m"(*(const uint32_t*)p), "m"(*((const uint32_t*)p+1))); | |
63 return v.v; | |
64 } | |
65 | |
66 #define AV_WN64 AV_WN64 | |
67 static inline void AV_WN64(void *p, uint64_t v) | |
68 { | |
69 union { uint64_t v; uint32_t hl[2]; } vv = { v }; | |
70 __asm__ ("str %2, %0 \n\t" | |
71 "str %3, %1 \n\t" | |
72 : "=m"(*(uint32_t*)p), "=m"(*((uint32_t*)p+1)) | |
73 : "r"(vv.hl[0]), "r"(vv.hl[1])); | |
74 } | |
75 | |
76 #endif /* HAVE_INLINE_ASM */ | |
77 | |
78 #endif /* AVUTIL_ARM_INTREADWRITE_H */ |