133N/A/*
1999N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
133N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
133N/A *
133N/A * This code is free software; you can redistribute it and/or modify it
133N/A * under the terms of the GNU General Public License version 2 only, as
133N/A * published by the Free Software Foundation.
133N/A *
133N/A * This code is distributed in the hope that it will be useful, but WITHOUT
133N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
133N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
133N/A * version 2 for more details (a copy is included in the LICENSE file that
133N/A * accompanied this code).
133N/A *
133N/A * You should have received a copy of the GNU General Public License version
133N/A * 2 along with this work; if not, write to the Free Software Foundation,
133N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
133N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
133N/A *
133N/A */
133N/A
1879N/A#ifndef OS_CPU_LINUX_SPARC_VM_ATOMIC_LINUX_SPARC_INLINE_HPP
1879N/A#define OS_CPU_LINUX_SPARC_VM_ATOMIC_LINUX_SPARC_INLINE_HPP
1879N/A
1879N/A#include "orderAccess_linux_sparc.inline.hpp"
1879N/A#include "runtime/atomic.hpp"
1879N/A#include "runtime/os.hpp"
1879N/A#include "vm_version_sparc.hpp"
1879N/A
133N/A// Implementation of class atomic
133N/A
133N/Ainline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; }
133N/Ainline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; }
133N/Ainline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; }
133N/Ainline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; }
133N/Ainline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; }
133N/Ainline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; }
133N/A
133N/Ainline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; }
133N/Ainline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; }
133N/Ainline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; }
133N/Ainline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; }
133N/Ainline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; }
133N/Ainline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; }
133N/A
133N/Ainline void Atomic::inc (volatile jint* dest) { (void)add (1, dest); }
133N/Ainline void Atomic::inc_ptr(volatile intptr_t* dest) { (void)add_ptr(1, dest); }
133N/Ainline void Atomic::inc_ptr(volatile void* dest) { (void)add_ptr(1, dest); }
133N/A
133N/Ainline void Atomic::dec (volatile jint* dest) { (void)add (-1, dest); }
133N/Ainline void Atomic::dec_ptr(volatile intptr_t* dest) { (void)add_ptr(-1, dest); }
133N/Ainline void Atomic::dec_ptr(volatile void* dest) { (void)add_ptr(-1, dest); }
133N/A
1999N/Ainline jlong Atomic::load(volatile jlong* src) { return *src; }
1999N/A
133N/Ainline jint Atomic::add (jint add_value, volatile jint* dest) {
133N/A intptr_t rv;
133N/A __asm__ volatile(
133N/A "1: \n\t"
133N/A " ld [%2], %%o2\n\t"
133N/A " add %1, %%o2, %%o3\n\t"
133N/A " cas [%2], %%o2, %%o3\n\t"
133N/A " cmp %%o2, %%o3\n\t"
133N/A " bne 1b\n\t"
133N/A " nop\n\t"
133N/A " add %1, %%o2, %0\n\t"
133N/A : "=r" (rv)
133N/A : "r" (add_value), "r" (dest)
133N/A : "memory", "o2", "o3");
133N/A return rv;
133N/A}
133N/A
133N/Ainline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) {
133N/A intptr_t rv;
133N/A#ifdef _LP64
133N/A __asm__ volatile(
133N/A "1: \n\t"
133N/A " ldx [%2], %%o2\n\t"
133N/A " add %0, %%o2, %%o3\n\t"
133N/A " casx [%2], %%o2, %%o3\n\t"
133N/A " cmp %%o2, %%o3\n\t"
133N/A " bne %%xcc, 1b\n\t"
133N/A " nop\n\t"
133N/A " add %0, %%o2, %0\n\t"
133N/A : "=r" (rv)
133N/A : "r" (add_value), "r" (dest)
133N/A : "memory", "o2", "o3");
133N/A#else
133N/A __asm__ volatile(
133N/A "1: \n\t"
133N/A " ld [%2], %%o2\n\t"
133N/A " add %1, %%o2, %%o3\n\t"
133N/A " cas [%2], %%o2, %%o3\n\t"
133N/A " cmp %%o2, %%o3\n\t"
133N/A " bne 1b\n\t"
133N/A " nop\n\t"
133N/A " add %1, %%o2, %0\n\t"
133N/A : "=r" (rv)
133N/A : "r" (add_value), "r" (dest)
133N/A : "memory", "o2", "o3");
133N/A#endif // _LP64
133N/A return rv;
133N/A}
133N/A
133N/Ainline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) {
133N/A return (void*)add_ptr((intptr_t)add_value, (volatile intptr_t*)dest);
133N/A}
133N/A
133N/A
133N/Ainline jint Atomic::xchg (jint exchange_value, volatile jint* dest) {
133N/A intptr_t rv = exchange_value;
133N/A __asm__ volatile(
133N/A " swap [%2],%1\n\t"
133N/A : "=r" (rv)
133N/A : "0" (exchange_value) /* we use same register as for return value */, "r" (dest)
133N/A : "memory");
133N/A return rv;
133N/A}
133N/A
133N/Ainline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) {
133N/A intptr_t rv = exchange_value;
133N/A#ifdef _LP64
133N/A __asm__ volatile(
133N/A "1:\n\t"
133N/A " mov %1, %%o3\n\t"
133N/A " ldx [%2], %%o2\n\t"
133N/A " casx [%2], %%o2, %%o3\n\t"
133N/A " cmp %%o2, %%o3\n\t"
133N/A " bne %%xcc, 1b\n\t"
133N/A " nop\n\t"
133N/A " mov %%o2, %0\n\t"
133N/A : "=r" (rv)
133N/A : "r" (exchange_value), "r" (dest)
133N/A : "memory", "o2", "o3");
133N/A#else
133N/A __asm__ volatile(
133N/A "swap [%2],%1\n\t"
133N/A : "=r" (rv)
133N/A : "0" (exchange_value) /* we use same register as for return value */, "r" (dest)
133N/A : "memory");
133N/A#endif // _LP64
133N/A return rv;
133N/A}
133N/A
133N/Ainline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) {
133N/A return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest);
133N/A}
133N/A
133N/A
133N/Ainline jint Atomic::cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value) {
133N/A jint rv;
133N/A __asm__ volatile(
133N/A " cas [%2], %3, %0"
133N/A : "=r" (rv)
133N/A : "0" (exchange_value), "r" (dest), "r" (compare_value)
133N/A : "memory");
133N/A return rv;
133N/A}
133N/A
133N/Ainline jlong Atomic::cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value) {
133N/A#ifdef _LP64
133N/A jlong rv;
133N/A __asm__ volatile(
133N/A " casx [%2], %3, %0"
133N/A : "=r" (rv)
133N/A : "0" (exchange_value), "r" (dest), "r" (compare_value)
133N/A : "memory");
133N/A return rv;
133N/A#else
133N/A assert(VM_Version::v9_instructions_work(), "cas only supported on v9");
133N/A volatile jlong_accessor evl, cvl, rv;
133N/A evl.long_value = exchange_value;
133N/A cvl.long_value = compare_value;
133N/A
133N/A __asm__ volatile(
133N/A " sllx %2, 32, %2\n\t"
133N/A " srl %3, 0, %3\n\t"
133N/A " or %2, %3, %2\n\t"
133N/A " sllx %5, 32, %5\n\t"
133N/A " srl %6, 0, %6\n\t"
133N/A " or %5, %6, %5\n\t"
133N/A " casx [%4], %5, %2\n\t"
133N/A " srl %2, 0, %1\n\t"
133N/A " srlx %2, 32, %0\n\t"
133N/A : "=r" (rv.words[0]), "=r" (rv.words[1])
133N/A : "r" (evl.words[0]), "r" (evl.words[1]), "r" (dest), "r" (cvl.words[0]), "r" (cvl.words[1])
133N/A : "memory");
133N/A
133N/A return rv.long_value;
133N/A#endif
133N/A}
133N/A
133N/Ainline intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value) {
133N/A intptr_t rv;
133N/A#ifdef _LP64
133N/A __asm__ volatile(
133N/A " casx [%2], %3, %0"
133N/A : "=r" (rv)
133N/A : "0" (exchange_value), "r" (dest), "r" (compare_value)
133N/A : "memory");
133N/A#else
133N/A __asm__ volatile(
133N/A " cas [%2], %3, %0"
133N/A : "=r" (rv)
133N/A : "0" (exchange_value), "r" (dest), "r" (compare_value)
133N/A : "memory");
133N/A#endif // _LP64
133N/A return rv;
133N/A}
133N/A
133N/Ainline void* Atomic::cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value) {
133N/A return (void*)cmpxchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest, (intptr_t)compare_value);
133N/A}
1879N/A
1879N/A#endif // OS_CPU_LINUX_SPARC_VM_ATOMIC_LINUX_SPARC_INLINE_HPP