Open juj opened 10 months ago
I would suggest replacing ':`` with
'9' + 1in
isdigit_2`, like so:
bool is_digit2(unsigned char ch)
{
ch -= ('9' + 1);
return ch >= 245;
}
and adapting isdigit_3
accordingly. While it is a good assumption in most character sets to assume that '0'
through '9'
are contiguous and in order, ':'
coming immediately after '9'
is specific to ASCII, which 65XX platforms (especially game consoles) don't always use.
The implementation of
isdigit()
readshttps://github.com/llvm-mos/llvm-mos-sdk/blob/b3c6a274c205c4f28e16fc70f6e4615718d6581e/mos-platform/common/c/ctype.c#L20-L23
which generates the following assembly:
that is 31 bytes.
By resorting to unsigned wraparound (and changing function signature for simplicity of presentation in this ticket), the C code can be written in the following form:
to get
for 13 bytes.
Although, following the observation in https://github.com/llvm-mos/llvm-mos/issues/388, doing
>
operations is faster than doing<
operations, since>
operations can avoid aEOR
operator. So the above C code could instead be written asfor the same effect. This can then be turned into
that would ideally be the smallest
for 11 bytes. Although compiler insists on emitting the
AND #$01
here (https://github.com/llvm-mos/llvm-mos/issues/389), so the above could be two bytes shorter still.