1 /*****************************************************************************/
5 /* Optimize test sequences */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
43 /*****************************************************************************/
45 /*****************************************************************************/
49 unsigned OptTest1 (CodeSeg* S)
56 * If X is zero, the sequence may be changed to
61 * which may be optimized further by another step.
63 * If A is zero, the sequence may be changed to
73 /* Generate register info for this step */
76 /* Walk over the entries */
78 while (I < CS_GetEntryCount (S)) {
83 L[0] = CS_GetEntry (S, I);
85 /* Check if it's the sequence we're searching for */
86 if (L[0]->OPC == OP65_STX &&
87 CS_GetEntries (S, L+1, I+1, 2) &&
88 !CE_HasLabel (L[1]) &&
89 L[1]->OPC == OP65_ORA &&
90 strcmp (L[0]->Arg, L[1]->Arg) == 0 &&
91 !CE_HasLabel (L[2]) &&
92 (L[2]->Info & OF_ZBRA) != 0) {
94 /* Check if X is zero */
95 if (L[0]->RI->In.RegX == 0) {
97 /* Insert the compare */
98 CodeEntry* N = NewCodeEntry (OP65_CMP, AM65_IMM, "$00", 0, L[0]->LI);
99 CS_InsertEntry (S, N, I+2);
101 /* Remove the two other insns */
102 CS_DelEntry (S, I+1);
108 /* Check if A is zero */
109 } else if (L[1]->RI->In.RegA == 0) {
112 CodeEntry* N = NewCodeEntry (OP65_TXA, AM65_IMP, 0, 0, L[1]->LI);
113 CS_InsertEntry (S, N, I+2);
115 /* Remove the two other insns */
116 CS_DelEntry (S, I+1);
129 /* Free register info */
132 /* Return the number of changes made */