Hacked const and volatile modifiers a bit.
[fw/sdcc] / src / pic / peeph.def
index bb586cc77f850454b5028a1d952410f8280b1fba..0dccf7b06ef91d512f93bf939f3a127a4f353417 100644 (file)
 // is smart enough to look more than one instruction past the
 // target block...
 //
+// Special commands
+//
+//
+//   _NOTBITSKIP_   %1   - Creates a wild card instruction that
+//                         will match all instructions except for
+//                         bit skip instructions (btfsc or btfss)
+//   _BITSKIP_  %1 - Creates a wild card instruction that only
+//                   will match a bit skip instruction (btfsc
+//                   or btfss)
+//   _INVERTBITSKIP_ %1  - For the wild card instruction %1, invert
+//                         the state of the bit skip. If %1 is not
+//                         a bit skip instruction, then there's an
+//                         error in the peep rule.
+//
+// 
 //
 
 
-replace restart {
-        btfss  %1
-        goto   %2
-       %3
-%2:    %4
-} by {
-       ;peep 1 - test/jump to test/skip
-       btfsc   %1
-       %3
-%2:    %4
-}
-
-replace restart {
-        btfsc  %1
-        goto   %2
-       %3
-%2:    %4
-} by {
-       ;peep 1a - test/jump to test/skip
-       btfss   %1
-       %3
-%2:    %4
-}
+// Peep 1 
+//   Converts 
+//
+//    btfss   reg1,bit
+//     goto   label
+//    incf    reg2,f
+//label
+//
+// Into:
+//
+//    btfsc   reg1,bit
+//     incf   reg2,f
+//label
+//
+// Notice that wild cards will allow any instruction
+// besides incf to be used in the above.
+//
+// Also, notice that this snippet is not valid if
+// it follows another skip
 
 replace restart {
-        btfss  %1
-        goto   %4
-%2:    %3
-%4:    %5
+        _NOTBITSKIP_   %1
+       _BITSKIP_       %2
+        goto   %3
+       %4
+%3:    %5
 } by {
-       ;peep 1b - test/jump to test/skip
-       btfsc   %1
-%2:    %3
-%4:    %5
-}
+       ;     peep 1 - test/jump to test/skip
+        %1
+       _INVERTBITSKIP_ %2
+       %4
+%3:    %5
+} 
 
 replace restart {
-        btfsc  %1
-        goto   %4
-%2:    %3
+        _NOTBITSKIP_   %1
+       _BITSKIP_       %2
+        goto   %3
 %4:    %5
+%3:    %6
 } by {
-       ;peep 1c - test/jump to test/skip
-       btfss   %1
-%2:    %3
+       ;     peep 1b - test/jump to test/skip
+        %1
+       _INVERTBITSKIP_ %2
 %4:    %5
-}
+%3:    %6
+} 
 
 
 //bogus test for pcode
@@ -141,7 +156,7 @@ replace restart {
        movwf   %1
        movf    %1,w
 } by {
-       ; peep 2 - Removed redundant move
+       ;     peep 2 - Removed redundant move
        movwf   %1
 } if NZ
 
@@ -149,10 +164,10 @@ replace restart {
 replace restart {
        decf    %1,f
        movf    %1,w
-       btfss   status,z
+       btfss   _STATUS,z
        goto    %2
 } by {
-       ; peep 3 - decf/mov/skpz to decfsz
+       ;     peep 3 - decf/mov/skpz to decfsz
        decfsz  %1,f
         goto   %2
 }
@@ -162,7 +177,7 @@ replace restart {
        movf    %1,w
        movf    %1,w
 } by {
-       ; peep 8 - Removed redundant move
+       ;     peep 4 - Removed redundant move
        movf    %1,w
 }
 
@@ -172,7 +187,7 @@ replace restart {
        movwf   %2
        movlw   %1
 } by {
-       ; peep 10 - Removed redundant move
+       ;     peep 5 - Removed redundant move
        movlw   %1
        movwf   %2
 }
@@ -181,6 +196,90 @@ replace restart {
        movwf   %1
        movwf   %1
 } by {
-       ; peep 11 - Removed redundant move
+       ;     peep 6 - Removed redundant move
+       movwf   %1
+}
+
+replace restart {
+       movlw   0
+       iorwf   %1,w
+} by {
+       ;     peep 7 - Removed redundant move
+       movf    %1,w
+}
+
+replace restart {
+       movf    %1,w
+       movwf   %2
+       decf    %2,f
+} by {
+       ;     peep 8 - Removed redundant move
+       decf    %1,w
+       movwf   %2
+}
+
+replace restart {
+       movwf   %1
+       movf    %2,w
+       xorwf   %1,w
+} by {
+       ;     peep 9a - Removed redundant move
+       movwf   %1
+       xorwf   %2,w
+}
+
+replace restart {
+       movwf   %1
+       movf    %2,w
+       iorwf   %1,w
+} by {
+       ;     peep 9b - Removed redundant move
+       movwf   %1
+       iorwf   %2,w
+}
+
+replace restart {
+       movf    %1,w
+       movwf   %2
+       movf    %2,w
+} by {
+       ;     peep 9c - Removed redundant move
+       movf    %1,w
+       movwf   %2
+}
+
+replace restart {
+       movwf   %1
+       movf    %1,w
+       movwf   %2
+} by {
+       ;     peep 9d - Removed redundant move
        movwf   %1
+       movwf   %2
+} if NZ
+
+// From: Frieder Ferlemann
+
+replace restart {
+        iorlw   0
+} by {
+        ;     peep 10a - Removed unnecessary iorlw
+} if NZ
+
+// From: Frieder Ferlemann
+
+replace restart {
+        xorlw   0
+} by {
+        ;     peep 10b - Removed unnecessary xorlw
+} if NZ
+
+// From: Frieder Ferlemann
+
+replace restart {
+        movf    %1,w
+        movwf   %1
+} by {
+        ;     peep 11 - Removed redundant move
+        movf    %1,w
 }