Compare and Swap/Exchange on an dsPIC33F with CPSNE instruction

118 Views Asked by At

Is there a better way to implement an interlocked variant of "compare and exchange" on a dsPIC33F?

unsigned int InterlockedCompareExchange(volatile unsigned int* Destination, unsigned int Exchange, unsigned int Compare) {
    register unsigned int Old;
    __asm volatile (
        "DISI #3\n"
        "MOV [%[DEST]], %[OLD]\n"
        "CPSNE %[COMPARE], %[OLD]\n" // required 1 cycle if not skipped, 2 otherwise
        "MOV %[EXCHANGE], [%[DEST]]\n" // is discarded if Compare NEQ [Destination]
    : [OLD] "=&a" (Old), [DEST] "+r" (Destination)
    : [EXCHANGE] "r" (Exchange), [COMPARE] "r" (Compare)
    );
    return Old;
}

Is there a variant to avoid DISI at all since "[...] this instruction does not prevent priority 7 interrupts and traps from running."

0

There are 0 best solutions below