extra_ops_gcc_ppc.hpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /*
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * Copyright (c) 2017 - 2018 Andrey Semashev
  7. */
  8. /*!
  9. * \file atomic/detail/extra_ops_gcc_ppc.hpp
  10. *
  11. * This header contains implementation of the extra atomic operations for PowerPC.
  12. */
  13. #ifndef BOOST_ATOMIC_DETAIL_EXTRA_OPS_GCC_PPC_HPP_INCLUDED_
  14. #define BOOST_ATOMIC_DETAIL_EXTRA_OPS_GCC_PPC_HPP_INCLUDED_
  15. #include <cstddef>
  16. #include <boost/memory_order.hpp>
  17. #include <boost/atomic/detail/config.hpp>
  18. #include <boost/atomic/detail/storage_traits.hpp>
  19. #include <boost/atomic/detail/extra_operations_fwd.hpp>
  20. #include <boost/atomic/detail/extra_ops_generic.hpp>
  21. #include <boost/atomic/detail/ops_gcc_ppc_common.hpp>
  22. #include <boost/atomic/detail/gcc_ppc_asm_common.hpp>
  23. #include <boost/atomic/detail/capabilities.hpp>
  24. #include <boost/atomic/detail/header.hpp>
  25. #ifdef BOOST_HAS_PRAGMA_ONCE
  26. #pragma once
  27. #endif
  28. namespace boost {
  29. namespace atomics {
  30. namespace detail {
  31. template< typename Base >
  32. struct extra_operations_gcc_ppc_common :
  33. public Base
  34. {
  35. typedef Base base_type;
  36. typedef typename base_type::storage_type storage_type;
  37. static BOOST_FORCEINLINE void opaque_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  38. {
  39. base_type::fetch_negate(storage, order);
  40. }
  41. static BOOST_FORCEINLINE void opaque_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  42. {
  43. base_type::fetch_complement(storage, order);
  44. }
  45. static BOOST_FORCEINLINE bool negate_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  46. {
  47. return !!base_type::negate(storage, order);
  48. }
  49. static BOOST_FORCEINLINE bool add_and_test(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  50. {
  51. return !!base_type::add(storage, v, order);
  52. }
  53. static BOOST_FORCEINLINE bool sub_and_test(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  54. {
  55. return !!base_type::sub(storage, v, order);
  56. }
  57. static BOOST_FORCEINLINE bool and_and_test(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  58. {
  59. return !!base_type::bitwise_and(storage, v, order);
  60. }
  61. static BOOST_FORCEINLINE bool or_and_test(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  62. {
  63. return !!base_type::bitwise_or(storage, v, order);
  64. }
  65. static BOOST_FORCEINLINE bool xor_and_test(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  66. {
  67. return !!base_type::bitwise_xor(storage, v, order);
  68. }
  69. static BOOST_FORCEINLINE bool complement_and_test(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  70. {
  71. return !!base_type::bitwise_complement(storage, order);
  72. }
  73. };
  74. template< typename Base, std::size_t Size, bool Signed >
  75. struct extra_operations_gcc_ppc;
  76. #if defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LBARX_STBCX)
  77. template< typename Base, bool Signed >
  78. struct extra_operations_gcc_ppc< Base, 1u, Signed > :
  79. public extra_operations_generic< Base, 1u, Signed >
  80. {
  81. typedef extra_operations_generic< Base, 1u, Signed > base_type;
  82. typedef typename base_type::storage_type storage_type;
  83. static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  84. {
  85. core_arch_operations_gcc_ppc_base::fence_before(order);
  86. storage_type original, result;
  87. __asm__ __volatile__
  88. (
  89. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  90. "lbarx %0,%y2\n\t"
  91. "neg %1,%0\n\t"
  92. "stbcx. %1,%y2\n\t"
  93. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  94. : "=&b" (original), "=&b" (result), "+Z" (storage)
  95. :
  96. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  97. );
  98. core_arch_operations_gcc_ppc_base::fence_after(order);
  99. return original;
  100. }
  101. static BOOST_FORCEINLINE storage_type negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  102. {
  103. core_arch_operations_gcc_ppc_base::fence_before(order);
  104. storage_type original, result;
  105. __asm__ __volatile__
  106. (
  107. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  108. "lbarx %0,%y2\n\t"
  109. "neg %1,%0\n\t"
  110. "stbcx. %1,%y2\n\t"
  111. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  112. : "=&b" (original), "=&b" (result), "+Z" (storage)
  113. :
  114. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  115. );
  116. core_arch_operations_gcc_ppc_base::fence_after(order);
  117. return result;
  118. }
  119. static BOOST_FORCEINLINE storage_type add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  120. {
  121. storage_type original, result;
  122. core_arch_operations_gcc_ppc_base::fence_before(order);
  123. __asm__ __volatile__
  124. (
  125. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  126. "lbarx %0,%y2\n\t"
  127. "add %1,%0,%3\n\t"
  128. "stbcx. %1,%y2\n\t"
  129. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  130. : "=&b" (original), "=&b" (result), "+Z" (storage)
  131. : "b" (v)
  132. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  133. );
  134. core_arch_operations_gcc_ppc_base::fence_after(order);
  135. return result;
  136. }
  137. static BOOST_FORCEINLINE storage_type sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  138. {
  139. storage_type original, result;
  140. core_arch_operations_gcc_ppc_base::fence_before(order);
  141. __asm__ __volatile__
  142. (
  143. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  144. "lbarx %0,%y2\n\t"
  145. "sub %1,%0,%3\n\t"
  146. "stbcx. %1,%y2\n\t"
  147. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  148. : "=&b" (original), "=&b" (result), "+Z" (storage)
  149. : "b" (v)
  150. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  151. );
  152. core_arch_operations_gcc_ppc_base::fence_after(order);
  153. return result;
  154. }
  155. static BOOST_FORCEINLINE storage_type bitwise_and(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  156. {
  157. storage_type original, result;
  158. core_arch_operations_gcc_ppc_base::fence_before(order);
  159. __asm__ __volatile__
  160. (
  161. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  162. "lbarx %0,%y2\n\t"
  163. "and %1,%0,%3\n\t"
  164. "stbcx. %1,%y2\n\t"
  165. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  166. : "=&b" (original), "=&b" (result), "+Z" (storage)
  167. : "b" (v)
  168. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  169. );
  170. core_arch_operations_gcc_ppc_base::fence_after(order);
  171. return result;
  172. }
  173. static BOOST_FORCEINLINE storage_type bitwise_or(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  174. {
  175. storage_type original, result;
  176. core_arch_operations_gcc_ppc_base::fence_before(order);
  177. __asm__ __volatile__
  178. (
  179. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  180. "lbarx %0,%y2\n\t"
  181. "or %1,%0,%3\n\t"
  182. "stbcx. %1,%y2\n\t"
  183. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  184. : "=&b" (original), "=&b" (result), "+Z" (storage)
  185. : "b" (v)
  186. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  187. );
  188. core_arch_operations_gcc_ppc_base::fence_after(order);
  189. return result;
  190. }
  191. static BOOST_FORCEINLINE storage_type bitwise_xor(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  192. {
  193. storage_type original, result;
  194. core_arch_operations_gcc_ppc_base::fence_before(order);
  195. __asm__ __volatile__
  196. (
  197. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  198. "lbarx %0,%y2\n\t"
  199. "xor %1,%0,%3\n\t"
  200. "stbcx. %1,%y2\n\t"
  201. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  202. : "=&b" (original), "=&b" (result), "+Z" (storage)
  203. : "b" (v)
  204. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  205. );
  206. core_arch_operations_gcc_ppc_base::fence_after(order);
  207. return result;
  208. }
  209. static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  210. {
  211. core_arch_operations_gcc_ppc_base::fence_before(order);
  212. storage_type original, result;
  213. __asm__ __volatile__
  214. (
  215. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  216. "lbarx %0,%y2\n\t"
  217. "nor %1,%0,%0\n\t"
  218. "stbcx. %1,%y2\n\t"
  219. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  220. : "=&b" (original), "=&b" (result), "+Z" (storage)
  221. :
  222. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  223. );
  224. core_arch_operations_gcc_ppc_base::fence_after(order);
  225. return original;
  226. }
  227. static BOOST_FORCEINLINE storage_type bitwise_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  228. {
  229. core_arch_operations_gcc_ppc_base::fence_before(order);
  230. storage_type original, result;
  231. __asm__ __volatile__
  232. (
  233. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  234. "lbarx %0,%y2\n\t"
  235. "nor %1,%0,%0\n\t"
  236. "stbcx. %1,%y2\n\t"
  237. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  238. : "=&b" (original), "=&b" (result), "+Z" (storage)
  239. :
  240. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  241. );
  242. core_arch_operations_gcc_ppc_base::fence_after(order);
  243. return result;
  244. }
  245. };
  246. template< typename Base, bool Signed >
  247. struct extra_operations< Base, 1u, Signed, true > :
  248. public extra_operations_gcc_ppc_common< extra_operations_gcc_ppc< Base, 1u, Signed > >
  249. {
  250. };
  251. #endif // defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LBARX_STBCX)
  252. #if defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LHARX_STHCX)
  253. template< typename Base, bool Signed >
  254. struct extra_operations_gcc_ppc< Base, 2u, Signed > :
  255. public extra_operations_generic< Base, 2u, Signed >
  256. {
  257. typedef extra_operations_generic< Base, 2u, Signed > base_type;
  258. typedef typename base_type::storage_type storage_type;
  259. static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  260. {
  261. core_arch_operations_gcc_ppc_base::fence_before(order);
  262. storage_type original, result;
  263. __asm__ __volatile__
  264. (
  265. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  266. "lharx %0,%y2\n\t"
  267. "neg %1,%0\n\t"
  268. "sthcx. %1,%y2\n\t"
  269. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  270. : "=&b" (original), "=&b" (result), "+Z" (storage)
  271. :
  272. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  273. );
  274. core_arch_operations_gcc_ppc_base::fence_after(order);
  275. return original;
  276. }
  277. static BOOST_FORCEINLINE storage_type negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  278. {
  279. core_arch_operations_gcc_ppc_base::fence_before(order);
  280. storage_type original, result;
  281. __asm__ __volatile__
  282. (
  283. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  284. "lharx %0,%y2\n\t"
  285. "neg %1,%0\n\t"
  286. "sthcx. %1,%y2\n\t"
  287. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  288. : "=&b" (original), "=&b" (result), "+Z" (storage)
  289. :
  290. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  291. );
  292. core_arch_operations_gcc_ppc_base::fence_after(order);
  293. return result;
  294. }
  295. static BOOST_FORCEINLINE storage_type add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  296. {
  297. storage_type original, result;
  298. core_arch_operations_gcc_ppc_base::fence_before(order);
  299. __asm__ __volatile__
  300. (
  301. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  302. "lharx %0,%y2\n\t"
  303. "add %1,%0,%3\n\t"
  304. "sthcx. %1,%y2\n\t"
  305. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  306. : "=&b" (original), "=&b" (result), "+Z" (storage)
  307. : "b" (v)
  308. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  309. );
  310. core_arch_operations_gcc_ppc_base::fence_after(order);
  311. return result;
  312. }
  313. static BOOST_FORCEINLINE storage_type sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  314. {
  315. storage_type original, result;
  316. core_arch_operations_gcc_ppc_base::fence_before(order);
  317. __asm__ __volatile__
  318. (
  319. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  320. "lharx %0,%y2\n\t"
  321. "sub %1,%0,%3\n\t"
  322. "sthcx. %1,%y2\n\t"
  323. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  324. : "=&b" (original), "=&b" (result), "+Z" (storage)
  325. : "b" (v)
  326. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  327. );
  328. core_arch_operations_gcc_ppc_base::fence_after(order);
  329. return result;
  330. }
  331. static BOOST_FORCEINLINE storage_type bitwise_and(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  332. {
  333. storage_type original, result;
  334. core_arch_operations_gcc_ppc_base::fence_before(order);
  335. __asm__ __volatile__
  336. (
  337. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  338. "lharx %0,%y2\n\t"
  339. "and %1,%0,%3\n\t"
  340. "sthcx. %1,%y2\n\t"
  341. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  342. : "=&b" (original), "=&b" (result), "+Z" (storage)
  343. : "b" (v)
  344. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  345. );
  346. core_arch_operations_gcc_ppc_base::fence_after(order);
  347. return result;
  348. }
  349. static BOOST_FORCEINLINE storage_type bitwise_or(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  350. {
  351. storage_type original, result;
  352. core_arch_operations_gcc_ppc_base::fence_before(order);
  353. __asm__ __volatile__
  354. (
  355. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  356. "lharx %0,%y2\n\t"
  357. "or %1,%0,%3\n\t"
  358. "sthcx. %1,%y2\n\t"
  359. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  360. : "=&b" (original), "=&b" (result), "+Z" (storage)
  361. : "b" (v)
  362. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  363. );
  364. core_arch_operations_gcc_ppc_base::fence_after(order);
  365. return result;
  366. }
  367. static BOOST_FORCEINLINE storage_type bitwise_xor(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  368. {
  369. storage_type original, result;
  370. core_arch_operations_gcc_ppc_base::fence_before(order);
  371. __asm__ __volatile__
  372. (
  373. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  374. "lharx %0,%y2\n\t"
  375. "xor %1,%0,%3\n\t"
  376. "sthcx. %1,%y2\n\t"
  377. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  378. : "=&b" (original), "=&b" (result), "+Z" (storage)
  379. : "b" (v)
  380. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  381. );
  382. core_arch_operations_gcc_ppc_base::fence_after(order);
  383. return result;
  384. }
  385. static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  386. {
  387. core_arch_operations_gcc_ppc_base::fence_before(order);
  388. storage_type original, result;
  389. __asm__ __volatile__
  390. (
  391. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  392. "lharx %0,%y2\n\t"
  393. "nor %1,%0,%0\n\t"
  394. "sthcx. %1,%y2\n\t"
  395. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  396. : "=&b" (original), "=&b" (result), "+Z" (storage)
  397. :
  398. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  399. );
  400. core_arch_operations_gcc_ppc_base::fence_after(order);
  401. return original;
  402. }
  403. static BOOST_FORCEINLINE storage_type bitwise_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  404. {
  405. core_arch_operations_gcc_ppc_base::fence_before(order);
  406. storage_type original, result;
  407. __asm__ __volatile__
  408. (
  409. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  410. "lharx %0,%y2\n\t"
  411. "nor %1,%0,%0\n\t"
  412. "sthcx. %1,%y2\n\t"
  413. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  414. : "=&b" (original), "=&b" (result), "+Z" (storage)
  415. :
  416. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  417. );
  418. core_arch_operations_gcc_ppc_base::fence_after(order);
  419. return result;
  420. }
  421. };
  422. #endif // defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LHARX_STHCX)
  423. template< typename Base, bool Signed >
  424. struct extra_operations_gcc_ppc< Base, 4u, Signed > :
  425. public extra_operations_generic< Base, 4u, Signed >
  426. {
  427. typedef extra_operations_generic< Base, 4u, Signed > base_type;
  428. typedef typename base_type::storage_type storage_type;
  429. static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  430. {
  431. core_arch_operations_gcc_ppc_base::fence_before(order);
  432. storage_type original, result;
  433. __asm__ __volatile__
  434. (
  435. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  436. "lwarx %0,%y2\n\t"
  437. "neg %1,%0\n\t"
  438. "stwcx. %1,%y2\n\t"
  439. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  440. : "=&b" (original), "=&b" (result), "+Z" (storage)
  441. :
  442. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  443. );
  444. core_arch_operations_gcc_ppc_base::fence_after(order);
  445. return original;
  446. }
  447. static BOOST_FORCEINLINE storage_type negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  448. {
  449. core_arch_operations_gcc_ppc_base::fence_before(order);
  450. storage_type original, result;
  451. __asm__ __volatile__
  452. (
  453. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  454. "lwarx %0,%y2\n\t"
  455. "neg %1,%0\n\t"
  456. "stwcx. %1,%y2\n\t"
  457. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  458. : "=&b" (original), "=&b" (result), "+Z" (storage)
  459. :
  460. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  461. );
  462. core_arch_operations_gcc_ppc_base::fence_after(order);
  463. return result;
  464. }
  465. static BOOST_FORCEINLINE storage_type add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  466. {
  467. storage_type original, result;
  468. core_arch_operations_gcc_ppc_base::fence_before(order);
  469. __asm__ __volatile__
  470. (
  471. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  472. "lwarx %0,%y2\n\t"
  473. "add %1,%0,%3\n\t"
  474. "stwcx. %1,%y2\n\t"
  475. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  476. : "=&b" (original), "=&b" (result), "+Z" (storage)
  477. : "b" (v)
  478. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  479. );
  480. core_arch_operations_gcc_ppc_base::fence_after(order);
  481. return result;
  482. }
  483. static BOOST_FORCEINLINE storage_type sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  484. {
  485. storage_type original, result;
  486. core_arch_operations_gcc_ppc_base::fence_before(order);
  487. __asm__ __volatile__
  488. (
  489. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  490. "lwarx %0,%y2\n\t"
  491. "sub %1,%0,%3\n\t"
  492. "stwcx. %1,%y2\n\t"
  493. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  494. : "=&b" (original), "=&b" (result), "+Z" (storage)
  495. : "b" (v)
  496. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  497. );
  498. core_arch_operations_gcc_ppc_base::fence_after(order);
  499. return result;
  500. }
  501. static BOOST_FORCEINLINE storage_type bitwise_and(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  502. {
  503. storage_type original, result;
  504. core_arch_operations_gcc_ppc_base::fence_before(order);
  505. __asm__ __volatile__
  506. (
  507. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  508. "lwarx %0,%y2\n\t"
  509. "and %1,%0,%3\n\t"
  510. "stwcx. %1,%y2\n\t"
  511. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  512. : "=&b" (original), "=&b" (result), "+Z" (storage)
  513. : "b" (v)
  514. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  515. );
  516. core_arch_operations_gcc_ppc_base::fence_after(order);
  517. return result;
  518. }
  519. static BOOST_FORCEINLINE storage_type bitwise_or(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  520. {
  521. storage_type original, result;
  522. core_arch_operations_gcc_ppc_base::fence_before(order);
  523. __asm__ __volatile__
  524. (
  525. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  526. "lwarx %0,%y2\n\t"
  527. "or %1,%0,%3\n\t"
  528. "stwcx. %1,%y2\n\t"
  529. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  530. : "=&b" (original), "=&b" (result), "+Z" (storage)
  531. : "b" (v)
  532. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  533. );
  534. core_arch_operations_gcc_ppc_base::fence_after(order);
  535. return result;
  536. }
  537. static BOOST_FORCEINLINE storage_type bitwise_xor(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  538. {
  539. storage_type original, result;
  540. core_arch_operations_gcc_ppc_base::fence_before(order);
  541. __asm__ __volatile__
  542. (
  543. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  544. "lwarx %0,%y2\n\t"
  545. "xor %1,%0,%3\n\t"
  546. "stwcx. %1,%y2\n\t"
  547. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  548. : "=&b" (original), "=&b" (result), "+Z" (storage)
  549. : "b" (v)
  550. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  551. );
  552. core_arch_operations_gcc_ppc_base::fence_after(order);
  553. return result;
  554. }
  555. static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  556. {
  557. core_arch_operations_gcc_ppc_base::fence_before(order);
  558. storage_type original, result;
  559. __asm__ __volatile__
  560. (
  561. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  562. "lwarx %0,%y2\n\t"
  563. "nor %1,%0,%0\n\t"
  564. "stwcx. %1,%y2\n\t"
  565. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  566. : "=&b" (original), "=&b" (result), "+Z" (storage)
  567. :
  568. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  569. );
  570. core_arch_operations_gcc_ppc_base::fence_after(order);
  571. return original;
  572. }
  573. static BOOST_FORCEINLINE storage_type bitwise_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  574. {
  575. core_arch_operations_gcc_ppc_base::fence_before(order);
  576. storage_type original, result;
  577. __asm__ __volatile__
  578. (
  579. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  580. "lwarx %0,%y2\n\t"
  581. "nor %1,%0,%0\n\t"
  582. "stwcx. %1,%y2\n\t"
  583. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  584. : "=&b" (original), "=&b" (result), "+Z" (storage)
  585. :
  586. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  587. );
  588. core_arch_operations_gcc_ppc_base::fence_after(order);
  589. return result;
  590. }
  591. };
  592. template< typename Base, bool Signed >
  593. struct extra_operations< Base, 4u, Signed, true > :
  594. public extra_operations_gcc_ppc_common< extra_operations_gcc_ppc< Base, 4u, Signed > >
  595. {
  596. };
  597. #if defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LDARX_STDCX)
  598. template< typename Base, bool Signed >
  599. struct extra_operations_gcc_ppc< Base, 8u, Signed > :
  600. public extra_operations_generic< Base, 8u, Signed >
  601. {
  602. typedef extra_operations_generic< Base, 8u, Signed > base_type;
  603. typedef typename base_type::storage_type storage_type;
  604. static BOOST_FORCEINLINE storage_type fetch_negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  605. {
  606. core_arch_operations_gcc_ppc_base::fence_before(order);
  607. storage_type original, result;
  608. __asm__ __volatile__
  609. (
  610. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  611. "ldarx %0,%y2\n\t"
  612. "neg %1,%0\n\t"
  613. "stdcx. %1,%y2\n\t"
  614. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  615. : "=&b" (original), "=&b" (result), "+Z" (storage)
  616. :
  617. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  618. );
  619. core_arch_operations_gcc_ppc_base::fence_after(order);
  620. return original;
  621. }
  622. static BOOST_FORCEINLINE storage_type negate(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  623. {
  624. core_arch_operations_gcc_ppc_base::fence_before(order);
  625. storage_type original, result;
  626. __asm__ __volatile__
  627. (
  628. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  629. "ldarx %0,%y2\n\t"
  630. "neg %1,%0\n\t"
  631. "stdcx. %1,%y2\n\t"
  632. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  633. : "=&b" (original), "=&b" (result), "+Z" (storage)
  634. :
  635. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  636. );
  637. core_arch_operations_gcc_ppc_base::fence_after(order);
  638. return result;
  639. }
  640. static BOOST_FORCEINLINE storage_type add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  641. {
  642. storage_type original, result;
  643. core_arch_operations_gcc_ppc_base::fence_before(order);
  644. __asm__ __volatile__
  645. (
  646. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  647. "ldarx %0,%y2\n\t"
  648. "add %1,%0,%3\n\t"
  649. "stdcx. %1,%y2\n\t"
  650. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  651. : "=&b" (original), "=&b" (result), "+Z" (storage)
  652. : "b" (v)
  653. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  654. );
  655. core_arch_operations_gcc_ppc_base::fence_after(order);
  656. return result;
  657. }
  658. static BOOST_FORCEINLINE storage_type sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  659. {
  660. storage_type original, result;
  661. core_arch_operations_gcc_ppc_base::fence_before(order);
  662. __asm__ __volatile__
  663. (
  664. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  665. "ldarx %0,%y2\n\t"
  666. "sub %1,%0,%3\n\t"
  667. "stdcx. %1,%y2\n\t"
  668. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  669. : "=&b" (original), "=&b" (result), "+Z" (storage)
  670. : "b" (v)
  671. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  672. );
  673. core_arch_operations_gcc_ppc_base::fence_after(order);
  674. return result;
  675. }
  676. static BOOST_FORCEINLINE storage_type bitwise_and(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  677. {
  678. storage_type original, result;
  679. core_arch_operations_gcc_ppc_base::fence_before(order);
  680. __asm__ __volatile__
  681. (
  682. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  683. "ldarx %0,%y2\n\t"
  684. "and %1,%0,%3\n\t"
  685. "stdcx. %1,%y2\n\t"
  686. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  687. : "=&b" (original), "=&b" (result), "+Z" (storage)
  688. : "b" (v)
  689. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  690. );
  691. core_arch_operations_gcc_ppc_base::fence_after(order);
  692. return result;
  693. }
  694. static BOOST_FORCEINLINE storage_type bitwise_or(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  695. {
  696. storage_type original, result;
  697. core_arch_operations_gcc_ppc_base::fence_before(order);
  698. __asm__ __volatile__
  699. (
  700. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  701. "ldarx %0,%y2\n\t"
  702. "or %1,%0,%3\n\t"
  703. "stdcx. %1,%y2\n\t"
  704. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  705. : "=&b" (original), "=&b" (result), "+Z" (storage)
  706. : "b" (v)
  707. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  708. );
  709. core_arch_operations_gcc_ppc_base::fence_after(order);
  710. return result;
  711. }
  712. static BOOST_FORCEINLINE storage_type bitwise_xor(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
  713. {
  714. storage_type original, result;
  715. core_arch_operations_gcc_ppc_base::fence_before(order);
  716. __asm__ __volatile__
  717. (
  718. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  719. "ldarx %0,%y2\n\t"
  720. "xor %1,%0,%3\n\t"
  721. "stdcx. %1,%y2\n\t"
  722. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  723. : "=&b" (original), "=&b" (result), "+Z" (storage)
  724. : "b" (v)
  725. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  726. );
  727. core_arch_operations_gcc_ppc_base::fence_after(order);
  728. return result;
  729. }
  730. static BOOST_FORCEINLINE storage_type fetch_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  731. {
  732. core_arch_operations_gcc_ppc_base::fence_before(order);
  733. storage_type original, result;
  734. __asm__ __volatile__
  735. (
  736. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  737. "ldarx %0,%y2\n\t"
  738. "nor %1,%0,%0\n\t"
  739. "stdcx. %1,%y2\n\t"
  740. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  741. : "=&b" (original), "=&b" (result), "+Z" (storage)
  742. :
  743. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  744. );
  745. core_arch_operations_gcc_ppc_base::fence_after(order);
  746. return original;
  747. }
  748. static BOOST_FORCEINLINE storage_type bitwise_complement(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
  749. {
  750. core_arch_operations_gcc_ppc_base::fence_before(order);
  751. storage_type original, result;
  752. __asm__ __volatile__
  753. (
  754. BOOST_ATOMIC_DETAIL_PPC_ASM_LABEL("1")
  755. "ldarx %0,%y2\n\t"
  756. "nor %1,%0,%0\n\t"
  757. "stdcx. %1,%y2\n\t"
  758. BOOST_ATOMIC_DETAIL_PPC_ASM_JUMP("bne-", "1b", "-12")
  759. : "=&b" (original), "=&b" (result), "+Z" (storage)
  760. :
  761. : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC
  762. );
  763. core_arch_operations_gcc_ppc_base::fence_after(order);
  764. return result;
  765. }
  766. };
  767. template< typename Base, bool Signed >
  768. struct extra_operations< Base, 8u, Signed, true > :
  769. public extra_operations_gcc_ppc_common< extra_operations_gcc_ppc< Base, 8u, Signed > >
  770. {
  771. };
  772. #endif // defined(BOOST_ATOMIC_DETAIL_PPC_HAS_LDARX_STDCX)
  773. } // namespace detail
  774. } // namespace atomics
  775. } // namespace boost
  776. #include <boost/atomic/detail/footer.hpp>
  777. #endif // BOOST_ATOMIC_DETAIL_EXTRA_OPS_GCC_ARM_PPC_INCLUDED_