intreadwrite.h 2.52 KB
Newer Older
Måns Rullgård's avatar
Måns Rullgård committed
1
/*
2
 * This file is part of Libav.
Måns Rullgård's avatar
Måns Rullgård committed
3
 *
4
 * Libav is free software; you can redistribute it and/or
Måns Rullgård's avatar
Måns Rullgård committed
5 6 7 8
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
9
 * Libav is distributed in the hope that it will be useful,
Måns Rullgård's avatar
Måns Rullgård committed
10 11 12 13 14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with Libav; if not, write to the Free Software
Måns Rullgård's avatar
Måns Rullgård committed
16 17 18 19 20 21 22 23
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef AVUTIL_ARM_INTREADWRITE_H
#define AVUTIL_ARM_INTREADWRITE_H

#include <stdint.h>
#include "config.h"
24
#include "libavutil/attributes.h"
Måns Rullgård's avatar
Måns Rullgård committed
25

26
#if HAVE_FAST_UNALIGNED && HAVE_INLINE_ASM && !AV_GCC_VERSION_AT_LEAST(4,7)
Måns Rullgård's avatar
Måns Rullgård committed
27 28

#define AV_RN16 AV_RN16
29
static av_always_inline unsigned AV_RN16(const void *p)
Måns Rullgård's avatar
Måns Rullgård committed
30
{
31
    const uint8_t *q = p;
32
    unsigned v;
33 34 35
#if !AV_GCC_VERSION_AT_LEAST(4,6)
    __asm__ ("ldrh %0, %1" : "=r"(v) : "m"(*(const uint16_t *)q));
#elif defined __thumb__
36 37 38 39
    __asm__ ("ldrh %0, %1" : "=r"(v) : "m"(q[0]), "m"(q[1]));
#else
    __asm__ ("ldrh %0, %1" : "=r"(v) : "Uq"(q[0]), "m"(q[1]));
#endif
Måns Rullgård's avatar
Måns Rullgård committed
40 41 42 43
    return v;
}

#define AV_WN16 AV_WN16
44
static av_always_inline void AV_WN16(void *p, uint16_t v)
Måns Rullgård's avatar
Måns Rullgård committed
45 46 47 48 49
{
    __asm__ ("strh %1, %0" : "=m"(*(uint16_t *)p) : "r"(v));
}

#define AV_RN32 AV_RN32
50
static av_always_inline uint32_t AV_RN32(const void *p)
Måns Rullgård's avatar
Måns Rullgård committed
51
{
52
    const struct __attribute__((packed)) { uint32_t v; } *q = p;
Måns Rullgård's avatar
Måns Rullgård committed
53
    uint32_t v;
54
    __asm__ ("ldr  %0, %1" : "=r"(v) : "m"(*q));
Måns Rullgård's avatar
Måns Rullgård committed
55 56 57 58
    return v;
}

#define AV_WN32 AV_WN32
59
static av_always_inline void AV_WN32(void *p, uint32_t v)
Måns Rullgård's avatar
Måns Rullgård committed
60 61 62 63
{
    __asm__ ("str  %1, %0" : "=m"(*(uint32_t *)p) : "r"(v));
}

64 65
#if HAVE_ASM_MOD_Q

Måns Rullgård's avatar
Måns Rullgård committed
66
#define AV_RN64 AV_RN64
67
static av_always_inline uint64_t AV_RN64(const void *p)
Måns Rullgård's avatar
Måns Rullgård committed
68
{
69
    const struct __attribute__((packed)) { uint32_t v; } *q = p;
70 71 72 73
    uint64_t v;
    __asm__ ("ldr   %Q0, %1  \n\t"
             "ldr   %R0, %2  \n\t"
             : "=&r"(v)
74
             : "m"(q[0]), "m"(q[1]));
75
    return v;
Måns Rullgård's avatar
Måns Rullgård committed
76 77 78
}

#define AV_WN64 AV_WN64
79
static av_always_inline void AV_WN64(void *p, uint64_t v)
Måns Rullgård's avatar
Måns Rullgård committed
80
{
81 82
    __asm__ ("str  %Q2, %0  \n\t"
             "str  %R2, %1  \n\t"
Måns Rullgård's avatar
Måns Rullgård committed
83
             : "=m"(*(uint32_t*)p), "=m"(*((uint32_t*)p+1))
84
             : "r"(v));
Måns Rullgård's avatar
Måns Rullgård committed
85 86
}

87 88
#endif /* HAVE_ASM_MOD_Q */

Måns Rullgård's avatar
Måns Rullgård committed
89 90 91
#endif /* HAVE_INLINE_ASM */

#endif /* AVUTIL_ARM_INTREADWRITE_H */