riscos: Add CPU feature detection
authorCameron Cawley
Mon, 06 Jan 2020 20:26:52 +0000
changeset 1339713ae0ea1ed2b
parent 13395 a71ca81d27ec
child 13398 1e585115ed86
riscos: Add CPU feature detection
src/cpuinfo/SDL_cpuinfo.c
     1.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Mon Jan 06 12:18:51 2020 -0800
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Mon Jan 06 20:26:52 2020 +0000
     1.3 @@ -90,6 +90,11 @@
     1.4  #endif
     1.5  #endif
     1.6  
     1.7 +#ifdef __RISCOS__
     1.8 +#include <kernel.h>
     1.9 +#include <swis.h>
    1.10 +#endif
    1.11 +
    1.12  #define CPU_HAS_RDTSC   (1 << 0)
    1.13  #define CPU_HAS_ALTIVEC (1 << 1)
    1.14  #define CPU_HAS_MMX     (1 << 2)
    1.15 @@ -333,7 +338,7 @@
    1.16      return altivec;
    1.17  }
    1.18  
    1.19 -#if !defined(__ARM_ARCH)
    1.20 +#if !defined(__arm__)
    1.21  static int
    1.22  CPU_haveARMSIMD(void)
    1.23  {
    1.24 @@ -373,6 +378,27 @@
    1.25      return arm_simd;
    1.26  }
    1.27  
    1.28 +#elif defined(__RISCOS__)
    1.29 +
    1.30 +static int
    1.31 +CPU_haveARMSIMD(void)
    1.32 +{
    1.33 +	_kernel_swi_regs regs;
    1.34 +	regs.r[0] = 0;
    1.35 +	if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL)
    1.36 +		return 0;
    1.37 +
    1.38 +	if (!(regs.r[0] & (1<<31)))
    1.39 +		return 0;
    1.40 +
    1.41 +	regs.r[0] = 34;
    1.42 +	regs.r[1] = 29;
    1.43 +	if (_kernel_swi(OS_PlatformFeatures, &regs, &regs) != NULL)
    1.44 +		return 0;
    1.45 +
    1.46 +	return regs.r[0];
    1.47 +}
    1.48 +
    1.49  #else
    1.50  static int
    1.51  CPU_haveARMSIMD(void)
    1.52 @@ -419,7 +445,7 @@
    1.53  #  endif
    1.54  /* All WinRT ARM devices are required to support NEON, but just in case. */
    1.55      return IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) != 0;
    1.56 -#elif !defined(__ARM_ARCH)
    1.57 +#elif !defined(__arm__)
    1.58      return 0;  /* not an ARM CPU at all. */
    1.59  #elif __ARM_ARCH >= 8
    1.60      return 1;  /* ARMv8 always has non-optional NEON support. */
    1.61 @@ -446,6 +472,18 @@
    1.62          }
    1.63          return 0;
    1.64      }
    1.65 +#elif defined(__RISCOS__)
    1.66 +    /* Use the VFPSupport_Features SWI to access the MVFR registers */
    1.67 +    {
    1.68 +        _kernel_swi_regs regs;
    1.69 +	regs.r[0] = 0;
    1.70 +        if (_kernel_swi(VFPSupport_Features, &regs, &regs) == NULL) {
    1.71 +            if ((regs.r[2] & 0xFFF000) == 0x111000) {
    1.72 +                return 1;
    1.73 +            }
    1.74 +        }
    1.75 +        return 0;
    1.76 +    }
    1.77  #else
    1.78  #warning SDL_HasNEON is not implemented for this ARM platform. Write me.
    1.79      return 0;
    1.80 @@ -871,6 +909,15 @@
    1.81              SDL_SystemRAM = (int) (sysram / 0x100000U);
    1.82          }
    1.83  #endif
    1.84 +#ifdef __RISCOS__
    1.85 +        if (SDL_SystemRAM <= 0) {
    1.86 +            _kernel_swi_regs regs;
    1.87 +            regs.r[0] = 0x108;
    1.88 +            if (_kernel_swi(OS_Memory, &regs, &regs) == NULL) {
    1.89 +                SDL_SystemRAM = (int)(regs.r[1] * regs.r[2] / (1024 * 1024));
    1.90 +            }
    1.91 +        }
    1.92 +#endif
    1.93  #endif
    1.94      }
    1.95      return SDL_SystemRAM;