00001 /* 00002 * Alpha optimized DSP utils 00003 * Copyright (c) 2002 Falk Hueffner <falk@debian.org> 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #ifndef AVCODEC_ALPHA_ASM_H 00023 #define AVCODEC_ALPHA_ASM_H 00024 00025 #include <inttypes.h> 00026 00027 #if defined __GNUC__ 00028 # define GNUC_PREREQ(maj, min) \ 00029 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) 00030 #else 00031 # define GNUC_PREREQ(maj, min) 0 00032 #endif 00033 00034 #if GNUC_PREREQ(2,96) 00035 # define likely(x) __builtin_expect((x) != 0, 1) 00036 # define unlikely(x) __builtin_expect((x) != 0, 0) 00037 #else 00038 # define likely(x) (x) 00039 # define unlikely(x) (x) 00040 #endif 00041 00042 #define AMASK_BWX (1 << 0) 00043 #define AMASK_FIX (1 << 1) 00044 #define AMASK_CIX (1 << 2) 00045 #define AMASK_MVI (1 << 8) 00046 00047 static inline uint64_t BYTE_VEC(uint64_t x) 00048 { 00049 x |= x << 8; 00050 x |= x << 16; 00051 x |= x << 32; 00052 return x; 00053 } 00054 static inline uint64_t WORD_VEC(uint64_t x) 00055 { 00056 x |= x << 16; 00057 x |= x << 32; 00058 return x; 00059 } 00060 00061 #define sextw(x) ((int16_t) (x)) 00062 00063 #ifdef __GNUC__ 00064 #define ldq(p) \ 00065 (((const union { \ 00066 uint64_t __l; \ 00067 __typeof__(*(p)) __s[sizeof (uint64_t) / sizeof *(p)]; \ 00068 } *) (p))->__l) 00069 #define ldl(p) \ 00070 (((const union { \ 00071 int32_t __l; \ 00072 __typeof__(*(p)) __s[sizeof (int32_t) / sizeof *(p)]; \ 00073 } *) (p))->__l) 00074 #define stq(l, p) \ 00075 do { \ 00076 (((union { \ 00077 uint64_t __l; \ 00078 __typeof__(*(p)) __s[sizeof (uint64_t) / sizeof *(p)]; \ 00079 } *) (p))->__l) = l; \ 00080 } while (0) 00081 #define stl(l, p) \ 00082 do { \ 00083 (((union { \ 00084 int32_t __l; \ 00085 __typeof__(*(p)) __s[sizeof (int32_t) / sizeof *(p)]; \ 00086 } *) (p))->__l) = l; \ 00087 } while (0) 00088 struct unaligned_long { uint64_t l; } __attribute__((packed)); 00089 #define ldq_u(p) (*(const uint64_t *) (((uint64_t) (p)) & ~7ul)) 00090 #define uldq(a) (((const struct unaligned_long *) (a))->l) 00091 00092 #if GNUC_PREREQ(3,3) 00093 #define prefetch(p) __builtin_prefetch((p), 0, 1) 00094 #define prefetch_en(p) __builtin_prefetch((p), 0, 0) 00095 #define prefetch_m(p) __builtin_prefetch((p), 1, 1) 00096 #define prefetch_men(p) __builtin_prefetch((p), 1, 0) 00097 #define cmpbge __builtin_alpha_cmpbge 00098 /* Avoid warnings. */ 00099 #define extql(a, b) __builtin_alpha_extql(a, (uint64_t) (b)) 00100 #define extwl(a, b) __builtin_alpha_extwl(a, (uint64_t) (b)) 00101 #define extqh(a, b) __builtin_alpha_extqh(a, (uint64_t) (b)) 00102 #define zap __builtin_alpha_zap 00103 #define zapnot __builtin_alpha_zapnot 00104 #define amask __builtin_alpha_amask 00105 #define implver __builtin_alpha_implver 00106 #define rpcc __builtin_alpha_rpcc 00107 #else 00108 #define prefetch(p) __asm__ volatile("ldl 31,ドル%0" : : "m"(*(const char *) (p)) : "memory") 00109 #define prefetch_en(p) __asm__ volatile("ldq 31,ドル%0" : : "m"(*(const char *) (p)) : "memory") 00110 #define prefetch_m(p) __asm__ volatile("lds $f31,%0" : : "m"(*(const char *) (p)) : "memory") 00111 #define prefetch_men(p) __asm__ volatile("ldt $f31,%0" : : "m"(*(const char *) (p)) : "memory") 00112 #define cmpbge(a, b) ({ uint64_t __r; __asm__ ("cmpbge %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; }) 00113 #define extql(a, b) ({ uint64_t __r; __asm__ ("extql %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; }) 00114 #define extwl(a, b) ({ uint64_t __r; __asm__ ("extwl %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; }) 00115 #define extqh(a, b) ({ uint64_t __r; __asm__ ("extqh %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; }) 00116 #define zap(a, b) ({ uint64_t __r; __asm__ ("zap %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; }) 00117 #define zapnot(a, b) ({ uint64_t __r; __asm__ ("zapnot %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; }) 00118 #define amask(a) ({ uint64_t __r; __asm__ ("amask %1,%0" : "=r" (__r) : "rI" (a)); __r; }) 00119 #define implver() ({ uint64_t __r; __asm__ ("implver %0" : "=r" (__r)); __r; }) 00120 #define rpcc() ({ uint64_t __r; __asm__ volatile ("rpcc %0" : "=r" (__r)); __r; }) 00121 #endif 00122 #define wh64(p) __asm__ volatile("wh64 (%0)" : : "r"(p) : "memory") 00123 00124 #if GNUC_PREREQ(3,3) && defined(__alpha_max__) 00125 #define minub8 __builtin_alpha_minub8 00126 #define minsb8 __builtin_alpha_minsb8 00127 #define minuw4 __builtin_alpha_minuw4 00128 #define minsw4 __builtin_alpha_minsw4 00129 #define maxub8 __builtin_alpha_maxub8 00130 #define maxsb8 __builtin_alpha_maxsb8 00131 #define maxuw4 __builtin_alpha_maxuw4 00132 #define maxsw4 __builtin_alpha_maxsw4 00133 #define perr __builtin_alpha_perr 00134 #define pklb __builtin_alpha_pklb 00135 #define pkwb __builtin_alpha_pkwb 00136 #define unpkbl __builtin_alpha_unpkbl 00137 #define unpkbw __builtin_alpha_unpkbw 00138 #else 00139 #define minub8(a, b) ({ uint64_t __r; __asm__ (".arch ev6; minub8 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; }) 00140 #define minsb8(a, b) ({ uint64_t __r; __asm__ (".arch ev6; minsb8 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; }) 00141 #define minuw4(a, b) ({ uint64_t __r; __asm__ (".arch ev6; minuw4 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; }) 00142 #define minsw4(a, b) ({ uint64_t __r; __asm__ (".arch ev6; minsw4 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; }) 00143 #define maxub8(a, b) ({ uint64_t __r; __asm__ (".arch ev6; maxub8 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; }) 00144 #define maxsb8(a, b) ({ uint64_t __r; __asm__ (".arch ev6; maxsb8 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; }) 00145 #define maxuw4(a, b) ({ uint64_t __r; __asm__ (".arch ev6; maxuw4 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; }) 00146 #define maxsw4(a, b) ({ uint64_t __r; __asm__ (".arch ev6; maxsw4 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; }) 00147 #define perr(a, b) ({ uint64_t __r; __asm__ (".arch ev6; perr %r1,%r2,%0" : "=r" (__r) : "%rJ" (a), "rJ" (b)); __r; }) 00148 #define pklb(a) ({ uint64_t __r; __asm__ (".arch ev6; pklb %r1,%0" : "=r" (__r) : "rJ" (a)); __r; }) 00149 #define pkwb(a) ({ uint64_t __r; __asm__ (".arch ev6; pkwb %r1,%0" : "=r" (__r) : "rJ" (a)); __r; }) 00150 #define unpkbl(a) ({ uint64_t __r; __asm__ (".arch ev6; unpkbl %r1,%0" : "=r" (__r) : "rJ" (a)); __r; }) 00151 #define unpkbw(a) ({ uint64_t __r; __asm__ (".arch ev6; unpkbw %r1,%0" : "=r" (__r) : "rJ" (a)); __r; }) 00152 #endif 00153 00154 #elif defined(__DECC) /* Digital/Compaq/hp "ccc" compiler */ 00155 00156 #include <c_asm.h> 00157 #define ldq(p) (*(const uint64_t *) (p)) 00158 #define ldl(p) (*(const int32_t *) (p)) 00159 #define stq(l, p) do { *(uint64_t *) (p) = (l); } while (0) 00160 #define stl(l, p) do { *(int32_t *) (p) = (l); } while (0) 00161 #define ldq_u(a) asm ("ldq_u %v0,0(%a0)", a) 00162 #define uldq(a) (*(const __unaligned uint64_t *) (a)) 00163 #define cmpbge(a, b) asm ("cmpbge %a0,%a1,%v0", a, b) 00164 #define extql(a, b) asm ("extql %a0,%a1,%v0", a, b) 00165 #define extwl(a, b) asm ("extwl %a0,%a1,%v0", a, b) 00166 #define extqh(a, b) asm ("extqh %a0,%a1,%v0", a, b) 00167 #define zap(a, b) asm ("zap %a0,%a1,%v0", a, b) 00168 #define zapnot(a, b) asm ("zapnot %a0,%a1,%v0", a, b) 00169 #define amask(a) asm ("amask %a0,%v0", a) 00170 #define implver() asm ("implver %v0") 00171 #define rpcc() asm ("rpcc %v0") 00172 #define minub8(a, b) asm ("minub8 %a0,%a1,%v0", a, b) 00173 #define minsb8(a, b) asm ("minsb8 %a0,%a1,%v0", a, b) 00174 #define minuw4(a, b) asm ("minuw4 %a0,%a1,%v0", a, b) 00175 #define minsw4(a, b) asm ("minsw4 %a0,%a1,%v0", a, b) 00176 #define maxub8(a, b) asm ("maxub8 %a0,%a1,%v0", a, b) 00177 #define maxsb8(a, b) asm ("maxsb8 %a0,%a1,%v0", a, b) 00178 #define maxuw4(a, b) asm ("maxuw4 %a0,%a1,%v0", a, b) 00179 #define maxsw4(a, b) asm ("maxsw4 %a0,%a1,%v0", a, b) 00180 #define perr(a, b) asm ("perr %a0,%a1,%v0", a, b) 00181 #define pklb(a) asm ("pklb %a0,%v0", a) 00182 #define pkwb(a) asm ("pkwb %a0,%v0", a) 00183 #define unpkbl(a) asm ("unpkbl %a0,%v0", a) 00184 #define unpkbw(a) asm ("unpkbw %a0,%v0", a) 00185 #define wh64(a) asm ("wh64 %a0", a) 00186 00187 #else 00188 #error "Unknown compiler!" 00189 #endif 00190 00191 #endif /* AVCODEC_ALPHA_ASM_H */