]> git.gag.com Git - fw/sdcc/commitdiff
using the atomic test and clear instruction jbc. Allows non-interrupt and interrupt...
authorfrief <frief@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 13 Dec 2003 13:17:53 +0000 (13:17 +0000)
committerfrief <frief@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 13 Dec 2003 13:17:53 +0000 (13:17 +0000)
without the non-interrupt code having to disable interrupts. Moved peephole 251 to the end and renumbered two to get
ascending numbers.

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3052 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/mcs51/peeph.def

index f0609f93d4ef41871a3d4ce71d2da13596ca7597..92d240fa982994a970fd219ea8cd7123736f4609 100644 (file)
@@ -215,25 +215,16 @@ replace {
         ljmp    %5
 %2:
 } by {
-        ;       Peephole 112    removed ljmp by inverse jump logic
+        ;       Peephole 112.a  removed ljmp by inverse jump logic
         jb      %1,%5
 %2:
 } if labelInRange
 
-
-replace {
-        ljmp    %5
-} by {
-       ;       Peephole 244    replaced ljmp to ret with ret
-       ret
-} if labelIsReturnOnly
-
-
 replace {
         ljmp    %5
 %1:
 } by {
-        ;       Peephole 132    changed ljmp to sjmp
+        ;       Peephole 112.b  changed ljmp to sjmp
         sjmp    %5
 %1:
 } if labelInRange
@@ -2366,7 +2357,7 @@ replace {
         sjmp    %7      
 %3:     
         clr     a
-%7:     
+%7:
 } by {
         ;       Peephole 241.d  optimized compare
         clr     a
@@ -3097,3 +3088,44 @@ replace {
 } by {
         ;       Peephole 249b    jump optimization
 } if labelRefCount %1 1
+
+
+// This allows non-interrupt and interrupt code to safely compete
+// for a resource without the non-interrupt code having to disable
+// interrupts:
+// volatile bit resource_is_free;
+// if( resource_is_free ) {
+//     resource_is_free=0; do_something; resource_is_free=1;
+// }
+replace {
+        jnb     %1,%2
+%3:
+        clr     %1
+} by {
+        ;       Peephole 250.a  using atomic test and clear
+        jbc     %1,%3
+        sjmp    %2
+%3:
+} if labelRefCount %3 0
+
+replace {
+        jb      %1,%2
+        ljmp    %3
+%2:
+        clr     %1
+} by {
+        ;       Peephole 250.b  using atomic test and clear
+        jbc     %1,%2
+        ljmp    %3
+%2:
+} if labelRefCount %2 1
+
+
+// not before peephole 250.b
+replace {
+        ljmp    %5
+} by {
+        ;       Peephole 251    replaced ljmp to ret with ret
+        ret
+} if labelIsReturnOnly
+