< prev index next >

src/os_cpu/linux_s390/vm/atomic_linux_s390.hpp

Print this page
rev 13459 : [mq]: s390_fix


 472 //   exchange value.
 473 // - If return value and compare value compare unequal, the compare-and-swap
 474 //   instruction was not successful. The value in memory was left unchanged.
 475 //
 476 // The s390 processors always fence before and after the csg instructions.
 477 // Thus we ignore the memory ordering argument. The docu says: "A serialization
 478 // function is performed before the operand is fetched and again after the
 479 // operation is completed."
 480 
 481 // No direct support for cmpxchg of bytes; emulate using int.
 482 template<>
 483 struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};
 484 
 485 template<>
 486 template<typename T>
 487 inline T Atomic::PlatformCmpxchg<4>::operator()(T xchg_val,
 488                                                 T volatile* dest,
 489                                                 T cmp_val,
 490                                                 cmpxchg_memory_order unused) const {
 491   STATIC_ASSERT(4 == sizeof(T));
 492   unsigned long old;
 493 
 494   __asm__ __volatile__ (
 495     "   CS       %[old],%[upd],%[mem]    \n\t" // Try to xchg upd with mem.
 496     // outputs
 497     : [old] "=&d" (old)      // Write-only, prev value irrelevant.
 498     , [mem] "+Q"  (*dest)    // Read/write, memory to be updated atomically.
 499     // inputs
 500     : [upd] "d"   (xchg_val)
 501     ,       "0"   (cmp_val)  // Read-only, initial value for [old] (operand #0).
 502     // clobbered
 503     : "cc"
 504   );
 505 
 506   return IntegerTypes::cast<T>((uint32_t)old);
 507 }
 508 
 509 template<>
 510 template<typename T>
 511 inline T Atomic::PlatformCmpxchg<8>::operator()(T xchg_val,
 512                                                 T volatile* dest,
 513                                                 T cmp_val,
 514                                                 cmpxchg_memory_order unused) const {
 515   STATIC_ASSERT(8 == sizeof(T));
 516   T old;
 517 
 518   __asm__ __volatile__ (
 519     "   CSG      %[old],%[upd],%[mem]    \n\t" // Try to xchg upd with mem.
 520     // outputs
 521     : [old] "=&d" (old)      // Write-only, prev value irrelevant.
 522     , [mem] "+Q"  (*dest)    // Read/write, memory to be updated atomically.
 523     // inputs
 524     : [upd] "d"   (xchg_val)
 525     ,       "0"   (cmp_val)  // Read-only, initial value for [old] (operand #0).
 526     // clobbered


 472 //   exchange value.
 473 // - If return value and compare value compare unequal, the compare-and-swap
 474 //   instruction was not successful. The value in memory was left unchanged.
 475 //
 476 // The s390 processors always fence before and after the csg instructions.
 477 // Thus we ignore the memory ordering argument. The docu says: "A serialization
 478 // function is performed before the operand is fetched and again after the
 479 // operation is completed."
 480 
 481 // No direct support for cmpxchg of bytes; emulate using int.
 482 template<>
 483 struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};
 484 
 485 template<>
 486 template<typename T>
 487 inline T Atomic::PlatformCmpxchg<4>::operator()(T xchg_val,
 488                                                 T volatile* dest,
 489                                                 T cmp_val,
 490                                                 cmpxchg_memory_order unused) const {
 491   STATIC_ASSERT(4 == sizeof(T));
 492   T old;
 493 
 494   __asm__ __volatile__ (
 495     "   CS       %[old],%[upd],%[mem]    \n\t" // Try to xchg upd with mem.
 496     // outputs
 497     : [old] "=&d" (old)      // Write-only, prev value irrelevant.
 498     , [mem] "+Q"  (*dest)    // Read/write, memory to be updated atomically.
 499     // inputs
 500     : [upd] "d"   (xchg_val)
 501     ,       "0"   (cmp_val)  // Read-only, initial value for [old] (operand #0).
 502     // clobbered
 503     : "cc"
 504   );
 505 
 506   return old;
 507 }
 508 
 509 template<>
 510 template<typename T>
 511 inline T Atomic::PlatformCmpxchg<8>::operator()(T xchg_val,
 512                                                 T volatile* dest,
 513                                                 T cmp_val,
 514                                                 cmpxchg_memory_order unused) const {
 515   STATIC_ASSERT(8 == sizeof(T));
 516   T old;
 517 
 518   __asm__ __volatile__ (
 519     "   CSG      %[old],%[upd],%[mem]    \n\t" // Try to xchg upd with mem.
 520     // outputs
 521     : [old] "=&d" (old)      // Write-only, prev value irrelevant.
 522     , [mem] "+Q"  (*dest)    // Read/write, memory to be updated atomically.
 523     // inputs
 524     : [upd] "d"   (xchg_val)
 525     ,       "0"   (cmp_val)  // Read-only, initial value for [old] (operand #0).
 526     // clobbered
< prev index next >