From 81ac28ff71b05bd829db36f544a144a83ad1d481 Mon Sep 17 00:00:00 2001 From: Greg King Date: Fri, 18 Sep 2020 16:33:12 -0400 Subject: [PATCH] Used TAY/TYA instead of PHA/PLA when extracting a bit-field. Without optimization, it saves a few CPU cycles. With optimization, it saves more cycles and a few bytes. --- src/cc65/codegen.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index cb448d738..bc85ba1de 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -4511,8 +4511,8 @@ void g_extractbitfield (unsigned Flags, unsigned FullWidthFlags, int IsSigned, /* Handle signed bit-fields. */ if (IsSigned) { - /* Push A, since the sign bit test will destroy it. */ - AddCodeLine ("pha"); + /* Save .A because the sign-bit test will destroy it. */ + AddCodeLine ("tay"); /* Check sign bit */ unsigned SignBitPos = BitWidth - 1U; @@ -4520,7 +4520,7 @@ void g_extractbitfield (unsigned Flags, unsigned FullWidthFlags, int IsSigned, unsigned SignBitPosInByte = SignBitPos % CHAR_BITS; unsigned SignBitMask = 1U << SignBitPosInByte; - /* Move the correct byte to A. This can only be X for now, + /* Move the correct byte to .A. This can be only .X for now, ** but more cases will be needed to support long. */ switch (SignBitByte) { @@ -4538,10 +4538,10 @@ void g_extractbitfield (unsigned Flags, unsigned FullWidthFlags, int IsSigned, unsigned ZeroExtendLabel = GetLocalLabel (); AddCodeLine ("beq %s", LocalLabelName (ZeroExtendLabel)); - /* Pop A back and sign-extend if required; operating on the full result needs - ** to sign-extend into high byte, too. + /* Get back .A and sign-extend if required; operating on the full result needs + ** to sign-extend into the high byte, too. */ - AddCodeLine ("pla"); + AddCodeLine ("tya"); g_or (FullWidthFlags | CF_CONST, ~Mask); /* We can generate a branch, instead of a jump, here because we know @@ -4551,11 +4551,11 @@ void g_extractbitfield (unsigned Flags, unsigned FullWidthFlags, int IsSigned, unsigned DoneLabel = GetLocalLabel (); g_branch (DoneLabel); - /* Pop A back, then zero-extend. We need to duplicate the PLA, rather than move it before - ** the branch to share with the other label, because PLA changes some condition codes. + /* Get back .A, then zero-extend. We need to duplicate the TYA, rather than move it before + ** the branch to share with the other label, because TYA changes some condition codes. */ g_defcodelabel (ZeroExtendLabel); - AddCodeLine ("pla"); + AddCodeLine ("tya"); /* Zero the upper bits, the same as the unsigned path. */ if (ZeroExtendMask != 0) {