SIMD on Playdate

,

The 3D Library example in the SDK contains the following SIMD headers:

  • core_cm7.h
  • core_cmFunc.h
  • core_cmInstr.h
  • core_cmSimd.h

They are not included or used at all in the example.

I tried using the headers from the example, but GCC assembler doesn't recognise the assembly instructions.
I do nothing special at build time, everything is stock from C_API/buildsupport.

// common.mk sets __FPU_USED but these headers expect __FPU_PRESENT
#define __FPU_PRESENT 1
#include "core_cm7.h"
int32_t accum = 0;
int32_t a = 10 << 16;
a |= 5;
int32_t b = 2 << 16;
b |= 7;
accum = __SMLAD(a, b, accum);

include/core_cmSimd.h:507: Error: no such instruction: `smlad %eax,%eax,%edx,%ecx'

From a quick glance at ARM's intrinsic documentation, Cortex M7 should support __SMLAD.
Before I investigate further into this, I'm asking here.

  • Has anyone used SIMD on the Playdate?
  • Are the headers in the 3D Library SDK appropriate for Cortex M7?
  • Is there any extra compiler flags needed for the assembler to recognise these instructions?
1 Like

I'm not sure how to properly use the smlad instruction but writing inline assembly at least compiles without errors.

As an example, here's how I'm using some inline asm for a saturating add:

static inline i16 saturating_add_i16(i16 i, i16 j) {
#if TARGET_PLAYDATE
    __asm__ volatile("qadd16 %0, %0, %1" : "+r"(i) : "r"(j));
    return i;
#endif
}
1 Like

Thanks.

Seeing your snippet made me realize my issue was actually very simple.

I only needed to wrap the SIMD around TARGET_PLAYDATE guards. Since the default SDK makefile will compile for the simulator also. The error I had was only when not cross-compiling in arm.

I can run SIMD on the device with this:

#if TARGET_PLAYDATE
#define __FPU_PRESENT 1
#include "core_cm7.h"
#endif

#if TARGET_PLAYDATE
[...]
accum = __SMLAD(a, b, accum);
#endif

2 Likes