From: Christian Thalinger Date: Fri, 4 Jul 2008 12:36:01 +0000 (+0200) Subject: * src/vm/jit/mips/md-atomic.hpp: New file. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=b0dfcc457440aa84e2f1ccee8bcefad72615a344;p=cacao.git * src/vm/jit/mips/md-atomic.hpp: New file. * src/vm/jit/mips/machine-instr.h: Removed. * src/vm/jit/mips/Makefile.am (noinst_HEADERS): Removed machine-instr.h, added md-atomic.hpp. * src/vm/jit/mips/asmpart.S (compare_and_swap): Removed. --HG-- branch : twisti --- diff --git a/src/vm/jit/mips/Makefile.am b/src/vm/jit/mips/Makefile.am index ce07cde79..86ef145db 100644 --- a/src/vm/jit/mips/Makefile.am +++ b/src/vm/jit/mips/Makefile.am @@ -35,9 +35,9 @@ LIBS = noinst_HEADERS = \ arch.h \ - machine-instr.h \ \ - md-asm.h + md-asm.h \ + md-atomic.hpp noinst_LTLIBRARIES = \ libarch.la diff --git a/src/vm/jit/mips/asmpart.S b/src/vm/jit/mips/asmpart.S index 2a3b5fc0c..547782d5b 100644 --- a/src/vm/jit/mips/asmpart.S +++ b/src/vm/jit/mips/asmpart.S @@ -51,8 +51,6 @@ .globl asm_abstractmethoderror - .globl compare_and_swap - /* asm_vm_call_method ********************************************************** * * @@ -466,40 +464,6 @@ asm_abstractmethoderror: .end asm_abstractmethoderror - .ent compare_and_swap - -compare_and_swap: -1: -#if defined(__GNUC__) - .set mips2 -#endif - all v0,0(a0) -#if defined(__GNUC__) - .set mips0 -#endif - bne v0,a1,2f - move t0,a2 -#if defined(__GNUC__) - .set mips2 -#endif - asc t0,0(a0) -#if defined(__GNUC__) - .set mips0 -#endif - beqz t0,1b -2: -#if defined(__GNUC__) - .set mips2 -#endif - sync -#if defined(__GNUC__) - .set mips0 -#endif - j ra - - .end compare_and_swap - - /* disable exec-stacks ********************************************************/ #if defined(__linux__) && defined(__ELF__) diff --git a/src/vm/jit/mips/machine-instr.h b/src/vm/jit/mips/machine-instr.h deleted file mode 100644 index 848a16480..000000000 --- a/src/vm/jit/mips/machine-instr.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _MACHINE_INSTR_H -#define _MACHINE_INSTR_H - -#if 0 - -/* If anyone wants to compile with gcc, use this section. - * It is not usable with the MIPSPro compiler. - * - * It is outdated, too. - */ - -static inline int -__attribute__ ((unused)) -compare_and_swap (volatile long *p, long oldval, long newval) -{ - long ret, temp; - - __asm__ __volatile__ - ("1:\n\t" - ".set push\n\t" - ".set mips2\n\t" - "lld %1,%5\n\t" - "move %0,$0\n\t" - "bne %1,%3,2f\n\t" - "move %0,%4\n\t" - "scd %0,%2\n\t" - ".set pop\n\t" - "beqz %0,1b\n" - "2:\n\t" - : "=&r" (ret), "=&r" (temp), "=m" (*p) - : "r" (oldval), "r" (newval), "m" (*p) - : "memory"); - - return ret; -} - -#else - -long compare_and_swap (long *p, long oldval, long newval); - -#define STORE_ORDER_BARRIER() -#define MEMORY_BARRIER_AFTER_ATOMIC() -#define MEMORY_BARRIER() - -#endif -#endif diff --git a/src/vm/jit/mips/md-atomic.hpp b/src/vm/jit/mips/md-atomic.hpp new file mode 100644 index 000000000..4bd83492f --- /dev/null +++ b/src/vm/jit/mips/md-atomic.hpp @@ -0,0 +1,153 @@ +/* src/vm/jit/mips/atomic.hpp - MIPS atomic instructions + + Copyright (C) 2008 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO + + This file is part of CACAO. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + +*/ + + +#ifndef _MD_ATOMIC_HPP +#define _MD_ATOMIC_HPP + +#include "config.h" + +#include + +#include "threads/atomic.hpp" + + +/** + * An atomic compare and swap for 32-bit integer values. + * + * @param p Pointer to memory address. + * @param oldval Old value to be expected. + * @param newval New value to be stored. + * + * @return value of the memory location before the store + */ +inline static uint32_t Atomic_compare_and_swap_32(volatile uint32_t *p, uint32_t oldval, uint32_t newval) +{ + uint32_t result; + uint32_t temp; + + __asm__ __volatile__ ( + " .set push \n" + " .set mips2 \n" + "1: \n" + " ll %0,%5 \n" + " bne %0,%3,2f \n" + " move %1,%4 \n" + " sc %1,%2 \n" + " .set pop \n" + " beqz %1,1b \n" + "2: \n" + : "=&r" (result), "=&r" (temp), "=m" (*p) + : "r" (oldval), "r" (newval), "m" (*p) + : "memory"); + + return result; +} + + +/** + * An atomic compare and swap for 64-bit integer values. + * + * @param p Pointer to memory address. + * @param oldval Old value to be expected. + * @param newval New value to be stored. + * + * @return value of the memory location before the store + */ +inline static uint64_t Atomic_compare_and_swap_64(volatile uint64_t *p, uint64_t oldval, uint64_t newval) +{ +#if SIZEOF_VOID_P == 8 + uint64_t result; + uint64_t temp; + + __asm__ __volatile__ ( + " .set push \n" + " .set mips2 \n" + "1: \n" + " lld %0,%5 \n" + " bne %0,%3,2f \n" + " move %1,%4 \n" + " scd %1,%2 \n" + " .set pop \n" + " beqz %1,1b \n" + "2: \n" + : "=&r" (result), "=&r" (temp), "=m" (*p) + : "r" (oldval), "r" (newval), "m" (*p) + : "memory"); + + return result; +#else +# warning Use generic version. + return 0; +#endif +} + + +/** + * An atomic compare and swap for pointer values. + * + * @param p Pointer to memory address. + * @param oldval Old value to be expected. + * @param newval New value to be stored. + * + * @return value of the memory location before the store + */ +inline static void* Atomic_compare_and_swap_ptr(volatile void** p, void* oldval, void* newval) +{ +#if SIZEOF_VOID_P == 8 + return (void*) Atomic_compare_and_swap_64((volatile uint64_t*) p, (uint64_t) oldval, (uint64_t) newval); +#else + return (void*) Atomic_compare_and_swap_32((volatile uint32_t*) p, (uint32_t) oldval, (uint32_t) newval); +#endif +} + + +/** + * A memory barrier. + */ +inline static void Atomic_memory_barrier(void) +{ + __asm__ __volatile__ ("" : : : "memory"); +} + + +#define STORE_ORDER_BARRIER() __asm__ __volatile__ ("" : : : "memory"); +#define MEMORY_BARRIER_AFTER_ATOMIC() __asm__ __volatile__ ("" : : : "memory"); + +#endif // _MD_ATOMIC_HPP + + +/* + * These are local overrides for various environment variables in Emacs. + * Please do not remove this and leave it at the end of the file, where + * Emacs will automagically detect them. + * --------------------------------------------------------------------- + * Local variables: + * mode: c++ + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim:noexpandtab:sw=4:ts=4: + */