[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Atomic test&exchange on alpha - assember code for verification



Thank's for hints.

I finally understood why there were "beq"s after stq_c, and I see that
stq_c overwrites source register with store result.

Final (I think) version below. Is it OK now?

static inline jboolean
_svmh_compare_and_swap (volatile _svmt_word *pword, _svmt_word
old_value, _svmt_word new_value) {
  register _svmt_word result, tmp;

  __asm__ __volatile__ (
"1:  mb\n\t"                    // make sure
"    ldq_l      %1,%4\n\t"      // load *pword into tmp (reg,<= mem)
"    cmpeq      %1,%5,%0\n\t"   // result = (*pword == tmp)
"    beq        %0,3f\n\t"      // nothing to do if they differ(0) -
// jump away
"    mov        %3,%1\n\t"      // copy tmp<=new so that we didn't
// lose it
"    stq_c      %1,%4\n\t"      // *pword = new_value (reg,=> mem)
"    beq        %1,2f\n\t"      // store could fail! (%1 overwritten!)
"    mb\n\t"                    // make sure
"    br         3f\n\t"         // we're done
"2:  br         1b\n\t"         // goto "again"
"3:  nop"
     : "=&r"(result), "=&r"(tmp), "=m"(*pword)
     : "r" (new_value), "m" (*pword), "r" (old_value));

  return result ? JNI_TRUE : JNI_FALSE;

_svmt_word is 64bit usingned defined as: unsigned long long

Regards

					Grzegorz B. Prokopski

Attachment: signature.asc
Description: PGP signature


Reply to: