comparison ppc/dsputil_altivec.c @ 5750:09f99af1db40 libavcodec

Sanitize altivec code so it can be built with runtime check properly
author lu_zero
date Tue, 02 Oct 2007 11:39:32 +0000
parents 784dcbdc910f
children af20477e9994
comparison
equal deleted inserted replaced
5749:784dcbdc910f 5750:09f99af1db40
23 #include "dsputil.h" 23 #include "dsputil.h"
24 24
25 #include "gcc_fixes.h" 25 #include "gcc_fixes.h"
26 26
27 #include "dsputil_altivec.h" 27 #include "dsputil_altivec.h"
28 28 #include "util_altivec.h"
29 #ifdef __APPLE__
30 #include <sys/sysctl.h>
31 #elif __AMIGAOS4__
32 #include <exec/exec.h>
33 #include <interfaces/exec.h>
34 #include <proto/exec.h>
35 #else
36 #include <signal.h>
37 #include <setjmp.h>
38
39 static sigjmp_buf jmpbuf;
40 static volatile sig_atomic_t canjump = 0;
41
42 static void sigill_handler (int sig)
43 {
44 if (!canjump) {
45 signal (sig, SIG_DFL);
46 raise (sig);
47 }
48
49 canjump = 0;
50 siglongjmp (jmpbuf, 1);
51 }
52 #endif /* __APPLE__ */
53 29
54 int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) 30 int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
55 { 31 {
56 int i; 32 int i;
57 DECLARE_ALIGNED_16(int, s); 33 DECLARE_ALIGNED_16(int, s);
1415 } 1391 }
1416 POWERPC_PERF_STOP_COUNT(altivec_hadamard8_diff16_num, 1); 1392 POWERPC_PERF_STOP_COUNT(altivec_hadamard8_diff16_num, 1);
1417 return score; 1393 return score;
1418 } 1394 }
1419 1395
1420 int has_altivec(void)
1421 {
1422 #ifdef __AMIGAOS4__
1423 ULONG result = 0;
1424 extern struct ExecIFace *IExec;
1425
1426 IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE);
1427 if (result == VECTORTYPE_ALTIVEC) return 1;
1428 return 0;
1429 #elif __APPLE__
1430 int sels[2] = {CTL_HW, HW_VECTORUNIT};
1431 int has_vu = 0;
1432 size_t len = sizeof(has_vu);
1433 int err;
1434
1435 err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
1436
1437 if (err == 0) return (has_vu != 0);
1438 return 0;
1439 #else
1440 /* Do it the brute-force way, borrowed from the libmpeg2 library. */
1441 {
1442 signal (SIGILL, sigill_handler);
1443 if (sigsetjmp (jmpbuf, 1)) {
1444 signal (SIGILL, SIG_DFL);
1445 } else {
1446 canjump = 1;
1447
1448 asm volatile ("mtspr 256, %0\n\t"
1449 "vand %%v0, %%v0, %%v0"
1450 :
1451 : "r" (-1));
1452
1453 signal (SIGILL, SIG_DFL);
1454 return 1;
1455 }
1456 }
1457 return 0;
1458 #endif /* __AMIGAOS4__ */
1459 }
1460
1461 static void vorbis_inverse_coupling_altivec(float *mag, float *ang, 1396 static void vorbis_inverse_coupling_altivec(float *mag, float *ang,
1462 int blocksize) 1397 int blocksize)
1463 { 1398 {
1464 int i; 1399 int i;
1465 vector float m, a; 1400 vector float m, a;