Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Aarch64 support to oclmath library #921

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion oclmath/fpcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
__asm__ volatile ("fmrx %0, fpscr" : "=r"(fpscr));
*mode = fpscr;
__asm__ volatile ("fmxr fpscr, %0" :: "r"(fpscr | (1U << 24)));
#elif defined ( __aarch64__ )
unsigned fpcr;
__asm__ volatile ("mrs %0, fpcr" : "=r"(fpcr));
*mode = fpcr;
__asm__ volatile ("msr fpcr, %0" :: "r"(fpcr | (1U << 24)));
#else
#error ForceFTZ needs an implentation
#endif
Expand All @@ -50,6 +55,11 @@
__asm__ volatile ("fmrx %0, fpscr" : "=r"(fpscr));
*mode = fpscr;
__asm__ volatile ("fmxr fpscr, %0" :: "r"(fpscr & ~(1U << 24)));
#elif defined ( __aarch64__ )
unsigned fpcr;
__asm__ volatile ("mrs %0, fpcr" : "=r"(fpcr));
*mode = fpcr;
__asm__ volatile ("msr fpcr, %0" :: "r"(fpcr & ~(1U << 24)));
#else
#error DisableFTZ needs an implentation
#endif
Expand All @@ -64,6 +74,8 @@
fpu_control = *mode;
#elif defined (__arm__)
__asm__ volatile ("fmxr fpscr, %0" :: "r"(*mode));
#elif defined( __aarch64__ )
__asm__ volatile ("msr fpcr, %0" :: "r"(*mode));
#else
#error RestoreFPState needs an implementation
#endif
Expand All @@ -72,4 +84,4 @@
#error ForceFTZ and RestoreFPState need implentations
#endif

#endif
#endif
2 changes: 1 addition & 1 deletion oclmath/reference_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4800,7 +4800,7 @@ static long double reference_scalblnl(long double x, long n)

return x;

#elif defined(__arm__) // ARM .. sizeof(long double) == sizeof(double)
#elif defined(__arm__) || defined( __aarch64__ ) // ARM .. sizeof(long double) == sizeof(double)

#if __DBL_MAX_EXP__ >= __LDBL_MAX_EXP__
if(reference_isinfl(x) || reference_isnanl(x))
Expand Down
24 changes: 15 additions & 9 deletions oclmath/rounding_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,14 @@ void *FlushToZero( void )
union{ unsigned int i; void *p; }u = { _mm_getcsr() };
_mm_setcsr( u.i | 0x8040 );
return u.p;
#elif defined( __arm__ )
#elif defined( __arm__ ) || defined( __aarch64__ )
#define _ARM_FE_FTZ 0x1000000
#define _ARM_FE_NFTZ 0x0
#define _FPU_SETCW(cw) __asm__ ("VMSR FPSCR,%0" : :"ri" (cw))

#define _ARM_FE_NFTZ 0x0
#if defined( __arm__ )
#define _FPU_SETCW(cw) __asm__ ("VMSR FPSCR,%0" : :"ri" (cw))
#elif defined(__aarch64__)
#define _FPU_SETCW(cw) __asm__ ("MSR FPCR,%0" : :"ri" (cw))
#endif
static const int ftz_modes[ kRoundingModeCount ] = { _ARM_FE_FTZ, _ARM_FE_NFTZ };
const int *f = ftz_modes;
_FPU_SETCW( f[0] );
Expand All @@ -199,7 +202,7 @@ void *FlushToZero( void )
fpu_control_t flags = 0;
_FPU_GETCW(flags);
flags |= _FPU_MASK_NI;
_FPU_SETCW(flags);
_FPU_SETCW(flags);
return NULL;
#else
#error Unknown arch
Expand All @@ -216,11 +219,14 @@ void UnFlushToZero( void *p)
#if defined( __i386__ ) || defined( __x86_64__ ) || defined(_MSC_VER)
union{ void *p; int i; }u = { p };
_mm_setcsr( u.i );
#elif defined( __arm__ )
#elif defined( __arm__ ) || defined( __aarch64__ )
#define _ARM_FE_FTZ 0x1000000
#define _ARM_FE_NFTZ 0x0
#define _FPU_SETCW(cw) __asm__ ("VMSR FPSCR,%0" : :"ri" (cw))

#define _ARM_FE_NFTZ 0x0
#if defined( __arm__ )
#define _FPU_SETCW(cw) __asm__ ("VMSR FPSCR,%0" : :"ri" (cw))
#elif defined( __aarch64__ )
#define _FPU_SETCW(cw) __asm__ ("MSR FPCR,%0" : :"ri" (cw))
#endif
static const int ftz_modes[ kRoundingModeCount ] = { _ARM_FE_FTZ, _ARM_FE_NFTZ };
const int *f = ftz_modes;
_FPU_SETCW( f[1] );
Expand Down