mirror of
https://github.com/cc65/cc65.git
synced 2025-02-11 00:31:06 +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. */
|
/* Handle signed bit-fields. */
|
||||||
if (IsSigned) {
|
if (IsSigned) {
|
||||||
/* Push A, since the sign bit test will destroy it. */
|
/* Save .A because the sign-bit test will destroy it. */
|
||||||
AddCodeLine ("pha");
|
AddCodeLine ("tay");
|
||||||
|
|
||||||
/* Check sign bit */
|
/* Check sign bit */
|
||||||
unsigned SignBitPos = BitWidth - 1U;
|
unsigned SignBitPos = BitWidth - 1U;
|
||||||
@ -4520,7 +4520,7 @@ void g_extractbitfield (unsigned Flags, unsigned FullWidthFlags, int IsSigned,
|
|||||||
unsigned SignBitPosInByte = SignBitPos % CHAR_BITS;
|
unsigned SignBitPosInByte = SignBitPos % CHAR_BITS;
|
||||||
unsigned SignBitMask = 1U << SignBitPosInByte;
|
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.
|
** but more cases will be needed to support long.
|
||||||
*/
|
*/
|
||||||
switch (SignBitByte) {
|
switch (SignBitByte) {
|
||||||
@ -4538,10 +4538,10 @@ void g_extractbitfield (unsigned Flags, unsigned FullWidthFlags, int IsSigned,
|
|||||||
unsigned ZeroExtendLabel = GetLocalLabel ();
|
unsigned ZeroExtendLabel = GetLocalLabel ();
|
||||||
AddCodeLine ("beq %s", LocalLabelName (ZeroExtendLabel));
|
AddCodeLine ("beq %s", LocalLabelName (ZeroExtendLabel));
|
||||||
|
|
||||||
/* Pop A back and sign-extend if required; operating on the full result needs
|
/* Get back .A and sign-extend if required; operating on the full result needs
|
||||||
** to sign-extend into high byte, too.
|
** to sign-extend into the high byte, too.
|
||||||
*/
|
*/
|
||||||
AddCodeLine ("pla");
|
AddCodeLine ("tya");
|
||||||
g_or (FullWidthFlags | CF_CONST, ~Mask);
|
g_or (FullWidthFlags | CF_CONST, ~Mask);
|
||||||
|
|
||||||
/* We can generate a branch, instead of a jump, here because we know
|
/* 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 ();
|
unsigned DoneLabel = GetLocalLabel ();
|
||||||
g_branch (DoneLabel);
|
g_branch (DoneLabel);
|
||||||
|
|
||||||
/* Pop A back, then zero-extend. We need to duplicate the PLA, rather than move it before
|
/* 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 PLA changes some condition codes.
|
** the branch to share with the other label, because TYA changes some condition codes.
|
||||||
*/
|
*/
|
||||||
g_defcodelabel (ZeroExtendLabel);
|
g_defcodelabel (ZeroExtendLabel);
|
||||||
AddCodeLine ("pla");
|
AddCodeLine ("tya");
|
||||||
|
|
||||||
/* Zero the upper bits, the same as the unsigned path. */
|
/* Zero the upper bits, the same as the unsigned path. */
|
||||||
if (ZeroExtendMask != 0) {
|
if (ZeroExtendMask != 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user