| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
| 3 * Use of this source code is governed by a BSD-style license that can be | |
| 4 * found in the LICENSE file. | |
| 5 */ | |
| 6 | |
| 7 #ifndef NATIVE_CLIENT_SRC_INCLUDE_LINUX_ARM_ATOMIC_OPS_LINUX_ARM_H_ | |
| 8 #define NATIVE_CLIENT_SRC_INCLUDE_LINUX_ARM_ATOMIC_OPS_LINUX_ARM_H_ 1 | |
| 9 | |
| 10 // Used only by trusted code. Untrusted code uses gcc intrinsics. | |
| 11 | |
| 12 #include "native_client/src/include/portability.h" | |
| 13 #include <stdint.h> | |
| 14 | |
| 15 typedef int32_t Atomic32; | |
| 16 | |
| 17 static INLINE Atomic32 CompareAndSwap(volatile Atomic32* ptr, | |
| 18 Atomic32 old_value, | |
| 19 Atomic32 new_value) { | |
| 20 Atomic32 oldval, res; | |
| 21 do { | |
| 22 __asm__ __volatile__( | |
| 23 "ldrex %1, [%3]\n" | |
| 24 "mov %0, #0\n" | |
| 25 "teq %1, %4\n" | |
| 26 /* | |
| 27 * The if-then block affects the following four instructions. | |
| 28 * But we only have one we want to predicate. So we have to | |
| 29 * add three nops when compiling for Thumb. | |
| 30 */ | |
| 31 "itt eq\n" | |
| 32 "strexeq %0, %5, [%3]\n" | |
| 33 #ifdef __thumb__ | |
| 34 "nop\n" | |
| 35 "nop\n" | |
| 36 "nop\n" | |
| 37 #endif | |
| 38 : "=&r" (res), "=&r" (oldval), "+Qo" (*ptr) | |
| 39 : "r" (ptr), "Ir" (old_value), "r" (new_value) | |
| 40 : "cc", "memory"); | |
| 41 } while (res); | |
| 42 return oldval; | |
| 43 } | |
| 44 | |
| 45 static INLINE Atomic32 AtomicExchange(volatile Atomic32* ptr, | |
| 46 Atomic32 new_value) { | |
| 47 Atomic32 tmp, old; | |
| 48 | |
| 49 __asm__ __volatile__( | |
| 50 "1:\n" | |
| 51 "ldrex %1, [%2]\n" | |
| 52 "strex %0, %3, [%2]\n" | |
| 53 "teq %0, #0\n" | |
| 54 "bne 1b" | |
| 55 : "=&r" (tmp), "=&r" (old) | |
| 56 : "r" (ptr), "r" (new_value) | |
| 57 : "cc", "memory"); | |
| 58 | |
| 59 return old; | |
| 60 } | |
| 61 | |
| 62 static INLINE Atomic32 AtomicIncrement(volatile Atomic32* ptr, | |
| 63 Atomic32 increment) { | |
| 64 Atomic32 tmp, res; | |
| 65 | |
| 66 __asm__ __volatile__( | |
| 67 "1:\n" | |
| 68 "ldrex %1, [%2]\n" | |
| 69 "add %1, %1, %3\n" | |
| 70 "strex %0, %1, [%2]\n" | |
| 71 "cmp %0, #0\n" | |
| 72 "bne 1b" | |
| 73 : "=&r" (tmp), // %0 | |
| 74 "=&r"(res) // %1 | |
| 75 : "r" (ptr), // %2 | |
| 76 "r"(increment) // %3 | |
| 77 : "cc", "memory"); | |
| 78 return res; | |
| 79 } | |
| 80 | |
| 81 #endif /* NATIVE_CLIENT_SRC_INCLUDE_LINUX_ARM_ATOMIC_OPS_LINUX_ARM_H_ */ | |
| OLD | NEW |