zaphod77 wrote on 2026-10-18, 17:30:So turns out the claim that compiler affected sound of 88emuplayer was *correct*. […]
Show full quote
So turns out the claim that compiler affected sound of 88emuplayer was *correct*.
It's fixed now...
[Fix] SC-88 family, SC-8820, SC-8850, NU-10B, MIIG5: A few calculations in
the XP sound chip relied on behaviour that C++ leaves undefined, which
an optimising compiler is free to break. The sound does not change.
In C and C++, undefined behaviour, unspecified behaviour, and implementation-defined behaviour are three categories of behaviour for which the standard does not fully specify the exact outcome.
Undefined behaviour (UB): The standard imposes no requirements on the behaviour. Programs should always avoid invoking undefined behaviour.
Unspecified behaviour: The standard permits several possible valid outcomes but does not specify which one is chosen. The implementation is not required to document its choice.
Implementation-defined behaviour: The standard leaves the definition of the behaviour to the implementation and requires the implementation to document its choice.
Code that invokes UB should never be written in the first place, and if it is, it must be fixed. Code that invokes unspecified behaviour is generally not used in contexts where it can affect the outcome. In my view, code that invokes implementation-defined behaviour is the kind of code that people genuinely do write, and whose results can actually differ between compilers.
There are many cases of implementation-defined behaviour involving signed integer arithmetic. It was not until C23 and C++20 mandated two’s complement representation for signed integers that many of these behaviours became specified by the standards. Unfortunately, however, gearmulator requires C++17.
Even with two’s complement mandated, the standards still seem conservative in how they define the behaviour of signed integer arithmetic. The C standard is even more conservative than the C++ standard.
That said, modern microcomputer architectures all use two’s complement anyway.