summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
Diffstat (limited to 'fitz')
-rw-r--r--fitz/base_cpudep.c283
-rw-r--r--fitz/base_string.c6
-rw-r--r--fitz/fitz_base.h28
3 files changed, 9 insertions, 308 deletions
diff --git a/fitz/base_cpudep.c b/fitz/base_cpudep.c
deleted file mode 100644
index 586a478a..00000000
--- a/fitz/base_cpudep.c
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
-run-time cpu feature detection code
-mm, alphabet soup...
-
-Glenn Kennard <d98gk@efd.lth.se>
-*/
-
-#include "fitz.h"
-
-/* global run-time constant */
-unsigned fz_cpuflags = 0;
-
-int fz_isbigendian(void)
-{
- static const int one = 1;
- return *(char*)&one == 0;
-}
-
-#ifndef HAVE_CPUDEP
-
-void fz_cpudetect(void)
-{
-}
-
-#else
-
-#ifndef _WIN32
-#include <signal.h> /* signal/sigaction */
-#include <setjmp.h> /* sigsetjmp/siglongjmp */
-#endif
-
-/*
-#ifdef _WIN32
-#define sigjmp_buf jmp_buf
-#define sigsetjmp(a,b) setjmp(a)
-#define siglongjmp longjmp
-#endif
-*/
-
-typedef struct {
- void (*test)(void);
- const unsigned flag;
- const char *name;
-} featuretest;
-
-
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
-
-#ifdef __GNUC__
-static void mmx(void)
-{ __asm__ ("pand %mm0, %mm0\n\t"); }
-
-static void m3dnow(void)
-{ __asm__ ("pavgusb %mm0, %mm0\n\t"); }
-
-static void mmxext(void) /* aka Extended 3DNow! */
-{ __asm__ ("pmaxsw %mm0, %mm0\n\t"); }
-
-static void sse(void)
-{ __asm__ ("andps %xmm0, %xmm0\n\t"); }
-
-static void sse2(void)
-{ __asm__ ("andpd %xmm0, %xmm0\n\t"); }
-
-/*
-static void sse3(void)
-{ __asm__ ("haddps %%xmm0, %%xmm0\n\t" : : : "%xmm0"); }
-*/
-#else
-static void mmx(void)
-{ __asm pand mm0, mm0; }
-
-static void m3dnow(void)
-{ __asm pavgusb mm0, mm0; }
-
-static void mmxext(void) /* aka Extended 3DNow! */
-{ __asm pmaxsw mm0, mm0; }
-
-static void sse(void)
-{ __asm andps xmm0, xmm0; }
-
-static void sse2(void)
-{ __asm andpd xmm0, xmm0; }
-#endif
-
-
-#ifdef ARCH_X86_64
-static void amd64(void)
-#ifdef __GNUC__
-{ __asm__ ("and %rax, %rax\n\t"); }
-#else
-{ __asm and rax, rax; }
-#endif
-#endif
-
-
-static const featuretest features[] = {
- { mmx, HAVE_MMX, "mmx" },
- { m3dnow, HAVE_3DNOW, "3dnow" },
- { mmxext, HAVE_MMXEXT, "mmxext" },
- { sse, HAVE_SSE, "sse" },
- { sse2, HAVE_SSE2, "sse2" },
- /* { sse3, HAVE_SSE3, "sse3" }, */
-#ifdef ARCH_X86_64
- { amd64, HAVE_AMD64, "amd64" },
-#endif
-};
-
-#endif
-
-static int
-enabled(char *env, const char *ext)
-{
- int len;
- char *s;
- if (!env)
- return 1;
- len = strlen(ext);
- s = env;
- while ((s = strstr(s, ext)))
- {
- int atstart = s == env || *(s-1) == ',' || *(s-1) == ' ';
- s += len;
- if (atstart && (*s == ' ' || *s == ',' || *s == '\0')) {
- return 1;
- }
- }
- return 0;
-}
-
-static void
-dumpflags(void)
-{
- unsigned f = fz_cpuflags;
- int i, n;
-
- fputs("detected cpu features:", stdout);
- n = 0;
- for (i = 0; i < sizeof(features) / sizeof(featuretest); i++)
- {
- if (f & features[i].flag)
- {
- fputc(' ', stdout);
- fputs(features[i].name, stdout);
- n ++;
- }
- }
- if (!n)
- fputs(" none", stdout);
- fputc('\n', stdout);
-}
-
-#ifndef _WIN32
-
-static sigjmp_buf jmpbuf;
-static volatile sig_atomic_t canjump;
-
-static void
-sigillhandler(int sig)
-{
- if (!canjump) {
- signal(sig, SIG_DFL);
- raise(sig);
- }
-
- canjump = 0;
- siglongjmp(jmpbuf, 1);
-}
-
-void fz_cpudetect(void)
-{
- static int hasrun = 0;
-
- unsigned flags = 0;
- int i;
- void (*oldhandler)(int) = NULL;
- void (*tmphandler)(int);
- char *env;
-
- if (hasrun)
- return;
- hasrun = 1;
-
- env = getenv("CPUACCEL");
-
- for (i = 0; i < sizeof(features) / sizeof(featuretest); i++)
- {
- canjump = 0;
-
- tmphandler = signal(SIGILL, sigillhandler);
- if (!oldhandler)
- oldhandler = tmphandler;
-
- if (sigsetjmp(jmpbuf, 1))
- {
- /* test failed - disable feature */
- flags &= ~features[i].flag;
- continue;
- }
-
- canjump = 1;
-
- features[i].test();
-
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
- /* reset mmx/x87 pipeline state */
- if (features[i].flag & (HAVE_MMX | HAVE_3DNOW | HAVE_MMXEXT)) {
- __asm__ __volatile__ ("emms\n\t");
- }
-#endif
-
- /* if we got here the test succeeded */
- if (enabled(env, features[i].name))
- flags |= features[i].flag;
- else
- flags &= ~features[i].flag;
- }
-
- /* restore previous signal handler */
- signal(SIGILL, oldhandler);
-
- fz_cpuflags = flags;
-
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
- __asm__ __volatile__ ("emms\n\t");
-#endif
-
- dumpflags();
-}
-
-#else /* _WIN32 */
-
-void fz_cpudetect(void)
-{
- static int hasrun = 0;
-
- unsigned flags = 0;
- int i;
- char *env;
-
- if (hasrun)
- return;
- hasrun = 1;
-
- env = getenv("CPUACCEL");
-
- for (i = 0; i < sizeof(features) / sizeof(featuretest); i++)
- {
- __try
- {
- features[i].test();
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
- {
- /* test failed - disable feature */
- flags &= ~features[i].flag;
- continue;
- }
-
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
- if (features[i].flag & (HAVE_MMX | HAVE_3DNOW | HAVE_MMXEXT)) {
- /* reset mmx/x87 pipeline state */
- __asm emms;
- }
-#endif
-
- /* if we got here the test succeeded */
- if (enabled(env, features[i].name))
- flags |= features[i].flag;
- else
- flags &= ~features[i].flag;
- }
-
- fz_cpuflags = flags;
-
- dumpflags();
-}
-
-
-#endif
-
-#endif
-
diff --git a/fitz/base_string.c b/fitz/base_string.c
index e18d8720..b6b85865 100644
--- a/fitz/base_string.c
+++ b/fitz/base_string.c
@@ -2,6 +2,12 @@
#include <string.h>
+int fz_isbigendian(void)
+{
+ static const int one = 1;
+ return *(char*)&one == 0;
+}
+
char *fz_strsep(char **stringp, const char *delim)
{
char *ret = *stringp;
diff --git a/fitz/fitz_base.h b/fitz/fitz_base.h
index ec1eb9fc..9563b0c9 100644
--- a/fitz/fitz_base.h
+++ b/fitz/fitz_base.h
@@ -69,33 +69,8 @@ extern int gettimeofday(struct timeval *tv, struct timezone *tz);
#endif
#endif
-/*
- * CPU detection and flags
- */
-
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
-#define HAVE_CPUDEP
-#define HAVE_MMX (1<<0)
-#define HAVE_MMXEXT (1<<1)
-#define HAVE_SSE (1<<2)
-#define HAVE_SSE2 (1<<3)
-#define HAVE_SSE3 (1<<4)
-#define HAVE_3DNOW (1<<5)
-#define HAVE_AMD64 (1<<6)
#endif
-#ifdef ARCH_ARM
-#define HAVE_CPUDEP
-#endif
-
-/* call this before using fitz */
-extern void fz_cpudetect(void);
-
-/* treat as constant! */
-extern unsigned fz_cpuflags;
-
-int fz_isbigendian(void);
-
/*
* Base Fitz runtime.
*/
@@ -137,6 +112,9 @@ int fz_isbigendian(void);
#define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) )
#endif
+/* runtime (hah!) test for endian-ness */
+int fz_isbigendian(void);
+
/* utf-8 encoding and decoding */
int chartorune(int *rune, char *str);
int runetochar(char *str, int *rune);