Statistics
| Branch: | Revision:

ffmpeg / libavcodec / alpha / asm.h @ 2d5e962b

History | View | Annotate | Download (7.46 KB)

1 1e98dffb Nick Kurshev
/*
2
 * Alpha optimized DSP utils
3
 * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
4
 *
5 ff4ec49e Fabrice Bellard
 * This library 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 of the License, or (at your option) any later version.
9 1e98dffb Nick Kurshev
 *
10 ff4ec49e Fabrice Bellard
 * This library is distributed in the hope that it will be useful,
11 1e98dffb Nick Kurshev
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ff4ec49e Fabrice Bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14 1e98dffb Nick Kurshev
 *
15 ff4ec49e Fabrice Bellard
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 1e98dffb Nick Kurshev
 */
19
20
#ifndef LIBAVCODEC_ALPHA_ASM_H
21
#define LIBAVCODEC_ALPHA_ASM_H
22
23 b210c96c Falk Hüffner
#include <inttypes.h>
24 1e98dffb Nick Kurshev
25 e447d7d6 Falk Hüffner
#if defined __GNUC__
26
# define GNUC_PREREQ(maj, min) \
27
        ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
28
#else
29
# define GNUC_PREREQ(maj, min) 0
30
#endif
31
32
#if GNUC_PREREQ(2,96)
33
# define likely(x)      __builtin_expect((x) != 0, 1)
34
# define unlikely(x)    __builtin_expect((x) != 0, 0)
35
#else
36
# define likely(x)      (x)
37
# define unlikely(x)    (x)
38
#endif
39
40 1e98dffb Nick Kurshev
#define AMASK_BWX (1 << 0)
41
#define AMASK_FIX (1 << 1)
42 b210c96c Falk Hüffner
#define AMASK_CIX (1 << 2)
43 1e98dffb Nick Kurshev
#define AMASK_MVI (1 << 8)
44
45 669e5093 Alex Beregszaszi
static inline uint64_t BYTE_VEC(uint64_t x)
46 1e98dffb Nick Kurshev
{
47
    x |= x <<  8;
48
    x |= x << 16;
49
    x |= x << 32;
50
    return x;
51
}
52 669e5093 Alex Beregszaszi
static inline uint64_t WORD_VEC(uint64_t x)
53 1e98dffb Nick Kurshev
{
54
    x |= x << 16;
55
    x |= x << 32;
56
    return x;
57
}
58
59 b210c96c Falk Hüffner
#define ldq(p) (*(const uint64_t *) (p))
60
#define ldl(p) (*(const int32_t *) (p))
61
#define stl(l, p) do { *(uint32_t *) (p) = (l); } while (0)
62
#define stq(l, p) do { *(uint64_t *) (p) = (l); } while (0)
63 e447d7d6 Falk Hüffner
#define sextw(x) ((int16_t) (x))
64 1e98dffb Nick Kurshev
65
#ifdef __GNUC__
66 b210c96c Falk Hüffner
#define ASM_ACCEPT_MVI asm (".arch pca56")
67
struct unaligned_long { uint64_t l; } __attribute__((packed));
68
#define ldq_u(p)     (*(const uint64_t *) (((uint64_t) (p)) & ~7ul))
69
#define uldq(a)             (((const struct unaligned_long *) (a))->l)
70
71 e447d7d6 Falk Hüffner
#if GNUC_PREREQ(3,0)
72
/* Unfortunately, __builtin_prefetch is slightly buggy on Alpha. The
73
   defines here are kludged so we still get the right
74
   instruction. This needs to be adapted as soon as gcc is fixed.  */
75
# define prefetch(p)     __builtin_prefetch((p), 0, 1)
76
# define prefetch_en(p)  __builtin_prefetch((p), 1, 1)
77
# define prefetch_m(p)   __builtin_prefetch((p), 0, 0)
78
# define prefetch_men(p) __builtin_prefetch((p), 1, 0)
79
#else
80
# define prefetch(p)     asm volatile("ldl $31,%0"  : : "m"(*(const char *) (p)) : "memory")
81
# define prefetch_en(p)  asm volatile("ldq $31,%0"  : : "m"(*(const char *) (p)) : "memory")
82
# define prefetch_m(p)   asm volatile("lds $f31,%0" : : "m"(*(const char *) (p)) : "memory")
83
# define prefetch_men(p) asm volatile("ldt $f31,%0" : : "m"(*(const char *) (p)) : "memory")
84
#endif
85
86
#if GNUC_PREREQ(3,3)
87 b210c96c Falk Hüffner
#define cmpbge        __builtin_alpha_cmpbge
88
/* Avoid warnings.  */
89
#define extql(a, b)        __builtin_alpha_extql(a, (uint64_t) (b))
90 e447d7d6 Falk Hüffner
#define extwl(a, b)        __builtin_alpha_extwl(a, (uint64_t) (b))
91 b210c96c Falk Hüffner
#define extqh(a, b)        __builtin_alpha_extqh(a, (uint64_t) (b))
92
#define zap        __builtin_alpha_zap
93
#define zapnot        __builtin_alpha_zapnot
94
#define amask        __builtin_alpha_amask
95
#define implver        __builtin_alpha_implver
96
#define rpcc        __builtin_alpha_rpcc
97
#define minub8        __builtin_alpha_minub8
98
#define minsb8        __builtin_alpha_minsb8
99
#define minuw4        __builtin_alpha_minuw4
100
#define minsw4        __builtin_alpha_minsw4
101
#define maxub8        __builtin_alpha_maxub8
102
#define maxsb8        __builtin_alpha_maxsb8
103
#define maxuw4        __builtin_alpha_maxuw4        
104
#define maxsw4        __builtin_alpha_maxsw4
105
#define perr        __builtin_alpha_perr
106
#define pklb        __builtin_alpha_pklb
107
#define pkwb        __builtin_alpha_pkwb
108
#define unpkbl        __builtin_alpha_unpkbl
109
#define unpkbw        __builtin_alpha_unpkbw
110
#else
111
#define cmpbge(a, b) ({ uint64_t __r; asm ("cmpbge  %r1,%2,%0"  : "=r" (__r) : "rJ"  (a), "rI" (b)); __r; })
112
#define extql(a, b)  ({ uint64_t __r; asm ("extql   %r1,%2,%0"  : "=r" (__r) : "rJ"  (a), "rI" (b)); __r; })
113 e447d7d6 Falk Hüffner
#define extwl(a, b)  ({ uint64_t __r; asm ("extwl   %r1,%2,%0"  : "=r" (__r) : "rJ"  (a), "rI" (b)); __r; })
114 b210c96c Falk Hüffner
#define extqh(a, b)  ({ uint64_t __r; asm ("extqh   %r1,%2,%0"  : "=r" (__r) : "rJ"  (a), "rI" (b)); __r; })
115
#define zap(a, b)    ({ uint64_t __r; asm ("zap     %r1,%2,%0"  : "=r" (__r) : "rJ"  (a), "rI" (b)); __r; })
116
#define zapnot(a, b) ({ uint64_t __r; asm ("zapnot  %r1,%2,%0"  : "=r" (__r) : "rJ"  (a), "rI" (b)); __r; })
117
#define amask(a)     ({ uint64_t __r; asm ("amask   %1,%0"      : "=r" (__r) : "rI"  (a));             __r; })
118
#define implver()    ({ uint64_t __r; asm ("implver %0"         : "=r" (__r));                             __r; })
119
#define rpcc()             ({ uint64_t __r; asm volatile ("rpcc %0"   : "=r" (__r));                             __r; })
120
#define minub8(a, b) ({ uint64_t __r; asm ("minub8  %r1,%2,%0"  : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
121
#define minsb8(a, b) ({ uint64_t __r; asm ("minsb8  %r1,%2,%0"  : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
122
#define minuw4(a, b) ({ uint64_t __r; asm ("minuw4  %r1,%2,%0"  : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
123
#define minsw4(a, b) ({ uint64_t __r; asm ("minsw4  %r1,%2,%0"  : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
124
#define maxub8(a, b) ({ uint64_t __r; asm ("maxub8  %r1,%2,%0"  : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
125
#define maxsb8(a, b) ({ uint64_t __r; asm ("maxsb8  %r1,%2,%0"  : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
126
#define maxuw4(a, b) ({ uint64_t __r; asm ("maxuw4  %r1,%2,%0"  : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
127
#define maxsw4(a, b) ({ uint64_t __r; asm ("maxsw4  %r1,%2,%0"  : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
128
#define perr(a, b)   ({ uint64_t __r; asm ("perr    %r1,%r2,%0" : "=r" (__r) : "%rJ" (a), "rJ" (b)); __r; })
129
#define pklb(a)      ({ uint64_t __r; asm ("pklb    %r1,%0"     : "=r" (__r) : "rJ"  (a));             __r; })
130
#define pkwb(a)      ({ uint64_t __r; asm ("pkwb    %r1,%0"     : "=r" (__r) : "rJ"  (a));             __r; })
131
#define unpkbl(a)    ({ uint64_t __r; asm ("unpkbl  %r1,%0"     : "=r" (__r) : "rJ"  (a));             __r; })
132
#define unpkbw(a)    ({ uint64_t __r; asm ("unpkbw  %r1,%0"     : "=r" (__r) : "rJ"  (a));             __r; })
133
#endif
134 1e98dffb Nick Kurshev
135 e447d7d6 Falk Hüffner
#elif defined(__DECC)                /* Digital/Compaq/hp "ccc" compiler */
136 1e98dffb Nick Kurshev
137
#include <c_asm.h>
138 b210c96c Falk Hüffner
#define ASM_ACCEPT_MVI
139
#define ldq_u(a)     asm ("ldq_u   %v0,0(%a0)", a)
140
#define uldq(a)             (*(const __unaligned uint64_t *) (a))
141
#define cmpbge(a, b) asm ("cmpbge  %a0,%a1,%v0", a, b)
142
#define extql(a, b)  asm ("extql   %a0,%a1,%v0", a, b)
143 e447d7d6 Falk Hüffner
#define extwl(a, b)  asm ("extwl   %a0,%a1,%v0", a, b)
144 b210c96c Falk Hüffner
#define extqh(a, b)  asm ("extqh   %a0,%a1,%v0", a, b)
145
#define zap(a, b)    asm ("zap     %a0,%a1,%v0", a, b)
146
#define zapnot(a, b) asm ("zapnot  %a0,%a1,%v0", a, b)
147
#define amask(a)     asm ("amask   %a0,%v0", a)
148
#define implver()    asm ("implver %v0")
149
#define rpcc()             asm ("rpcc           %v0")
150
#define minub8(a, b) asm ("minub8  %a0,%a1,%v0", a, b)
151
#define minsb8(a, b) asm ("minsb8  %a0,%a1,%v0", a, b)
152
#define minuw4(a, b) asm ("minuw4  %a0,%a1,%v0", a, b)
153
#define minsw4(a, b) asm ("minsw4  %a0,%a1,%v0", a, b)
154
#define maxub8(a, b) asm ("maxub8  %a0,%a1,%v0", a, b)
155
#define maxsb8(a, b) asm ("maxsb8  %a0,%a1,%v0", a, b)
156
#define maxuw4(a, b) asm ("maxuw4  %a0,%a1,%v0", a, b)
157
#define maxsw4(a, b) asm ("maxsw4  %a0,%a1,%v0", a, b)
158
#define perr(a, b)   asm ("perr    %a0,%a1,%v0", a, b)
159
#define pklb(a)      asm ("pklb    %a0,%v0", a)
160
#define pkwb(a)      asm ("pkwb    %a0,%v0", a)
161
#define unpkbl(a)    asm ("unpkbl  %a0,%v0", a)
162
#define unpkbw(a)    asm ("unpkbw  %a0,%v0", a)
163
164
#else
165
#error "Unknown compiler!"
166 1e98dffb Nick Kurshev
#endif
167
168
#endif /* LIBAVCODEC_ALPHA_ASM_H */