extra_ops_gcc_ppc.hpp 27 KB

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