< prev index next >

src/hotspot/os_cpu/linux_sparc/atomic_linux_sparc.hpp

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef OS_CPU_LINUX_SPARC_ATOMIC_LINUX_SPARC_HPP
  26 #define OS_CPU_LINUX_SPARC_ATOMIC_LINUX_SPARC_HPP
  27 
  28 // Implementation of class atomic
  29 
  30 template<size_t byte_size>
  31 struct Atomic::PlatformAdd
  32   : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> >
  33 {
  34   template<typename I, typename D>
  35   D add_and_fetch(I add_value, D volatile* dest, atomic_memory_order order) const;
  36 };
  37 
  38 template<>
  39 template<typename I, typename D>
  40 inline D Atomic::PlatformAdd<4>::add_and_fetch(I add_value, D volatile* dest,
  41                                                atomic_memory_order order) const {
  42   STATIC_ASSERT(4 == sizeof(I));
  43   STATIC_ASSERT(4 == sizeof(D));
  44 
  45   D rv;
  46   __asm__ volatile(
  47     "1: \n\t"
  48     " ld     [%2], %%o2\n\t"
  49     " add    %1, %%o2, %%o3\n\t"
  50     " cas    [%2], %%o2, %%o3\n\t"
  51     " cmp    %%o2, %%o3\n\t"
  52     " bne    1b\n\t"
  53     "  nop\n\t"
  54     " add    %1, %%o2, %0\n\t"
  55     : "=r" (rv)
  56     : "r" (add_value), "r" (dest)
  57     : "memory", "o2", "o3");
  58   return rv;
  59 }
  60 
  61 template<>
  62 template<typename I, typename D>
  63 inline D Atomic::PlatformAdd<8>::add_and_fetch(I add_value, D volatile* dest,
  64                                                atomic_memory_order order) const {
  65   STATIC_ASSERT(8 == sizeof(I));
  66   STATIC_ASSERT(8 == sizeof(D));
  67 
  68   D rv;
  69   __asm__ volatile(
  70     "1: \n\t"
  71     " ldx    [%2], %%o2\n\t"
  72     " add    %1, %%o2, %%o3\n\t"
  73     " casx   [%2], %%o2, %%o3\n\t"
  74     " cmp    %%o2, %%o3\n\t"
  75     " bne    %%xcc, 1b\n\t"
  76     "  nop\n\t"
  77     " add    %1, %%o2, %0\n\t"
  78     : "=r" (rv)
  79     : "r" (add_value), "r" (dest)
  80     : "memory", "o2", "o3");
  81   return rv;
  82 }
  83 




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef OS_CPU_LINUX_SPARC_ATOMIC_LINUX_SPARC_HPP
  26 #define OS_CPU_LINUX_SPARC_ATOMIC_LINUX_SPARC_HPP
  27 
  28 // Implementation of class atomic
  29 
  30 template<size_t byte_size>
  31 struct Atomic::PlatformAdd
  32   : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> >
  33 {
  34   template<typename D, typename I>
  35   D add_and_fetch(D volatile* dest, I add_value, atomic_memory_order order) const;
  36 };
  37 
  38 template<>
  39 template<typename D, typename I>
  40 inline D Atomic::PlatformAdd<4>::add_and_fetch(D volatile* dest, I add_value,
  41                                                atomic_memory_order order) const {
  42   STATIC_ASSERT(4 == sizeof(I));
  43   STATIC_ASSERT(4 == sizeof(D));
  44 
  45   D rv;
  46   __asm__ volatile(
  47     "1: \n\t"
  48     " ld     [%2], %%o2\n\t"
  49     " add    %1, %%o2, %%o3\n\t"
  50     " cas    [%2], %%o2, %%o3\n\t"
  51     " cmp    %%o2, %%o3\n\t"
  52     " bne    1b\n\t"
  53     "  nop\n\t"
  54     " add    %1, %%o2, %0\n\t"
  55     : "=r" (rv)
  56     : "r" (add_value), "r" (dest)
  57     : "memory", "o2", "o3");
  58   return rv;
  59 }
  60 
  61 template<>
  62 template<typename D, typename I>
  63 inline D Atomic::PlatformAdd<8>::add_and_fetch(D volatile* dest, I add_value,
  64                                                atomic_memory_order order) const {
  65   STATIC_ASSERT(8 == sizeof(I));
  66   STATIC_ASSERT(8 == sizeof(D));
  67 
  68   D rv;
  69   __asm__ volatile(
  70     "1: \n\t"
  71     " ldx    [%2], %%o2\n\t"
  72     " add    %1, %%o2, %%o3\n\t"
  73     " casx   [%2], %%o2, %%o3\n\t"
  74     " cmp    %%o2, %%o3\n\t"
  75     " bne    %%xcc, 1b\n\t"
  76     "  nop\n\t"
  77     " add    %1, %%o2, %0\n\t"
  78     : "=r" (rv)
  79     : "r" (add_value), "r" (dest)
  80     : "memory", "o2", "o3");
  81   return rv;
  82 }
  83 


< prev index next >