src/hotspot/os_cpu/linux_s390/atomic_linux_s390.hpp
author hannesw
Thu, 23 Nov 2017 16:20:10 +0100
changeset 47929 df9e7f2df01f
parent 47593 2d56326b98f0
child 50029 ea0a16ba6ac0
permissions -rw-r--r--
8191819: String.prototype.match should follow ES6 specification Reviewed-by: sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     1
/*
46523
cbcc0ebaa044 8166651: OrderAccess::load_acquire &etc should have const parameters
kbarrett
parents: 42065
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     3
 * Copyright (c) 2016 SAP SE. All rights reserved.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     5
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     8
 * published by the Free Software Foundation.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     9
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    14
 * accompanied this code).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    15
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    19
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    22
 * questions.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    23
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    24
 */
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    25
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    26
#ifndef OS_CPU_LINUX_S390_VM_ATOMIC_LINUX_S390_INLINE_HPP
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    27
#define OS_CPU_LINUX_S390_VM_ATOMIC_LINUX_S390_INLINE_HPP
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    28
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    29
#include "runtime/atomic.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    30
#include "runtime/os.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    31
#include "vm_version_s390.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    32
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    33
// Note that the compare-and-swap instructions on System z perform
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    34
// a serialization function before the storage operand is fetched
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    35
// and again after the operation is completed.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    36
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    37
// Used constraint modifiers:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    38
// = write-only access: Value on entry to inline-assembler code irrelevant.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    39
// + read/write access: Value on entry is used; on exit value is changed.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    40
//   read-only  access: Value on entry is used and never changed.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    41
// & early-clobber access: Might be modified before all read-only operands
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    42
//                         have been used.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    43
// a address register operand (not GR0).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    44
// d general register operand (including GR0)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    45
// Q memory operand w/o index register.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    46
// 0..9 operand reference (by operand position).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    47
//      Used for operands that fill multiple roles. One example would be a
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    48
//      write-only operand receiving its initial value from a read-only operand.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    49
//      Refer to cmpxchg(..) operand #0 and variable cmp_val for a real-life example.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    50
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    51
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    52
// On System z, all store operations are atomic if the address where the data is stored into
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    53
// is an integer multiple of the data length. Furthermore, all stores are ordered:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    54
// a store which occurs conceptually before another store becomes visible to other CPUs
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    55
// before the other store becomes visible.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    56
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    57
//------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    58
// Atomic::add
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    59
//------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    60
// These methods force the value in memory to be augmented by the passed increment.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    61
// Both, memory value and increment, are treated as 32bit signed binary integers.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    62
// No overflow exceptions are recognized, and the condition code does not hold
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    63
// information about the value in memory.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    64
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    65
// The value in memory is updated by using a compare-and-swap instruction. The
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    66
// instruction is retried as often as required.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    67
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    68
// The return value of the method is the value that was successfully stored. At the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    69
// time the caller receives back control, the value in memory may have changed already.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    70
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    71
template<size_t byte_size>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    72
struct Atomic::PlatformAdd
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    73
  : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> >
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    74
{
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    75
  template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    76
  D add_and_fetch(I add_value, D volatile* dest) const;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    77
};
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    78
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    79
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    80
template<typename I, typename D>
47091
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
    81
inline D Atomic::PlatformAdd<4>::add_and_fetch(I inc, D volatile* dest) const {
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
    82
  STATIC_ASSERT(4 == sizeof(I));
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
    83
  STATIC_ASSERT(4 == sizeof(D));
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    84
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    85
  D old, upd;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    86
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    87
  if (VM_Version::has_LoadAndALUAtomicV1()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    88
    __asm__ __volatile__ (
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    89
      "   LGFR     0,%[inc]                \n\t" // save increment
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    90
      "   LA       3,%[mem]                \n\t" // force data address into ARG2
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    91
//    "   LAA      %[upd],%[inc],%[mem]    \n\t" // increment and get old value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    92
//    "   LAA      2,0,0(3)                \n\t" // actually coded instruction
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    93
      "   .byte    0xeb                    \n\t" // LAA main opcode
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    94
      "   .byte    0x20                    \n\t" // R1,R3
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    95
      "   .byte    0x30                    \n\t" // R2,disp1
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    96
      "   .byte    0x00                    \n\t" // disp2,disp3
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    97
      "   .byte    0x00                    \n\t" // disp4,disp5
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    98
      "   .byte    0xf8                    \n\t" // LAA minor opcode
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    99
      "   AR       2,0                     \n\t" // calc new value in register
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   100
      "   LR       %[upd],2                \n\t" // move to result register
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   101
      //---<  outputs  >---
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   102
      : [upd]  "=&d" (upd)    // write-only, updated counter value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   103
      , [mem]  "+Q"  (*dest)  // read/write, memory to be updated atomically
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   104
      //---<  inputs  >---
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   105
      : [inc]  "a"   (inc)    // read-only.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   106
      //---<  clobbered  >---
46953
39063b484ec2 8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents: 46523
diff changeset
   107
      : "cc", "r0", "r2", "r3", "memory"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   108
    );
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   109
  } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   110
    __asm__ __volatile__ (
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   111
      "   LLGF     %[old],%[mem]           \n\t" // get old value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   112
      "0: LA       %[upd],0(%[inc],%[old]) \n\t" // calc result
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   113
      "   CS       %[old],%[upd],%[mem]    \n\t" // try to xchg res with mem
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   114
      "   JNE      0b                      \n\t" // no success? -> retry
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   115
      //---<  outputs  >---
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   116
      : [old] "=&a" (old)    // write-only, old counter value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   117
      , [upd] "=&d" (upd)    // write-only, updated counter value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   118
      , [mem] "+Q"  (*dest)  // read/write, memory to be updated atomically
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   119
      //---<  inputs  >---
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   120
      : [inc] "a"   (inc)    // read-only.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   121
      //---<  clobbered  >---
46953
39063b484ec2 8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents: 46523
diff changeset
   122
      : "cc", "memory"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   123
    );
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   124
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   125
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   126
  return upd;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   127
}
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   128
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   129
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   130
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   131
template<typename I, typename D>
47091
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   132
inline D Atomic::PlatformAdd<8>::add_and_fetch(I inc, D volatile* dest) const {
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   133
  STATIC_ASSERT(8 == sizeof(I));
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   134
  STATIC_ASSERT(8 == sizeof(D));
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   135
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   136
  D old, upd;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   137
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   138
  if (VM_Version::has_LoadAndALUAtomicV1()) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   139
    __asm__ __volatile__ (
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   140
      "   LGR      0,%[inc]                \n\t" // save increment
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   141
      "   LA       3,%[mem]                \n\t" // force data address into ARG2
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   142
//    "   LAAG     %[upd],%[inc],%[mem]    \n\t" // increment and get old value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   143
//    "   LAAG     2,0,0(3)                \n\t" // actually coded instruction
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   144
      "   .byte    0xeb                    \n\t" // LAA main opcode
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   145
      "   .byte    0x20                    \n\t" // R1,R3
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   146
      "   .byte    0x30                    \n\t" // R2,disp1
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   147
      "   .byte    0x00                    \n\t" // disp2,disp3
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   148
      "   .byte    0x00                    \n\t" // disp4,disp5
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   149
      "   .byte    0xe8                    \n\t" // LAA minor opcode
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   150
      "   AGR      2,0                     \n\t" // calc new value in register
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   151
      "   LGR      %[upd],2                \n\t" // move to result register
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   152
      //---<  outputs  >---
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   153
      : [upd]  "=&d" (upd)    // write-only, updated counter value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   154
      , [mem]  "+Q"  (*dest)  // read/write, memory to be updated atomically
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   155
      //---<  inputs  >---
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   156
      : [inc]  "a"   (inc)    // read-only.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   157
      //---<  clobbered  >---
46953
39063b484ec2 8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents: 46523
diff changeset
   158
      : "cc", "r0", "r2", "r3", "memory"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   159
    );
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   160
  } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   161
    __asm__ __volatile__ (
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   162
      "   LG       %[old],%[mem]           \n\t" // get old value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   163
      "0: LA       %[upd],0(%[inc],%[old]) \n\t" // calc result
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   164
      "   CSG      %[old],%[upd],%[mem]    \n\t" // try to xchg res with mem
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   165
      "   JNE      0b                      \n\t" // no success? -> retry
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   166
      //---<  outputs  >---
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   167
      : [old] "=&a" (old)    // write-only, old counter value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   168
      , [upd] "=&d" (upd)    // write-only, updated counter value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   169
      , [mem] "+Q"  (*dest)  // read/write, memory to be updated atomically
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   170
      //---<  inputs  >---
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   171
      : [inc] "a"   (inc)    // read-only.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   172
      //---<  clobbered  >---
46953
39063b484ec2 8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents: 46523
diff changeset
   173
      : "cc", "memory"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   174
    );
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   175
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   176
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   177
  return upd;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   178
}
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   179
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   180
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   181
//-------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   182
// Atomic::xchg
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   183
//-------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   184
// These methods force the value in memory to be replaced by the new value passed
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   185
// in as argument.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   186
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   187
// The value in memory is replaced by using a compare-and-swap instruction. The
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   188
// instruction is retried as often as required. This makes sure that the new
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   189
// value can be seen, at least for a very short period of time, by other CPUs.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   190
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   191
// If we would use a normal "load(old value) store(new value)" sequence,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   192
// the new value could be lost unnoticed, due to a store(new value) from
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   193
// another thread.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   194
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   195
// The return value is the (unchanged) value from memory as it was when the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   196
// replacement succeeded.
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   197
template<>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   198
template<typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   199
inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   200
                                             T volatile* dest) const {
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   201
  STATIC_ASSERT(4 == sizeof(T));
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   202
  T old;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   203
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   204
  __asm__ __volatile__ (
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   205
    "   LLGF     %[old],%[mem]           \n\t" // get old value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   206
    "0: CS       %[old],%[upd],%[mem]    \n\t" // try to xchg upd with mem
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   207
    "   JNE      0b                      \n\t" // no success? -> retry
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   208
    //---<  outputs  >---
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   209
    : [old] "=&d" (old)      // write-only, prev value irrelevant
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   210
    , [mem] "+Q"  (*dest)    // read/write, memory to be updated atomically
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   211
    //---<  inputs  >---
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   212
    : [upd] "d"   (exchange_value) // read-only, value to be written to memory
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   213
    //---<  clobbered  >---
46953
39063b484ec2 8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents: 46523
diff changeset
   214
    : "cc", "memory"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   215
  );
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   216
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   217
  return old;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   218
}
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   219
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   220
template<>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   221
template<typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   222
inline T Atomic::PlatformXchg<8>::operator()(T exchange_value,
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   223
                                             T volatile* dest) const {
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   224
  STATIC_ASSERT(8 == sizeof(T));
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   225
  T old;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   226
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   227
  __asm__ __volatile__ (
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   228
    "   LG       %[old],%[mem]           \n\t" // get old value
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   229
    "0: CSG      %[old],%[upd],%[mem]    \n\t" // try to xchg upd with mem
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   230
    "   JNE      0b                      \n\t" // no success? -> retry
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   231
    //---<  outputs  >---
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   232
    : [old] "=&d" (old)      // write-only, init from memory
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   233
    , [mem] "+Q"  (*dest)    // read/write, memory to be updated atomically
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   234
    //---<  inputs  >---
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   235
    : [upd] "d"   (exchange_value) // read-only, value to be written to memory
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   236
    //---<  clobbered  >---
46953
39063b484ec2 8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents: 46523
diff changeset
   237
    : "cc", "memory"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   238
  );
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   239
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   240
  return old;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   241
}
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   242
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   243
//----------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   244
// Atomic::cmpxchg
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   245
//----------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   246
// These methods compare the value in memory with a given compare value.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   247
// If both values compare equal, the value in memory is replaced with
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   248
// the exchange value.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   249
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   250
// The value in memory is compared and replaced by using a compare-and-swap
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   251
// instruction. The instruction is NOT retried (one shot only).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   252
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   253
// The return value is the (unchanged) value from memory as it was when the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   254
// compare-and-swap instruction completed. A successful exchange operation
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   255
// is indicated by (return value == compare_value). If unsuccessful, a new
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   256
// exchange value can be calculated based on the return value which is the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   257
// latest contents of the memory location.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   258
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   259
// Inspecting the return value is the only way for the caller to determine
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   260
// if the compare-and-swap instruction was successful:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   261
// - If return value and compare value compare equal, the compare-and-swap
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   262
//   instruction was successful and the value in memory was replaced by the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   263
//   exchange value.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   264
// - If return value and compare value compare unequal, the compare-and-swap
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   265
//   instruction was not successful. The value in memory was left unchanged.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   266
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   267
// The s390 processors always fence before and after the csg instructions.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   268
// Thus we ignore the memory ordering argument. The docu says: "A serialization
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   269
// function is performed before the operand is fetched and again after the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   270
// operation is completed."
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   271
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   272
// No direct support for cmpxchg of bytes; emulate using int.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   273
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   274
struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   275
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   276
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   277
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   278
inline T Atomic::PlatformCmpxchg<4>::operator()(T xchg_val,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   279
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   280
                                                T cmp_val,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   281
                                                cmpxchg_memory_order unused) const {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   282
  STATIC_ASSERT(4 == sizeof(T));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   283
  T old;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   284
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   285
  __asm__ __volatile__ (
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   286
    "   CS       %[old],%[upd],%[mem]    \n\t" // Try to xchg upd with mem.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   287
    // outputs
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   288
    : [old] "=&d" (old)      // Write-only, prev value irrelevant.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   289
    , [mem] "+Q"  (*dest)    // Read/write, memory to be updated atomically.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   290
    // inputs
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   291
    : [upd] "d"   (xchg_val)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   292
    ,       "0"   (cmp_val)  // Read-only, initial value for [old] (operand #0).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   293
    // clobbered
46953
39063b484ec2 8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents: 46523
diff changeset
   294
    : "cc", "memory"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   295
  );
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   296
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   297
  return old;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   298
}
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   299
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   300
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   301
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   302
inline T Atomic::PlatformCmpxchg<8>::operator()(T xchg_val,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   303
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   304
                                                T cmp_val,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   305
                                                cmpxchg_memory_order unused) const {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   306
  STATIC_ASSERT(8 == sizeof(T));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   307
  T old;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   308
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   309
  __asm__ __volatile__ (
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   310
    "   CSG      %[old],%[upd],%[mem]    \n\t" // Try to xchg upd with mem.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   311
    // outputs
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   312
    : [old] "=&d" (old)      // Write-only, prev value irrelevant.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   313
    , [mem] "+Q"  (*dest)    // Read/write, memory to be updated atomically.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   314
    // inputs
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   315
    : [upd] "d"   (xchg_val)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   316
    ,       "0"   (cmp_val)  // Read-only, initial value for [old] (operand #0).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   317
    // clobbered
46953
39063b484ec2 8186611: s390: Add missing compiler barriers and fix assembler
mdoerr
parents: 46523
diff changeset
   318
    : "cc", "memory"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   319
  );
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   320
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46953
diff changeset
   321
  return old;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   322
}
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   323
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   324
#endif // OS_CPU_LINUX_S390_VM_ATOMIC_LINUX_S390_INLINE_HPP