Table of Contents

Optimizing programs

This page serves as a loose list of advice for getting the most out of the WonderSwan.

Optimizing C code

Optimizing for code speed

To optimize for speed, compile your code with -O2.

Optimizing for code size

To optimize for size, compile your code with -Os.

Optimizing for memory usage

Optimizing assembly code

Optimizing for speed

While the V30MZ is an 80186-compatible CPU, its instruction timings differ wildly from common expectations and are more reflective of its 1990s-era design:

You can study the instruction timings in detail on the WSdev wiki.

There are also some additional tricks you can take advantage of:

Measuring programs

Measuring code size

Wonderful Toolchain comes with a tool for observing the RAM/ROM allocation and per-symbol sizes: wf-wswantool usage build/your_program.elf. It is also provided in the default Makefile as make usage.

Measuring performance

The best option is to use Mesen 2's profiler. While Mesen 2 is not 100% cycle-accurate for the WonderSwan yet, it's close enough for non-demoscene use cases.

TODO: Document how to use it.