src/hotspot/os_cpu/linux_ppc/atomic_linux_ppc.hpp
author eosterlund
Tue, 26 Sep 2017 14:05:27 +0200
changeset 47552 8a3599d60996
parent 47216 71c04702a3d5
child 47578 09c41c4913d9
permissions -rw-r--r--
8186838: Generalize Atomic::inc/dec with templates Reviewed-by: kbarrett, coleenp, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     1
/*
46523
cbcc0ebaa044 8166651: OrderAccess::load_acquire &etc should have const parameters
kbarrett
parents: 40655
diff changeset
     2
 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
35594
cc13089c6327 8147937: Adapt SAP copyrights to new company name.
goetz
parents: 35063
diff changeset
     3
 * Copyright (c) 2012, 2014 SAP SE. All rights reserved.
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     5
 *
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     8
 * published by the Free Software Foundation.
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
     9
 *
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    14
 * accompanied this code).
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    15
 *
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    19
 *
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    22
 * questions.
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    23
 *
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    24
 */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    25
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
    26
#ifndef OS_CPU_LINUX_PPC_VM_ATOMIC_LINUX_PPC_HPP
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
    27
#define OS_CPU_LINUX_PPC_VM_ATOMIC_LINUX_PPC_HPP
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    28
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    29
#ifndef PPC64
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    30
#error "Atomic currently only implemented for PPC64"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    31
#endif
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    32
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    33
// Implementation of class atomic
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    34
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    35
inline void Atomic::store    (jbyte    store_value, jbyte*    dest) { *dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    36
inline void Atomic::store    (jshort   store_value, jshort*   dest) { *dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    37
inline void Atomic::store    (jint     store_value, jint*     dest) { *dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    38
inline void Atomic::store    (jlong    store_value, jlong*    dest) { *dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    39
inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    40
inline void Atomic::store_ptr(void*    store_value, void*     dest) { *(void**)dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    41
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    42
inline void Atomic::store    (jbyte    store_value, volatile jbyte*    dest) { *dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    43
inline void Atomic::store    (jshort   store_value, volatile jshort*   dest) { *dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    44
inline void Atomic::store    (jint     store_value, volatile jint*     dest) { *dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    45
inline void Atomic::store    (jlong    store_value, volatile jlong*    dest) { *dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    46
inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    47
inline void Atomic::store_ptr(void*    store_value, volatile void*     dest) { *(void* volatile *)dest = store_value; }
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    48
46523
cbcc0ebaa044 8166651: OrderAccess::load_acquire &etc should have const parameters
kbarrett
parents: 40655
diff changeset
    49
inline jlong Atomic::load(const volatile jlong* src) { return *src; }
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    50
24349
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    51
//
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    52
// machine barrier instructions:
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    53
//
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    54
// - sync            two-way memory barrier, aka fence
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    55
// - lwsync          orders  Store|Store,
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    56
//                            Load|Store,
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    57
//                            Load|Load,
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    58
//                   but not Store|Load
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    59
// - eieio           orders memory accesses for device memory (only)
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    60
// - isync           invalidates speculatively executed instructions
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    61
//                   From the POWER ISA 2.06 documentation:
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    62
//                    "[...] an isync instruction prevents the execution of
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    63
//                   instructions following the isync until instructions
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    64
//                   preceding the isync have completed, [...]"
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    65
//                   From IBM's AIX assembler reference:
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    66
//                    "The isync [...] instructions causes the processor to
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    67
//                   refetch any instructions that might have been fetched
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    68
//                   prior to the isync instruction. The instruction isync
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    69
//                   causes the processor to wait for all previous instructions
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    70
//                   to complete. Then any instructions already fetched are
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    71
//                   discarded and instruction processing continues in the
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    72
//                   environment established by the previous instructions."
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    73
//
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    74
// semantic barrier instructions:
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    75
// (as defined in orderAccess.hpp)
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    76
//
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    77
// - release         orders Store|Store,       (maps to lwsync)
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    78
//                           Load|Store
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    79
// - acquire         orders  Load|Store,       (maps to lwsync)
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    80
//                           Load|Load
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    81
// - fence           orders Store|Store,       (maps to sync)
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    82
//                           Load|Store,
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    83
//                           Load|Load,
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    84
//                          Store|Load
d8f40e5b392d 8042309: Some bugfixes for the ppc64 port.
goetz
parents: 22861
diff changeset
    85
//
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    86
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    87
#define strasm_sync                       "\n  sync    \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    88
#define strasm_lwsync                     "\n  lwsync  \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    89
#define strasm_isync                      "\n  isync   \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    90
#define strasm_release                    strasm_lwsync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    91
#define strasm_acquire                    strasm_lwsync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    92
#define strasm_fence                      strasm_sync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    93
#define strasm_nobarrier                  ""
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    94
#define strasm_nobarrier_clobber_memory   ""
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
    95
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    96
template<size_t byte_size>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    97
struct Atomic::PlatformAdd
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    98
  : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> >
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    99
{
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   100
  template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   101
  D add_and_fetch(I add_value, D volatile* dest) const;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   102
};
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   103
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   104
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   105
template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   106
inline D Atomic::PlatformAdd<4>::add_and_fetch(I add_value, D volatile* dest) const {
47091
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   107
  STATIC_ASSERT(4 == sizeof(I));
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   108
  STATIC_ASSERT(4 == sizeof(D));
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   109
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   110
  D result;
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   111
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   112
  __asm__ __volatile__ (
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   113
    strasm_lwsync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   114
    "1: lwarx   %0,  0, %2    \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   115
    "   add     %0, %0, %1    \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   116
    "   stwcx.  %0,  0, %2    \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   117
    "   bne-    1b            \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   118
    strasm_isync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   119
    : /*%0*/"=&r" (result)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   120
    : /*%1*/"r" (add_value), /*%2*/"r" (dest)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   121
    : "cc", "memory" );
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   122
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   123
  return result;
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   124
}
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   125
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   126
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   127
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   128
template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   129
inline D Atomic::PlatformAdd<8>::add_and_fetch(I add_value, D volatile* dest) const {
47091
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   130
  STATIC_ASSERT(8 == sizeof(I));
4cc46bb5057b 8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents: 46993
diff changeset
   131
  STATIC_ASSERT(8 == sizeof(D));
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   132
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   133
  D result;
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   134
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   135
  __asm__ __volatile__ (
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   136
    strasm_lwsync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   137
    "1: ldarx   %0,  0, %2    \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   138
    "   add     %0, %0, %1    \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   139
    "   stdcx.  %0,  0, %2    \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   140
    "   bne-    1b            \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   141
    strasm_isync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   142
    : /*%0*/"=&r" (result)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   143
    : /*%1*/"r" (add_value), /*%2*/"r" (dest)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   144
    : "cc", "memory" );
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   145
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   146
  return result;
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   147
}
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   148
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   149
inline jint Atomic::xchg(jint exchange_value, volatile jint* dest) {
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   150
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   151
  // Note that xchg_ptr doesn't necessarily do an acquire
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   152
  // (see synchronizer.cpp).
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   153
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   154
  unsigned int old_value;
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   155
  const uint64_t zero = 0;
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   156
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   157
  __asm__ __volatile__ (
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   158
    /* lwsync */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   159
    strasm_lwsync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   160
    /* atomic loop */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   161
    "1:                                                 \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   162
    "   lwarx   %[old_value], %[dest], %[zero]          \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   163
    "   stwcx.  %[exchange_value], %[dest], %[zero]     \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   164
    "   bne-    1b                                      \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   165
    /* isync */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   166
    strasm_sync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   167
    /* exit */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   168
    "2:                                                 \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   169
    /* out */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   170
    : [old_value]       "=&r"   (old_value),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   171
                        "=m"    (*dest)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   172
    /* in */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   173
    : [dest]            "b"     (dest),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   174
      [zero]            "r"     (zero),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   175
      [exchange_value]  "r"     (exchange_value),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   176
                        "m"     (*dest)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   177
    /* clobber */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   178
    : "cc",
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   179
      "memory"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   180
    );
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   181
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   182
  return (jint) old_value;
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   183
}
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   184
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   185
inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   186
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   187
  // Note that xchg_ptr doesn't necessarily do an acquire
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   188
  // (see synchronizer.cpp).
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   189
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   190
  long old_value;
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   191
  const uint64_t zero = 0;
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   192
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   193
  __asm__ __volatile__ (
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   194
    /* lwsync */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   195
    strasm_lwsync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   196
    /* atomic loop */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   197
    "1:                                                 \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   198
    "   ldarx   %[old_value], %[dest], %[zero]          \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   199
    "   stdcx.  %[exchange_value], %[dest], %[zero]     \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   200
    "   bne-    1b                                      \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   201
    /* isync */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   202
    strasm_sync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   203
    /* exit */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   204
    "2:                                                 \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   205
    /* out */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   206
    : [old_value]       "=&r"   (old_value),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   207
                        "=m"    (*dest)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   208
    /* in */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   209
    : [dest]            "b"     (dest),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   210
      [zero]            "r"     (zero),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   211
      [exchange_value]  "r"     (exchange_value),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   212
                        "m"     (*dest)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   213
    /* clobber */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   214
    : "cc",
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   215
      "memory"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   216
    );
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   217
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   218
  return (intptr_t) old_value;
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   219
}
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   220
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   221
inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   222
  return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest);
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   223
}
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   224
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   225
inline void cmpxchg_pre_membar(cmpxchg_memory_order order) {
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   226
  if (order != memory_order_relaxed) {
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   227
    __asm__ __volatile__ (
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   228
      /* fence */
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   229
      strasm_sync
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   230
      );
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   231
  }
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   232
}
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   233
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   234
inline void cmpxchg_post_membar(cmpxchg_memory_order order) {
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   235
  if (order != memory_order_relaxed) {
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   236
    __asm__ __volatile__ (
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   237
      /* fence */
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   238
      strasm_sync
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   239
      );
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   240
  }
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   241
}
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   242
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   243
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   244
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   245
inline T Atomic::PlatformCmpxchg<1>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   246
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   247
                                                T compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   248
                                                cmpxchg_memory_order order) const {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   249
  STATIC_ASSERT(1 == sizeof(T));
35063
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   250
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   251
  // Note that cmpxchg guarantees a two-way memory barrier across
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   252
  // the cmpxchg, so it's really a a 'fence_cmpxchg_fence' if not
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   253
  // specified otherwise (see atomic.hpp).
35063
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   254
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   255
  // Using 32 bit internally.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   256
  volatile int *dest_base = (volatile int*)((uintptr_t)dest & ~3);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   257
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   258
#ifdef VM_LITTLE_ENDIAN
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   259
  const unsigned int shift_amount        = ((uintptr_t)dest & 3) * 8;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   260
#else
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   261
  const unsigned int shift_amount        = ((~(uintptr_t)dest) & 3) * 8;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   262
#endif
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   263
  const unsigned int masked_compare_val  = ((unsigned int)(unsigned char)compare_value),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   264
                     masked_exchange_val = ((unsigned int)(unsigned char)exchange_value),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   265
                     xor_value           = (masked_compare_val ^ masked_exchange_val) << shift_amount;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   266
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   267
  unsigned int old_value, value32;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   268
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   269
  cmpxchg_pre_membar(order);
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   270
35063
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   271
  __asm__ __volatile__ (
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   272
    /* simple guard */
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   273
    "   lbz     %[old_value], 0(%[dest])                  \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   274
    "   cmpw    %[masked_compare_val], %[old_value]       \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   275
    "   bne-    2f                                        \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   276
    /* atomic loop */
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   277
    "1:                                                   \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   278
    "   lwarx   %[value32], 0, %[dest_base]               \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   279
    /* extract byte and compare */
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   280
    "   srd     %[old_value], %[value32], %[shift_amount] \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   281
    "   clrldi  %[old_value], %[old_value], 56            \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   282
    "   cmpw    %[masked_compare_val], %[old_value]       \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   283
    "   bne-    2f                                        \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   284
    /* replace byte and try to store */
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   285
    "   xor     %[value32], %[xor_value], %[value32]      \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   286
    "   stwcx.  %[value32], 0, %[dest_base]               \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   287
    "   bne-    1b                                        \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   288
    /* exit */
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   289
    "2:                                                   \n"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   290
    /* out */
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   291
    : [old_value]           "=&r"   (old_value),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   292
      [value32]             "=&r"   (value32),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   293
                            "=m"    (*dest),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   294
                            "=m"    (*dest_base)
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   295
    /* in */
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   296
    : [dest]                "b"     (dest),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   297
      [dest_base]           "b"     (dest_base),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   298
      [shift_amount]        "r"     (shift_amount),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   299
      [masked_compare_val]  "r"     (masked_compare_val),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   300
      [xor_value]           "r"     (xor_value),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   301
                            "m"     (*dest),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   302
                            "m"     (*dest_base)
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   303
    /* clobber */
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   304
    : "cc",
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   305
      "memory"
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   306
    );
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   307
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   308
  cmpxchg_post_membar(order);
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   309
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   310
  return PrimitiveConversions::cast<T>((unsigned char)old_value);
35063
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   311
}
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents: 25715
diff changeset
   312
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   313
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   314
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   315
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   316
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   317
                                                T compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   318
                                                cmpxchg_memory_order order) const {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   319
  STATIC_ASSERT(4 == sizeof(T));
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   320
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   321
  // Note that cmpxchg guarantees a two-way memory barrier across
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   322
  // the cmpxchg, so it's really a a 'fence_cmpxchg_fence' if not
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   323
  // specified otherwise (see atomic.hpp).
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   324
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   325
  T old_value;
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   326
  const uint64_t zero = 0;
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   327
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   328
  cmpxchg_pre_membar(order);
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   329
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   330
  __asm__ __volatile__ (
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   331
    /* simple guard */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   332
    "   lwz     %[old_value], 0(%[dest])                \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   333
    "   cmpw    %[compare_value], %[old_value]          \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   334
    "   bne-    2f                                      \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   335
    /* atomic loop */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   336
    "1:                                                 \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   337
    "   lwarx   %[old_value], %[dest], %[zero]          \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   338
    "   cmpw    %[compare_value], %[old_value]          \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   339
    "   bne-    2f                                      \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   340
    "   stwcx.  %[exchange_value], %[dest], %[zero]     \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   341
    "   bne-    1b                                      \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   342
    /* exit */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   343
    "2:                                                 \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   344
    /* out */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   345
    : [old_value]       "=&r"   (old_value),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   346
                        "=m"    (*dest)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   347
    /* in */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   348
    : [dest]            "b"     (dest),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   349
      [zero]            "r"     (zero),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   350
      [compare_value]   "r"     (compare_value),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   351
      [exchange_value]  "r"     (exchange_value),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   352
                        "m"     (*dest)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   353
    /* clobber */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   354
    : "cc",
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   355
      "memory"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   356
    );
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   357
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   358
  cmpxchg_post_membar(order);
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   359
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   360
  return old_value;
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   361
}
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   362
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   363
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   364
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   365
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   366
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   367
                                                T compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   368
                                                cmpxchg_memory_order order) const {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   369
  STATIC_ASSERT(8 == sizeof(T));
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   370
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   371
  // Note that cmpxchg guarantees a two-way memory barrier across
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   372
  // the cmpxchg, so it's really a a 'fence_cmpxchg_fence' if not
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   373
  // specified otherwise (see atomic.hpp).
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   374
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   375
  T old_value;
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   376
  const uint64_t zero = 0;
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   377
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   378
  cmpxchg_pre_membar(order);
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   379
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   380
  __asm__ __volatile__ (
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   381
    /* simple guard */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   382
    "   ld      %[old_value], 0(%[dest])                \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   383
    "   cmpd    %[compare_value], %[old_value]          \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   384
    "   bne-    2f                                      \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   385
    /* atomic loop */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   386
    "1:                                                 \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   387
    "   ldarx   %[old_value], %[dest], %[zero]          \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   388
    "   cmpd    %[compare_value], %[old_value]          \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   389
    "   bne-    2f                                      \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   390
    "   stdcx.  %[exchange_value], %[dest], %[zero]     \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   391
    "   bne-    1b                                      \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   392
    /* exit */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   393
    "2:                                                 \n"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   394
    /* out */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   395
    : [old_value]       "=&r"   (old_value),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   396
                        "=m"    (*dest)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   397
    /* in */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   398
    : [dest]            "b"     (dest),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   399
      [zero]            "r"     (zero),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   400
      [compare_value]   "r"     (compare_value),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   401
      [exchange_value]  "r"     (exchange_value),
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   402
                        "m"     (*dest)
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   403
    /* clobber */
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   404
    : "cc",
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   405
      "memory"
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   406
    );
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   407
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   408
  cmpxchg_post_membar(order);
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 35594
diff changeset
   409
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   410
  return old_value;
22824
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   411
}
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   412
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   413
#undef strasm_sync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   414
#undef strasm_lwsync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   415
#undef strasm_isync
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   416
#undef strasm_release
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   417
#undef strasm_acquire
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   418
#undef strasm_fence
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   419
#undef strasm_nobarrier
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   420
#undef strasm_nobarrier_clobber_memory
28258dd5cb2e 8019972: PPC64 (part 9): platform files for interpreter only VM.
goetz
parents:
diff changeset
   421
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   422
#endif // OS_CPU_LINUX_PPC_VM_ATOMIC_LINUX_PPC_HPP