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:16:08 +0000 (13:16 +0000)
committerfrief <frief@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 13 Dec 2003 13:16:08 +0000 (13:16 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3051 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/ds390/peeph.def

index 7ffbf7103ff32e6f838f7405f35a8bce3aec99fa..38d81982a41dac746d4b3098d2b0bb0bffcc6789 100644 (file)
@@ -2707,3 +2707,35 @@ replace {
 } by {
         ;       Peephole 243b    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 244.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 244.b  using atomic test and clear
+        jbc     %1,%2
+        ljmp    %3
+%2:
+} if labelRefCount %2 1
+