intreadwrite.h
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; 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 av_always_inline unsigned AV_RN16(const void *p)
29 {
30  unsigned 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 av_always_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 av_always_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 av_always_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 av_always_inline uint64_t AV_RN64(const void *p)
57 {
58  uint64_t v;
59  __asm__ ("ldr %Q0, %1 \n\t"
60  "ldr %R0, %2 \n\t"
61  : "=&r"(v)
62  : "m"(*(const uint32_t*)p), "m"(*((const uint32_t*)p+1)));
63  return v;
64 }
65 
66 #define AV_WN64 AV_WN64
67 static av_always_inline void AV_WN64(void *p, uint64_t v)
68 {
69  __asm__ ("str %Q2, %0 \n\t"
70  "str %R2, %1 \n\t"
71  : "=m"(*(uint32_t*)p), "=m"(*((uint32_t*)p+1))
72  : "r"(v));
73 }
74 
75 #endif /* HAVE_INLINE_ASM */
76 
77 #endif /* AVUTIL_ARM_INTREADWRITE_H */