mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
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.
This commit is contained in:
parent
ea95728330
commit
81ac28ff71
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user