Odin Programming Language Support

Hi folks,

Have already started down this avenue and wanted to document progress here so I could share the load a bit, and get any feedback on the problem space anyone here might have.

Odin Compiler:
I’ve created a draft PR to the Odin Programming Language here with the main change that has unlocked this: Playdate Support by MauriceElliott · Pull Request #6900 · odin-lang/Odin

To explain the change a little better, Odin currently only supports a generic arm32 instruction set when compiling for freestanding_arm32 target, and our sweet lil yellow box uses a cortex-m7, which only supports the thumb instruction set, prevalent in the cortex-m series.

As well as this, we’re using a target triple that assume hard float, i.e. the playdate’s cortex-m7 includes an FPU, so we need to give the LLVM backend that knowledge.

So far that’s all the codified logic included in the Odin compiler, I’m keeping this as a draft, as there are still issues to work out which I’ll detail now.

Build/Project Side:
On the build side of things I am using a library I found on github from user BazzaGibbs who created a loose implementation of the playdate sdk for Odin. I assume it was completely untested though for the aforementioned reasons, but worked well enough for the simulator.

To get as far as I have, I had to fix a few issues in the SDK implementation, mostly around the allocator. But for the most part it came down to the following compiler feature flag: “+no-movt”

Supposedly +no-movt is required because the way functions are handled in memory when this isn’t removed it to split them up over 16 bits each, which the actual playdate allocator is unaware of causing it to lose access to the function after allocation before it was able to call it, effectively calling out into dead air.

Here’s the actual repo where I’m currently testing this stuff which should give you an idea of where we are: build.fish at testing_odin_playdate_target · codedawa.dev/gutwound · Tangled

Current Issues:

The main issue I am now dealing with is the playdate implementation of games works fine with whole numbers, but seems to be having issues with floats. I have tried using feature flags in the build to remove the usage of none single point precision floats, but some seem to be getting in anyways.

If anyone has any experience with the LLVM backend or Odin that has time or energy to take a look I’d be hugely appreciative.

Edits: Could add the links in the initial post to edited to add them.

I would guess that soft floats aren’t currently supported. I would look here: Compiler crashes when compiling with `-target-features:soft-float` · Issue #4868 · odin-lang/Odin · GitHub and at this draft PR Float emulation start for more embedded support by laytan · Pull Request #4143 · odin-lang/Odin · GitHub

@DraperDanMan I don’t think the Playdate uses soft floats though does it? All the information I can find says it has an onboard FPU.

I’ve just had a complete scour of the produced IR, and Assembly as well and confirmed its not using anything that’s not single point precision anywhere.

I’ve fixed it, it was more Odin compiler work. The calling convention used for C calls was defaulting to using soft floats, causing the floats to be passed in the wrong register, hence why it was making all the spawned sprites appear at 0,0.

Need to fix up the change before submitting but again we are a little closer to this being a reality!

1 Like