-// ; Peephole 2 removed pop %1 push %1 (not push pop)
-// mov %2,%3
-//}
+// PIC Port Peep rules
+//
+//
+// INTRODUCTION:
+//
+// The peep hole optimizer searchs the
+// the SDCC generated code for small snippets
+// that can be optimized. As a user, you have
+// control over this optimization process without
+// having to learn the SDCC source code. (However
+// you'll still need access to the source since
+// these rules are compiled into the source.)
+//
+// The way it works is you specify the target
+// snippet that you want replaced with a more
+// efficient snippet that you write. Wild card
+// variables allow the rules to be parameterized.
+//
+// In all of the SDCC ports, labels and operands
+// can be wild cards. However, in the PIC even the
+// instructions can be wild cards.
+//
+// EXAMPLE:
+//
+// Consider Peep Rule 1 as an example. This rule
+// replaces some code like:
+//
+// skpz ;i.e. btfss status,Z
+// goto lab1
+// clrw
+//lab1:
+//
+// with:
+//
+// skpnz ;i.e. btfsc status,Z
+// clrw
+//lab1
+//
+// However, the Rule has wild cards four wild cards.
+// The first allows the btfss instruction operate
+// on anything, not just the Z bit in status register.
+// The second wild card applies to a label.
+// The third wild card is for an instruction - any
+// single instruction can be substituted.
+// The fourth wild card is also an instruction. It's
+// just an instruction place holder associated with
+// a label (think of it as the PIC Port author's laziness
+// imposed upon the user).
+//
+//
+// CONDITIONS
+//
+// There are certain instances where a peep rule may not
+// be applicable. Consider this subtle example:
+//
+// movwf R0
+// movf R0,W
+//
+// It would seem that the second move is unnecessary. But
+// be careful! The movf instruction affects the 'Z' bit.
+// So if this sequence is followed by a btfsc status,Z, you
+// will have to leave the second move in.
+//
+// To get around this proble, the peep rule can be followed
+// by a conditon: "if NZ". Which is to say, apply the rule
+// if Z bit is not needed in the code that follows. The optimizer
+// is smart enough to look more than one instruction past the
+// target block...
+//
+//
+
-// peep 1
replace restart {
- skpz
- goto %1
- incf %2,f
-%1:
+ btfss %1
+ goto %2
+ %3
+%2: %4
} by {
- ;peep 1
- skpnz
- incf %2,f
-%1:
+ ;peep 1 - test/jump to test/skip
+ btfsc %1
+ %3
+%2: %4
}
-// like peep1
replace restart {
- skpz
- goto %1
-%2:
- incf %3,f
-%1:
+ btfsc %1
+ goto %2
+ %3
+%2: %4
} by {
- ;peep 2
- skpnz
-%2:
- incf %3,f
-%1:
+ ;peep 1a - test/jump to test/skip
+ btfss %1
+ %3
+%2: %4
}
+
+//bogus test for pcode
+//replace restart {
+// movf %1,w ;comment at end
+//%4: movf %1,w
+// RETURN
+// clrf INDF
+// movlw 0xa5
+// movf fsr,w
+// incf indf,f
+// %2
+//} by {
+// ; peep test remove redundant move
+//%4: movf %1,w ;another comment
+// %2
+//} if AYBABTU %3
+
+
+// peep 2
replace restart {
- skpnz
- goto %1
- incf %2,f
-%1:
+ movwf %1
+ movf %1,w
} by {
- ;peep 3
- skpz
- incf %2,f
-%1:
-}
+ ; peep 2 - Removed redundant move
+ movwf %1
+} if NZ
+// peep 3
replace restart {
- skpnz
- goto %1
-%2:
- incf %3,f
-%1:
+ decf %1,f
+ movf %1,w
+ btfss status,z
+ goto %2
} by {
- ;peep 4
- skpz
-%2:
- incf %3,f
-%1:
+ ; peep 3 - decf/mov/skpz to decfsz
+ decfsz %1,f
+ goto %2
}
-// peep 5
+
replace restart {
- skpc
- goto %1
- incf %2,f
-%1:
+ movf %1,w
+ movf %1,w
} by {
- ;peep 5
- skpnc
- incf %2,f
-%1:
+ ; peep 8 - Removed redundant move
+ movf %1,w
}
-// like peep5
+
replace restart {
- skpc
- goto %1
-%2:
- incf %3,f
-%1:
+ movlw %1
+ movwf %2
+ movlw %1
} by {
- ;peep 5a
- skpnc
-%2:
- incf %3,f
-%1:
+ ; peep 10 - Removed redundant move
+ movlw %1
+ movwf %2
}
-// peep 6
replace restart {
- skpnc
- goto %1
- incf %2,f
-%1:
+ movwf %1
+ movwf %1
} by {
- ;peep 6
- skpc
- incf %2,f
-%1:
+ ; peep 11 - Removed redundant move
+ movwf %1
}
-