Browse code

MIPS: inline asm for intreadwrite.h

Originally committed as revision 18980 to svn://svn.ffmpeg.org/ffmpeg/trunk

Måns Rullgård authored on 2009/05/29 08:19:35
Showing 2 changed files
... ...
@@ -31,6 +31,8 @@
31 31
 
32 32
 #if   ARCH_ARM
33 33
 #   include "arm/intreadwrite.h"
34
+#elif ARCH_MIPS
35
+#   include "mips/intreadwrite.h"
34 36
 #elif ARCH_PPC
35 37
 #   include "ppc/intreadwrite.h"
36 38
 #endif
37 39
new file mode 100644
... ...
@@ -0,0 +1,94 @@
0
+/*
1
+ * Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#ifndef AVUTIL_MIPS_INTREADWRITE_H
21
+#define AVUTIL_MIPS_INTREADWRITE_H
22
+
23
+#include <stdint.h>
24
+#include "config.h"
25
+
26
+#define AV_RN32 AV_RN32
27
+static inline uint32_t AV_RN32(const void *p)
28
+{
29
+    uint32_t v;
30
+    __asm__ ("lwl %0, %1  \n\t"
31
+             "lwr %0, %2  \n\t"
32
+             : "=&r"(v)
33
+             : "m"(*(const uint32_t *)((const uint8_t *)p+3*!HAVE_BIGENDIAN)),
34
+               "m"(*(const uint32_t *)((const uint8_t *)p+3*HAVE_BIGENDIAN)));
35
+    return v;
36
+}
37
+
38
+#define AV_WN32 AV_WN32
39
+static inline void AV_WN32(void *p, uint32_t v)
40
+{
41
+    __asm__ ("swl %2, %0  \n\t"
42
+             "swr %2, %1  \n\t"
43
+             : "=m"(*(uint32_t *)((uint8_t *)p+3*!HAVE_BIGENDIAN)),
44
+               "=m"(*(uint32_t *)((uint8_t *)p+3*HAVE_BIGENDIAN))
45
+             : "r"(v));
46
+}
47
+
48
+#if ARCH_MIPS64
49
+
50
+#define AV_RN64 AV_RN64
51
+static inline uint64_t AV_RN64(const void *p)
52
+{
53
+    uint64_t v;
54
+    __asm__ ("lwl %0, %1  \n\t"
55
+             "lwr %0, %2  \n\t"
56
+             : "=&r"(v)
57
+             : "m"(*(const uint64_t *)((const uint8_t *)p+3*!HAVE_BIGENDIAN)),
58
+               "m"(*(const uint64_t *)((const uint8_t *)p+3*HAVE_BIGENDIAN)));
59
+    return v;
60
+}
61
+
62
+#define AV_WN64 AV_WN64
63
+static inline void AV_WN64(void *p, uint64_t v)
64
+{
65
+    __asm__ ("swl %2, %0  \n\t"
66
+             "swr %2, %1  \n\t"
67
+             : "=m"(*(uint64_t *)((uint8_t *)p+7*!HAVE_BIGENDIAN)),
68
+               "=m"(*(uint64_t *)((uint8_t *)p+7*HAVE_BIGENDIAN))
69
+             : "r"(v));
70
+}
71
+
72
+#else
73
+
74
+#define AV_RN64 AV_RN64
75
+static inline uint64_t AV_RN64(const void *p)
76
+{
77
+    union { uint64_t v; uint32_t hl[2]; } v;
78
+    v.hl[0] = AV_RN32(p);
79
+    v.hl[1] = AV_RN32((const uint8_t *)p + 4);
80
+    return v.v;
81
+}
82
+
83
+#define AV_WN64 AV_WN64
84
+static inline void AV_WN64(void *p, uint64_t v)
85
+{
86
+    union { uint64_t v; uint32_t hl[2]; } vv = { v };
87
+    AV_WN32(p, vv.hl[0]);
88
+    AV_WN32((uint8_t *)p + 4, vv.hl[1]);
89
+}
90
+
91
+#endif /* ARCH_MIPS64 */
92
+
93
+#endif /* AVUTIL_MIPS_INTREADWRITE_H */