-//bogus test for pcode
-replace restart {
- movf %1,w ;comment at end
-%4: movf %1,w
- %2 %3,w
-} by {
- ; peep test remove redundant move
-%4: movf %1,w ;another comment
- %2 %3,w
-} if AYBABTU %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 {
- movf %1,w
- movwf %2
- movf %2,w
+ btfss %1
+ goto %2
+ %3
+%2: %4
} by {
- ; peep 1 - Removed redundant move
- movf %1,w
- movwf %2
+ ;peep 1 - test/jump to test/skip
+ btfsc %1
+ %3
+%2: %4
}
-// peep 2
replace restart {
- decf %1,f
- movf %1,w
- btfss status,z
- goto %2
+ btfsc %1
+ goto %2
+ %3
+%2: %4
} by {
- ; peep 2 - decf/mov/skpz to decfsz
- decfsz %1,f
- goto %2
+ ;peep 1a - test/jump to test/skip
+ btfss %1
+ %3
+%2: %4
}
-// peep 3
-replace restart {
- movwf %1
- movf %1,w
- xorlw %2
-} by {
- ; peep 3 - redundant move
- movwf %1
- xorlw %2
-}
-// peep 4
-replace restart {
- btfsc %1,%2
- goto %3
- incf %4,f
-%3:
-} by {
- ;peep 4 - test/jump to test/skip
- btfss %1,%2
- incf %4,f
-%3:
-}
+//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 5
+// peep 2
replace restart {
- btfss %1,%2
- goto %3
- incf %4,f
-%3:
+ movwf %1
+ movf %1,w
} by {
- ;peep 5 - test/jump to test/skip
- btfsc %1,%2
- incf %4,f
-%3:
-}
+ ; peep 2 - Removed redundant move
+ movwf %1
+} if NZ
-// peep 6
+// peep 3
replace restart {
- btfss %1,%2
- goto %3
-%4:
- incf %5,f
-%3:
+ decf %1,f
+ movf %1,w
+ btfss status,z
+ goto %2
} by {
- ;peep 6 - test/jump to test/skip
- btfsc %1,%2
-%4:
- incf %5,f
-%3:
+ ; peep 3 - decf/mov/skpz to decfsz
+ decfsz %1,f
+ goto %2
}
-// peep 7
-replace restart {
- btfsc %1,%2
- goto %3
-%4:
- incf %5,f
-%3:
-} by {
- ;peep 6 - test/jump to test/skip
- btfss %1,%2
-%4:
- incf %5,f
-%3:
-}
replace restart {
movf %1,w
movf %1,w
}
-replace restart {
- movwf %1
- movf %1,w
-} by {
- ; peep 9 - Removed redundant move
- movwf %1
-}
replace restart {
movlw %1
; peep 11 - Removed redundant move
movwf %1
}
-