#include "../dsputil.h"
#include "dsputil_altivec.h"
-#if CONFIG_DARWIN
+#ifdef CONFIG_DARWIN
#include <sys/sysctl.h>
-#endif
+#else /* CONFIG_DARWIN */
+#include <signal.h>
+#include <setjmp.h>
+
+static sigjmp_buf jmpbuf;
+static volatile sig_atomic_t canjump = 0;
+
+static void sigill_handler (int sig)
+{
+ if (!canjump) {
+ signal (sig, SIG_DFL);
+ raise (sig);
+ }
+
+ canjump = 0;
+ siglongjmp (jmpbuf, 1);
+}
+#endif /* CONFIG_DARWIN */
int pix_abs16x16_x2_altivec(uint8_t *pix1, uint8_t *pix2, int line_size)
{
int i;
int s __attribute__((aligned(16)));
- const vector unsigned char zero = (const vector unsigned char)(0);
+ const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
vector unsigned char *tv;
vector unsigned char pix1v, pix2v, pix2iv, avgv, t5;
vector unsigned int sad;
vector signed int sumdiffs;
s = 0;
- sad = (vector unsigned int)(0);
+ sad = (vector unsigned int)vec_splat_u32(0);
for(i=0;i<16;i++) {
/*
Read unaligned pixels into our vectors. The vectors are as follows:
{
int i;
int s __attribute__((aligned(16)));
- const vector unsigned char zero = (const vector unsigned char)(0);
+ const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
vector unsigned char *tv;
vector unsigned char pix1v, pix2v, pix3v, avgv, t5;
vector unsigned int sad;
uint8_t *pix3 = pix2 + line_size;
s = 0;
- sad = (vector unsigned int)(0);
+ sad = (vector unsigned int)vec_splat_u32(0);
/*
Due to the fact that pix3 = pix2 + line_size, the pix3 of one
int i;
int s __attribute__((aligned(16)));
uint8_t *pix3 = pix2 + line_size;
- const vector unsigned char zero = (const vector unsigned char)(0);
- const vector unsigned short two = (const vector unsigned short)(2);
+ const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
+ const vector unsigned short two = (const vector unsigned short)vec_splat_u16(2);
vector unsigned char *tv, avgv, t5;
vector unsigned char pix1v, pix2v, pix3v, pix2iv, pix3iv;
vector unsigned short pix2lv, pix2hv, pix2ilv, pix2ihv;
vector unsigned int sad;
vector signed int sumdiffs;
- sad = (vector unsigned int)(0);
+ sad = (vector unsigned int)vec_splat_u32(0);
s = 0;
{
int i;
int s __attribute__((aligned(16)));
- const vector unsigned int zero = (const vector unsigned int)(0);
+ const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
vector unsigned char perm1, perm2, *pix1v, *pix2v;
vector unsigned char t1, t2, t3,t4, t5;
vector unsigned int sad;
vector signed int sumdiffs;
- sad = (vector unsigned int) (0);
+ sad = (vector unsigned int)vec_splat_u32(0);
for(i=0;i<16;i++) {
{
int i;
int s __attribute__((aligned(16)));
- const vector unsigned int zero = (const vector unsigned int)(0);
+ const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
vector unsigned char perm1, perm2, permclear, *pix1v, *pix2v;
vector unsigned char t1, t2, t3,t4, t5;
vector unsigned int sad;
vector signed int sumdiffs;
- sad = (vector unsigned int)(0);
- permclear = (vector unsigned char) (255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0);
+ sad = (vector unsigned int)vec_splat_u32(0);
+#ifdef CONFIG_DARWIN
+ permclear = (vector unsigned char)(255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0);
+#else
+ permclear = (vector unsigned char){255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0};
+#endif
for(i=0;i<8;i++) {
/* Read potentially unaligned pixels into t1 and t2
{
int i;
int s __attribute__((aligned(16)));
- const vector unsigned int zero = (const vector unsigned int)(0);
+ const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
vector unsigned char *tv;
vector unsigned char pixv;
vector unsigned int sv;
vector signed int sum;
- sv = (vector unsigned int)(0);
+ sv = (vector unsigned int)vec_splat_u32(0);
s = 0;
for (i = 0; i < 16; i++) {
{
int i;
int s __attribute__((aligned(16)));
- const vector unsigned int zero = (const vector unsigned int)(0);
+ const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
vector unsigned char perm1, perm2, permclear, *pix1v, *pix2v;
vector unsigned char t1, t2, t3,t4, t5;
vector unsigned int sum;
vector signed int sumsqr;
- sum = (vector unsigned int)(0);
- permclear = (vector unsigned char)(0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
+ sum = (vector unsigned int)vec_splat_u32(0);
+#ifdef CONFIG_DARWIN
+ permclear = (vector unsigned char)(255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0);
+#else
+ permclear = (vector unsigned char){255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0};
+#endif
for(i=0;i<8;i++) {
/* Read potentially unaligned pixels into t1 and t2
{
int i;
int s __attribute__((aligned(16)));
- const vector unsigned int zero = (const vector unsigned int)(0);
+ const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
vector unsigned char perm1, perm2, *pix1v, *pix2v;
vector unsigned char t1, t2, t3,t4, t5;
vector unsigned int sum;
vector signed int sumsqr;
- sum = (vector unsigned int)(0);
+ sum = (vector unsigned int)vec_splat_u32(0);
for(i=0;i<16;i++) {
/* Read potentially unaligned pixels into t1 and t2 */
int pix_sum_altivec(UINT8 * pix, int line_size)
{
- const vector unsigned int zero = (const vector unsigned int)(0);
+ const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
vector unsigned char perm, *pixv;
vector unsigned char t1;
vector unsigned int sad;
int i;
int s __attribute__((aligned(16)));
- sad = (vector unsigned int) (0);
+ sad = (vector unsigned int)vec_splat_u32(0);
for (i = 0; i < 16; i++) {
/* Read the potentially unaligned 16 pixels into t1 */
{
int i;
vector unsigned char perm, bytes, *pixv;
- const vector unsigned char zero = (const vector unsigned char) (0);
+ const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
vector signed short shorts;
for(i=0;i<8;i++)
{
int i;
vector unsigned char perm, bytes, *pixv;
- const vector unsigned char zero = (const vector unsigned char) (0);
+ const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
vector signed short shorts1, shorts2;
for(i=0;i<4;i++)
blockv, temp1, temp2;
register vector unsigned short
pixelssum1, pixelssum2, temp3;
- register const vector unsigned char vczero = (const vector unsigned char)(0);
- register const vector unsigned short vctwo = (const vector unsigned short)(2);
+ register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
+ register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
temp1 = vec_ld(0, pixels);
temp2 = vec_ld(16, pixels);
blockv, temp1, temp2;
register vector unsigned short
pixelssum1, pixelssum2, temp3;
- register const vector unsigned char vczero = (const vector unsigned char)(0);
- register const vector unsigned short vcone = (const vector unsigned short)(1);
- register const vector unsigned short vctwo = (const vector unsigned short)(2);
+ register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
+ register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1);
+ register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
temp1 = vec_ld(0, pixels);
temp2 = vec_ld(16, pixels);
register vector unsigned short
pixelssum1, pixelssum2, temp3,
pixelssum3, pixelssum4, temp4;
- register const vector unsigned char vczero = (const vector unsigned char)(0);
- register const vector unsigned short vctwo = (const vector unsigned short)(2);
+ register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
+ register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
temp1 = vec_ld(0, pixels);
temp2 = vec_ld(16, pixels);
register vector unsigned short
pixelssum1, pixelssum2, temp3,
pixelssum3, pixelssum4, temp4;
- register const vector unsigned char vczero = (const vector unsigned char)(0);
- register const vector unsigned short vcone = (const vector unsigned short)(1);
- register const vector unsigned short vctwo = (const vector unsigned short)(2);
+ register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
+ register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1);
+ register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
temp1 = vec_ld(0, pixels);
temp2 = vec_ld(16, pixels);
int has_altivec(void)
{
-#if CONFIG_DARWIN
+#ifdef CONFIG_DARWIN
int sels[2] = {CTL_HW, HW_VECTORUNIT};
int has_vu = 0;
size_t len = sizeof(has_vu);
err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
if (err == 0) return (has_vu != 0);
-#endif
+#else /* CONFIG_DARWIN */
+/* no Darwin, do it the brute-force way */
+/* this is borrowed from the libmpeg2 library */
+ {
+ signal (SIGILL, sigill_handler);
+ if (sigsetjmp (jmpbuf, 1)) {
+ signal (SIGILL, SIG_DFL);
+ } else {
+ canjump = 1;
+
+ asm volatile ("mtspr 256, %0\n\t"
+ "vand %%v0, %%v0, %%v0"
+ :
+ : "r" (-1));
+
+ signal (SIGILL, SIG_DFL);
+ return 1;
+ }
+ }
+#endif /* CONFIG_DARWIN */
return 0;
}
vec = vec_splat(vec, 0); \
}
+
+#ifdef CONFIG_DARWIN
+#define FOUROF(a) (a)
+#else
+// slower, for dumb non-apple GCC
+#define FOUROF(a) {a,a,a,a}
+#endif
int dct_quantize_altivec(MpegEncContext* s,
DCTELEM* data, int n,
int qscale, int* overflow)
int lastNonZero;
vector float row0, row1, row2, row3, row4, row5, row6, row7;
vector float alt0, alt1, alt2, alt3, alt4, alt5, alt6, alt7;
- const vector float zero = (const vector float)(0.0f);
+ const vector float zero = (const vector float)FOUROF(0.);
// Load the data into the row/alt vectors
{
// in the vector local variables, as floats, which we'll use during the
// quantize step...
{
- const vector float vec_0_298631336 = (vector float)(0.298631336f);
- const vector float vec_0_390180644 = (vector float)(-0.390180644f);
- const vector float vec_0_541196100 = (vector float)(0.541196100f);
- const vector float vec_0_765366865 = (vector float)(0.765366865f);
- const vector float vec_0_899976223 = (vector float)(-0.899976223f);
- const vector float vec_1_175875602 = (vector float)(1.175875602f);
- const vector float vec_1_501321110 = (vector float)(1.501321110f);
- const vector float vec_1_847759065 = (vector float)(-1.847759065f);
- const vector float vec_1_961570560 = (vector float)(-1.961570560f);
- const vector float vec_2_053119869 = (vector float)(2.053119869f);
- const vector float vec_2_562915447 = (vector float)(-2.562915447f);
- const vector float vec_3_072711026 = (vector float)(3.072711026f);
+ const vector float vec_0_298631336 = (vector float)FOUROF(0.298631336f);
+ const vector float vec_0_390180644 = (vector float)FOUROF(-0.390180644f);
+ const vector float vec_0_541196100 = (vector float)FOUROF(0.541196100f);
+ const vector float vec_0_765366865 = (vector float)FOUROF(0.765366865f);
+ const vector float vec_0_899976223 = (vector float)FOUROF(-0.899976223f);
+ const vector float vec_1_175875602 = (vector float)FOUROF(1.175875602f);
+ const vector float vec_1_501321110 = (vector float)FOUROF(1.501321110f);
+ const vector float vec_1_847759065 = (vector float)FOUROF(-1.847759065f);
+ const vector float vec_1_961570560 = (vector float)FOUROF(-1.961570560f);
+ const vector float vec_2_053119869 = (vector float)FOUROF(2.053119869f);
+ const vector float vec_2_562915447 = (vector float)FOUROF(-2.562915447f);
+ const vector float vec_3_072711026 = (vector float)FOUROF(3.072711026f);
int whichPass, whichHalf;
// rounding when we convert to int, instead of flooring.)
{
vector signed int biasInt;
- const vector float negOneFloat = (vector float)(-1.0f);
+ const vector float negOneFloat = (vector float)FOUROF(-1.0f);
LOAD4(biasInt, biasAddr);
bias = vec_ctf(biasInt, QUANT_BIAS_SHIFT);
negBias = vec_madd(bias, negOneFloat, zero);
return lastNonZero;
}
+#undef FOUROF
/*
AltiVec version of dct_unquantize_h263
}
#else /* ALTIVEC_USE_REFERENCE_C_CODE */
{
- register const vector short vczero = (const vector short)(0);
+ register const vector short vczero = (const vector short)vec_splat_s16(0);
short __attribute__ ((aligned(16))) qmul8[] =
{
qmul, qmul, qmul, qmul,