FFmpeg
intreadwrite.h
Go to the documentation of this file.
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 #include "libavutil/attributes.h"
25 
26 #if HAVE_FAST_UNALIGNED && HAVE_INLINE_ASM && AV_GCC_VERSION_AT_MOST(4,6)
27 
28 #define AV_RN16 AV_RN16
29 static av_always_inline unsigned AV_RN16(const void *p)
30 {
31  const uint8_t *q = p;
32  unsigned v;
33 #if AV_GCC_VERSION_AT_MOST(4,5)
34  __asm__ ("ldrh %0, %1" : "=r"(v) : "m"(*(const uint16_t *)q));
35 #elif defined __thumb__
36  __asm__ ("ldrh %0, %1" : "=r"(v) : "m"(q[0]), "m"(q[1]));
37 #else
38  __asm__ ("ldrh %0, %1" : "=r"(v) : "Uq"(q[0]), "m"(q[1]));
39 #endif
40  return v;
41 }
42 
43 #define AV_WN16 AV_WN16
44 static av_always_inline void AV_WN16(void *p, uint16_t v)
45 {
46  __asm__ ("strh %1, %0" : "=m"(*(uint16_t *)p) : "r"(v));
47 }
48 
49 #define AV_RN32 AV_RN32
50 static av_always_inline uint32_t AV_RN32(const void *p)
51 {
52  const struct __attribute__((packed)) { uint32_t v; } *q = p;
53  uint32_t v;
54  __asm__ ("ldr %0, %1" : "=r"(v) : "m"(*q));
55  return v;
56 }
57 
58 #define AV_WN32 AV_WN32
59 static av_always_inline void AV_WN32(void *p, uint32_t v)
60 {
61  __asm__ ("str %1, %0" : "=m"(*(uint32_t *)p) : "r"(v));
62 }
63 
64 #if HAVE_ASM_MOD_Q
65 
66 #define AV_RN64 AV_RN64
67 static av_always_inline uint64_t AV_RN64(const void *p)
68 {
69  const struct __attribute__((packed)) { uint32_t v; } *q = p;
70  uint64_t v;
71  __asm__ ("ldr %Q0, %1 \n\t"
72  "ldr %R0, %2 \n\t"
73  : "=&r"(v)
74  : "m"(q[0]), "m"(q[1]));
75  return v;
76 }
77 
78 #define AV_WN64 AV_WN64
79 static av_always_inline void AV_WN64(void *p, uint64_t v)
80 {
81  __asm__ ("str %Q2, %0 \n\t"
82  "str %R2, %1 \n\t"
83  : "=m"(*(uint32_t*)p), "=m"(*((uint32_t*)p+1))
84  : "r"(v));
85 }
86 
87 #endif /* HAVE_ASM_MOD_Q */
88 
89 #endif /* HAVE_INLINE_ASM */
90 
91 #endif /* AVUTIL_ARM_INTREADWRITE_H */
AV_RN16
#define AV_RN16(p)
Definition: intreadwrite.h:358
AV_RN64
#define AV_RN64(p)
Definition: intreadwrite.h:366
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:362
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:374
attributes.h
av_always_inline
#define av_always_inline
Definition: attributes.h:49
__asm__
__asm__(".macro parse_r var r\n\t" "\\var = -1\n\t" _IFC_REG(0) _IFC_REG(1) _IFC_REG(2) _IFC_REG(3) _IFC_REG(4) _IFC_REG(5) _IFC_REG(6) _IFC_REG(7) _IFC_REG(8) _IFC_REG(9) _IFC_REG(10) _IFC_REG(11) _IFC_REG(12) _IFC_REG(13) _IFC_REG(14) _IFC_REG(15) _IFC_REG(16) _IFC_REG(17) _IFC_REG(18) _IFC_REG(19) _IFC_REG(20) _IFC_REG(21) _IFC_REG(22) _IFC_REG(23) _IFC_REG(24) _IFC_REG(25) _IFC_REG(26) _IFC_REG(27) _IFC_REG(28) _IFC_REG(29) _IFC_REG(30) _IFC_REG(31) ".iflt \\var\n\t" ".error \"Unable to parse register name \\r\"\n\t" ".endif\n\t" ".endm")
AV_WN64
#define AV_WN64(p, v)
Definition: intreadwrite.h:378
AV_WN16
#define AV_WN16(p, v)
Definition: intreadwrite.h:370