From a39bdaf6dca8ef640a2928a863993a11691fdf57 Mon Sep 17 00:00:00 2001 From: Bernard Blackham Date: Mon, 11 Aug 2003 16:51:25 +0000 Subject: [PATCH] bset & bclr had optimisation bugs with gcc --- ROM2/asm.h | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/ROM2/asm.h b/ROM2/asm.h index 14e01ed..2c07ac8 100644 --- a/ROM2/asm.h +++ b/ROM2/asm.h @@ -7,24 +7,31 @@ * always be an immediate value. Using "g" makes the compiler be quiet, but * the assembler should fail if the value is not an immediate. */ -extern inline void bset(void* addr, u8 mask) { - asm volatile ( - "ldx %0\n" - "bset 00,x,%1" - : /* outputs */ - : "p" (addr), "g" (mask) /* inputs */ - : "x" /* altered registers */ - ); +extern inline void bset(const void* addr, const u8 mask) { + /* The assembly breaks when gcc tries to optimise consecutive calls to + * bset/bclr on the same memory address. Sigh. Either turn off optimisation + * (-O1 without -Os works), or we do it the dumb way. + */ + *(u8*)addr |= mask; + // asm volatile ( + // "ldx %0\n" + // "bset 00,x,%1" + // : /* outputs */ + // : "p" (addr), "g" (mask) /* inputs */ + // : "x" /* altered registers */ + // ); } -extern inline void bclr(void* addr, u8 mask) { - asm volatile ( - "ldx %0\n" - "bclr 00,x,%1" - : /* outputs */ - : "p" (addr), "g" (mask) /* inputs */ - : "x" /* altered registers */ - ); +extern inline void bclr(const void* addr, const u8 mask) { + /* same issue as above */ + *(u8*)addr &= ~mask; + // asm volatile ( + // "ldx %0\n" + // "bclr 00,x,%1" + // : /* outputs */ + // : "p" (addr), "g" (mask) /* inputs */ + // : "x" /* altered registers */ + // ); } #endif /* _ASM_H_ */ -- 2.20.1