6 // The peep hole optimizer searchs the
7 // the SDCC generated code for small snippets
8 // that can be optimized. As a user, you have
9 // control over this optimization process without
10 // having to learn the SDCC source code. (However
11 // you'll still need access to the source since
12 // these rules are compiled into the source.)
14 // The way it works is you specify the target
15 // snippet that you want replaced with a more
16 // efficient snippet that you write. Wild card
17 // variables allow the rules to be parameterized.
19 // In all of the SDCC ports, labels and operands
20 // can be wild cards. However, in the PIC even the
21 // instructions can be wild cards.
25 // Consider Peep Rule 1 as an example. This rule
26 // replaces some code like:
28 // skpz ;i.e. btfss status,Z
35 // skpnz ;i.e. btfsc status,Z
39 // However, the Rule has four wild cards.
40 // The first allows the btfss instruction operator
41 // be anything, not just the Z bit in status register.
42 // The second wild card applies to a label.
43 // The third wild card is for an instruction - any
44 // single instruction can be substituted.
45 // The fourth wild card is also an instruction. It's
46 // just an instruction place holder associated with
47 // a label (think of it as the PIC Port author's laziness
48 // imposed upon the user).
53 // There are certain instances where a peep rule may not
54 // be applicable. Consider this subtle example:
59 // It would seem that the second move is unnecessary. But
60 // be careful! The movf instruction affects the 'Z' bit.
61 // So if this sequence is followed by a btfsc status,Z, you
62 // will have to leave the second move in.
64 // To get around this proble, the peep rule can be followed
65 // by a conditon: "if NZ". Which is to say, apply the rule
66 // if Z bit is not needed in the code that follows. The optimizer
67 // is smart enough to look more than one instruction past the
79 ;peep 1 - test/jump to test/skip
91 ;peep 1a - test/jump to test/skip
103 ;peep 1b - test/jump to test/skip
115 ;peep 1c - test/jump to test/skip
122 //bogus test for pcode
124 // movf %1,w ;comment at end
133 // ; peep test remove redundant move
134 //%4: movf %1,w ;another comment
144 ; peep 2 - Removed redundant move
155 ; peep 3 - decf/mov/skpz to decfsz
165 ; peep 8 - Removed redundant move
175 ; peep 10 - Removed redundant move
184 ; peep 11 - Removed redundant move