mirror of
https://github.com/cc65/cc65.git
synced 2025-02-22 12:29:12 +00:00
Fixed a signed char shift optimization so that it won't be used on signed int also.
(It would lose significant bits from the high byte.)
This commit is contained in:
parent
377f31d085
commit
4716083f3f
@ -308,50 +308,62 @@ NextEntry:
|
||||
|
||||
|
||||
unsigned OptShift2 (CodeSeg* S)
|
||||
/* A call to the asrax1 routines may get replaced by something simpler, if
|
||||
** X is not used later:
|
||||
/* The sequence
|
||||
**
|
||||
** bpl L
|
||||
** dex
|
||||
** L: jsr asraxN
|
||||
**
|
||||
** might be replaced by N copies of
|
||||
**
|
||||
** cmp #$80
|
||||
** ror a
|
||||
**
|
||||
** if X is not used later (X is assumed to be zero on entry).
|
||||
*/
|
||||
{
|
||||
unsigned Changes = 0;
|
||||
unsigned I;
|
||||
unsigned I = 0;
|
||||
|
||||
/* Walk over the entries */
|
||||
I = 0;
|
||||
while (I < CS_GetEntryCount (S)) {
|
||||
|
||||
unsigned Shift;
|
||||
unsigned Count;
|
||||
CodeEntry* L[3];
|
||||
|
||||
/* Get next entry */
|
||||
CodeEntry* E = CS_GetEntry (S, I);
|
||||
L[0] = CS_GetEntry (S, I);
|
||||
|
||||
/* Check for the sequence */
|
||||
if (E->OPC == OP65_JSR &&
|
||||
(Shift = GetShift (E->Arg)) != SHIFT_NONE &&
|
||||
SHIFT_TYPE (Shift) == SHIFT_TYPE_ASR &&
|
||||
if (L[0]->OPC == OP65_BPL &&
|
||||
L[0]->JumpTo != 0 &&
|
||||
CS_GetEntries (S, L+1, I+1, 2) &&
|
||||
L[1]->OPC == OP65_DEX &&
|
||||
L[0]->JumpTo->Owner == L[2] &&
|
||||
!CS_RangeHasLabel (S, I, 2) &&
|
||||
L[2]->OPC == OP65_JSR &&
|
||||
SHIFT_TYPE (Shift = GetShift (L[2]->Arg)) == SHIFT_TYPE_ASR &&
|
||||
(Count = SHIFT_COUNT (Shift)) > 0 &&
|
||||
Count * 100 <= S->CodeSizeFactor &&
|
||||
!RegXUsed (S, I+1)) {
|
||||
!RegXUsed (S, I+3)) {
|
||||
|
||||
CodeEntry* X;
|
||||
unsigned J = I+1;
|
||||
unsigned J = I+2;
|
||||
|
||||
/* Generate the replacement sequence */
|
||||
while (Count--) {
|
||||
/* cmp #$80 */
|
||||
X = NewCodeEntry (OP65_CMP, AM65_IMM, "$80", 0, E->LI);
|
||||
CS_InsertEntry (S, X, J++);
|
||||
X = NewCodeEntry (OP65_CMP, AM65_IMM, "$80", 0, L[2]->LI);
|
||||
CS_InsertEntry (S, X, ++J);
|
||||
|
||||
/* ror a */
|
||||
X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, E->LI);
|
||||
CS_InsertEntry (S, X, J++);
|
||||
X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, L[2]->LI);
|
||||
CS_InsertEntry (S, X, ++J);
|
||||
}
|
||||
|
||||
/* Delete the call to asrax */
|
||||
CS_DelEntry (S, I);
|
||||
/* Remove the bpl/dex/jsr */
|
||||
CS_DelEntries (S, I, 3);
|
||||
|
||||
/* Remember, we had changes */
|
||||
++Changes;
|
||||
@ -421,7 +433,7 @@ unsigned OptShift3 (CodeSeg* S)
|
||||
CS_InsertEntry (S, X, I+4);
|
||||
}
|
||||
|
||||
/* Remove the bcs/dex/jsr */
|
||||
/* Remove the bcc/inx/jsr */
|
||||
CS_DelEntries (S, I, 3);
|
||||
|
||||
/* Remember, we had changes */
|
||||
|
@ -61,11 +61,18 @@ unsigned OptShift1 (CodeSeg* S);
|
||||
*/
|
||||
|
||||
unsigned OptShift2 (CodeSeg* S);
|
||||
/* A call to the asrax1 routines may get replaced by something simpler, if
|
||||
** X is not used later:
|
||||
/* The sequence
|
||||
**
|
||||
** bpl L
|
||||
** dex
|
||||
** L: jsr asraxN
|
||||
**
|
||||
** might be replaced by N copies of
|
||||
**
|
||||
** cmp #$80
|
||||
** ror a
|
||||
**
|
||||
** if X is not used later (X is assumed to be zero on entry).
|
||||
*/
|
||||
|
||||
unsigned OptShift3 (CodeSeg* S);
|
||||
|
Loading…
x
Reference in New Issue
Block a user