aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-core/openjdk/openjdk-7-25b30/icedtea-jdk-powerpc-atomic64.patch
blob: cc5e4e893420507c77e48c924234639e9b735610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
http://mail.openjdk.java.net/pipermail/zero-dev/2010-June/000346.html

this cute C code does the same thing on powerpc as the assembly code that
was here before. If the compiler was built with the SPE extensions instead
of traditional FPU and double operations are performed in HW then we are
one step further: The compiler turns this into evldd & evstdd. Voila :)

This C code could also be activated on s390. The compiler turns this into
a single mvc instruction which does the copy operation. I don't know if
mvc's copy ability is atomic _or_ not and therefore I leave it as it.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy at linutronix.de>

./openjdk-src-dir/hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.hpp
Index: openjdk/hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.hpp
===================================================================
--- openjdk/hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.hpp.org	2011-11-14 14:07:32.000000000 -0800
+++ openjdk/hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.hpp	2012-07-19 07:28:26.208405923 -0700
@@ -25,6 +25,16 @@
 
 #ifndef OS_CPU_LINUX_ZERO_VM_OS_LINUX_ZERO_HPP
 #define OS_CPU_LINUX_ZERO_VM_OS_LINUX_ZERO_HPP
+#if defined(PPC) && !defined(_LP64)
+
+#ifndef __NO_FPRS__
+#define ATOMIC64_COPY_THROUGH_DOUBLE 1
+
+#elif defined(__SPE__) && !defined(_SOFT_DOUBLE)
+#define ATOMIC64_COPY_THROUGH_DOUBLE 1
+
+#endif
+#endif
 
   static void setup_fpu() {}
 
@@ -36,12 +46,23 @@
 
   // Atomically copy 64 bits of data
   static void atomic_copy64(volatile void *src, volatile void *dst) {
-#if defined(PPC) && !defined(_LP64)
-    double tmp;
-    asm volatile ("lfd  %0, 0(%1)\n"
-                  "stfd %0, 0(%2)\n"
-                  : "=f"(tmp)
-                  : "b"(src), "b"(dst));
+#if ATOMIC64_COPY_THROUGH_DOUBLE
+  /*
+   * In order to copy 8 bytes atomicly we rely on the trick that some
+   * architectures can load and store a double as a single operation.
+   * gcc picks the correct opcode here and with optimization turned on
+   * all temporary assignments are gone.                       - bigeasy
+   */
+   union {
+          double *d;
+          volatile void *v;
+   } s, d;
+
+   s.v = src;
+   d.v = dst;
+
+   *d.d = *s.d;
+
 #elif defined(S390) && !defined(_LP64)
     double tmp;
     asm volatile ("ld  %0, 0(%1)\n"