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 /*****************************************************************************/
45 /*****************************************************************************/
47 /*****************************************************************************/
51 unsigned OptTest1 (CodeSeg* S)
58 * If X is zero, the sequence may be changed to
63 * which may be optimized further by another step.
65 * If A is zero, the sequence may be changed to
75 /* Generate register info for this step */
78 /* Walk over the entries */
80 while (I < CS_GetEntryCount (S)) {
85 L[0] = CS_GetEntry (S, I);
87 /* Check if it's the sequence we're searching for */
88 if (L[0]->OPC == OP65_STX &&
89 CS_GetEntries (S, L+1, I+1, 2) &&
90 !CE_HasLabel (L[1]) &&
91 L[1]->OPC == OP65_ORA &&
92 strcmp (L[0]->Arg, L[1]->Arg) == 0 &&
93 !CE_HasLabel (L[2]) &&
94 (L[2]->Info & OF_ZBRA) != 0) {
96 /* Check if X is zero */
97 if (L[0]->RI->In.RegX == 0) {
99 /* Insert the compare */
100 CodeEntry* N = NewCodeEntry (OP65_CMP, AM65_IMM, "$00", 0, L[0]->LI);
101 CS_InsertEntry (S, N, I+2);
103 /* Remove the two other insns */
104 CS_DelEntry (S, I+1);
110 /* Check if A is zero */
111 } else if (L[1]->RI->In.RegA == 0) {
114 CodeEntry* N = NewCodeEntry (OP65_TXA, AM65_IMP, 0, 0, L[1]->LI);
115 CS_InsertEntry (S, N, I+2);
117 /* Remove the two other insns */
118 CS_DelEntry (S, I+1);
131 /* Free register info */
134 /* Return the number of changes made */