From 09f8891e170e591bc89718cff635510d1ce839f4 Mon Sep 17 00:00:00 2001 From: frief Date: Sat, 13 Dec 2003 13:16:08 +0000 Subject: [PATCH] using the atomic test and clear instruction jbc. Allows non-interrupt and interrupt code to safely compete for a resource without the non-interrupt code having to disable interrupts. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3051 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/ds390/peeph.def | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/ds390/peeph.def b/src/ds390/peeph.def index 7ffbf710..38d81982 100644 --- a/src/ds390/peeph.def +++ b/src/ds390/peeph.def @@ -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 + -- 2.30.2