annotate src/os_cpu/linux_sparc/vm/atomic_linux_sparc.inline.hpp @ 122:435e64505015

6693457: Open-source hotspot linux-sparc support Summary: Move os_cpu/linux_sparc from closed to open Reviewed-by: kamg
author phh
date Thu, 24 Apr 2008 15:07:57 -0400
parents
children d1605aabd0a1
rev   line source
phh@122 1 /*
phh@122 2 * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
phh@122 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
phh@122 4 *
phh@122 5 * This code is free software; you can redistribute it and/or modify it
phh@122 6 * under the terms of the GNU General Public License version 2 only, as
phh@122 7 * published by the Free Software Foundation.
phh@122 8 *
phh@122 9 * This code is distributed in the hope that it will be useful, but WITHOUT
phh@122 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
phh@122 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
phh@122 12 * version 2 for more details (a copy is included in the LICENSE file that
phh@122 13 * accompanied this code).
phh@122 14 *
phh@122 15 * You should have received a copy of the GNU General Public License version
phh@122 16 * 2 along with this work; if not, write to the Free Software Foundation,
phh@122 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
phh@122 18 *
phh@122 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
phh@122 20 * CA 95054 USA or visit www.sun.com if you need additional information or
phh@122 21 * have any questions.
phh@122 22 *
phh@122 23 */
phh@122 24
phh@122 25 // Implementation of class atomic
phh@122 26
phh@122 27 inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; }
phh@122 28 inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; }
phh@122 29 inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; }
phh@122 30 inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; }
phh@122 31 inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; }
phh@122 32 inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; }
phh@122 33
phh@122 34 inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; }
phh@122 35 inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; }
phh@122 36 inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; }
phh@122 37 inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; }
phh@122 38 inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; }
phh@122 39 inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; }
phh@122 40
phh@122 41 inline void Atomic::inc (volatile jint* dest) { (void)add (1, dest); }
phh@122 42 inline void Atomic::inc_ptr(volatile intptr_t* dest) { (void)add_ptr(1, dest); }
phh@122 43 inline void Atomic::inc_ptr(volatile void* dest) { (void)add_ptr(1, dest); }
phh@122 44
phh@122 45 inline void Atomic::dec (volatile jint* dest) { (void)add (-1, dest); }
phh@122 46 inline void Atomic::dec_ptr(volatile intptr_t* dest) { (void)add_ptr(-1, dest); }
phh@122 47 inline void Atomic::dec_ptr(volatile void* dest) { (void)add_ptr(-1, dest); }
phh@122 48
phh@122 49 inline jint Atomic::add (jint add_value, volatile jint* dest) {
phh@122 50 intptr_t rv;
phh@122 51 __asm__ volatile(
phh@122 52 "1: \n\t"
phh@122 53 " ld [%2], %%o2\n\t"
phh@122 54 " add %1, %%o2, %%o3\n\t"
phh@122 55 " cas [%2], %%o2, %%o3\n\t"
phh@122 56 " cmp %%o2, %%o3\n\t"
phh@122 57 " bne 1b\n\t"
phh@122 58 " nop\n\t"
phh@122 59 " add %1, %%o2, %0\n\t"
phh@122 60 : "=r" (rv)
phh@122 61 : "r" (add_value), "r" (dest)
phh@122 62 : "memory", "o2", "o3");
phh@122 63 return rv;
phh@122 64 }
phh@122 65
phh@122 66 inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
phh@122 67 intptr_t rv;
phh@122 68 #ifdef _LP64
phh@122 69 __asm__ volatile(
phh@122 70 "1: \n\t"
phh@122 71 " ldx [%2], %%o2\n\t"
phh@122 72 " add %0, %%o2, %%o3\n\t"
phh@122 73 " casx [%2], %%o2, %%o3\n\t"
phh@122 74 " cmp %%o2, %%o3\n\t"
phh@122 75 " bne %%xcc, 1b\n\t"
phh@122 76 " nop\n\t"
phh@122 77 " add %0, %%o2, %0\n\t"
phh@122 78 : "=r" (rv)
phh@122 79 : "r" (add_value), "r" (dest)
phh@122 80 : "memory", "o2", "o3");
phh@122 81 #else
phh@122 82 __asm__ volatile(
phh@122 83 "1: \n\t"
phh@122 84 " ld [%2], %%o2\n\t"
phh@122 85 " add %1, %%o2, %%o3\n\t"
phh@122 86 " cas [%2], %%o2, %%o3\n\t"
phh@122 87 " cmp %%o2, %%o3\n\t"
phh@122 88 " bne 1b\n\t"
phh@122 89 " nop\n\t"
phh@122 90 " add %1, %%o2, %0\n\t"
phh@122 91 : "=r" (rv)
phh@122 92 : "r" (add_value), "r" (dest)
phh@122 93 : "memory", "o2", "o3");
phh@122 94 #endif // _LP64
phh@122 95 return rv;
phh@122 96 }
phh@122 97
phh@122 98 inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
phh@122 99 return (void*)add_ptr((intptr_t)add_value, (volatile intptr_t*)dest);
phh@122 100 }
phh@122 101
phh@122 102
phh@122 103 inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) {
phh@122 104 intptr_t rv = exchange_value;
phh@122 105 __asm__ volatile(
phh@122 106 " swap [%2],%1\n\t"
phh@122 107 : "=r" (rv)
phh@122 108 : "0" (exchange_value) /* we use same register as for return value */, "r" (dest)
phh@122 109 : "memory");
phh@122 110 return rv;
phh@122 111 }
phh@122 112
phh@122 113 inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
phh@122 114 intptr_t rv = exchange_value;
phh@122 115 #ifdef _LP64
phh@122 116 __asm__ volatile(
phh@122 117 "1:\n\t"
phh@122 118 " mov %1, %%o3\n\t"
phh@122 119 " ldx [%2], %%o2\n\t"
phh@122 120 " casx [%2], %%o2, %%o3\n\t"
phh@122 121 " cmp %%o2, %%o3\n\t"
phh@122 122 " bne %%xcc, 1b\n\t"
phh@122 123 " nop\n\t"
phh@122 124 " mov %%o2, %0\n\t"
phh@122 125 : "=r" (rv)
phh@122 126 : "r" (exchange_value), "r" (dest)
phh@122 127 : "memory", "o2", "o3");
phh@122 128 #else
phh@122 129 __asm__ volatile(
phh@122 130 "swap [%2],%1\n\t"
phh@122 131 : "=r" (rv)
phh@122 132 : "0" (exchange_value) /* we use same register as for return value */, "r" (dest)
phh@122 133 : "memory");
phh@122 134 #endif // _LP64
phh@122 135 return rv;
phh@122 136 }
phh@122 137
phh@122 138 inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
phh@122 139 return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest);
phh@122 140 }
phh@122 141
phh@122 142
phh@122 143 inline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) {
phh@122 144 jint rv;
phh@122 145 __asm__ volatile(
phh@122 146 " cas [%2], %3, %0"
phh@122 147 : "=r" (rv)
phh@122 148 : "0" (exchange_value), "r" (dest), "r" (compare_value)
phh@122 149 : "memory");
phh@122 150 return rv;
phh@122 151 }
phh@122 152
phh@122 153 inline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) {
phh@122 154 #ifdef _LP64
phh@122 155 jlong rv;
phh@122 156 __asm__ volatile(
phh@122 157 " casx [%2], %3, %0"
phh@122 158 : "=r" (rv)
phh@122 159 : "0" (exchange_value), "r" (dest), "r" (compare_value)
phh@122 160 : "memory");
phh@122 161 return rv;
phh@122 162 #else
phh@122 163 assert(VM_Version::v9_instructions_work(), "cas only supported on v9");
phh@122 164 volatile jlong_accessor evl, cvl, rv;
phh@122 165 evl.long_value = exchange_value;
phh@122 166 cvl.long_value = compare_value;
phh@122 167
phh@122 168 __asm__ volatile(
phh@122 169 " sllx %2, 32, %2\n\t"
phh@122 170 " srl %3, 0, %3\n\t"
phh@122 171 " or %2, %3, %2\n\t"
phh@122 172 " sllx %5, 32, %5\n\t"
phh@122 173 " srl %6, 0, %6\n\t"
phh@122 174 " or %5, %6, %5\n\t"
phh@122 175 " casx [%4], %5, %2\n\t"
phh@122 176 " srl %2, 0, %1\n\t"
phh@122 177 " srlx %2, 32, %0\n\t"
phh@122 178 : "=r" (rv.words[0]), "=r" (rv.words[1])
phh@122 179 : "r" (evl.words[0]), "r" (evl.words[1]), "r" (dest), "r" (cvl.words[0]), "r" (cvl.words[1])
phh@122 180 : "memory");
phh@122 181
phh@122 182 return rv.long_value;
phh@122 183 #endif
phh@122 184 }
phh@122 185
phh@122 186 inline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
phh@122 187 intptr_t rv;
phh@122 188 #ifdef _LP64
phh@122 189 __asm__ volatile(
phh@122 190 " casx [%2], %3, %0"
phh@122 191 : "=r" (rv)
phh@122 192 : "0" (exchange_value), "r" (dest), "r" (compare_value)
phh@122 193 : "memory");
phh@122 194 #else
phh@122 195 __asm__ volatile(
phh@122 196 " cas [%2], %3, %0"
phh@122 197 : "=r" (rv)
phh@122 198 : "0" (exchange_value), "r" (dest), "r" (compare_value)
phh@122 199 : "memory");
phh@122 200 #endif // _LP64
phh@122 201 return rv;
phh@122 202 }
phh@122 203
phh@122 204 inline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
phh@122 205 return (void*)cmpxchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest, (intptr_t)compare_value);
phh@122 206 }