generalize-small.h 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600
  1. /*
  2. * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. /* char_fetch_compare_and_swap */
  23. #if defined(AO_HAVE_char_fetch_compare_and_swap) \
  24. && defined(AO_HAVE_nop_full) \
  25. && !defined(AO_HAVE_char_fetch_compare_and_swap_acquire)
  26. AO_INLINE unsigned/**/char
  27. AO_char_fetch_compare_and_swap_acquire(volatile unsigned/**/char *addr,
  28. unsigned/**/char old_val, unsigned/**/char new_val)
  29. {
  30. unsigned/**/char result = AO_char_fetch_compare_and_swap(addr, old_val, new_val);
  31. AO_nop_full();
  32. return result;
  33. }
  34. # define AO_HAVE_char_fetch_compare_and_swap_acquire
  35. #endif
  36. #if defined(AO_HAVE_char_fetch_compare_and_swap) \
  37. && defined(AO_HAVE_nop_full) \
  38. && !defined(AO_HAVE_char_fetch_compare_and_swap_release)
  39. # define AO_char_fetch_compare_and_swap_release(addr, old_val, new_val) \
  40. (AO_nop_full(), \
  41. AO_char_fetch_compare_and_swap(addr, old_val, new_val))
  42. # define AO_HAVE_char_fetch_compare_and_swap_release
  43. #endif
  44. #if defined(AO_HAVE_char_fetch_compare_and_swap_full)
  45. # if !defined(AO_HAVE_char_fetch_compare_and_swap_release)
  46. # define AO_char_fetch_compare_and_swap_release(addr, old_val, new_val) \
  47. AO_char_fetch_compare_and_swap_full(addr, old_val, new_val)
  48. # define AO_HAVE_char_fetch_compare_and_swap_release
  49. # endif
  50. # if !defined(AO_HAVE_char_fetch_compare_and_swap_acquire)
  51. # define AO_char_fetch_compare_and_swap_acquire(addr, old_val, new_val) \
  52. AO_char_fetch_compare_and_swap_full(addr, old_val, new_val)
  53. # define AO_HAVE_char_fetch_compare_and_swap_acquire
  54. # endif
  55. # if !defined(AO_HAVE_char_fetch_compare_and_swap_write)
  56. # define AO_char_fetch_compare_and_swap_write(addr, old_val, new_val) \
  57. AO_char_fetch_compare_and_swap_full(addr, old_val, new_val)
  58. # define AO_HAVE_char_fetch_compare_and_swap_write
  59. # endif
  60. # if !defined(AO_HAVE_char_fetch_compare_and_swap_read)
  61. # define AO_char_fetch_compare_and_swap_read(addr, old_val, new_val) \
  62. AO_char_fetch_compare_and_swap_full(addr, old_val, new_val)
  63. # define AO_HAVE_char_fetch_compare_and_swap_read
  64. # endif
  65. #endif /* AO_HAVE_char_fetch_compare_and_swap_full */
  66. #if !defined(AO_HAVE_char_fetch_compare_and_swap) \
  67. && defined(AO_HAVE_char_fetch_compare_and_swap_release)
  68. # define AO_char_fetch_compare_and_swap(addr, old_val, new_val) \
  69. AO_char_fetch_compare_and_swap_release(addr, old_val, new_val)
  70. # define AO_HAVE_char_fetch_compare_and_swap
  71. #endif
  72. #if !defined(AO_HAVE_char_fetch_compare_and_swap) \
  73. && defined(AO_HAVE_char_fetch_compare_and_swap_acquire)
  74. # define AO_char_fetch_compare_and_swap(addr, old_val, new_val) \
  75. AO_char_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  76. # define AO_HAVE_char_fetch_compare_and_swap
  77. #endif
  78. #if !defined(AO_HAVE_char_fetch_compare_and_swap) \
  79. && defined(AO_HAVE_char_fetch_compare_and_swap_write)
  80. # define AO_char_fetch_compare_and_swap(addr, old_val, new_val) \
  81. AO_char_fetch_compare_and_swap_write(addr, old_val, new_val)
  82. # define AO_HAVE_char_fetch_compare_and_swap
  83. #endif
  84. #if !defined(AO_HAVE_char_fetch_compare_and_swap) \
  85. && defined(AO_HAVE_char_fetch_compare_and_swap_read)
  86. # define AO_char_fetch_compare_and_swap(addr, old_val, new_val) \
  87. AO_char_fetch_compare_and_swap_read(addr, old_val, new_val)
  88. # define AO_HAVE_char_fetch_compare_and_swap
  89. #endif
  90. #if defined(AO_HAVE_char_fetch_compare_and_swap_acquire) \
  91. && defined(AO_HAVE_nop_full) \
  92. && !defined(AO_HAVE_char_fetch_compare_and_swap_full)
  93. # define AO_char_fetch_compare_and_swap_full(addr, old_val, new_val) \
  94. (AO_nop_full(), \
  95. AO_char_fetch_compare_and_swap_acquire(addr, old_val, new_val))
  96. # define AO_HAVE_char_fetch_compare_and_swap_full
  97. #endif
  98. #if !defined(AO_HAVE_char_fetch_compare_and_swap_release_write) \
  99. && defined(AO_HAVE_char_fetch_compare_and_swap_write)
  100. # define AO_char_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
  101. AO_char_fetch_compare_and_swap_write(addr, old_val, new_val)
  102. # define AO_HAVE_char_fetch_compare_and_swap_release_write
  103. #endif
  104. #if !defined(AO_HAVE_char_fetch_compare_and_swap_release_write) \
  105. && defined(AO_HAVE_char_fetch_compare_and_swap_release)
  106. # define AO_char_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
  107. AO_char_fetch_compare_and_swap_release(addr, old_val, new_val)
  108. # define AO_HAVE_char_fetch_compare_and_swap_release_write
  109. #endif
  110. #if !defined(AO_HAVE_char_fetch_compare_and_swap_acquire_read) \
  111. && defined(AO_HAVE_char_fetch_compare_and_swap_read)
  112. # define AO_char_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
  113. AO_char_fetch_compare_and_swap_read(addr, old_val, new_val)
  114. # define AO_HAVE_char_fetch_compare_and_swap_acquire_read
  115. #endif
  116. #if !defined(AO_HAVE_char_fetch_compare_and_swap_acquire_read) \
  117. && defined(AO_HAVE_char_fetch_compare_and_swap_acquire)
  118. # define AO_char_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
  119. AO_char_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  120. # define AO_HAVE_char_fetch_compare_and_swap_acquire_read
  121. #endif
  122. #ifdef AO_NO_DD_ORDERING
  123. # if defined(AO_HAVE_char_fetch_compare_and_swap_acquire_read)
  124. # define AO_char_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
  125. AO_char_fetch_compare_and_swap_acquire_read(addr, old_val, new_val)
  126. # define AO_HAVE_char_fetch_compare_and_swap_dd_acquire_read
  127. # endif
  128. #else
  129. # if defined(AO_HAVE_char_fetch_compare_and_swap)
  130. # define AO_char_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
  131. AO_char_fetch_compare_and_swap(addr, old_val, new_val)
  132. # define AO_HAVE_char_fetch_compare_and_swap_dd_acquire_read
  133. # endif
  134. #endif /* !AO_NO_DD_ORDERING */
  135. /* char_compare_and_swap */
  136. #if defined(AO_HAVE_char_compare_and_swap) && defined(AO_HAVE_nop_full) \
  137. && !defined(AO_HAVE_char_compare_and_swap_acquire)
  138. AO_INLINE int
  139. AO_char_compare_and_swap_acquire(volatile unsigned/**/char *addr, unsigned/**/char old,
  140. unsigned/**/char new_val)
  141. {
  142. int result = AO_char_compare_and_swap(addr, old, new_val);
  143. AO_nop_full();
  144. return result;
  145. }
  146. # define AO_HAVE_char_compare_and_swap_acquire
  147. #endif
  148. #if defined(AO_HAVE_char_compare_and_swap) && defined(AO_HAVE_nop_full) \
  149. && !defined(AO_HAVE_char_compare_and_swap_release)
  150. # define AO_char_compare_and_swap_release(addr, old, new_val) \
  151. (AO_nop_full(), AO_char_compare_and_swap(addr, old, new_val))
  152. # define AO_HAVE_char_compare_and_swap_release
  153. #endif
  154. #if defined(AO_HAVE_char_compare_and_swap_full)
  155. # if !defined(AO_HAVE_char_compare_and_swap_release)
  156. # define AO_char_compare_and_swap_release(addr, old, new_val) \
  157. AO_char_compare_and_swap_full(addr, old, new_val)
  158. # define AO_HAVE_char_compare_and_swap_release
  159. # endif
  160. # if !defined(AO_HAVE_char_compare_and_swap_acquire)
  161. # define AO_char_compare_and_swap_acquire(addr, old, new_val) \
  162. AO_char_compare_and_swap_full(addr, old, new_val)
  163. # define AO_HAVE_char_compare_and_swap_acquire
  164. # endif
  165. # if !defined(AO_HAVE_char_compare_and_swap_write)
  166. # define AO_char_compare_and_swap_write(addr, old, new_val) \
  167. AO_char_compare_and_swap_full(addr, old, new_val)
  168. # define AO_HAVE_char_compare_and_swap_write
  169. # endif
  170. # if !defined(AO_HAVE_char_compare_and_swap_read)
  171. # define AO_char_compare_and_swap_read(addr, old, new_val) \
  172. AO_char_compare_and_swap_full(addr, old, new_val)
  173. # define AO_HAVE_char_compare_and_swap_read
  174. # endif
  175. #endif /* AO_HAVE_char_compare_and_swap_full */
  176. #if !defined(AO_HAVE_char_compare_and_swap) \
  177. && defined(AO_HAVE_char_compare_and_swap_release)
  178. # define AO_char_compare_and_swap(addr, old, new_val) \
  179. AO_char_compare_and_swap_release(addr, old, new_val)
  180. # define AO_HAVE_char_compare_and_swap
  181. #endif
  182. #if !defined(AO_HAVE_char_compare_and_swap) \
  183. && defined(AO_HAVE_char_compare_and_swap_acquire)
  184. # define AO_char_compare_and_swap(addr, old, new_val) \
  185. AO_char_compare_and_swap_acquire(addr, old, new_val)
  186. # define AO_HAVE_char_compare_and_swap
  187. #endif
  188. #if !defined(AO_HAVE_char_compare_and_swap) \
  189. && defined(AO_HAVE_char_compare_and_swap_write)
  190. # define AO_char_compare_and_swap(addr, old, new_val) \
  191. AO_char_compare_and_swap_write(addr, old, new_val)
  192. # define AO_HAVE_char_compare_and_swap
  193. #endif
  194. #if !defined(AO_HAVE_char_compare_and_swap) \
  195. && defined(AO_HAVE_char_compare_and_swap_read)
  196. # define AO_char_compare_and_swap(addr, old, new_val) \
  197. AO_char_compare_and_swap_read(addr, old, new_val)
  198. # define AO_HAVE_char_compare_and_swap
  199. #endif
  200. #if defined(AO_HAVE_char_compare_and_swap_acquire) \
  201. && defined(AO_HAVE_nop_full) \
  202. && !defined(AO_HAVE_char_compare_and_swap_full)
  203. # define AO_char_compare_and_swap_full(addr, old, new_val) \
  204. (AO_nop_full(), \
  205. AO_char_compare_and_swap_acquire(addr, old, new_val))
  206. # define AO_HAVE_char_compare_and_swap_full
  207. #endif
  208. #if !defined(AO_HAVE_char_compare_and_swap_release_write) \
  209. && defined(AO_HAVE_char_compare_and_swap_write)
  210. # define AO_char_compare_and_swap_release_write(addr, old, new_val) \
  211. AO_char_compare_and_swap_write(addr, old, new_val)
  212. # define AO_HAVE_char_compare_and_swap_release_write
  213. #endif
  214. #if !defined(AO_HAVE_char_compare_and_swap_release_write) \
  215. && defined(AO_HAVE_char_compare_and_swap_release)
  216. # define AO_char_compare_and_swap_release_write(addr, old, new_val) \
  217. AO_char_compare_and_swap_release(addr, old, new_val)
  218. # define AO_HAVE_char_compare_and_swap_release_write
  219. #endif
  220. #if !defined(AO_HAVE_char_compare_and_swap_acquire_read) \
  221. && defined(AO_HAVE_char_compare_and_swap_read)
  222. # define AO_char_compare_and_swap_acquire_read(addr, old, new_val) \
  223. AO_char_compare_and_swap_read(addr, old, new_val)
  224. # define AO_HAVE_char_compare_and_swap_acquire_read
  225. #endif
  226. #if !defined(AO_HAVE_char_compare_and_swap_acquire_read) \
  227. && defined(AO_HAVE_char_compare_and_swap_acquire)
  228. # define AO_char_compare_and_swap_acquire_read(addr, old, new_val) \
  229. AO_char_compare_and_swap_acquire(addr, old, new_val)
  230. # define AO_HAVE_char_compare_and_swap_acquire_read
  231. #endif
  232. #ifdef AO_NO_DD_ORDERING
  233. # if defined(AO_HAVE_char_compare_and_swap_acquire_read)
  234. # define AO_char_compare_and_swap_dd_acquire_read(addr, old, new_val) \
  235. AO_char_compare_and_swap_acquire_read(addr, old, new_val)
  236. # define AO_HAVE_char_compare_and_swap_dd_acquire_read
  237. # endif
  238. #else
  239. # if defined(AO_HAVE_char_compare_and_swap)
  240. # define AO_char_compare_and_swap_dd_acquire_read(addr, old, new_val) \
  241. AO_char_compare_and_swap(addr, old, new_val)
  242. # define AO_HAVE_char_compare_and_swap_dd_acquire_read
  243. # endif
  244. #endif /* !AO_NO_DD_ORDERING */
  245. /* char_load */
  246. #if defined(AO_HAVE_char_load_full) && !defined(AO_HAVE_char_load_acquire)
  247. # define AO_char_load_acquire(addr) AO_char_load_full(addr)
  248. # define AO_HAVE_char_load_acquire
  249. #endif
  250. #if defined(AO_HAVE_char_load_acquire) && !defined(AO_HAVE_char_load)
  251. # define AO_char_load(addr) AO_char_load_acquire(addr)
  252. # define AO_HAVE_char_load
  253. #endif
  254. #if defined(AO_HAVE_char_load_full) && !defined(AO_HAVE_char_load_read)
  255. # define AO_char_load_read(addr) AO_char_load_full(addr)
  256. # define AO_HAVE_char_load_read
  257. #endif
  258. #if !defined(AO_HAVE_char_load_acquire_read) \
  259. && defined(AO_HAVE_char_load_acquire)
  260. # define AO_char_load_acquire_read(addr) AO_char_load_acquire(addr)
  261. # define AO_HAVE_char_load_acquire_read
  262. #endif
  263. #if defined(AO_HAVE_char_load) && defined(AO_HAVE_nop_full) \
  264. && !defined(AO_HAVE_char_load_acquire)
  265. AO_INLINE unsigned/**/char
  266. AO_char_load_acquire(const volatile unsigned/**/char *addr)
  267. {
  268. unsigned/**/char result = AO_char_load(addr);
  269. /* Acquire barrier would be useless, since the load could be delayed */
  270. /* beyond it. */
  271. AO_nop_full();
  272. return result;
  273. }
  274. # define AO_HAVE_char_load_acquire
  275. #endif
  276. #if defined(AO_HAVE_char_load) && defined(AO_HAVE_nop_read) \
  277. && !defined(AO_HAVE_char_load_read)
  278. AO_INLINE unsigned/**/char
  279. AO_char_load_read(const volatile unsigned/**/char *addr)
  280. {
  281. unsigned/**/char result = AO_char_load(addr);
  282. AO_nop_read();
  283. return result;
  284. }
  285. # define AO_HAVE_char_load_read
  286. #endif
  287. #if defined(AO_HAVE_char_load_acquire) && defined(AO_HAVE_nop_full) \
  288. && !defined(AO_HAVE_char_load_full)
  289. # define AO_char_load_full(addr) (AO_nop_full(), AO_char_load_acquire(addr))
  290. # define AO_HAVE_char_load_full
  291. #endif
  292. #if defined(AO_HAVE_char_compare_and_swap_read) \
  293. && !defined(AO_HAVE_char_load_read)
  294. # define AO_char_CAS_BASED_LOAD_READ
  295. AO_INLINE unsigned/**/char
  296. AO_char_load_read(const volatile unsigned/**/char *addr)
  297. {
  298. unsigned/**/char result;
  299. do {
  300. result = *(const unsigned/**/char *)addr;
  301. } while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_read(
  302. (volatile unsigned/**/char *)addr,
  303. result, result)));
  304. return result;
  305. }
  306. # define AO_HAVE_char_load_read
  307. #endif
  308. #if !defined(AO_HAVE_char_load_acquire_read) \
  309. && defined(AO_HAVE_char_load_read)
  310. # define AO_char_load_acquire_read(addr) AO_char_load_read(addr)
  311. # define AO_HAVE_char_load_acquire_read
  312. #endif
  313. #if defined(AO_HAVE_char_load_acquire_read) && !defined(AO_HAVE_char_load) \
  314. && (!defined(AO_char_CAS_BASED_LOAD_READ) \
  315. || !defined(AO_HAVE_char_compare_and_swap))
  316. # define AO_char_load(addr) AO_char_load_acquire_read(addr)
  317. # define AO_HAVE_char_load
  318. #endif
  319. #if defined(AO_HAVE_char_compare_and_swap_full) \
  320. && !defined(AO_HAVE_char_load_full)
  321. AO_INLINE unsigned/**/char
  322. AO_char_load_full(const volatile unsigned/**/char *addr)
  323. {
  324. unsigned/**/char result;
  325. do {
  326. result = *(const unsigned/**/char *)addr;
  327. } while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_full(
  328. (volatile unsigned/**/char *)addr,
  329. result, result)));
  330. return result;
  331. }
  332. # define AO_HAVE_char_load_full
  333. #endif
  334. #if defined(AO_HAVE_char_compare_and_swap_acquire) \
  335. && !defined(AO_HAVE_char_load_acquire)
  336. AO_INLINE unsigned/**/char
  337. AO_char_load_acquire(const volatile unsigned/**/char *addr)
  338. {
  339. unsigned/**/char result;
  340. do {
  341. result = *(const unsigned/**/char *)addr;
  342. } while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_acquire(
  343. (volatile unsigned/**/char *)addr,
  344. result, result)));
  345. return result;
  346. }
  347. # define AO_HAVE_char_load_acquire
  348. #endif
  349. #if defined(AO_HAVE_char_compare_and_swap) && !defined(AO_HAVE_char_load)
  350. AO_INLINE unsigned/**/char
  351. AO_char_load(const volatile unsigned/**/char *addr)
  352. {
  353. unsigned/**/char result;
  354. do {
  355. result = *(const unsigned/**/char *)addr;
  356. } while (AO_EXPECT_FALSE(!AO_char_compare_and_swap(
  357. (volatile unsigned/**/char *)addr,
  358. result, result)));
  359. return result;
  360. }
  361. # define AO_HAVE_char_load
  362. #endif
  363. #ifdef AO_NO_DD_ORDERING
  364. # if defined(AO_HAVE_char_load_acquire_read)
  365. # define AO_char_load_dd_acquire_read(addr) \
  366. AO_char_load_acquire_read(addr)
  367. # define AO_HAVE_char_load_dd_acquire_read
  368. # endif
  369. #else
  370. # if defined(AO_HAVE_char_load)
  371. # define AO_char_load_dd_acquire_read(addr) AO_char_load(addr)
  372. # define AO_HAVE_char_load_dd_acquire_read
  373. # endif
  374. #endif /* !AO_NO_DD_ORDERING */
  375. /* char_store */
  376. #if defined(AO_HAVE_char_store_full) && !defined(AO_HAVE_char_store_release)
  377. # define AO_char_store_release(addr, val) AO_char_store_full(addr, val)
  378. # define AO_HAVE_char_store_release
  379. #endif
  380. #if defined(AO_HAVE_char_store_release) && !defined(AO_HAVE_char_store)
  381. # define AO_char_store(addr, val) AO_char_store_release(addr, val)
  382. # define AO_HAVE_char_store
  383. #endif
  384. #if defined(AO_HAVE_char_store_full) && !defined(AO_HAVE_char_store_write)
  385. # define AO_char_store_write(addr, val) AO_char_store_full(addr, val)
  386. # define AO_HAVE_char_store_write
  387. #endif
  388. #if defined(AO_HAVE_char_store_release) \
  389. && !defined(AO_HAVE_char_store_release_write)
  390. # define AO_char_store_release_write(addr, val) \
  391. AO_char_store_release(addr, val)
  392. # define AO_HAVE_char_store_release_write
  393. #endif
  394. #if defined(AO_HAVE_char_store_write) && !defined(AO_HAVE_char_store)
  395. # define AO_char_store(addr, val) AO_char_store_write(addr, val)
  396. # define AO_HAVE_char_store
  397. #endif
  398. #if defined(AO_HAVE_char_store) && defined(AO_HAVE_nop_full) \
  399. && !defined(AO_HAVE_char_store_release)
  400. # define AO_char_store_release(addr, val) \
  401. (AO_nop_full(), AO_char_store(addr, val))
  402. # define AO_HAVE_char_store_release
  403. #endif
  404. #if defined(AO_HAVE_char_store) && defined(AO_HAVE_nop_write) \
  405. && !defined(AO_HAVE_char_store_write)
  406. # define AO_char_store_write(addr, val) \
  407. (AO_nop_write(), AO_char_store(addr, val))
  408. # define AO_HAVE_char_store_write
  409. #endif
  410. #if defined(AO_HAVE_char_compare_and_swap_write) \
  411. && !defined(AO_HAVE_char_store_write)
  412. AO_INLINE void
  413. AO_char_store_write(volatile unsigned/**/char *addr, unsigned/**/char new_val)
  414. {
  415. unsigned/**/char old_val;
  416. do {
  417. old_val = *(unsigned/**/char *)addr;
  418. } while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_write(addr, old_val,
  419. new_val)));
  420. }
  421. # define AO_HAVE_char_store_write
  422. #endif
  423. #if defined(AO_HAVE_char_store_write) \
  424. && !defined(AO_HAVE_char_store_release_write)
  425. # define AO_char_store_release_write(addr, val) \
  426. AO_char_store_write(addr, val)
  427. # define AO_HAVE_char_store_release_write
  428. #endif
  429. #if defined(AO_HAVE_char_store_release) && defined(AO_HAVE_nop_full) \
  430. && !defined(AO_HAVE_char_store_full)
  431. # define AO_char_store_full(addr, val) \
  432. (AO_char_store_release(addr, val), \
  433. AO_nop_full())
  434. # define AO_HAVE_char_store_full
  435. #endif
  436. #if defined(AO_HAVE_char_compare_and_swap) && !defined(AO_HAVE_char_store)
  437. AO_INLINE void
  438. AO_char_store(volatile unsigned/**/char *addr, unsigned/**/char new_val)
  439. {
  440. unsigned/**/char old_val;
  441. do {
  442. old_val = *(unsigned/**/char *)addr;
  443. } while (AO_EXPECT_FALSE(!AO_char_compare_and_swap(addr,
  444. old_val, new_val)));
  445. }
  446. # define AO_HAVE_char_store
  447. #endif
  448. #if defined(AO_HAVE_char_compare_and_swap_release) \
  449. && !defined(AO_HAVE_char_store_release)
  450. AO_INLINE void
  451. AO_char_store_release(volatile unsigned/**/char *addr, unsigned/**/char new_val)
  452. {
  453. unsigned/**/char old_val;
  454. do {
  455. old_val = *(unsigned/**/char *)addr;
  456. } while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_release(addr, old_val,
  457. new_val)));
  458. }
  459. # define AO_HAVE_char_store_release
  460. #endif
  461. #if defined(AO_HAVE_char_compare_and_swap_full) \
  462. && !defined(AO_HAVE_char_store_full)
  463. AO_INLINE void
  464. AO_char_store_full(volatile unsigned/**/char *addr, unsigned/**/char new_val)
  465. {
  466. unsigned/**/char old_val;
  467. do {
  468. old_val = *(unsigned/**/char *)addr;
  469. } while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_full(addr, old_val,
  470. new_val)));
  471. }
  472. # define AO_HAVE_char_store_full
  473. #endif
  474. /*
  475. * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
  476. *
  477. * Permission is hereby granted, free of charge, to any person obtaining a copy
  478. * of this software and associated documentation files (the "Software"), to deal
  479. * in the Software without restriction, including without limitation the rights
  480. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  481. * copies of the Software, and to permit persons to whom the Software is
  482. * furnished to do so, subject to the following conditions:
  483. *
  484. * The above copyright notice and this permission notice shall be included in
  485. * all copies or substantial portions of the Software.
  486. *
  487. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  488. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  489. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  490. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  491. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  492. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  493. * SOFTWARE.
  494. */
  495. /* short_fetch_compare_and_swap */
  496. #if defined(AO_HAVE_short_fetch_compare_and_swap) \
  497. && defined(AO_HAVE_nop_full) \
  498. && !defined(AO_HAVE_short_fetch_compare_and_swap_acquire)
  499. AO_INLINE unsigned/**/short
  500. AO_short_fetch_compare_and_swap_acquire(volatile unsigned/**/short *addr,
  501. unsigned/**/short old_val, unsigned/**/short new_val)
  502. {
  503. unsigned/**/short result = AO_short_fetch_compare_and_swap(addr, old_val, new_val);
  504. AO_nop_full();
  505. return result;
  506. }
  507. # define AO_HAVE_short_fetch_compare_and_swap_acquire
  508. #endif
  509. #if defined(AO_HAVE_short_fetch_compare_and_swap) \
  510. && defined(AO_HAVE_nop_full) \
  511. && !defined(AO_HAVE_short_fetch_compare_and_swap_release)
  512. # define AO_short_fetch_compare_and_swap_release(addr, old_val, new_val) \
  513. (AO_nop_full(), \
  514. AO_short_fetch_compare_and_swap(addr, old_val, new_val))
  515. # define AO_HAVE_short_fetch_compare_and_swap_release
  516. #endif
  517. #if defined(AO_HAVE_short_fetch_compare_and_swap_full)
  518. # if !defined(AO_HAVE_short_fetch_compare_and_swap_release)
  519. # define AO_short_fetch_compare_and_swap_release(addr, old_val, new_val) \
  520. AO_short_fetch_compare_and_swap_full(addr, old_val, new_val)
  521. # define AO_HAVE_short_fetch_compare_and_swap_release
  522. # endif
  523. # if !defined(AO_HAVE_short_fetch_compare_and_swap_acquire)
  524. # define AO_short_fetch_compare_and_swap_acquire(addr, old_val, new_val) \
  525. AO_short_fetch_compare_and_swap_full(addr, old_val, new_val)
  526. # define AO_HAVE_short_fetch_compare_and_swap_acquire
  527. # endif
  528. # if !defined(AO_HAVE_short_fetch_compare_and_swap_write)
  529. # define AO_short_fetch_compare_and_swap_write(addr, old_val, new_val) \
  530. AO_short_fetch_compare_and_swap_full(addr, old_val, new_val)
  531. # define AO_HAVE_short_fetch_compare_and_swap_write
  532. # endif
  533. # if !defined(AO_HAVE_short_fetch_compare_and_swap_read)
  534. # define AO_short_fetch_compare_and_swap_read(addr, old_val, new_val) \
  535. AO_short_fetch_compare_and_swap_full(addr, old_val, new_val)
  536. # define AO_HAVE_short_fetch_compare_and_swap_read
  537. # endif
  538. #endif /* AO_HAVE_short_fetch_compare_and_swap_full */
  539. #if !defined(AO_HAVE_short_fetch_compare_and_swap) \
  540. && defined(AO_HAVE_short_fetch_compare_and_swap_release)
  541. # define AO_short_fetch_compare_and_swap(addr, old_val, new_val) \
  542. AO_short_fetch_compare_and_swap_release(addr, old_val, new_val)
  543. # define AO_HAVE_short_fetch_compare_and_swap
  544. #endif
  545. #if !defined(AO_HAVE_short_fetch_compare_and_swap) \
  546. && defined(AO_HAVE_short_fetch_compare_and_swap_acquire)
  547. # define AO_short_fetch_compare_and_swap(addr, old_val, new_val) \
  548. AO_short_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  549. # define AO_HAVE_short_fetch_compare_and_swap
  550. #endif
  551. #if !defined(AO_HAVE_short_fetch_compare_and_swap) \
  552. && defined(AO_HAVE_short_fetch_compare_and_swap_write)
  553. # define AO_short_fetch_compare_and_swap(addr, old_val, new_val) \
  554. AO_short_fetch_compare_and_swap_write(addr, old_val, new_val)
  555. # define AO_HAVE_short_fetch_compare_and_swap
  556. #endif
  557. #if !defined(AO_HAVE_short_fetch_compare_and_swap) \
  558. && defined(AO_HAVE_short_fetch_compare_and_swap_read)
  559. # define AO_short_fetch_compare_and_swap(addr, old_val, new_val) \
  560. AO_short_fetch_compare_and_swap_read(addr, old_val, new_val)
  561. # define AO_HAVE_short_fetch_compare_and_swap
  562. #endif
  563. #if defined(AO_HAVE_short_fetch_compare_and_swap_acquire) \
  564. && defined(AO_HAVE_nop_full) \
  565. && !defined(AO_HAVE_short_fetch_compare_and_swap_full)
  566. # define AO_short_fetch_compare_and_swap_full(addr, old_val, new_val) \
  567. (AO_nop_full(), \
  568. AO_short_fetch_compare_and_swap_acquire(addr, old_val, new_val))
  569. # define AO_HAVE_short_fetch_compare_and_swap_full
  570. #endif
  571. #if !defined(AO_HAVE_short_fetch_compare_and_swap_release_write) \
  572. && defined(AO_HAVE_short_fetch_compare_and_swap_write)
  573. # define AO_short_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
  574. AO_short_fetch_compare_and_swap_write(addr, old_val, new_val)
  575. # define AO_HAVE_short_fetch_compare_and_swap_release_write
  576. #endif
  577. #if !defined(AO_HAVE_short_fetch_compare_and_swap_release_write) \
  578. && defined(AO_HAVE_short_fetch_compare_and_swap_release)
  579. # define AO_short_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
  580. AO_short_fetch_compare_and_swap_release(addr, old_val, new_val)
  581. # define AO_HAVE_short_fetch_compare_and_swap_release_write
  582. #endif
  583. #if !defined(AO_HAVE_short_fetch_compare_and_swap_acquire_read) \
  584. && defined(AO_HAVE_short_fetch_compare_and_swap_read)
  585. # define AO_short_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
  586. AO_short_fetch_compare_and_swap_read(addr, old_val, new_val)
  587. # define AO_HAVE_short_fetch_compare_and_swap_acquire_read
  588. #endif
  589. #if !defined(AO_HAVE_short_fetch_compare_and_swap_acquire_read) \
  590. && defined(AO_HAVE_short_fetch_compare_and_swap_acquire)
  591. # define AO_short_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
  592. AO_short_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  593. # define AO_HAVE_short_fetch_compare_and_swap_acquire_read
  594. #endif
  595. #ifdef AO_NO_DD_ORDERING
  596. # if defined(AO_HAVE_short_fetch_compare_and_swap_acquire_read)
  597. # define AO_short_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
  598. AO_short_fetch_compare_and_swap_acquire_read(addr, old_val, new_val)
  599. # define AO_HAVE_short_fetch_compare_and_swap_dd_acquire_read
  600. # endif
  601. #else
  602. # if defined(AO_HAVE_short_fetch_compare_and_swap)
  603. # define AO_short_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
  604. AO_short_fetch_compare_and_swap(addr, old_val, new_val)
  605. # define AO_HAVE_short_fetch_compare_and_swap_dd_acquire_read
  606. # endif
  607. #endif /* !AO_NO_DD_ORDERING */
  608. /* short_compare_and_swap */
  609. #if defined(AO_HAVE_short_compare_and_swap) && defined(AO_HAVE_nop_full) \
  610. && !defined(AO_HAVE_short_compare_and_swap_acquire)
  611. AO_INLINE int
  612. AO_short_compare_and_swap_acquire(volatile unsigned/**/short *addr, unsigned/**/short old,
  613. unsigned/**/short new_val)
  614. {
  615. int result = AO_short_compare_and_swap(addr, old, new_val);
  616. AO_nop_full();
  617. return result;
  618. }
  619. # define AO_HAVE_short_compare_and_swap_acquire
  620. #endif
  621. #if defined(AO_HAVE_short_compare_and_swap) && defined(AO_HAVE_nop_full) \
  622. && !defined(AO_HAVE_short_compare_and_swap_release)
  623. # define AO_short_compare_and_swap_release(addr, old, new_val) \
  624. (AO_nop_full(), AO_short_compare_and_swap(addr, old, new_val))
  625. # define AO_HAVE_short_compare_and_swap_release
  626. #endif
  627. #if defined(AO_HAVE_short_compare_and_swap_full)
  628. # if !defined(AO_HAVE_short_compare_and_swap_release)
  629. # define AO_short_compare_and_swap_release(addr, old, new_val) \
  630. AO_short_compare_and_swap_full(addr, old, new_val)
  631. # define AO_HAVE_short_compare_and_swap_release
  632. # endif
  633. # if !defined(AO_HAVE_short_compare_and_swap_acquire)
  634. # define AO_short_compare_and_swap_acquire(addr, old, new_val) \
  635. AO_short_compare_and_swap_full(addr, old, new_val)
  636. # define AO_HAVE_short_compare_and_swap_acquire
  637. # endif
  638. # if !defined(AO_HAVE_short_compare_and_swap_write)
  639. # define AO_short_compare_and_swap_write(addr, old, new_val) \
  640. AO_short_compare_and_swap_full(addr, old, new_val)
  641. # define AO_HAVE_short_compare_and_swap_write
  642. # endif
  643. # if !defined(AO_HAVE_short_compare_and_swap_read)
  644. # define AO_short_compare_and_swap_read(addr, old, new_val) \
  645. AO_short_compare_and_swap_full(addr, old, new_val)
  646. # define AO_HAVE_short_compare_and_swap_read
  647. # endif
  648. #endif /* AO_HAVE_short_compare_and_swap_full */
  649. #if !defined(AO_HAVE_short_compare_and_swap) \
  650. && defined(AO_HAVE_short_compare_and_swap_release)
  651. # define AO_short_compare_and_swap(addr, old, new_val) \
  652. AO_short_compare_and_swap_release(addr, old, new_val)
  653. # define AO_HAVE_short_compare_and_swap
  654. #endif
  655. #if !defined(AO_HAVE_short_compare_and_swap) \
  656. && defined(AO_HAVE_short_compare_and_swap_acquire)
  657. # define AO_short_compare_and_swap(addr, old, new_val) \
  658. AO_short_compare_and_swap_acquire(addr, old, new_val)
  659. # define AO_HAVE_short_compare_and_swap
  660. #endif
  661. #if !defined(AO_HAVE_short_compare_and_swap) \
  662. && defined(AO_HAVE_short_compare_and_swap_write)
  663. # define AO_short_compare_and_swap(addr, old, new_val) \
  664. AO_short_compare_and_swap_write(addr, old, new_val)
  665. # define AO_HAVE_short_compare_and_swap
  666. #endif
  667. #if !defined(AO_HAVE_short_compare_and_swap) \
  668. && defined(AO_HAVE_short_compare_and_swap_read)
  669. # define AO_short_compare_and_swap(addr, old, new_val) \
  670. AO_short_compare_and_swap_read(addr, old, new_val)
  671. # define AO_HAVE_short_compare_and_swap
  672. #endif
  673. #if defined(AO_HAVE_short_compare_and_swap_acquire) \
  674. && defined(AO_HAVE_nop_full) \
  675. && !defined(AO_HAVE_short_compare_and_swap_full)
  676. # define AO_short_compare_and_swap_full(addr, old, new_val) \
  677. (AO_nop_full(), \
  678. AO_short_compare_and_swap_acquire(addr, old, new_val))
  679. # define AO_HAVE_short_compare_and_swap_full
  680. #endif
  681. #if !defined(AO_HAVE_short_compare_and_swap_release_write) \
  682. && defined(AO_HAVE_short_compare_and_swap_write)
  683. # define AO_short_compare_and_swap_release_write(addr, old, new_val) \
  684. AO_short_compare_and_swap_write(addr, old, new_val)
  685. # define AO_HAVE_short_compare_and_swap_release_write
  686. #endif
  687. #if !defined(AO_HAVE_short_compare_and_swap_release_write) \
  688. && defined(AO_HAVE_short_compare_and_swap_release)
  689. # define AO_short_compare_and_swap_release_write(addr, old, new_val) \
  690. AO_short_compare_and_swap_release(addr, old, new_val)
  691. # define AO_HAVE_short_compare_and_swap_release_write
  692. #endif
  693. #if !defined(AO_HAVE_short_compare_and_swap_acquire_read) \
  694. && defined(AO_HAVE_short_compare_and_swap_read)
  695. # define AO_short_compare_and_swap_acquire_read(addr, old, new_val) \
  696. AO_short_compare_and_swap_read(addr, old, new_val)
  697. # define AO_HAVE_short_compare_and_swap_acquire_read
  698. #endif
  699. #if !defined(AO_HAVE_short_compare_and_swap_acquire_read) \
  700. && defined(AO_HAVE_short_compare_and_swap_acquire)
  701. # define AO_short_compare_and_swap_acquire_read(addr, old, new_val) \
  702. AO_short_compare_and_swap_acquire(addr, old, new_val)
  703. # define AO_HAVE_short_compare_and_swap_acquire_read
  704. #endif
  705. #ifdef AO_NO_DD_ORDERING
  706. # if defined(AO_HAVE_short_compare_and_swap_acquire_read)
  707. # define AO_short_compare_and_swap_dd_acquire_read(addr, old, new_val) \
  708. AO_short_compare_and_swap_acquire_read(addr, old, new_val)
  709. # define AO_HAVE_short_compare_and_swap_dd_acquire_read
  710. # endif
  711. #else
  712. # if defined(AO_HAVE_short_compare_and_swap)
  713. # define AO_short_compare_and_swap_dd_acquire_read(addr, old, new_val) \
  714. AO_short_compare_and_swap(addr, old, new_val)
  715. # define AO_HAVE_short_compare_and_swap_dd_acquire_read
  716. # endif
  717. #endif /* !AO_NO_DD_ORDERING */
  718. /* short_load */
  719. #if defined(AO_HAVE_short_load_full) && !defined(AO_HAVE_short_load_acquire)
  720. # define AO_short_load_acquire(addr) AO_short_load_full(addr)
  721. # define AO_HAVE_short_load_acquire
  722. #endif
  723. #if defined(AO_HAVE_short_load_acquire) && !defined(AO_HAVE_short_load)
  724. # define AO_short_load(addr) AO_short_load_acquire(addr)
  725. # define AO_HAVE_short_load
  726. #endif
  727. #if defined(AO_HAVE_short_load_full) && !defined(AO_HAVE_short_load_read)
  728. # define AO_short_load_read(addr) AO_short_load_full(addr)
  729. # define AO_HAVE_short_load_read
  730. #endif
  731. #if !defined(AO_HAVE_short_load_acquire_read) \
  732. && defined(AO_HAVE_short_load_acquire)
  733. # define AO_short_load_acquire_read(addr) AO_short_load_acquire(addr)
  734. # define AO_HAVE_short_load_acquire_read
  735. #endif
  736. #if defined(AO_HAVE_short_load) && defined(AO_HAVE_nop_full) \
  737. && !defined(AO_HAVE_short_load_acquire)
  738. AO_INLINE unsigned/**/short
  739. AO_short_load_acquire(const volatile unsigned/**/short *addr)
  740. {
  741. unsigned/**/short result = AO_short_load(addr);
  742. /* Acquire barrier would be useless, since the load could be delayed */
  743. /* beyond it. */
  744. AO_nop_full();
  745. return result;
  746. }
  747. # define AO_HAVE_short_load_acquire
  748. #endif
  749. #if defined(AO_HAVE_short_load) && defined(AO_HAVE_nop_read) \
  750. && !defined(AO_HAVE_short_load_read)
  751. AO_INLINE unsigned/**/short
  752. AO_short_load_read(const volatile unsigned/**/short *addr)
  753. {
  754. unsigned/**/short result = AO_short_load(addr);
  755. AO_nop_read();
  756. return result;
  757. }
  758. # define AO_HAVE_short_load_read
  759. #endif
  760. #if defined(AO_HAVE_short_load_acquire) && defined(AO_HAVE_nop_full) \
  761. && !defined(AO_HAVE_short_load_full)
  762. # define AO_short_load_full(addr) (AO_nop_full(), AO_short_load_acquire(addr))
  763. # define AO_HAVE_short_load_full
  764. #endif
  765. #if defined(AO_HAVE_short_compare_and_swap_read) \
  766. && !defined(AO_HAVE_short_load_read)
  767. # define AO_short_CAS_BASED_LOAD_READ
  768. AO_INLINE unsigned/**/short
  769. AO_short_load_read(const volatile unsigned/**/short *addr)
  770. {
  771. unsigned/**/short result;
  772. do {
  773. result = *(const unsigned/**/short *)addr;
  774. } while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_read(
  775. (volatile unsigned/**/short *)addr,
  776. result, result)));
  777. return result;
  778. }
  779. # define AO_HAVE_short_load_read
  780. #endif
  781. #if !defined(AO_HAVE_short_load_acquire_read) \
  782. && defined(AO_HAVE_short_load_read)
  783. # define AO_short_load_acquire_read(addr) AO_short_load_read(addr)
  784. # define AO_HAVE_short_load_acquire_read
  785. #endif
  786. #if defined(AO_HAVE_short_load_acquire_read) && !defined(AO_HAVE_short_load) \
  787. && (!defined(AO_short_CAS_BASED_LOAD_READ) \
  788. || !defined(AO_HAVE_short_compare_and_swap))
  789. # define AO_short_load(addr) AO_short_load_acquire_read(addr)
  790. # define AO_HAVE_short_load
  791. #endif
  792. #if defined(AO_HAVE_short_compare_and_swap_full) \
  793. && !defined(AO_HAVE_short_load_full)
  794. AO_INLINE unsigned/**/short
  795. AO_short_load_full(const volatile unsigned/**/short *addr)
  796. {
  797. unsigned/**/short result;
  798. do {
  799. result = *(const unsigned/**/short *)addr;
  800. } while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_full(
  801. (volatile unsigned/**/short *)addr,
  802. result, result)));
  803. return result;
  804. }
  805. # define AO_HAVE_short_load_full
  806. #endif
  807. #if defined(AO_HAVE_short_compare_and_swap_acquire) \
  808. && !defined(AO_HAVE_short_load_acquire)
  809. AO_INLINE unsigned/**/short
  810. AO_short_load_acquire(const volatile unsigned/**/short *addr)
  811. {
  812. unsigned/**/short result;
  813. do {
  814. result = *(const unsigned/**/short *)addr;
  815. } while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_acquire(
  816. (volatile unsigned/**/short *)addr,
  817. result, result)));
  818. return result;
  819. }
  820. # define AO_HAVE_short_load_acquire
  821. #endif
  822. #if defined(AO_HAVE_short_compare_and_swap) && !defined(AO_HAVE_short_load)
  823. AO_INLINE unsigned/**/short
  824. AO_short_load(const volatile unsigned/**/short *addr)
  825. {
  826. unsigned/**/short result;
  827. do {
  828. result = *(const unsigned/**/short *)addr;
  829. } while (AO_EXPECT_FALSE(!AO_short_compare_and_swap(
  830. (volatile unsigned/**/short *)addr,
  831. result, result)));
  832. return result;
  833. }
  834. # define AO_HAVE_short_load
  835. #endif
  836. #ifdef AO_NO_DD_ORDERING
  837. # if defined(AO_HAVE_short_load_acquire_read)
  838. # define AO_short_load_dd_acquire_read(addr) \
  839. AO_short_load_acquire_read(addr)
  840. # define AO_HAVE_short_load_dd_acquire_read
  841. # endif
  842. #else
  843. # if defined(AO_HAVE_short_load)
  844. # define AO_short_load_dd_acquire_read(addr) AO_short_load(addr)
  845. # define AO_HAVE_short_load_dd_acquire_read
  846. # endif
  847. #endif /* !AO_NO_DD_ORDERING */
  848. /* short_store */
  849. #if defined(AO_HAVE_short_store_full) && !defined(AO_HAVE_short_store_release)
  850. # define AO_short_store_release(addr, val) AO_short_store_full(addr, val)
  851. # define AO_HAVE_short_store_release
  852. #endif
  853. #if defined(AO_HAVE_short_store_release) && !defined(AO_HAVE_short_store)
  854. # define AO_short_store(addr, val) AO_short_store_release(addr, val)
  855. # define AO_HAVE_short_store
  856. #endif
  857. #if defined(AO_HAVE_short_store_full) && !defined(AO_HAVE_short_store_write)
  858. # define AO_short_store_write(addr, val) AO_short_store_full(addr, val)
  859. # define AO_HAVE_short_store_write
  860. #endif
  861. #if defined(AO_HAVE_short_store_release) \
  862. && !defined(AO_HAVE_short_store_release_write)
  863. # define AO_short_store_release_write(addr, val) \
  864. AO_short_store_release(addr, val)
  865. # define AO_HAVE_short_store_release_write
  866. #endif
  867. #if defined(AO_HAVE_short_store_write) && !defined(AO_HAVE_short_store)
  868. # define AO_short_store(addr, val) AO_short_store_write(addr, val)
  869. # define AO_HAVE_short_store
  870. #endif
  871. #if defined(AO_HAVE_short_store) && defined(AO_HAVE_nop_full) \
  872. && !defined(AO_HAVE_short_store_release)
  873. # define AO_short_store_release(addr, val) \
  874. (AO_nop_full(), AO_short_store(addr, val))
  875. # define AO_HAVE_short_store_release
  876. #endif
  877. #if defined(AO_HAVE_short_store) && defined(AO_HAVE_nop_write) \
  878. && !defined(AO_HAVE_short_store_write)
  879. # define AO_short_store_write(addr, val) \
  880. (AO_nop_write(), AO_short_store(addr, val))
  881. # define AO_HAVE_short_store_write
  882. #endif
  883. #if defined(AO_HAVE_short_compare_and_swap_write) \
  884. && !defined(AO_HAVE_short_store_write)
  885. AO_INLINE void
  886. AO_short_store_write(volatile unsigned/**/short *addr, unsigned/**/short new_val)
  887. {
  888. unsigned/**/short old_val;
  889. do {
  890. old_val = *(unsigned/**/short *)addr;
  891. } while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_write(addr, old_val,
  892. new_val)));
  893. }
  894. # define AO_HAVE_short_store_write
  895. #endif
  896. #if defined(AO_HAVE_short_store_write) \
  897. && !defined(AO_HAVE_short_store_release_write)
  898. # define AO_short_store_release_write(addr, val) \
  899. AO_short_store_write(addr, val)
  900. # define AO_HAVE_short_store_release_write
  901. #endif
  902. #if defined(AO_HAVE_short_store_release) && defined(AO_HAVE_nop_full) \
  903. && !defined(AO_HAVE_short_store_full)
  904. # define AO_short_store_full(addr, val) \
  905. (AO_short_store_release(addr, val), \
  906. AO_nop_full())
  907. # define AO_HAVE_short_store_full
  908. #endif
  909. #if defined(AO_HAVE_short_compare_and_swap) && !defined(AO_HAVE_short_store)
  910. AO_INLINE void
  911. AO_short_store(volatile unsigned/**/short *addr, unsigned/**/short new_val)
  912. {
  913. unsigned/**/short old_val;
  914. do {
  915. old_val = *(unsigned/**/short *)addr;
  916. } while (AO_EXPECT_FALSE(!AO_short_compare_and_swap(addr,
  917. old_val, new_val)));
  918. }
  919. # define AO_HAVE_short_store
  920. #endif
  921. #if defined(AO_HAVE_short_compare_and_swap_release) \
  922. && !defined(AO_HAVE_short_store_release)
  923. AO_INLINE void
  924. AO_short_store_release(volatile unsigned/**/short *addr, unsigned/**/short new_val)
  925. {
  926. unsigned/**/short old_val;
  927. do {
  928. old_val = *(unsigned/**/short *)addr;
  929. } while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_release(addr, old_val,
  930. new_val)));
  931. }
  932. # define AO_HAVE_short_store_release
  933. #endif
  934. #if defined(AO_HAVE_short_compare_and_swap_full) \
  935. && !defined(AO_HAVE_short_store_full)
  936. AO_INLINE void
  937. AO_short_store_full(volatile unsigned/**/short *addr, unsigned/**/short new_val)
  938. {
  939. unsigned/**/short old_val;
  940. do {
  941. old_val = *(unsigned/**/short *)addr;
  942. } while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_full(addr, old_val,
  943. new_val)));
  944. }
  945. # define AO_HAVE_short_store_full
  946. #endif
  947. /*
  948. * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
  949. *
  950. * Permission is hereby granted, free of charge, to any person obtaining a copy
  951. * of this software and associated documentation files (the "Software"), to deal
  952. * in the Software without restriction, including without limitation the rights
  953. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  954. * copies of the Software, and to permit persons to whom the Software is
  955. * furnished to do so, subject to the following conditions:
  956. *
  957. * The above copyright notice and this permission notice shall be included in
  958. * all copies or substantial portions of the Software.
  959. *
  960. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  961. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  962. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  963. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  964. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  965. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  966. * SOFTWARE.
  967. */
  968. /* int_fetch_compare_and_swap */
  969. #if defined(AO_HAVE_int_fetch_compare_and_swap) \
  970. && defined(AO_HAVE_nop_full) \
  971. && !defined(AO_HAVE_int_fetch_compare_and_swap_acquire)
  972. AO_INLINE unsigned
  973. AO_int_fetch_compare_and_swap_acquire(volatile unsigned *addr,
  974. unsigned old_val, unsigned new_val)
  975. {
  976. unsigned result = AO_int_fetch_compare_and_swap(addr, old_val, new_val);
  977. AO_nop_full();
  978. return result;
  979. }
  980. # define AO_HAVE_int_fetch_compare_and_swap_acquire
  981. #endif
  982. #if defined(AO_HAVE_int_fetch_compare_and_swap) \
  983. && defined(AO_HAVE_nop_full) \
  984. && !defined(AO_HAVE_int_fetch_compare_and_swap_release)
  985. # define AO_int_fetch_compare_and_swap_release(addr, old_val, new_val) \
  986. (AO_nop_full(), \
  987. AO_int_fetch_compare_and_swap(addr, old_val, new_val))
  988. # define AO_HAVE_int_fetch_compare_and_swap_release
  989. #endif
  990. #if defined(AO_HAVE_int_fetch_compare_and_swap_full)
  991. # if !defined(AO_HAVE_int_fetch_compare_and_swap_release)
  992. # define AO_int_fetch_compare_and_swap_release(addr, old_val, new_val) \
  993. AO_int_fetch_compare_and_swap_full(addr, old_val, new_val)
  994. # define AO_HAVE_int_fetch_compare_and_swap_release
  995. # endif
  996. # if !defined(AO_HAVE_int_fetch_compare_and_swap_acquire)
  997. # define AO_int_fetch_compare_and_swap_acquire(addr, old_val, new_val) \
  998. AO_int_fetch_compare_and_swap_full(addr, old_val, new_val)
  999. # define AO_HAVE_int_fetch_compare_and_swap_acquire
  1000. # endif
  1001. # if !defined(AO_HAVE_int_fetch_compare_and_swap_write)
  1002. # define AO_int_fetch_compare_and_swap_write(addr, old_val, new_val) \
  1003. AO_int_fetch_compare_and_swap_full(addr, old_val, new_val)
  1004. # define AO_HAVE_int_fetch_compare_and_swap_write
  1005. # endif
  1006. # if !defined(AO_HAVE_int_fetch_compare_and_swap_read)
  1007. # define AO_int_fetch_compare_and_swap_read(addr, old_val, new_val) \
  1008. AO_int_fetch_compare_and_swap_full(addr, old_val, new_val)
  1009. # define AO_HAVE_int_fetch_compare_and_swap_read
  1010. # endif
  1011. #endif /* AO_HAVE_int_fetch_compare_and_swap_full */
  1012. #if !defined(AO_HAVE_int_fetch_compare_and_swap) \
  1013. && defined(AO_HAVE_int_fetch_compare_and_swap_release)
  1014. # define AO_int_fetch_compare_and_swap(addr, old_val, new_val) \
  1015. AO_int_fetch_compare_and_swap_release(addr, old_val, new_val)
  1016. # define AO_HAVE_int_fetch_compare_and_swap
  1017. #endif
  1018. #if !defined(AO_HAVE_int_fetch_compare_and_swap) \
  1019. && defined(AO_HAVE_int_fetch_compare_and_swap_acquire)
  1020. # define AO_int_fetch_compare_and_swap(addr, old_val, new_val) \
  1021. AO_int_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  1022. # define AO_HAVE_int_fetch_compare_and_swap
  1023. #endif
  1024. #if !defined(AO_HAVE_int_fetch_compare_and_swap) \
  1025. && defined(AO_HAVE_int_fetch_compare_and_swap_write)
  1026. # define AO_int_fetch_compare_and_swap(addr, old_val, new_val) \
  1027. AO_int_fetch_compare_and_swap_write(addr, old_val, new_val)
  1028. # define AO_HAVE_int_fetch_compare_and_swap
  1029. #endif
  1030. #if !defined(AO_HAVE_int_fetch_compare_and_swap) \
  1031. && defined(AO_HAVE_int_fetch_compare_and_swap_read)
  1032. # define AO_int_fetch_compare_and_swap(addr, old_val, new_val) \
  1033. AO_int_fetch_compare_and_swap_read(addr, old_val, new_val)
  1034. # define AO_HAVE_int_fetch_compare_and_swap
  1035. #endif
  1036. #if defined(AO_HAVE_int_fetch_compare_and_swap_acquire) \
  1037. && defined(AO_HAVE_nop_full) \
  1038. && !defined(AO_HAVE_int_fetch_compare_and_swap_full)
  1039. # define AO_int_fetch_compare_and_swap_full(addr, old_val, new_val) \
  1040. (AO_nop_full(), \
  1041. AO_int_fetch_compare_and_swap_acquire(addr, old_val, new_val))
  1042. # define AO_HAVE_int_fetch_compare_and_swap_full
  1043. #endif
  1044. #if !defined(AO_HAVE_int_fetch_compare_and_swap_release_write) \
  1045. && defined(AO_HAVE_int_fetch_compare_and_swap_write)
  1046. # define AO_int_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
  1047. AO_int_fetch_compare_and_swap_write(addr, old_val, new_val)
  1048. # define AO_HAVE_int_fetch_compare_and_swap_release_write
  1049. #endif
  1050. #if !defined(AO_HAVE_int_fetch_compare_and_swap_release_write) \
  1051. && defined(AO_HAVE_int_fetch_compare_and_swap_release)
  1052. # define AO_int_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
  1053. AO_int_fetch_compare_and_swap_release(addr, old_val, new_val)
  1054. # define AO_HAVE_int_fetch_compare_and_swap_release_write
  1055. #endif
  1056. #if !defined(AO_HAVE_int_fetch_compare_and_swap_acquire_read) \
  1057. && defined(AO_HAVE_int_fetch_compare_and_swap_read)
  1058. # define AO_int_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
  1059. AO_int_fetch_compare_and_swap_read(addr, old_val, new_val)
  1060. # define AO_HAVE_int_fetch_compare_and_swap_acquire_read
  1061. #endif
  1062. #if !defined(AO_HAVE_int_fetch_compare_and_swap_acquire_read) \
  1063. && defined(AO_HAVE_int_fetch_compare_and_swap_acquire)
  1064. # define AO_int_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
  1065. AO_int_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  1066. # define AO_HAVE_int_fetch_compare_and_swap_acquire_read
  1067. #endif
  1068. #ifdef AO_NO_DD_ORDERING
  1069. # if defined(AO_HAVE_int_fetch_compare_and_swap_acquire_read)
  1070. # define AO_int_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
  1071. AO_int_fetch_compare_and_swap_acquire_read(addr, old_val, new_val)
  1072. # define AO_HAVE_int_fetch_compare_and_swap_dd_acquire_read
  1073. # endif
  1074. #else
  1075. # if defined(AO_HAVE_int_fetch_compare_and_swap)
  1076. # define AO_int_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
  1077. AO_int_fetch_compare_and_swap(addr, old_val, new_val)
  1078. # define AO_HAVE_int_fetch_compare_and_swap_dd_acquire_read
  1079. # endif
  1080. #endif /* !AO_NO_DD_ORDERING */
  1081. /* int_compare_and_swap */
  1082. #if defined(AO_HAVE_int_compare_and_swap) && defined(AO_HAVE_nop_full) \
  1083. && !defined(AO_HAVE_int_compare_and_swap_acquire)
  1084. AO_INLINE int
  1085. AO_int_compare_and_swap_acquire(volatile unsigned *addr, unsigned old,
  1086. unsigned new_val)
  1087. {
  1088. int result = AO_int_compare_and_swap(addr, old, new_val);
  1089. AO_nop_full();
  1090. return result;
  1091. }
  1092. # define AO_HAVE_int_compare_and_swap_acquire
  1093. #endif
  1094. #if defined(AO_HAVE_int_compare_and_swap) && defined(AO_HAVE_nop_full) \
  1095. && !defined(AO_HAVE_int_compare_and_swap_release)
  1096. # define AO_int_compare_and_swap_release(addr, old, new_val) \
  1097. (AO_nop_full(), AO_int_compare_and_swap(addr, old, new_val))
  1098. # define AO_HAVE_int_compare_and_swap_release
  1099. #endif
  1100. #if defined(AO_HAVE_int_compare_and_swap_full)
  1101. # if !defined(AO_HAVE_int_compare_and_swap_release)
  1102. # define AO_int_compare_and_swap_release(addr, old, new_val) \
  1103. AO_int_compare_and_swap_full(addr, old, new_val)
  1104. # define AO_HAVE_int_compare_and_swap_release
  1105. # endif
  1106. # if !defined(AO_HAVE_int_compare_and_swap_acquire)
  1107. # define AO_int_compare_and_swap_acquire(addr, old, new_val) \
  1108. AO_int_compare_and_swap_full(addr, old, new_val)
  1109. # define AO_HAVE_int_compare_and_swap_acquire
  1110. # endif
  1111. # if !defined(AO_HAVE_int_compare_and_swap_write)
  1112. # define AO_int_compare_and_swap_write(addr, old, new_val) \
  1113. AO_int_compare_and_swap_full(addr, old, new_val)
  1114. # define AO_HAVE_int_compare_and_swap_write
  1115. # endif
  1116. # if !defined(AO_HAVE_int_compare_and_swap_read)
  1117. # define AO_int_compare_and_swap_read(addr, old, new_val) \
  1118. AO_int_compare_and_swap_full(addr, old, new_val)
  1119. # define AO_HAVE_int_compare_and_swap_read
  1120. # endif
  1121. #endif /* AO_HAVE_int_compare_and_swap_full */
  1122. #if !defined(AO_HAVE_int_compare_and_swap) \
  1123. && defined(AO_HAVE_int_compare_and_swap_release)
  1124. # define AO_int_compare_and_swap(addr, old, new_val) \
  1125. AO_int_compare_and_swap_release(addr, old, new_val)
  1126. # define AO_HAVE_int_compare_and_swap
  1127. #endif
  1128. #if !defined(AO_HAVE_int_compare_and_swap) \
  1129. && defined(AO_HAVE_int_compare_and_swap_acquire)
  1130. # define AO_int_compare_and_swap(addr, old, new_val) \
  1131. AO_int_compare_and_swap_acquire(addr, old, new_val)
  1132. # define AO_HAVE_int_compare_and_swap
  1133. #endif
  1134. #if !defined(AO_HAVE_int_compare_and_swap) \
  1135. && defined(AO_HAVE_int_compare_and_swap_write)
  1136. # define AO_int_compare_and_swap(addr, old, new_val) \
  1137. AO_int_compare_and_swap_write(addr, old, new_val)
  1138. # define AO_HAVE_int_compare_and_swap
  1139. #endif
  1140. #if !defined(AO_HAVE_int_compare_and_swap) \
  1141. && defined(AO_HAVE_int_compare_and_swap_read)
  1142. # define AO_int_compare_and_swap(addr, old, new_val) \
  1143. AO_int_compare_and_swap_read(addr, old, new_val)
  1144. # define AO_HAVE_int_compare_and_swap
  1145. #endif
  1146. #if defined(AO_HAVE_int_compare_and_swap_acquire) \
  1147. && defined(AO_HAVE_nop_full) \
  1148. && !defined(AO_HAVE_int_compare_and_swap_full)
  1149. # define AO_int_compare_and_swap_full(addr, old, new_val) \
  1150. (AO_nop_full(), \
  1151. AO_int_compare_and_swap_acquire(addr, old, new_val))
  1152. # define AO_HAVE_int_compare_and_swap_full
  1153. #endif
  1154. #if !defined(AO_HAVE_int_compare_and_swap_release_write) \
  1155. && defined(AO_HAVE_int_compare_and_swap_write)
  1156. # define AO_int_compare_and_swap_release_write(addr, old, new_val) \
  1157. AO_int_compare_and_swap_write(addr, old, new_val)
  1158. # define AO_HAVE_int_compare_and_swap_release_write
  1159. #endif
  1160. #if !defined(AO_HAVE_int_compare_and_swap_release_write) \
  1161. && defined(AO_HAVE_int_compare_and_swap_release)
  1162. # define AO_int_compare_and_swap_release_write(addr, old, new_val) \
  1163. AO_int_compare_and_swap_release(addr, old, new_val)
  1164. # define AO_HAVE_int_compare_and_swap_release_write
  1165. #endif
  1166. #if !defined(AO_HAVE_int_compare_and_swap_acquire_read) \
  1167. && defined(AO_HAVE_int_compare_and_swap_read)
  1168. # define AO_int_compare_and_swap_acquire_read(addr, old, new_val) \
  1169. AO_int_compare_and_swap_read(addr, old, new_val)
  1170. # define AO_HAVE_int_compare_and_swap_acquire_read
  1171. #endif
  1172. #if !defined(AO_HAVE_int_compare_and_swap_acquire_read) \
  1173. && defined(AO_HAVE_int_compare_and_swap_acquire)
  1174. # define AO_int_compare_and_swap_acquire_read(addr, old, new_val) \
  1175. AO_int_compare_and_swap_acquire(addr, old, new_val)
  1176. # define AO_HAVE_int_compare_and_swap_acquire_read
  1177. #endif
  1178. #ifdef AO_NO_DD_ORDERING
  1179. # if defined(AO_HAVE_int_compare_and_swap_acquire_read)
  1180. # define AO_int_compare_and_swap_dd_acquire_read(addr, old, new_val) \
  1181. AO_int_compare_and_swap_acquire_read(addr, old, new_val)
  1182. # define AO_HAVE_int_compare_and_swap_dd_acquire_read
  1183. # endif
  1184. #else
  1185. # if defined(AO_HAVE_int_compare_and_swap)
  1186. # define AO_int_compare_and_swap_dd_acquire_read(addr, old, new_val) \
  1187. AO_int_compare_and_swap(addr, old, new_val)
  1188. # define AO_HAVE_int_compare_and_swap_dd_acquire_read
  1189. # endif
  1190. #endif /* !AO_NO_DD_ORDERING */
  1191. /* int_load */
  1192. #if defined(AO_HAVE_int_load_full) && !defined(AO_HAVE_int_load_acquire)
  1193. # define AO_int_load_acquire(addr) AO_int_load_full(addr)
  1194. # define AO_HAVE_int_load_acquire
  1195. #endif
  1196. #if defined(AO_HAVE_int_load_acquire) && !defined(AO_HAVE_int_load)
  1197. # define AO_int_load(addr) AO_int_load_acquire(addr)
  1198. # define AO_HAVE_int_load
  1199. #endif
  1200. #if defined(AO_HAVE_int_load_full) && !defined(AO_HAVE_int_load_read)
  1201. # define AO_int_load_read(addr) AO_int_load_full(addr)
  1202. # define AO_HAVE_int_load_read
  1203. #endif
  1204. #if !defined(AO_HAVE_int_load_acquire_read) \
  1205. && defined(AO_HAVE_int_load_acquire)
  1206. # define AO_int_load_acquire_read(addr) AO_int_load_acquire(addr)
  1207. # define AO_HAVE_int_load_acquire_read
  1208. #endif
  1209. #if defined(AO_HAVE_int_load) && defined(AO_HAVE_nop_full) \
  1210. && !defined(AO_HAVE_int_load_acquire)
  1211. AO_INLINE unsigned
  1212. AO_int_load_acquire(const volatile unsigned *addr)
  1213. {
  1214. unsigned result = AO_int_load(addr);
  1215. /* Acquire barrier would be useless, since the load could be delayed */
  1216. /* beyond it. */
  1217. AO_nop_full();
  1218. return result;
  1219. }
  1220. # define AO_HAVE_int_load_acquire
  1221. #endif
  1222. #if defined(AO_HAVE_int_load) && defined(AO_HAVE_nop_read) \
  1223. && !defined(AO_HAVE_int_load_read)
  1224. AO_INLINE unsigned
  1225. AO_int_load_read(const volatile unsigned *addr)
  1226. {
  1227. unsigned result = AO_int_load(addr);
  1228. AO_nop_read();
  1229. return result;
  1230. }
  1231. # define AO_HAVE_int_load_read
  1232. #endif
  1233. #if defined(AO_HAVE_int_load_acquire) && defined(AO_HAVE_nop_full) \
  1234. && !defined(AO_HAVE_int_load_full)
  1235. # define AO_int_load_full(addr) (AO_nop_full(), AO_int_load_acquire(addr))
  1236. # define AO_HAVE_int_load_full
  1237. #endif
  1238. #if defined(AO_HAVE_int_compare_and_swap_read) \
  1239. && !defined(AO_HAVE_int_load_read)
  1240. # define AO_int_CAS_BASED_LOAD_READ
  1241. AO_INLINE unsigned
  1242. AO_int_load_read(const volatile unsigned *addr)
  1243. {
  1244. unsigned result;
  1245. do {
  1246. result = *(const unsigned *)addr;
  1247. } while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_read(
  1248. (volatile unsigned *)addr,
  1249. result, result)));
  1250. return result;
  1251. }
  1252. # define AO_HAVE_int_load_read
  1253. #endif
  1254. #if !defined(AO_HAVE_int_load_acquire_read) \
  1255. && defined(AO_HAVE_int_load_read)
  1256. # define AO_int_load_acquire_read(addr) AO_int_load_read(addr)
  1257. # define AO_HAVE_int_load_acquire_read
  1258. #endif
  1259. #if defined(AO_HAVE_int_load_acquire_read) && !defined(AO_HAVE_int_load) \
  1260. && (!defined(AO_int_CAS_BASED_LOAD_READ) \
  1261. || !defined(AO_HAVE_int_compare_and_swap))
  1262. # define AO_int_load(addr) AO_int_load_acquire_read(addr)
  1263. # define AO_HAVE_int_load
  1264. #endif
  1265. #if defined(AO_HAVE_int_compare_and_swap_full) \
  1266. && !defined(AO_HAVE_int_load_full)
  1267. AO_INLINE unsigned
  1268. AO_int_load_full(const volatile unsigned *addr)
  1269. {
  1270. unsigned result;
  1271. do {
  1272. result = *(const unsigned *)addr;
  1273. } while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_full(
  1274. (volatile unsigned *)addr,
  1275. result, result)));
  1276. return result;
  1277. }
  1278. # define AO_HAVE_int_load_full
  1279. #endif
  1280. #if defined(AO_HAVE_int_compare_and_swap_acquire) \
  1281. && !defined(AO_HAVE_int_load_acquire)
  1282. AO_INLINE unsigned
  1283. AO_int_load_acquire(const volatile unsigned *addr)
  1284. {
  1285. unsigned result;
  1286. do {
  1287. result = *(const unsigned *)addr;
  1288. } while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_acquire(
  1289. (volatile unsigned *)addr,
  1290. result, result)));
  1291. return result;
  1292. }
  1293. # define AO_HAVE_int_load_acquire
  1294. #endif
  1295. #if defined(AO_HAVE_int_compare_and_swap) && !defined(AO_HAVE_int_load)
  1296. AO_INLINE unsigned
  1297. AO_int_load(const volatile unsigned *addr)
  1298. {
  1299. unsigned result;
  1300. do {
  1301. result = *(const unsigned *)addr;
  1302. } while (AO_EXPECT_FALSE(!AO_int_compare_and_swap(
  1303. (volatile unsigned *)addr,
  1304. result, result)));
  1305. return result;
  1306. }
  1307. # define AO_HAVE_int_load
  1308. #endif
  1309. #ifdef AO_NO_DD_ORDERING
  1310. # if defined(AO_HAVE_int_load_acquire_read)
  1311. # define AO_int_load_dd_acquire_read(addr) \
  1312. AO_int_load_acquire_read(addr)
  1313. # define AO_HAVE_int_load_dd_acquire_read
  1314. # endif
  1315. #else
  1316. # if defined(AO_HAVE_int_load)
  1317. # define AO_int_load_dd_acquire_read(addr) AO_int_load(addr)
  1318. # define AO_HAVE_int_load_dd_acquire_read
  1319. # endif
  1320. #endif /* !AO_NO_DD_ORDERING */
  1321. /* int_store */
  1322. #if defined(AO_HAVE_int_store_full) && !defined(AO_HAVE_int_store_release)
  1323. # define AO_int_store_release(addr, val) AO_int_store_full(addr, val)
  1324. # define AO_HAVE_int_store_release
  1325. #endif
  1326. #if defined(AO_HAVE_int_store_release) && !defined(AO_HAVE_int_store)
  1327. # define AO_int_store(addr, val) AO_int_store_release(addr, val)
  1328. # define AO_HAVE_int_store
  1329. #endif
  1330. #if defined(AO_HAVE_int_store_full) && !defined(AO_HAVE_int_store_write)
  1331. # define AO_int_store_write(addr, val) AO_int_store_full(addr, val)
  1332. # define AO_HAVE_int_store_write
  1333. #endif
  1334. #if defined(AO_HAVE_int_store_release) \
  1335. && !defined(AO_HAVE_int_store_release_write)
  1336. # define AO_int_store_release_write(addr, val) \
  1337. AO_int_store_release(addr, val)
  1338. # define AO_HAVE_int_store_release_write
  1339. #endif
  1340. #if defined(AO_HAVE_int_store_write) && !defined(AO_HAVE_int_store)
  1341. # define AO_int_store(addr, val) AO_int_store_write(addr, val)
  1342. # define AO_HAVE_int_store
  1343. #endif
  1344. #if defined(AO_HAVE_int_store) && defined(AO_HAVE_nop_full) \
  1345. && !defined(AO_HAVE_int_store_release)
  1346. # define AO_int_store_release(addr, val) \
  1347. (AO_nop_full(), AO_int_store(addr, val))
  1348. # define AO_HAVE_int_store_release
  1349. #endif
  1350. #if defined(AO_HAVE_int_store) && defined(AO_HAVE_nop_write) \
  1351. && !defined(AO_HAVE_int_store_write)
  1352. # define AO_int_store_write(addr, val) \
  1353. (AO_nop_write(), AO_int_store(addr, val))
  1354. # define AO_HAVE_int_store_write
  1355. #endif
  1356. #if defined(AO_HAVE_int_compare_and_swap_write) \
  1357. && !defined(AO_HAVE_int_store_write)
  1358. AO_INLINE void
  1359. AO_int_store_write(volatile unsigned *addr, unsigned new_val)
  1360. {
  1361. unsigned old_val;
  1362. do {
  1363. old_val = *(unsigned *)addr;
  1364. } while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_write(addr, old_val,
  1365. new_val)));
  1366. }
  1367. # define AO_HAVE_int_store_write
  1368. #endif
  1369. #if defined(AO_HAVE_int_store_write) \
  1370. && !defined(AO_HAVE_int_store_release_write)
  1371. # define AO_int_store_release_write(addr, val) \
  1372. AO_int_store_write(addr, val)
  1373. # define AO_HAVE_int_store_release_write
  1374. #endif
  1375. #if defined(AO_HAVE_int_store_release) && defined(AO_HAVE_nop_full) \
  1376. && !defined(AO_HAVE_int_store_full)
  1377. # define AO_int_store_full(addr, val) \
  1378. (AO_int_store_release(addr, val), \
  1379. AO_nop_full())
  1380. # define AO_HAVE_int_store_full
  1381. #endif
  1382. #if defined(AO_HAVE_int_compare_and_swap) && !defined(AO_HAVE_int_store)
  1383. AO_INLINE void
  1384. AO_int_store(volatile unsigned *addr, unsigned new_val)
  1385. {
  1386. unsigned old_val;
  1387. do {
  1388. old_val = *(unsigned *)addr;
  1389. } while (AO_EXPECT_FALSE(!AO_int_compare_and_swap(addr,
  1390. old_val, new_val)));
  1391. }
  1392. # define AO_HAVE_int_store
  1393. #endif
  1394. #if defined(AO_HAVE_int_compare_and_swap_release) \
  1395. && !defined(AO_HAVE_int_store_release)
  1396. AO_INLINE void
  1397. AO_int_store_release(volatile unsigned *addr, unsigned new_val)
  1398. {
  1399. unsigned old_val;
  1400. do {
  1401. old_val = *(unsigned *)addr;
  1402. } while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_release(addr, old_val,
  1403. new_val)));
  1404. }
  1405. # define AO_HAVE_int_store_release
  1406. #endif
  1407. #if defined(AO_HAVE_int_compare_and_swap_full) \
  1408. && !defined(AO_HAVE_int_store_full)
  1409. AO_INLINE void
  1410. AO_int_store_full(volatile unsigned *addr, unsigned new_val)
  1411. {
  1412. unsigned old_val;
  1413. do {
  1414. old_val = *(unsigned *)addr;
  1415. } while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_full(addr, old_val,
  1416. new_val)));
  1417. }
  1418. # define AO_HAVE_int_store_full
  1419. #endif
  1420. /*
  1421. * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
  1422. *
  1423. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1424. * of this software and associated documentation files (the "Software"), to deal
  1425. * in the Software without restriction, including without limitation the rights
  1426. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1427. * copies of the Software, and to permit persons to whom the Software is
  1428. * furnished to do so, subject to the following conditions:
  1429. *
  1430. * The above copyright notice and this permission notice shall be included in
  1431. * all copies or substantial portions of the Software.
  1432. *
  1433. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1434. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1435. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1436. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1437. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1438. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1439. * SOFTWARE.
  1440. */
  1441. /* fetch_compare_and_swap */
  1442. #if defined(AO_HAVE_fetch_compare_and_swap) \
  1443. && defined(AO_HAVE_nop_full) \
  1444. && !defined(AO_HAVE_fetch_compare_and_swap_acquire)
  1445. AO_INLINE AO_t
  1446. AO_fetch_compare_and_swap_acquire(volatile AO_t *addr,
  1447. AO_t old_val, AO_t new_val)
  1448. {
  1449. AO_t result = AO_fetch_compare_and_swap(addr, old_val, new_val);
  1450. AO_nop_full();
  1451. return result;
  1452. }
  1453. # define AO_HAVE_fetch_compare_and_swap_acquire
  1454. #endif
  1455. #if defined(AO_HAVE_fetch_compare_and_swap) \
  1456. && defined(AO_HAVE_nop_full) \
  1457. && !defined(AO_HAVE_fetch_compare_and_swap_release)
  1458. # define AO_fetch_compare_and_swap_release(addr, old_val, new_val) \
  1459. (AO_nop_full(), \
  1460. AO_fetch_compare_and_swap(addr, old_val, new_val))
  1461. # define AO_HAVE_fetch_compare_and_swap_release
  1462. #endif
  1463. #if defined(AO_HAVE_fetch_compare_and_swap_full)
  1464. # if !defined(AO_HAVE_fetch_compare_and_swap_release)
  1465. # define AO_fetch_compare_and_swap_release(addr, old_val, new_val) \
  1466. AO_fetch_compare_and_swap_full(addr, old_val, new_val)
  1467. # define AO_HAVE_fetch_compare_and_swap_release
  1468. # endif
  1469. # if !defined(AO_HAVE_fetch_compare_and_swap_acquire)
  1470. # define AO_fetch_compare_and_swap_acquire(addr, old_val, new_val) \
  1471. AO_fetch_compare_and_swap_full(addr, old_val, new_val)
  1472. # define AO_HAVE_fetch_compare_and_swap_acquire
  1473. # endif
  1474. # if !defined(AO_HAVE_fetch_compare_and_swap_write)
  1475. # define AO_fetch_compare_and_swap_write(addr, old_val, new_val) \
  1476. AO_fetch_compare_and_swap_full(addr, old_val, new_val)
  1477. # define AO_HAVE_fetch_compare_and_swap_write
  1478. # endif
  1479. # if !defined(AO_HAVE_fetch_compare_and_swap_read)
  1480. # define AO_fetch_compare_and_swap_read(addr, old_val, new_val) \
  1481. AO_fetch_compare_and_swap_full(addr, old_val, new_val)
  1482. # define AO_HAVE_fetch_compare_and_swap_read
  1483. # endif
  1484. #endif /* AO_HAVE_fetch_compare_and_swap_full */
  1485. #if !defined(AO_HAVE_fetch_compare_and_swap) \
  1486. && defined(AO_HAVE_fetch_compare_and_swap_release)
  1487. # define AO_fetch_compare_and_swap(addr, old_val, new_val) \
  1488. AO_fetch_compare_and_swap_release(addr, old_val, new_val)
  1489. # define AO_HAVE_fetch_compare_and_swap
  1490. #endif
  1491. #if !defined(AO_HAVE_fetch_compare_and_swap) \
  1492. && defined(AO_HAVE_fetch_compare_and_swap_acquire)
  1493. # define AO_fetch_compare_and_swap(addr, old_val, new_val) \
  1494. AO_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  1495. # define AO_HAVE_fetch_compare_and_swap
  1496. #endif
  1497. #if !defined(AO_HAVE_fetch_compare_and_swap) \
  1498. && defined(AO_HAVE_fetch_compare_and_swap_write)
  1499. # define AO_fetch_compare_and_swap(addr, old_val, new_val) \
  1500. AO_fetch_compare_and_swap_write(addr, old_val, new_val)
  1501. # define AO_HAVE_fetch_compare_and_swap
  1502. #endif
  1503. #if !defined(AO_HAVE_fetch_compare_and_swap) \
  1504. && defined(AO_HAVE_fetch_compare_and_swap_read)
  1505. # define AO_fetch_compare_and_swap(addr, old_val, new_val) \
  1506. AO_fetch_compare_and_swap_read(addr, old_val, new_val)
  1507. # define AO_HAVE_fetch_compare_and_swap
  1508. #endif
  1509. #if defined(AO_HAVE_fetch_compare_and_swap_acquire) \
  1510. && defined(AO_HAVE_nop_full) \
  1511. && !defined(AO_HAVE_fetch_compare_and_swap_full)
  1512. # define AO_fetch_compare_and_swap_full(addr, old_val, new_val) \
  1513. (AO_nop_full(), \
  1514. AO_fetch_compare_and_swap_acquire(addr, old_val, new_val))
  1515. # define AO_HAVE_fetch_compare_and_swap_full
  1516. #endif
  1517. #if !defined(AO_HAVE_fetch_compare_and_swap_release_write) \
  1518. && defined(AO_HAVE_fetch_compare_and_swap_write)
  1519. # define AO_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
  1520. AO_fetch_compare_and_swap_write(addr, old_val, new_val)
  1521. # define AO_HAVE_fetch_compare_and_swap_release_write
  1522. #endif
  1523. #if !defined(AO_HAVE_fetch_compare_and_swap_release_write) \
  1524. && defined(AO_HAVE_fetch_compare_and_swap_release)
  1525. # define AO_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
  1526. AO_fetch_compare_and_swap_release(addr, old_val, new_val)
  1527. # define AO_HAVE_fetch_compare_and_swap_release_write
  1528. #endif
  1529. #if !defined(AO_HAVE_fetch_compare_and_swap_acquire_read) \
  1530. && defined(AO_HAVE_fetch_compare_and_swap_read)
  1531. # define AO_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
  1532. AO_fetch_compare_and_swap_read(addr, old_val, new_val)
  1533. # define AO_HAVE_fetch_compare_and_swap_acquire_read
  1534. #endif
  1535. #if !defined(AO_HAVE_fetch_compare_and_swap_acquire_read) \
  1536. && defined(AO_HAVE_fetch_compare_and_swap_acquire)
  1537. # define AO_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
  1538. AO_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  1539. # define AO_HAVE_fetch_compare_and_swap_acquire_read
  1540. #endif
  1541. #ifdef AO_NO_DD_ORDERING
  1542. # if defined(AO_HAVE_fetch_compare_and_swap_acquire_read)
  1543. # define AO_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
  1544. AO_fetch_compare_and_swap_acquire_read(addr, old_val, new_val)
  1545. # define AO_HAVE_fetch_compare_and_swap_dd_acquire_read
  1546. # endif
  1547. #else
  1548. # if defined(AO_HAVE_fetch_compare_and_swap)
  1549. # define AO_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
  1550. AO_fetch_compare_and_swap(addr, old_val, new_val)
  1551. # define AO_HAVE_fetch_compare_and_swap_dd_acquire_read
  1552. # endif
  1553. #endif /* !AO_NO_DD_ORDERING */
  1554. /* compare_and_swap */
  1555. #if defined(AO_HAVE_compare_and_swap) && defined(AO_HAVE_nop_full) \
  1556. && !defined(AO_HAVE_compare_and_swap_acquire)
  1557. AO_INLINE int
  1558. AO_compare_and_swap_acquire(volatile AO_t *addr, AO_t old,
  1559. AO_t new_val)
  1560. {
  1561. int result = AO_compare_and_swap(addr, old, new_val);
  1562. AO_nop_full();
  1563. return result;
  1564. }
  1565. # define AO_HAVE_compare_and_swap_acquire
  1566. #endif
  1567. #if defined(AO_HAVE_compare_and_swap) && defined(AO_HAVE_nop_full) \
  1568. && !defined(AO_HAVE_compare_and_swap_release)
  1569. # define AO_compare_and_swap_release(addr, old, new_val) \
  1570. (AO_nop_full(), AO_compare_and_swap(addr, old, new_val))
  1571. # define AO_HAVE_compare_and_swap_release
  1572. #endif
  1573. #if defined(AO_HAVE_compare_and_swap_full)
  1574. # if !defined(AO_HAVE_compare_and_swap_release)
  1575. # define AO_compare_and_swap_release(addr, old, new_val) \
  1576. AO_compare_and_swap_full(addr, old, new_val)
  1577. # define AO_HAVE_compare_and_swap_release
  1578. # endif
  1579. # if !defined(AO_HAVE_compare_and_swap_acquire)
  1580. # define AO_compare_and_swap_acquire(addr, old, new_val) \
  1581. AO_compare_and_swap_full(addr, old, new_val)
  1582. # define AO_HAVE_compare_and_swap_acquire
  1583. # endif
  1584. # if !defined(AO_HAVE_compare_and_swap_write)
  1585. # define AO_compare_and_swap_write(addr, old, new_val) \
  1586. AO_compare_and_swap_full(addr, old, new_val)
  1587. # define AO_HAVE_compare_and_swap_write
  1588. # endif
  1589. # if !defined(AO_HAVE_compare_and_swap_read)
  1590. # define AO_compare_and_swap_read(addr, old, new_val) \
  1591. AO_compare_and_swap_full(addr, old, new_val)
  1592. # define AO_HAVE_compare_and_swap_read
  1593. # endif
  1594. #endif /* AO_HAVE_compare_and_swap_full */
  1595. #if !defined(AO_HAVE_compare_and_swap) \
  1596. && defined(AO_HAVE_compare_and_swap_release)
  1597. # define AO_compare_and_swap(addr, old, new_val) \
  1598. AO_compare_and_swap_release(addr, old, new_val)
  1599. # define AO_HAVE_compare_and_swap
  1600. #endif
  1601. #if !defined(AO_HAVE_compare_and_swap) \
  1602. && defined(AO_HAVE_compare_and_swap_acquire)
  1603. # define AO_compare_and_swap(addr, old, new_val) \
  1604. AO_compare_and_swap_acquire(addr, old, new_val)
  1605. # define AO_HAVE_compare_and_swap
  1606. #endif
  1607. #if !defined(AO_HAVE_compare_and_swap) \
  1608. && defined(AO_HAVE_compare_and_swap_write)
  1609. # define AO_compare_and_swap(addr, old, new_val) \
  1610. AO_compare_and_swap_write(addr, old, new_val)
  1611. # define AO_HAVE_compare_and_swap
  1612. #endif
  1613. #if !defined(AO_HAVE_compare_and_swap) \
  1614. && defined(AO_HAVE_compare_and_swap_read)
  1615. # define AO_compare_and_swap(addr, old, new_val) \
  1616. AO_compare_and_swap_read(addr, old, new_val)
  1617. # define AO_HAVE_compare_and_swap
  1618. #endif
  1619. #if defined(AO_HAVE_compare_and_swap_acquire) \
  1620. && defined(AO_HAVE_nop_full) \
  1621. && !defined(AO_HAVE_compare_and_swap_full)
  1622. # define AO_compare_and_swap_full(addr, old, new_val) \
  1623. (AO_nop_full(), \
  1624. AO_compare_and_swap_acquire(addr, old, new_val))
  1625. # define AO_HAVE_compare_and_swap_full
  1626. #endif
  1627. #if !defined(AO_HAVE_compare_and_swap_release_write) \
  1628. && defined(AO_HAVE_compare_and_swap_write)
  1629. # define AO_compare_and_swap_release_write(addr, old, new_val) \
  1630. AO_compare_and_swap_write(addr, old, new_val)
  1631. # define AO_HAVE_compare_and_swap_release_write
  1632. #endif
  1633. #if !defined(AO_HAVE_compare_and_swap_release_write) \
  1634. && defined(AO_HAVE_compare_and_swap_release)
  1635. # define AO_compare_and_swap_release_write(addr, old, new_val) \
  1636. AO_compare_and_swap_release(addr, old, new_val)
  1637. # define AO_HAVE_compare_and_swap_release_write
  1638. #endif
  1639. #if !defined(AO_HAVE_compare_and_swap_acquire_read) \
  1640. && defined(AO_HAVE_compare_and_swap_read)
  1641. # define AO_compare_and_swap_acquire_read(addr, old, new_val) \
  1642. AO_compare_and_swap_read(addr, old, new_val)
  1643. # define AO_HAVE_compare_and_swap_acquire_read
  1644. #endif
  1645. #if !defined(AO_HAVE_compare_and_swap_acquire_read) \
  1646. && defined(AO_HAVE_compare_and_swap_acquire)
  1647. # define AO_compare_and_swap_acquire_read(addr, old, new_val) \
  1648. AO_compare_and_swap_acquire(addr, old, new_val)
  1649. # define AO_HAVE_compare_and_swap_acquire_read
  1650. #endif
  1651. #ifdef AO_NO_DD_ORDERING
  1652. # if defined(AO_HAVE_compare_and_swap_acquire_read)
  1653. # define AO_compare_and_swap_dd_acquire_read(addr, old, new_val) \
  1654. AO_compare_and_swap_acquire_read(addr, old, new_val)
  1655. # define AO_HAVE_compare_and_swap_dd_acquire_read
  1656. # endif
  1657. #else
  1658. # if defined(AO_HAVE_compare_and_swap)
  1659. # define AO_compare_and_swap_dd_acquire_read(addr, old, new_val) \
  1660. AO_compare_and_swap(addr, old, new_val)
  1661. # define AO_HAVE_compare_and_swap_dd_acquire_read
  1662. # endif
  1663. #endif /* !AO_NO_DD_ORDERING */
  1664. /* load */
  1665. #if defined(AO_HAVE_load_full) && !defined(AO_HAVE_load_acquire)
  1666. # define AO_load_acquire(addr) AO_load_full(addr)
  1667. # define AO_HAVE_load_acquire
  1668. #endif
  1669. #if defined(AO_HAVE_load_acquire) && !defined(AO_HAVE_load)
  1670. # define AO_load(addr) AO_load_acquire(addr)
  1671. # define AO_HAVE_load
  1672. #endif
  1673. #if defined(AO_HAVE_load_full) && !defined(AO_HAVE_load_read)
  1674. # define AO_load_read(addr) AO_load_full(addr)
  1675. # define AO_HAVE_load_read
  1676. #endif
  1677. #if !defined(AO_HAVE_load_acquire_read) \
  1678. && defined(AO_HAVE_load_acquire)
  1679. # define AO_load_acquire_read(addr) AO_load_acquire(addr)
  1680. # define AO_HAVE_load_acquire_read
  1681. #endif
  1682. #if defined(AO_HAVE_load) && defined(AO_HAVE_nop_full) \
  1683. && !defined(AO_HAVE_load_acquire)
  1684. AO_INLINE AO_t
  1685. AO_load_acquire(const volatile AO_t *addr)
  1686. {
  1687. AO_t result = AO_load(addr);
  1688. /* Acquire barrier would be useless, since the load could be delayed */
  1689. /* beyond it. */
  1690. AO_nop_full();
  1691. return result;
  1692. }
  1693. # define AO_HAVE_load_acquire
  1694. #endif
  1695. #if defined(AO_HAVE_load) && defined(AO_HAVE_nop_read) \
  1696. && !defined(AO_HAVE_load_read)
  1697. AO_INLINE AO_t
  1698. AO_load_read(const volatile AO_t *addr)
  1699. {
  1700. AO_t result = AO_load(addr);
  1701. AO_nop_read();
  1702. return result;
  1703. }
  1704. # define AO_HAVE_load_read
  1705. #endif
  1706. #if defined(AO_HAVE_load_acquire) && defined(AO_HAVE_nop_full) \
  1707. && !defined(AO_HAVE_load_full)
  1708. # define AO_load_full(addr) (AO_nop_full(), AO_load_acquire(addr))
  1709. # define AO_HAVE_load_full
  1710. #endif
  1711. #if defined(AO_HAVE_compare_and_swap_read) \
  1712. && !defined(AO_HAVE_load_read)
  1713. # define AO_CAS_BASED_LOAD_READ
  1714. AO_INLINE AO_t
  1715. AO_load_read(const volatile AO_t *addr)
  1716. {
  1717. AO_t result;
  1718. do {
  1719. result = *(const AO_t *)addr;
  1720. } while (AO_EXPECT_FALSE(!AO_compare_and_swap_read(
  1721. (volatile AO_t *)addr,
  1722. result, result)));
  1723. return result;
  1724. }
  1725. # define AO_HAVE_load_read
  1726. #endif
  1727. #if !defined(AO_HAVE_load_acquire_read) \
  1728. && defined(AO_HAVE_load_read)
  1729. # define AO_load_acquire_read(addr) AO_load_read(addr)
  1730. # define AO_HAVE_load_acquire_read
  1731. #endif
  1732. #if defined(AO_HAVE_load_acquire_read) && !defined(AO_HAVE_load) \
  1733. && (!defined(AO_CAS_BASED_LOAD_READ) \
  1734. || !defined(AO_HAVE_compare_and_swap))
  1735. # define AO_load(addr) AO_load_acquire_read(addr)
  1736. # define AO_HAVE_load
  1737. #endif
  1738. #if defined(AO_HAVE_compare_and_swap_full) \
  1739. && !defined(AO_HAVE_load_full)
  1740. AO_INLINE AO_t
  1741. AO_load_full(const volatile AO_t *addr)
  1742. {
  1743. AO_t result;
  1744. do {
  1745. result = *(const AO_t *)addr;
  1746. } while (AO_EXPECT_FALSE(!AO_compare_and_swap_full(
  1747. (volatile AO_t *)addr,
  1748. result, result)));
  1749. return result;
  1750. }
  1751. # define AO_HAVE_load_full
  1752. #endif
  1753. #if defined(AO_HAVE_compare_and_swap_acquire) \
  1754. && !defined(AO_HAVE_load_acquire)
  1755. AO_INLINE AO_t
  1756. AO_load_acquire(const volatile AO_t *addr)
  1757. {
  1758. AO_t result;
  1759. do {
  1760. result = *(const AO_t *)addr;
  1761. } while (AO_EXPECT_FALSE(!AO_compare_and_swap_acquire(
  1762. (volatile AO_t *)addr,
  1763. result, result)));
  1764. return result;
  1765. }
  1766. # define AO_HAVE_load_acquire
  1767. #endif
  1768. #if defined(AO_HAVE_compare_and_swap) && !defined(AO_HAVE_load)
  1769. AO_INLINE AO_t
  1770. AO_load(const volatile AO_t *addr)
  1771. {
  1772. AO_t result;
  1773. do {
  1774. result = *(const AO_t *)addr;
  1775. } while (AO_EXPECT_FALSE(!AO_compare_and_swap(
  1776. (volatile AO_t *)addr,
  1777. result, result)));
  1778. return result;
  1779. }
  1780. # define AO_HAVE_load
  1781. #endif
  1782. #ifdef AO_NO_DD_ORDERING
  1783. # if defined(AO_HAVE_load_acquire_read)
  1784. # define AO_load_dd_acquire_read(addr) \
  1785. AO_load_acquire_read(addr)
  1786. # define AO_HAVE_load_dd_acquire_read
  1787. # endif
  1788. #else
  1789. # if defined(AO_HAVE_load)
  1790. # define AO_load_dd_acquire_read(addr) AO_load(addr)
  1791. # define AO_HAVE_load_dd_acquire_read
  1792. # endif
  1793. #endif /* !AO_NO_DD_ORDERING */
  1794. /* store */
  1795. #if defined(AO_HAVE_store_full) && !defined(AO_HAVE_store_release)
  1796. # define AO_store_release(addr, val) AO_store_full(addr, val)
  1797. # define AO_HAVE_store_release
  1798. #endif
  1799. #if defined(AO_HAVE_store_release) && !defined(AO_HAVE_store)
  1800. # define AO_store(addr, val) AO_store_release(addr, val)
  1801. # define AO_HAVE_store
  1802. #endif
  1803. #if defined(AO_HAVE_store_full) && !defined(AO_HAVE_store_write)
  1804. # define AO_store_write(addr, val) AO_store_full(addr, val)
  1805. # define AO_HAVE_store_write
  1806. #endif
  1807. #if defined(AO_HAVE_store_release) \
  1808. && !defined(AO_HAVE_store_release_write)
  1809. # define AO_store_release_write(addr, val) \
  1810. AO_store_release(addr, val)
  1811. # define AO_HAVE_store_release_write
  1812. #endif
  1813. #if defined(AO_HAVE_store_write) && !defined(AO_HAVE_store)
  1814. # define AO_store(addr, val) AO_store_write(addr, val)
  1815. # define AO_HAVE_store
  1816. #endif
  1817. #if defined(AO_HAVE_store) && defined(AO_HAVE_nop_full) \
  1818. && !defined(AO_HAVE_store_release)
  1819. # define AO_store_release(addr, val) \
  1820. (AO_nop_full(), AO_store(addr, val))
  1821. # define AO_HAVE_store_release
  1822. #endif
  1823. #if defined(AO_HAVE_store) && defined(AO_HAVE_nop_write) \
  1824. && !defined(AO_HAVE_store_write)
  1825. # define AO_store_write(addr, val) \
  1826. (AO_nop_write(), AO_store(addr, val))
  1827. # define AO_HAVE_store_write
  1828. #endif
  1829. #if defined(AO_HAVE_compare_and_swap_write) \
  1830. && !defined(AO_HAVE_store_write)
  1831. AO_INLINE void
  1832. AO_store_write(volatile AO_t *addr, AO_t new_val)
  1833. {
  1834. AO_t old_val;
  1835. do {
  1836. old_val = *(AO_t *)addr;
  1837. } while (AO_EXPECT_FALSE(!AO_compare_and_swap_write(addr, old_val,
  1838. new_val)));
  1839. }
  1840. # define AO_HAVE_store_write
  1841. #endif
  1842. #if defined(AO_HAVE_store_write) \
  1843. && !defined(AO_HAVE_store_release_write)
  1844. # define AO_store_release_write(addr, val) \
  1845. AO_store_write(addr, val)
  1846. # define AO_HAVE_store_release_write
  1847. #endif
  1848. #if defined(AO_HAVE_store_release) && defined(AO_HAVE_nop_full) \
  1849. && !defined(AO_HAVE_store_full)
  1850. # define AO_store_full(addr, val) \
  1851. (AO_store_release(addr, val), \
  1852. AO_nop_full())
  1853. # define AO_HAVE_store_full
  1854. #endif
  1855. #if defined(AO_HAVE_compare_and_swap) && !defined(AO_HAVE_store)
  1856. AO_INLINE void
  1857. AO_store(volatile AO_t *addr, AO_t new_val)
  1858. {
  1859. AO_t old_val;
  1860. do {
  1861. old_val = *(AO_t *)addr;
  1862. } while (AO_EXPECT_FALSE(!AO_compare_and_swap(addr,
  1863. old_val, new_val)));
  1864. }
  1865. # define AO_HAVE_store
  1866. #endif
  1867. #if defined(AO_HAVE_compare_and_swap_release) \
  1868. && !defined(AO_HAVE_store_release)
  1869. AO_INLINE void
  1870. AO_store_release(volatile AO_t *addr, AO_t new_val)
  1871. {
  1872. AO_t old_val;
  1873. do {
  1874. old_val = *(AO_t *)addr;
  1875. } while (AO_EXPECT_FALSE(!AO_compare_and_swap_release(addr, old_val,
  1876. new_val)));
  1877. }
  1878. # define AO_HAVE_store_release
  1879. #endif
  1880. #if defined(AO_HAVE_compare_and_swap_full) \
  1881. && !defined(AO_HAVE_store_full)
  1882. AO_INLINE void
  1883. AO_store_full(volatile AO_t *addr, AO_t new_val)
  1884. {
  1885. AO_t old_val;
  1886. do {
  1887. old_val = *(AO_t *)addr;
  1888. } while (AO_EXPECT_FALSE(!AO_compare_and_swap_full(addr, old_val,
  1889. new_val)));
  1890. }
  1891. # define AO_HAVE_store_full
  1892. #endif
  1893. /*
  1894. * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
  1895. *
  1896. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1897. * of this software and associated documentation files (the "Software"), to deal
  1898. * in the Software without restriction, including without limitation the rights
  1899. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1900. * copies of the Software, and to permit persons to whom the Software is
  1901. * furnished to do so, subject to the following conditions:
  1902. *
  1903. * The above copyright notice and this permission notice shall be included in
  1904. * all copies or substantial portions of the Software.
  1905. *
  1906. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1907. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1908. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1909. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1910. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1911. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1912. * SOFTWARE.
  1913. */
  1914. /* double_fetch_compare_and_swap */
  1915. #if defined(AO_HAVE_double_fetch_compare_and_swap) \
  1916. && defined(AO_HAVE_nop_full) \
  1917. && !defined(AO_HAVE_double_fetch_compare_and_swap_acquire)
  1918. AO_INLINE AO_double_t
  1919. AO_double_fetch_compare_and_swap_acquire(volatile AO_double_t *addr,
  1920. AO_double_t old_val, AO_double_t new_val)
  1921. {
  1922. AO_double_t result = AO_double_fetch_compare_and_swap(addr, old_val, new_val);
  1923. AO_nop_full();
  1924. return result;
  1925. }
  1926. # define AO_HAVE_double_fetch_compare_and_swap_acquire
  1927. #endif
  1928. #if defined(AO_HAVE_double_fetch_compare_and_swap) \
  1929. && defined(AO_HAVE_nop_full) \
  1930. && !defined(AO_HAVE_double_fetch_compare_and_swap_release)
  1931. # define AO_double_fetch_compare_and_swap_release(addr, old_val, new_val) \
  1932. (AO_nop_full(), \
  1933. AO_double_fetch_compare_and_swap(addr, old_val, new_val))
  1934. # define AO_HAVE_double_fetch_compare_and_swap_release
  1935. #endif
  1936. #if defined(AO_HAVE_double_fetch_compare_and_swap_full)
  1937. # if !defined(AO_HAVE_double_fetch_compare_and_swap_release)
  1938. # define AO_double_fetch_compare_and_swap_release(addr, old_val, new_val) \
  1939. AO_double_fetch_compare_and_swap_full(addr, old_val, new_val)
  1940. # define AO_HAVE_double_fetch_compare_and_swap_release
  1941. # endif
  1942. # if !defined(AO_HAVE_double_fetch_compare_and_swap_acquire)
  1943. # define AO_double_fetch_compare_and_swap_acquire(addr, old_val, new_val) \
  1944. AO_double_fetch_compare_and_swap_full(addr, old_val, new_val)
  1945. # define AO_HAVE_double_fetch_compare_and_swap_acquire
  1946. # endif
  1947. # if !defined(AO_HAVE_double_fetch_compare_and_swap_write)
  1948. # define AO_double_fetch_compare_and_swap_write(addr, old_val, new_val) \
  1949. AO_double_fetch_compare_and_swap_full(addr, old_val, new_val)
  1950. # define AO_HAVE_double_fetch_compare_and_swap_write
  1951. # endif
  1952. # if !defined(AO_HAVE_double_fetch_compare_and_swap_read)
  1953. # define AO_double_fetch_compare_and_swap_read(addr, old_val, new_val) \
  1954. AO_double_fetch_compare_and_swap_full(addr, old_val, new_val)
  1955. # define AO_HAVE_double_fetch_compare_and_swap_read
  1956. # endif
  1957. #endif /* AO_HAVE_double_fetch_compare_and_swap_full */
  1958. #if !defined(AO_HAVE_double_fetch_compare_and_swap) \
  1959. && defined(AO_HAVE_double_fetch_compare_and_swap_release)
  1960. # define AO_double_fetch_compare_and_swap(addr, old_val, new_val) \
  1961. AO_double_fetch_compare_and_swap_release(addr, old_val, new_val)
  1962. # define AO_HAVE_double_fetch_compare_and_swap
  1963. #endif
  1964. #if !defined(AO_HAVE_double_fetch_compare_and_swap) \
  1965. && defined(AO_HAVE_double_fetch_compare_and_swap_acquire)
  1966. # define AO_double_fetch_compare_and_swap(addr, old_val, new_val) \
  1967. AO_double_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  1968. # define AO_HAVE_double_fetch_compare_and_swap
  1969. #endif
  1970. #if !defined(AO_HAVE_double_fetch_compare_and_swap) \
  1971. && defined(AO_HAVE_double_fetch_compare_and_swap_write)
  1972. # define AO_double_fetch_compare_and_swap(addr, old_val, new_val) \
  1973. AO_double_fetch_compare_and_swap_write(addr, old_val, new_val)
  1974. # define AO_HAVE_double_fetch_compare_and_swap
  1975. #endif
  1976. #if !defined(AO_HAVE_double_fetch_compare_and_swap) \
  1977. && defined(AO_HAVE_double_fetch_compare_and_swap_read)
  1978. # define AO_double_fetch_compare_and_swap(addr, old_val, new_val) \
  1979. AO_double_fetch_compare_and_swap_read(addr, old_val, new_val)
  1980. # define AO_HAVE_double_fetch_compare_and_swap
  1981. #endif
  1982. #if defined(AO_HAVE_double_fetch_compare_and_swap_acquire) \
  1983. && defined(AO_HAVE_nop_full) \
  1984. && !defined(AO_HAVE_double_fetch_compare_and_swap_full)
  1985. # define AO_double_fetch_compare_and_swap_full(addr, old_val, new_val) \
  1986. (AO_nop_full(), \
  1987. AO_double_fetch_compare_and_swap_acquire(addr, old_val, new_val))
  1988. # define AO_HAVE_double_fetch_compare_and_swap_full
  1989. #endif
  1990. #if !defined(AO_HAVE_double_fetch_compare_and_swap_release_write) \
  1991. && defined(AO_HAVE_double_fetch_compare_and_swap_write)
  1992. # define AO_double_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
  1993. AO_double_fetch_compare_and_swap_write(addr, old_val, new_val)
  1994. # define AO_HAVE_double_fetch_compare_and_swap_release_write
  1995. #endif
  1996. #if !defined(AO_HAVE_double_fetch_compare_and_swap_release_write) \
  1997. && defined(AO_HAVE_double_fetch_compare_and_swap_release)
  1998. # define AO_double_fetch_compare_and_swap_release_write(addr,old_val,new_val) \
  1999. AO_double_fetch_compare_and_swap_release(addr, old_val, new_val)
  2000. # define AO_HAVE_double_fetch_compare_and_swap_release_write
  2001. #endif
  2002. #if !defined(AO_HAVE_double_fetch_compare_and_swap_acquire_read) \
  2003. && defined(AO_HAVE_double_fetch_compare_and_swap_read)
  2004. # define AO_double_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
  2005. AO_double_fetch_compare_and_swap_read(addr, old_val, new_val)
  2006. # define AO_HAVE_double_fetch_compare_and_swap_acquire_read
  2007. #endif
  2008. #if !defined(AO_HAVE_double_fetch_compare_and_swap_acquire_read) \
  2009. && defined(AO_HAVE_double_fetch_compare_and_swap_acquire)
  2010. # define AO_double_fetch_compare_and_swap_acquire_read(addr,old_val,new_val) \
  2011. AO_double_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  2012. # define AO_HAVE_double_fetch_compare_and_swap_acquire_read
  2013. #endif
  2014. #ifdef AO_NO_DD_ORDERING
  2015. # if defined(AO_HAVE_double_fetch_compare_and_swap_acquire_read)
  2016. # define AO_double_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
  2017. AO_double_fetch_compare_and_swap_acquire_read(addr, old_val, new_val)
  2018. # define AO_HAVE_double_fetch_compare_and_swap_dd_acquire_read
  2019. # endif
  2020. #else
  2021. # if defined(AO_HAVE_double_fetch_compare_and_swap)
  2022. # define AO_double_fetch_compare_and_swap_dd_acquire_read(addr,old_val,new_val) \
  2023. AO_double_fetch_compare_and_swap(addr, old_val, new_val)
  2024. # define AO_HAVE_double_fetch_compare_and_swap_dd_acquire_read
  2025. # endif
  2026. #endif /* !AO_NO_DD_ORDERING */
  2027. /* double_compare_and_swap */
  2028. #if defined(AO_HAVE_double_compare_and_swap) && defined(AO_HAVE_nop_full) \
  2029. && !defined(AO_HAVE_double_compare_and_swap_acquire)
  2030. AO_INLINE int
  2031. AO_double_compare_and_swap_acquire(volatile AO_double_t *addr, AO_double_t old,
  2032. AO_double_t new_val)
  2033. {
  2034. int result = AO_double_compare_and_swap(addr, old, new_val);
  2035. AO_nop_full();
  2036. return result;
  2037. }
  2038. # define AO_HAVE_double_compare_and_swap_acquire
  2039. #endif
  2040. #if defined(AO_HAVE_double_compare_and_swap) && defined(AO_HAVE_nop_full) \
  2041. && !defined(AO_HAVE_double_compare_and_swap_release)
  2042. # define AO_double_compare_and_swap_release(addr, old, new_val) \
  2043. (AO_nop_full(), AO_double_compare_and_swap(addr, old, new_val))
  2044. # define AO_HAVE_double_compare_and_swap_release
  2045. #endif
  2046. #if defined(AO_HAVE_double_compare_and_swap_full)
  2047. # if !defined(AO_HAVE_double_compare_and_swap_release)
  2048. # define AO_double_compare_and_swap_release(addr, old, new_val) \
  2049. AO_double_compare_and_swap_full(addr, old, new_val)
  2050. # define AO_HAVE_double_compare_and_swap_release
  2051. # endif
  2052. # if !defined(AO_HAVE_double_compare_and_swap_acquire)
  2053. # define AO_double_compare_and_swap_acquire(addr, old, new_val) \
  2054. AO_double_compare_and_swap_full(addr, old, new_val)
  2055. # define AO_HAVE_double_compare_and_swap_acquire
  2056. # endif
  2057. # if !defined(AO_HAVE_double_compare_and_swap_write)
  2058. # define AO_double_compare_and_swap_write(addr, old, new_val) \
  2059. AO_double_compare_and_swap_full(addr, old, new_val)
  2060. # define AO_HAVE_double_compare_and_swap_write
  2061. # endif
  2062. # if !defined(AO_HAVE_double_compare_and_swap_read)
  2063. # define AO_double_compare_and_swap_read(addr, old, new_val) \
  2064. AO_double_compare_and_swap_full(addr, old, new_val)
  2065. # define AO_HAVE_double_compare_and_swap_read
  2066. # endif
  2067. #endif /* AO_HAVE_double_compare_and_swap_full */
  2068. #if !defined(AO_HAVE_double_compare_and_swap) \
  2069. && defined(AO_HAVE_double_compare_and_swap_release)
  2070. # define AO_double_compare_and_swap(addr, old, new_val) \
  2071. AO_double_compare_and_swap_release(addr, old, new_val)
  2072. # define AO_HAVE_double_compare_and_swap
  2073. #endif
  2074. #if !defined(AO_HAVE_double_compare_and_swap) \
  2075. && defined(AO_HAVE_double_compare_and_swap_acquire)
  2076. # define AO_double_compare_and_swap(addr, old, new_val) \
  2077. AO_double_compare_and_swap_acquire(addr, old, new_val)
  2078. # define AO_HAVE_double_compare_and_swap
  2079. #endif
  2080. #if !defined(AO_HAVE_double_compare_and_swap) \
  2081. && defined(AO_HAVE_double_compare_and_swap_write)
  2082. # define AO_double_compare_and_swap(addr, old, new_val) \
  2083. AO_double_compare_and_swap_write(addr, old, new_val)
  2084. # define AO_HAVE_double_compare_and_swap
  2085. #endif
  2086. #if !defined(AO_HAVE_double_compare_and_swap) \
  2087. && defined(AO_HAVE_double_compare_and_swap_read)
  2088. # define AO_double_compare_and_swap(addr, old, new_val) \
  2089. AO_double_compare_and_swap_read(addr, old, new_val)
  2090. # define AO_HAVE_double_compare_and_swap
  2091. #endif
  2092. #if defined(AO_HAVE_double_compare_and_swap_acquire) \
  2093. && defined(AO_HAVE_nop_full) \
  2094. && !defined(AO_HAVE_double_compare_and_swap_full)
  2095. # define AO_double_compare_and_swap_full(addr, old, new_val) \
  2096. (AO_nop_full(), \
  2097. AO_double_compare_and_swap_acquire(addr, old, new_val))
  2098. # define AO_HAVE_double_compare_and_swap_full
  2099. #endif
  2100. #if !defined(AO_HAVE_double_compare_and_swap_release_write) \
  2101. && defined(AO_HAVE_double_compare_and_swap_write)
  2102. # define AO_double_compare_and_swap_release_write(addr, old, new_val) \
  2103. AO_double_compare_and_swap_write(addr, old, new_val)
  2104. # define AO_HAVE_double_compare_and_swap_release_write
  2105. #endif
  2106. #if !defined(AO_HAVE_double_compare_and_swap_release_write) \
  2107. && defined(AO_HAVE_double_compare_and_swap_release)
  2108. # define AO_double_compare_and_swap_release_write(addr, old, new_val) \
  2109. AO_double_compare_and_swap_release(addr, old, new_val)
  2110. # define AO_HAVE_double_compare_and_swap_release_write
  2111. #endif
  2112. #if !defined(AO_HAVE_double_compare_and_swap_acquire_read) \
  2113. && defined(AO_HAVE_double_compare_and_swap_read)
  2114. # define AO_double_compare_and_swap_acquire_read(addr, old, new_val) \
  2115. AO_double_compare_and_swap_read(addr, old, new_val)
  2116. # define AO_HAVE_double_compare_and_swap_acquire_read
  2117. #endif
  2118. #if !defined(AO_HAVE_double_compare_and_swap_acquire_read) \
  2119. && defined(AO_HAVE_double_compare_and_swap_acquire)
  2120. # define AO_double_compare_and_swap_acquire_read(addr, old, new_val) \
  2121. AO_double_compare_and_swap_acquire(addr, old, new_val)
  2122. # define AO_HAVE_double_compare_and_swap_acquire_read
  2123. #endif
  2124. #ifdef AO_NO_DD_ORDERING
  2125. # if defined(AO_HAVE_double_compare_and_swap_acquire_read)
  2126. # define AO_double_compare_and_swap_dd_acquire_read(addr, old, new_val) \
  2127. AO_double_compare_and_swap_acquire_read(addr, old, new_val)
  2128. # define AO_HAVE_double_compare_and_swap_dd_acquire_read
  2129. # endif
  2130. #else
  2131. # if defined(AO_HAVE_double_compare_and_swap)
  2132. # define AO_double_compare_and_swap_dd_acquire_read(addr, old, new_val) \
  2133. AO_double_compare_and_swap(addr, old, new_val)
  2134. # define AO_HAVE_double_compare_and_swap_dd_acquire_read
  2135. # endif
  2136. #endif /* !AO_NO_DD_ORDERING */
  2137. /* double_load */
  2138. #if defined(AO_HAVE_double_load_full) && !defined(AO_HAVE_double_load_acquire)
  2139. # define AO_double_load_acquire(addr) AO_double_load_full(addr)
  2140. # define AO_HAVE_double_load_acquire
  2141. #endif
  2142. #if defined(AO_HAVE_double_load_acquire) && !defined(AO_HAVE_double_load)
  2143. # define AO_double_load(addr) AO_double_load_acquire(addr)
  2144. # define AO_HAVE_double_load
  2145. #endif
  2146. #if defined(AO_HAVE_double_load_full) && !defined(AO_HAVE_double_load_read)
  2147. # define AO_double_load_read(addr) AO_double_load_full(addr)
  2148. # define AO_HAVE_double_load_read
  2149. #endif
  2150. #if !defined(AO_HAVE_double_load_acquire_read) \
  2151. && defined(AO_HAVE_double_load_acquire)
  2152. # define AO_double_load_acquire_read(addr) AO_double_load_acquire(addr)
  2153. # define AO_HAVE_double_load_acquire_read
  2154. #endif
  2155. #if defined(AO_HAVE_double_load) && defined(AO_HAVE_nop_full) \
  2156. && !defined(AO_HAVE_double_load_acquire)
  2157. AO_INLINE AO_double_t
  2158. AO_double_load_acquire(const volatile AO_double_t *addr)
  2159. {
  2160. AO_double_t result = AO_double_load(addr);
  2161. /* Acquire barrier would be useless, since the load could be delayed */
  2162. /* beyond it. */
  2163. AO_nop_full();
  2164. return result;
  2165. }
  2166. # define AO_HAVE_double_load_acquire
  2167. #endif
  2168. #if defined(AO_HAVE_double_load) && defined(AO_HAVE_nop_read) \
  2169. && !defined(AO_HAVE_double_load_read)
  2170. AO_INLINE AO_double_t
  2171. AO_double_load_read(const volatile AO_double_t *addr)
  2172. {
  2173. AO_double_t result = AO_double_load(addr);
  2174. AO_nop_read();
  2175. return result;
  2176. }
  2177. # define AO_HAVE_double_load_read
  2178. #endif
  2179. #if defined(AO_HAVE_double_load_acquire) && defined(AO_HAVE_nop_full) \
  2180. && !defined(AO_HAVE_double_load_full)
  2181. # define AO_double_load_full(addr) (AO_nop_full(), AO_double_load_acquire(addr))
  2182. # define AO_HAVE_double_load_full
  2183. #endif
  2184. #if defined(AO_HAVE_double_compare_and_swap_read) \
  2185. && !defined(AO_HAVE_double_load_read)
  2186. # define AO_double_CAS_BASED_LOAD_READ
  2187. AO_INLINE AO_double_t
  2188. AO_double_load_read(const volatile AO_double_t *addr)
  2189. {
  2190. AO_double_t result;
  2191. do {
  2192. result = *(const AO_double_t *)addr;
  2193. } while (AO_EXPECT_FALSE(!AO_double_compare_and_swap_read(
  2194. (volatile AO_double_t *)addr,
  2195. result, result)));
  2196. return result;
  2197. }
  2198. # define AO_HAVE_double_load_read
  2199. #endif
  2200. #if !defined(AO_HAVE_double_load_acquire_read) \
  2201. && defined(AO_HAVE_double_load_read)
  2202. # define AO_double_load_acquire_read(addr) AO_double_load_read(addr)
  2203. # define AO_HAVE_double_load_acquire_read
  2204. #endif
  2205. #if defined(AO_HAVE_double_load_acquire_read) && !defined(AO_HAVE_double_load) \
  2206. && (!defined(AO_double_CAS_BASED_LOAD_READ) \
  2207. || !defined(AO_HAVE_double_compare_and_swap))
  2208. # define AO_double_load(addr) AO_double_load_acquire_read(addr)
  2209. # define AO_HAVE_double_load
  2210. #endif
  2211. #if defined(AO_HAVE_double_compare_and_swap_full) \
  2212. && !defined(AO_HAVE_double_load_full)
  2213. AO_INLINE AO_double_t
  2214. AO_double_load_full(const volatile AO_double_t *addr)
  2215. {
  2216. AO_double_t result;
  2217. do {
  2218. result = *(const AO_double_t *)addr;
  2219. } while (AO_EXPECT_FALSE(!AO_double_compare_and_swap_full(
  2220. (volatile AO_double_t *)addr,
  2221. result, result)));
  2222. return result;
  2223. }
  2224. # define AO_HAVE_double_load_full
  2225. #endif
  2226. #if defined(AO_HAVE_double_compare_and_swap_acquire) \
  2227. && !defined(AO_HAVE_double_load_acquire)
  2228. AO_INLINE AO_double_t
  2229. AO_double_load_acquire(const volatile AO_double_t *addr)
  2230. {
  2231. AO_double_t result;
  2232. do {
  2233. result = *(const AO_double_t *)addr;
  2234. } while (AO_EXPECT_FALSE(!AO_double_compare_and_swap_acquire(
  2235. (volatile AO_double_t *)addr,
  2236. result, result)));
  2237. return result;
  2238. }
  2239. # define AO_HAVE_double_load_acquire
  2240. #endif
  2241. #if defined(AO_HAVE_double_compare_and_swap) && !defined(AO_HAVE_double_load)
  2242. AO_INLINE AO_double_t
  2243. AO_double_load(const volatile AO_double_t *addr)
  2244. {
  2245. AO_double_t result;
  2246. do {
  2247. result = *(const AO_double_t *)addr;
  2248. } while (AO_EXPECT_FALSE(!AO_double_compare_and_swap(
  2249. (volatile AO_double_t *)addr,
  2250. result, result)));
  2251. return result;
  2252. }
  2253. # define AO_HAVE_double_load
  2254. #endif
  2255. #ifdef AO_NO_DD_ORDERING
  2256. # if defined(AO_HAVE_double_load_acquire_read)
  2257. # define AO_double_load_dd_acquire_read(addr) \
  2258. AO_double_load_acquire_read(addr)
  2259. # define AO_HAVE_double_load_dd_acquire_read
  2260. # endif
  2261. #else
  2262. # if defined(AO_HAVE_double_load)
  2263. # define AO_double_load_dd_acquire_read(addr) AO_double_load(addr)
  2264. # define AO_HAVE_double_load_dd_acquire_read
  2265. # endif
  2266. #endif /* !AO_NO_DD_ORDERING */
  2267. /* double_store */
  2268. #if defined(AO_HAVE_double_store_full) && !defined(AO_HAVE_double_store_release)
  2269. # define AO_double_store_release(addr, val) AO_double_store_full(addr, val)
  2270. # define AO_HAVE_double_store_release
  2271. #endif
  2272. #if defined(AO_HAVE_double_store_release) && !defined(AO_HAVE_double_store)
  2273. # define AO_double_store(addr, val) AO_double_store_release(addr, val)
  2274. # define AO_HAVE_double_store
  2275. #endif
  2276. #if defined(AO_HAVE_double_store_full) && !defined(AO_HAVE_double_store_write)
  2277. # define AO_double_store_write(addr, val) AO_double_store_full(addr, val)
  2278. # define AO_HAVE_double_store_write
  2279. #endif
  2280. #if defined(AO_HAVE_double_store_release) \
  2281. && !defined(AO_HAVE_double_store_release_write)
  2282. # define AO_double_store_release_write(addr, val) \
  2283. AO_double_store_release(addr, val)
  2284. # define AO_HAVE_double_store_release_write
  2285. #endif
  2286. #if defined(AO_HAVE_double_store_write) && !defined(AO_HAVE_double_store)
  2287. # define AO_double_store(addr, val) AO_double_store_write(addr, val)
  2288. # define AO_HAVE_double_store
  2289. #endif
  2290. #if defined(AO_HAVE_double_store) && defined(AO_HAVE_nop_full) \
  2291. && !defined(AO_HAVE_double_store_release)
  2292. # define AO_double_store_release(addr, val) \
  2293. (AO_nop_full(), AO_double_store(addr, val))
  2294. # define AO_HAVE_double_store_release
  2295. #endif
  2296. #if defined(AO_HAVE_double_store) && defined(AO_HAVE_nop_write) \
  2297. && !defined(AO_HAVE_double_store_write)
  2298. # define AO_double_store_write(addr, val) \
  2299. (AO_nop_write(), AO_double_store(addr, val))
  2300. # define AO_HAVE_double_store_write
  2301. #endif
  2302. #if defined(AO_HAVE_double_compare_and_swap_write) \
  2303. && !defined(AO_HAVE_double_store_write)
  2304. AO_INLINE void
  2305. AO_double_store_write(volatile AO_double_t *addr, AO_double_t new_val)
  2306. {
  2307. AO_double_t old_val;
  2308. do {
  2309. old_val = *(AO_double_t *)addr;
  2310. } while (AO_EXPECT_FALSE(!AO_double_compare_and_swap_write(addr, old_val,
  2311. new_val)));
  2312. }
  2313. # define AO_HAVE_double_store_write
  2314. #endif
  2315. #if defined(AO_HAVE_double_store_write) \
  2316. && !defined(AO_HAVE_double_store_release_write)
  2317. # define AO_double_store_release_write(addr, val) \
  2318. AO_double_store_write(addr, val)
  2319. # define AO_HAVE_double_store_release_write
  2320. #endif
  2321. #if defined(AO_HAVE_double_store_release) && defined(AO_HAVE_nop_full) \
  2322. && !defined(AO_HAVE_double_store_full)
  2323. # define AO_double_store_full(addr, val) \
  2324. (AO_double_store_release(addr, val), \
  2325. AO_nop_full())
  2326. # define AO_HAVE_double_store_full
  2327. #endif
  2328. #if defined(AO_HAVE_double_compare_and_swap) && !defined(AO_HAVE_double_store)
  2329. AO_INLINE void
  2330. AO_double_store(volatile AO_double_t *addr, AO_double_t new_val)
  2331. {
  2332. AO_double_t old_val;
  2333. do {
  2334. old_val = *(AO_double_t *)addr;
  2335. } while (AO_EXPECT_FALSE(!AO_double_compare_and_swap(addr,
  2336. old_val, new_val)));
  2337. }
  2338. # define AO_HAVE_double_store
  2339. #endif
  2340. #if defined(AO_HAVE_double_compare_and_swap_release) \
  2341. && !defined(AO_HAVE_double_store_release)
  2342. AO_INLINE void
  2343. AO_double_store_release(volatile AO_double_t *addr, AO_double_t new_val)
  2344. {
  2345. AO_double_t old_val;
  2346. do {
  2347. old_val = *(AO_double_t *)addr;
  2348. } while (AO_EXPECT_FALSE(!AO_double_compare_and_swap_release(addr, old_val,
  2349. new_val)));
  2350. }
  2351. # define AO_HAVE_double_store_release
  2352. #endif
  2353. #if defined(AO_HAVE_double_compare_and_swap_full) \
  2354. && !defined(AO_HAVE_double_store_full)
  2355. AO_INLINE void
  2356. AO_double_store_full(volatile AO_double_t *addr, AO_double_t new_val)
  2357. {
  2358. AO_double_t old_val;
  2359. do {
  2360. old_val = *(AO_double_t *)addr;
  2361. } while (AO_EXPECT_FALSE(!AO_double_compare_and_swap_full(addr, old_val,
  2362. new_val)));
  2363. }
  2364. # define AO_HAVE_double_store_full
  2365. #endif