Commit 47dc8676 by Nicolas Capens

Fix ARM compilation.

This does not provide full support for ARM, but merely makes things (statically) compile. Bug b/37478805 Change-Id: I01d1d84e396c04c84e74d521946595014d2eafb5 Reviewed-on: https://swiftshader-review.googlesource.com/9430Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 1cc44388
...@@ -164,10 +164,17 @@ namespace sw ...@@ -164,10 +164,17 @@ namespace sw
static void cpuid(int registers[4], int info) static void cpuid(int registers[4], int info)
{ {
#if defined(_WIN32) #if defined(__i386__) || defined(__x86_64__)
__cpuid(registers, info); #if defined(_WIN32)
__cpuid(registers, info);
#else
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info));
#endif
#else #else
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); registers[0] = 0;
registers[1] = 0;
registers[2] = 0;
registers[3] = 0;
#endif #endif
} }
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
namespace sw namespace sw
{ {
#if !defined(__i386__) && defined(_M_IX86)
#define __i386__ 1
#endif
#if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64)) #if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64))
#define __x86_64__ 1 #define __x86_64__ 1
#endif #endif
......
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
#include "Timer.hpp" #include "Timer.hpp"
#if !defined(__i386__) && defined(_M_IX86)
#define __i386__ 1
#endif
#if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64))
#define __x86_64__ 1
#endif
#if defined(_WIN32) #if defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
...@@ -22,7 +30,9 @@ ...@@ -22,7 +30,9 @@
#include <intrin.h> #include <intrin.h>
#else #else
#include <sys/time.h> #include <sys/time.h>
#include <x86intrin.h> #if defined(__i386__) || defined(__x86_64__)
#include <x86intrin.h>
#endif
#endif #endif
namespace sw namespace sw
...@@ -50,10 +60,12 @@ namespace sw ...@@ -50,10 +60,12 @@ namespace sw
{ {
#if defined(_WIN32) #if defined(_WIN32)
return __rdtsc(); return __rdtsc();
#else #elif defined(__i386__) || defined(__x86_64__)
int64_t tsc; int64_t tsc;
__asm volatile("rdtsc": "=A" (tsc)); __asm volatile("rdtsc": "=A" (tsc));
return tsc; return tsc;
#else
return 0;
#endif #endif
} }
......
...@@ -84,12 +84,27 @@ Display::~Display() ...@@ -84,12 +84,27 @@ Display::~Display()
#endif #endif
} }
#if !defined(__i386__) && defined(_M_IX86)
#define __i386__ 1
#endif
#if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64))
#define __x86_64__ 1
#endif
static void cpuid(int registers[4], int info) static void cpuid(int registers[4], int info)
{ {
#if defined(_WIN32) #if defined(__i386__) || defined(__x86_64__)
__cpuid(registers, info); #if defined(_WIN32)
__cpuid(registers, info);
#else
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info));
#endif
#else #else
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); registers[0] = 0;
registers[1] = 0;
registers[2] = 0;
registers[3] = 0;
#endif #endif
} }
...@@ -107,10 +122,12 @@ bool Display::initialize() ...@@ -107,10 +122,12 @@ bool Display::initialize()
return true; return true;
} }
if(!detectSSE()) #if defined(__i386__) || defined(__x86_64__)
{ if(!detectSSE())
return false; {
} return false;
}
#endif
mMinSwapInterval = 0; mMinSwapInterval = 0;
mMaxSwapInterval = 4; mMaxSwapInterval = 4;
......
...@@ -37,9 +37,12 @@ ...@@ -37,9 +37,12 @@
#include "Memory.hpp" #include "Memory.hpp"
#include "MutexLock.hpp" #include "MutexLock.hpp"
#include <xmmintrin.h>
#include <fstream> #include <fstream>
#if defined(__i386__) || defined(__x86_64__)
#include <xmmintrin.h>
#endif
#if defined(__x86_64__) && defined(_WIN32) #if defined(__x86_64__) && defined(_WIN32)
extern "C" void X86CompilationCallback() extern "C" void X86CompilationCallback()
{ {
...@@ -5734,16 +5737,16 @@ namespace sw ...@@ -5734,16 +5737,16 @@ namespace sw
RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2)
{ {
if(exactAtPow2) #if defined(__i386__) || defined(__x86_64__)
{ if(exactAtPow2)
// rcpss uses a piecewise-linear approximation which minimizes the relative error {
// but is not exact at power-of-two values. Rectify by multiplying by the inverse. // rcpss uses a piecewise-linear approximation which minimizes the relative error
return x86::rcpss(x) * Float(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); // but is not exact at power-of-two values. Rectify by multiplying by the inverse.
} return x86::rcpss(x) * Float(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f))));
else }
{ #endif
return x86::rcpss(x);
} return x86::rcpss(x);
} }
RValue<Float> RcpSqrt_pp(RValue<Float> x) RValue<Float> RcpSqrt_pp(RValue<Float> x)
...@@ -6114,16 +6117,16 @@ namespace sw ...@@ -6114,16 +6117,16 @@ namespace sw
RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2)
{ {
if(exactAtPow2) #if defined(__i386__) || defined(__x86_64__)
{ if(exactAtPow2)
// rcpps uses a piecewise-linear approximation which minimizes the relative error {
// but is not exact at power-of-two values. Rectify by multiplying by the inverse. // rcpps uses a piecewise-linear approximation which minimizes the relative error
return x86::rcpps(x) * Float4(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f)))); // but is not exact at power-of-two values. Rectify by multiplying by the inverse.
} return x86::rcpps(x) * Float4(1.0f / _mm_cvtss_f32(_mm_rcp_ss(_mm_set_ps1(1.0f))));
else }
{ #endif
return x86::rcpps(x);
} return x86::rcpps(x);
} }
RValue<Float4> RcpSqrt_pp(RValue<Float4> x) RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
......
...@@ -66,6 +66,14 @@ namespace ...@@ -66,6 +66,14 @@ namespace
namespace namespace
{ {
#if !defined(__i386__) && defined(_M_IX86)
#define __i386__ 1
#endif
#if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64))
#define __x86_64__ 1
#endif
class CPUID class CPUID
{ {
public: public:
...@@ -74,18 +82,29 @@ namespace ...@@ -74,18 +82,29 @@ namespace
private: private:
static void cpuid(int registers[4], int info) static void cpuid(int registers[4], int info)
{ {
#if defined(_WIN32) #if defined(__i386__) || defined(__x86_64__)
__cpuid(registers, info); #if defined(_WIN32)
__cpuid(registers, info);
#else
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info));
#endif
#else #else
__asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); registers[0] = 0;
registers[1] = 0;
registers[2] = 0;
registers[3] = 0;
#endif #endif
} }
static bool detectSSE4_1() static bool detectSSE4_1()
{ {
int registers[4]; #if defined(__i386__) || defined(__x86_64__)
cpuid(registers, 1); int registers[4];
return (registers[2] & 0x00080000) != 0; cpuid(registers, 1);
return (registers[2] & 0x00080000) != 0;
#else
return false;
#endif
} }
}; };
......
...@@ -69,7 +69,7 @@ void llvm::sys::Memory::InvalidateInstructionCache(const void *Addr, ...@@ -69,7 +69,7 @@ void llvm::sys::Memory::InvalidateInstructionCache(const void *Addr,
// FIXME: Can we safely always call this for __GNUC__ everywhere? // FIXME: Can we safely always call this for __GNUC__ everywhere?
char *Start = (char*) Addr; char *Start = (char*) Addr;
char *End = Start + Len; char *End = Start + Len;
__clear_cache(Start, End); __builtin___clear_cache(Start, End);
# elif defined(__mips__) # elif defined(__mips__)
cacheflush((char*)Addr, Len, BCACHE); cacheflush((char*)Addr, Len, BCACHE);
# endif # endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment