generalize-arithm.h 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380
  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_compare_and_swap (based on fetch_compare_and_swap) */
  23. #if defined(AO_HAVE_char_fetch_compare_and_swap_full) \
  24. && !defined(AO_HAVE_char_compare_and_swap_full)
  25. AO_INLINE int
  26. AO_char_compare_and_swap_full(volatile unsigned/**/char *addr, unsigned/**/char old_val,
  27. unsigned/**/char new_val)
  28. {
  29. return AO_char_fetch_compare_and_swap_full(addr, old_val, new_val)
  30. == old_val;
  31. }
  32. # define AO_HAVE_char_compare_and_swap_full
  33. #endif
  34. #if defined(AO_HAVE_char_fetch_compare_and_swap_acquire) \
  35. && !defined(AO_HAVE_char_compare_and_swap_acquire)
  36. AO_INLINE int
  37. AO_char_compare_and_swap_acquire(volatile unsigned/**/char *addr, unsigned/**/char old_val,
  38. unsigned/**/char new_val)
  39. {
  40. return AO_char_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  41. == old_val;
  42. }
  43. # define AO_HAVE_char_compare_and_swap_acquire
  44. #endif
  45. #if defined(AO_HAVE_char_fetch_compare_and_swap_release) \
  46. && !defined(AO_HAVE_char_compare_and_swap_release)
  47. AO_INLINE int
  48. AO_char_compare_and_swap_release(volatile unsigned/**/char *addr, unsigned/**/char old_val,
  49. unsigned/**/char new_val)
  50. {
  51. return AO_char_fetch_compare_and_swap_release(addr, old_val, new_val)
  52. == old_val;
  53. }
  54. # define AO_HAVE_char_compare_and_swap_release
  55. #endif
  56. #if defined(AO_HAVE_char_fetch_compare_and_swap_write) \
  57. && !defined(AO_HAVE_char_compare_and_swap_write)
  58. AO_INLINE int
  59. AO_char_compare_and_swap_write(volatile unsigned/**/char *addr, unsigned/**/char old_val,
  60. unsigned/**/char new_val)
  61. {
  62. return AO_char_fetch_compare_and_swap_write(addr, old_val, new_val)
  63. == old_val;
  64. }
  65. # define AO_HAVE_char_compare_and_swap_write
  66. #endif
  67. #if defined(AO_HAVE_char_fetch_compare_and_swap_read) \
  68. && !defined(AO_HAVE_char_compare_and_swap_read)
  69. AO_INLINE int
  70. AO_char_compare_and_swap_read(volatile unsigned/**/char *addr, unsigned/**/char old_val,
  71. unsigned/**/char new_val)
  72. {
  73. return AO_char_fetch_compare_and_swap_read(addr, old_val, new_val)
  74. == old_val;
  75. }
  76. # define AO_HAVE_char_compare_and_swap_read
  77. #endif
  78. #if defined(AO_HAVE_char_fetch_compare_and_swap) \
  79. && !defined(AO_HAVE_char_compare_and_swap)
  80. AO_INLINE int
  81. AO_char_compare_and_swap(volatile unsigned/**/char *addr, unsigned/**/char old_val,
  82. unsigned/**/char new_val)
  83. {
  84. return AO_char_fetch_compare_and_swap(addr, old_val, new_val) == old_val;
  85. }
  86. # define AO_HAVE_char_compare_and_swap
  87. #endif
  88. #if defined(AO_HAVE_char_fetch_compare_and_swap_release_write) \
  89. && !defined(AO_HAVE_char_compare_and_swap_release_write)
  90. AO_INLINE int
  91. AO_char_compare_and_swap_release_write(volatile unsigned/**/char *addr,
  92. unsigned/**/char old_val, unsigned/**/char new_val)
  93. {
  94. return AO_char_fetch_compare_and_swap_release_write(addr, old_val,
  95. new_val) == old_val;
  96. }
  97. # define AO_HAVE_char_compare_and_swap_release_write
  98. #endif
  99. #if defined(AO_HAVE_char_fetch_compare_and_swap_acquire_read) \
  100. && !defined(AO_HAVE_char_compare_and_swap_acquire_read)
  101. AO_INLINE int
  102. AO_char_compare_and_swap_acquire_read(volatile unsigned/**/char *addr,
  103. unsigned/**/char old_val, unsigned/**/char new_val)
  104. {
  105. return AO_char_fetch_compare_and_swap_acquire_read(addr, old_val,
  106. new_val) == old_val;
  107. }
  108. # define AO_HAVE_char_compare_and_swap_acquire_read
  109. #endif
  110. #if defined(AO_HAVE_char_fetch_compare_and_swap_dd_acquire_read) \
  111. && !defined(AO_HAVE_char_compare_and_swap_dd_acquire_read)
  112. AO_INLINE int
  113. AO_char_compare_and_swap_dd_acquire_read(volatile unsigned/**/char *addr,
  114. unsigned/**/char old_val, unsigned/**/char new_val)
  115. {
  116. return AO_char_fetch_compare_and_swap_dd_acquire_read(addr, old_val,
  117. new_val) == old_val;
  118. }
  119. # define AO_HAVE_char_compare_and_swap_dd_acquire_read
  120. #endif
  121. /* char_fetch_and_add */
  122. /* We first try to implement fetch_and_add variants in terms of the */
  123. /* corresponding compare_and_swap variants to minimize adding barriers. */
  124. #if defined(AO_HAVE_char_compare_and_swap_full) \
  125. && !defined(AO_HAVE_char_fetch_and_add_full)
  126. AO_INLINE unsigned/**/char
  127. AO_char_fetch_and_add_full(volatile unsigned/**/char *addr, unsigned/**/char incr)
  128. {
  129. unsigned/**/char old;
  130. do
  131. {
  132. old = *(unsigned/**/char *)addr;
  133. }
  134. while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_full(addr, old,
  135. old + incr)));
  136. return old;
  137. }
  138. # define AO_HAVE_char_fetch_and_add_full
  139. #endif
  140. #if defined(AO_HAVE_char_compare_and_swap_acquire) \
  141. && !defined(AO_HAVE_char_fetch_and_add_acquire)
  142. AO_INLINE unsigned/**/char
  143. AO_char_fetch_and_add_acquire(volatile unsigned/**/char *addr, unsigned/**/char incr)
  144. {
  145. unsigned/**/char old;
  146. do
  147. {
  148. old = *(unsigned/**/char *)addr;
  149. }
  150. while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_acquire(addr, old,
  151. old + incr)));
  152. return old;
  153. }
  154. # define AO_HAVE_char_fetch_and_add_acquire
  155. #endif
  156. #if defined(AO_HAVE_char_compare_and_swap_release) \
  157. && !defined(AO_HAVE_char_fetch_and_add_release)
  158. AO_INLINE unsigned/**/char
  159. AO_char_fetch_and_add_release(volatile unsigned/**/char *addr, unsigned/**/char incr)
  160. {
  161. unsigned/**/char old;
  162. do
  163. {
  164. old = *(unsigned/**/char *)addr;
  165. }
  166. while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_release(addr, old,
  167. old + incr)));
  168. return old;
  169. }
  170. # define AO_HAVE_char_fetch_and_add_release
  171. #endif
  172. #if defined(AO_HAVE_char_compare_and_swap) \
  173. && !defined(AO_HAVE_char_fetch_and_add)
  174. AO_INLINE unsigned/**/char
  175. AO_char_fetch_and_add(volatile unsigned/**/char *addr, unsigned/**/char incr)
  176. {
  177. unsigned/**/char old;
  178. do
  179. {
  180. old = *(unsigned/**/char *)addr;
  181. }
  182. while (AO_EXPECT_FALSE(!AO_char_compare_and_swap(addr, old,
  183. old + incr)));
  184. return old;
  185. }
  186. # define AO_HAVE_char_fetch_and_add
  187. #endif
  188. #if defined(AO_HAVE_char_fetch_and_add_full)
  189. # if !defined(AO_HAVE_char_fetch_and_add_release)
  190. # define AO_char_fetch_and_add_release(addr, val) \
  191. AO_char_fetch_and_add_full(addr, val)
  192. # define AO_HAVE_char_fetch_and_add_release
  193. # endif
  194. # if !defined(AO_HAVE_char_fetch_and_add_acquire)
  195. # define AO_char_fetch_and_add_acquire(addr, val) \
  196. AO_char_fetch_and_add_full(addr, val)
  197. # define AO_HAVE_char_fetch_and_add_acquire
  198. # endif
  199. # if !defined(AO_HAVE_char_fetch_and_add_write)
  200. # define AO_char_fetch_and_add_write(addr, val) \
  201. AO_char_fetch_and_add_full(addr, val)
  202. # define AO_HAVE_char_fetch_and_add_write
  203. # endif
  204. # if !defined(AO_HAVE_char_fetch_and_add_read)
  205. # define AO_char_fetch_and_add_read(addr, val) \
  206. AO_char_fetch_and_add_full(addr, val)
  207. # define AO_HAVE_char_fetch_and_add_read
  208. # endif
  209. #endif /* AO_HAVE_char_fetch_and_add_full */
  210. #if defined(AO_HAVE_char_fetch_and_add) && defined(AO_HAVE_nop_full) \
  211. && !defined(AO_HAVE_char_fetch_and_add_acquire)
  212. AO_INLINE unsigned/**/char
  213. AO_char_fetch_and_add_acquire(volatile unsigned/**/char *addr, unsigned/**/char incr)
  214. {
  215. unsigned/**/char result = AO_char_fetch_and_add(addr, incr);
  216. AO_nop_full();
  217. return result;
  218. }
  219. # define AO_HAVE_char_fetch_and_add_acquire
  220. #endif
  221. #if defined(AO_HAVE_char_fetch_and_add) && defined(AO_HAVE_nop_full) \
  222. && !defined(AO_HAVE_char_fetch_and_add_release)
  223. # define AO_char_fetch_and_add_release(addr, incr) \
  224. (AO_nop_full(), AO_char_fetch_and_add(addr, incr))
  225. # define AO_HAVE_char_fetch_and_add_release
  226. #endif
  227. #if !defined(AO_HAVE_char_fetch_and_add) \
  228. && defined(AO_HAVE_char_fetch_and_add_release)
  229. # define AO_char_fetch_and_add(addr, val) \
  230. AO_char_fetch_and_add_release(addr, val)
  231. # define AO_HAVE_char_fetch_and_add
  232. #endif
  233. #if !defined(AO_HAVE_char_fetch_and_add) \
  234. && defined(AO_HAVE_char_fetch_and_add_acquire)
  235. # define AO_char_fetch_and_add(addr, val) \
  236. AO_char_fetch_and_add_acquire(addr, val)
  237. # define AO_HAVE_char_fetch_and_add
  238. #endif
  239. #if !defined(AO_HAVE_char_fetch_and_add) \
  240. && defined(AO_HAVE_char_fetch_and_add_write)
  241. # define AO_char_fetch_and_add(addr, val) \
  242. AO_char_fetch_and_add_write(addr, val)
  243. # define AO_HAVE_char_fetch_and_add
  244. #endif
  245. #if !defined(AO_HAVE_char_fetch_and_add) \
  246. && defined(AO_HAVE_char_fetch_and_add_read)
  247. # define AO_char_fetch_and_add(addr, val) \
  248. AO_char_fetch_and_add_read(addr, val)
  249. # define AO_HAVE_char_fetch_and_add
  250. #endif
  251. #if defined(AO_HAVE_char_fetch_and_add_acquire) \
  252. && defined(AO_HAVE_nop_full) && !defined(AO_HAVE_char_fetch_and_add_full)
  253. # define AO_char_fetch_and_add_full(addr, val) \
  254. (AO_nop_full(), AO_char_fetch_and_add_acquire(addr, val))
  255. # define AO_HAVE_char_fetch_and_add_full
  256. #endif
  257. #if !defined(AO_HAVE_char_fetch_and_add_release_write) \
  258. && defined(AO_HAVE_char_fetch_and_add_write)
  259. # define AO_char_fetch_and_add_release_write(addr, val) \
  260. AO_char_fetch_and_add_write(addr, val)
  261. # define AO_HAVE_char_fetch_and_add_release_write
  262. #endif
  263. #if !defined(AO_HAVE_char_fetch_and_add_release_write) \
  264. && defined(AO_HAVE_char_fetch_and_add_release)
  265. # define AO_char_fetch_and_add_release_write(addr, val) \
  266. AO_char_fetch_and_add_release(addr, val)
  267. # define AO_HAVE_char_fetch_and_add_release_write
  268. #endif
  269. #if !defined(AO_HAVE_char_fetch_and_add_acquire_read) \
  270. && defined(AO_HAVE_char_fetch_and_add_read)
  271. # define AO_char_fetch_and_add_acquire_read(addr, val) \
  272. AO_char_fetch_and_add_read(addr, val)
  273. # define AO_HAVE_char_fetch_and_add_acquire_read
  274. #endif
  275. #if !defined(AO_HAVE_char_fetch_and_add_acquire_read) \
  276. && defined(AO_HAVE_char_fetch_and_add_acquire)
  277. # define AO_char_fetch_and_add_acquire_read(addr, val) \
  278. AO_char_fetch_and_add_acquire(addr, val)
  279. # define AO_HAVE_char_fetch_and_add_acquire_read
  280. #endif
  281. #ifdef AO_NO_DD_ORDERING
  282. # if defined(AO_HAVE_char_fetch_and_add_acquire_read)
  283. # define AO_char_fetch_and_add_dd_acquire_read(addr, val) \
  284. AO_char_fetch_and_add_acquire_read(addr, val)
  285. # define AO_HAVE_char_fetch_and_add_dd_acquire_read
  286. # endif
  287. #else
  288. # if defined(AO_HAVE_char_fetch_and_add)
  289. # define AO_char_fetch_and_add_dd_acquire_read(addr, val) \
  290. AO_char_fetch_and_add(addr, val)
  291. # define AO_HAVE_char_fetch_and_add_dd_acquire_read
  292. # endif
  293. #endif /* !AO_NO_DD_ORDERING */
  294. /* char_fetch_and_add1 */
  295. #if defined(AO_HAVE_char_fetch_and_add_full) \
  296. && !defined(AO_HAVE_char_fetch_and_add1_full)
  297. # define AO_char_fetch_and_add1_full(addr) \
  298. AO_char_fetch_and_add_full(addr, 1)
  299. # define AO_HAVE_char_fetch_and_add1_full
  300. #endif
  301. #if defined(AO_HAVE_char_fetch_and_add_release) \
  302. && !defined(AO_HAVE_char_fetch_and_add1_release)
  303. # define AO_char_fetch_and_add1_release(addr) \
  304. AO_char_fetch_and_add_release(addr, 1)
  305. # define AO_HAVE_char_fetch_and_add1_release
  306. #endif
  307. #if defined(AO_HAVE_char_fetch_and_add_acquire) \
  308. && !defined(AO_HAVE_char_fetch_and_add1_acquire)
  309. # define AO_char_fetch_and_add1_acquire(addr) \
  310. AO_char_fetch_and_add_acquire(addr, 1)
  311. # define AO_HAVE_char_fetch_and_add1_acquire
  312. #endif
  313. #if defined(AO_HAVE_char_fetch_and_add_write) \
  314. && !defined(AO_HAVE_char_fetch_and_add1_write)
  315. # define AO_char_fetch_and_add1_write(addr) \
  316. AO_char_fetch_and_add_write(addr, 1)
  317. # define AO_HAVE_char_fetch_and_add1_write
  318. #endif
  319. #if defined(AO_HAVE_char_fetch_and_add_read) \
  320. && !defined(AO_HAVE_char_fetch_and_add1_read)
  321. # define AO_char_fetch_and_add1_read(addr) \
  322. AO_char_fetch_and_add_read(addr, 1)
  323. # define AO_HAVE_char_fetch_and_add1_read
  324. #endif
  325. #if defined(AO_HAVE_char_fetch_and_add_release_write) \
  326. && !defined(AO_HAVE_char_fetch_and_add1_release_write)
  327. # define AO_char_fetch_and_add1_release_write(addr) \
  328. AO_char_fetch_and_add_release_write(addr, 1)
  329. # define AO_HAVE_char_fetch_and_add1_release_write
  330. #endif
  331. #if defined(AO_HAVE_char_fetch_and_add_acquire_read) \
  332. && !defined(AO_HAVE_char_fetch_and_add1_acquire_read)
  333. # define AO_char_fetch_and_add1_acquire_read(addr) \
  334. AO_char_fetch_and_add_acquire_read(addr, 1)
  335. # define AO_HAVE_char_fetch_and_add1_acquire_read
  336. #endif
  337. #if defined(AO_HAVE_char_fetch_and_add) \
  338. && !defined(AO_HAVE_char_fetch_and_add1)
  339. # define AO_char_fetch_and_add1(addr) AO_char_fetch_and_add(addr, 1)
  340. # define AO_HAVE_char_fetch_and_add1
  341. #endif
  342. #if defined(AO_HAVE_char_fetch_and_add1_full)
  343. # if !defined(AO_HAVE_char_fetch_and_add1_release)
  344. # define AO_char_fetch_and_add1_release(addr) \
  345. AO_char_fetch_and_add1_full(addr)
  346. # define AO_HAVE_char_fetch_and_add1_release
  347. # endif
  348. # if !defined(AO_HAVE_char_fetch_and_add1_acquire)
  349. # define AO_char_fetch_and_add1_acquire(addr) \
  350. AO_char_fetch_and_add1_full(addr)
  351. # define AO_HAVE_char_fetch_and_add1_acquire
  352. # endif
  353. # if !defined(AO_HAVE_char_fetch_and_add1_write)
  354. # define AO_char_fetch_and_add1_write(addr) \
  355. AO_char_fetch_and_add1_full(addr)
  356. # define AO_HAVE_char_fetch_and_add1_write
  357. # endif
  358. # if !defined(AO_HAVE_char_fetch_and_add1_read)
  359. # define AO_char_fetch_and_add1_read(addr) \
  360. AO_char_fetch_and_add1_full(addr)
  361. # define AO_HAVE_char_fetch_and_add1_read
  362. # endif
  363. #endif /* AO_HAVE_char_fetch_and_add1_full */
  364. #if !defined(AO_HAVE_char_fetch_and_add1) \
  365. && defined(AO_HAVE_char_fetch_and_add1_release)
  366. # define AO_char_fetch_and_add1(addr) AO_char_fetch_and_add1_release(addr)
  367. # define AO_HAVE_char_fetch_and_add1
  368. #endif
  369. #if !defined(AO_HAVE_char_fetch_and_add1) \
  370. && defined(AO_HAVE_char_fetch_and_add1_acquire)
  371. # define AO_char_fetch_and_add1(addr) AO_char_fetch_and_add1_acquire(addr)
  372. # define AO_HAVE_char_fetch_and_add1
  373. #endif
  374. #if !defined(AO_HAVE_char_fetch_and_add1) \
  375. && defined(AO_HAVE_char_fetch_and_add1_write)
  376. # define AO_char_fetch_and_add1(addr) AO_char_fetch_and_add1_write(addr)
  377. # define AO_HAVE_char_fetch_and_add1
  378. #endif
  379. #if !defined(AO_HAVE_char_fetch_and_add1) \
  380. && defined(AO_HAVE_char_fetch_and_add1_read)
  381. # define AO_char_fetch_and_add1(addr) AO_char_fetch_and_add1_read(addr)
  382. # define AO_HAVE_char_fetch_and_add1
  383. #endif
  384. #if defined(AO_HAVE_char_fetch_and_add1_acquire) \
  385. && defined(AO_HAVE_nop_full) \
  386. && !defined(AO_HAVE_char_fetch_and_add1_full)
  387. # define AO_char_fetch_and_add1_full(addr) \
  388. (AO_nop_full(), AO_char_fetch_and_add1_acquire(addr))
  389. # define AO_HAVE_char_fetch_and_add1_full
  390. #endif
  391. #if !defined(AO_HAVE_char_fetch_and_add1_release_write) \
  392. && defined(AO_HAVE_char_fetch_and_add1_write)
  393. # define AO_char_fetch_and_add1_release_write(addr) \
  394. AO_char_fetch_and_add1_write(addr)
  395. # define AO_HAVE_char_fetch_and_add1_release_write
  396. #endif
  397. #if !defined(AO_HAVE_char_fetch_and_add1_release_write) \
  398. && defined(AO_HAVE_char_fetch_and_add1_release)
  399. # define AO_char_fetch_and_add1_release_write(addr) \
  400. AO_char_fetch_and_add1_release(addr)
  401. # define AO_HAVE_char_fetch_and_add1_release_write
  402. #endif
  403. #if !defined(AO_HAVE_char_fetch_and_add1_acquire_read) \
  404. && defined(AO_HAVE_char_fetch_and_add1_read)
  405. # define AO_char_fetch_and_add1_acquire_read(addr) \
  406. AO_char_fetch_and_add1_read(addr)
  407. # define AO_HAVE_char_fetch_and_add1_acquire_read
  408. #endif
  409. #if !defined(AO_HAVE_char_fetch_and_add1_acquire_read) \
  410. && defined(AO_HAVE_char_fetch_and_add1_acquire)
  411. # define AO_char_fetch_and_add1_acquire_read(addr) \
  412. AO_char_fetch_and_add1_acquire(addr)
  413. # define AO_HAVE_char_fetch_and_add1_acquire_read
  414. #endif
  415. #ifdef AO_NO_DD_ORDERING
  416. # if defined(AO_HAVE_char_fetch_and_add1_acquire_read)
  417. # define AO_char_fetch_and_add1_dd_acquire_read(addr) \
  418. AO_char_fetch_and_add1_acquire_read(addr)
  419. # define AO_HAVE_char_fetch_and_add1_dd_acquire_read
  420. # endif
  421. #else
  422. # if defined(AO_HAVE_char_fetch_and_add1)
  423. # define AO_char_fetch_and_add1_dd_acquire_read(addr) \
  424. AO_char_fetch_and_add1(addr)
  425. # define AO_HAVE_char_fetch_and_add1_dd_acquire_read
  426. # endif
  427. #endif /* !AO_NO_DD_ORDERING */
  428. /* char_fetch_and_sub1 */
  429. #if defined(AO_HAVE_char_fetch_and_add_full) \
  430. && !defined(AO_HAVE_char_fetch_and_sub1_full)
  431. # define AO_char_fetch_and_sub1_full(addr) \
  432. AO_char_fetch_and_add_full(addr, (unsigned/**/char)(-1))
  433. # define AO_HAVE_char_fetch_and_sub1_full
  434. #endif
  435. #if defined(AO_HAVE_char_fetch_and_add_release) \
  436. && !defined(AO_HAVE_char_fetch_and_sub1_release)
  437. # define AO_char_fetch_and_sub1_release(addr) \
  438. AO_char_fetch_and_add_release(addr, (unsigned/**/char)(-1))
  439. # define AO_HAVE_char_fetch_and_sub1_release
  440. #endif
  441. #if defined(AO_HAVE_char_fetch_and_add_acquire) \
  442. && !defined(AO_HAVE_char_fetch_and_sub1_acquire)
  443. # define AO_char_fetch_and_sub1_acquire(addr) \
  444. AO_char_fetch_and_add_acquire(addr, (unsigned/**/char)(-1))
  445. # define AO_HAVE_char_fetch_and_sub1_acquire
  446. #endif
  447. #if defined(AO_HAVE_char_fetch_and_add_write) \
  448. && !defined(AO_HAVE_char_fetch_and_sub1_write)
  449. # define AO_char_fetch_and_sub1_write(addr) \
  450. AO_char_fetch_and_add_write(addr, (unsigned/**/char)(-1))
  451. # define AO_HAVE_char_fetch_and_sub1_write
  452. #endif
  453. #if defined(AO_HAVE_char_fetch_and_add_read) \
  454. && !defined(AO_HAVE_char_fetch_and_sub1_read)
  455. # define AO_char_fetch_and_sub1_read(addr) \
  456. AO_char_fetch_and_add_read(addr, (unsigned/**/char)(-1))
  457. # define AO_HAVE_char_fetch_and_sub1_read
  458. #endif
  459. #if defined(AO_HAVE_char_fetch_and_add_release_write) \
  460. && !defined(AO_HAVE_char_fetch_and_sub1_release_write)
  461. # define AO_char_fetch_and_sub1_release_write(addr) \
  462. AO_char_fetch_and_add_release_write(addr, (unsigned/**/char)(-1))
  463. # define AO_HAVE_char_fetch_and_sub1_release_write
  464. #endif
  465. #if defined(AO_HAVE_char_fetch_and_add_acquire_read) \
  466. && !defined(AO_HAVE_char_fetch_and_sub1_acquire_read)
  467. # define AO_char_fetch_and_sub1_acquire_read(addr) \
  468. AO_char_fetch_and_add_acquire_read(addr, (unsigned/**/char)(-1))
  469. # define AO_HAVE_char_fetch_and_sub1_acquire_read
  470. #endif
  471. #if defined(AO_HAVE_char_fetch_and_add) \
  472. && !defined(AO_HAVE_char_fetch_and_sub1)
  473. # define AO_char_fetch_and_sub1(addr) \
  474. AO_char_fetch_and_add(addr, (unsigned/**/char)(-1))
  475. # define AO_HAVE_char_fetch_and_sub1
  476. #endif
  477. #if defined(AO_HAVE_char_fetch_and_sub1_full)
  478. # if !defined(AO_HAVE_char_fetch_and_sub1_release)
  479. # define AO_char_fetch_and_sub1_release(addr) \
  480. AO_char_fetch_and_sub1_full(addr)
  481. # define AO_HAVE_char_fetch_and_sub1_release
  482. # endif
  483. # if !defined(AO_HAVE_char_fetch_and_sub1_acquire)
  484. # define AO_char_fetch_and_sub1_acquire(addr) \
  485. AO_char_fetch_and_sub1_full(addr)
  486. # define AO_HAVE_char_fetch_and_sub1_acquire
  487. # endif
  488. # if !defined(AO_HAVE_char_fetch_and_sub1_write)
  489. # define AO_char_fetch_and_sub1_write(addr) \
  490. AO_char_fetch_and_sub1_full(addr)
  491. # define AO_HAVE_char_fetch_and_sub1_write
  492. # endif
  493. # if !defined(AO_HAVE_char_fetch_and_sub1_read)
  494. # define AO_char_fetch_and_sub1_read(addr) \
  495. AO_char_fetch_and_sub1_full(addr)
  496. # define AO_HAVE_char_fetch_and_sub1_read
  497. # endif
  498. #endif /* AO_HAVE_char_fetch_and_sub1_full */
  499. #if !defined(AO_HAVE_char_fetch_and_sub1) \
  500. && defined(AO_HAVE_char_fetch_and_sub1_release)
  501. # define AO_char_fetch_and_sub1(addr) AO_char_fetch_and_sub1_release(addr)
  502. # define AO_HAVE_char_fetch_and_sub1
  503. #endif
  504. #if !defined(AO_HAVE_char_fetch_and_sub1) \
  505. && defined(AO_HAVE_char_fetch_and_sub1_acquire)
  506. # define AO_char_fetch_and_sub1(addr) AO_char_fetch_and_sub1_acquire(addr)
  507. # define AO_HAVE_char_fetch_and_sub1
  508. #endif
  509. #if !defined(AO_HAVE_char_fetch_and_sub1) \
  510. && defined(AO_HAVE_char_fetch_and_sub1_write)
  511. # define AO_char_fetch_and_sub1(addr) AO_char_fetch_and_sub1_write(addr)
  512. # define AO_HAVE_char_fetch_and_sub1
  513. #endif
  514. #if !defined(AO_HAVE_char_fetch_and_sub1) \
  515. && defined(AO_HAVE_char_fetch_and_sub1_read)
  516. # define AO_char_fetch_and_sub1(addr) AO_char_fetch_and_sub1_read(addr)
  517. # define AO_HAVE_char_fetch_and_sub1
  518. #endif
  519. #if defined(AO_HAVE_char_fetch_and_sub1_acquire) \
  520. && defined(AO_HAVE_nop_full) \
  521. && !defined(AO_HAVE_char_fetch_and_sub1_full)
  522. # define AO_char_fetch_and_sub1_full(addr) \
  523. (AO_nop_full(), AO_char_fetch_and_sub1_acquire(addr))
  524. # define AO_HAVE_char_fetch_and_sub1_full
  525. #endif
  526. #if !defined(AO_HAVE_char_fetch_and_sub1_release_write) \
  527. && defined(AO_HAVE_char_fetch_and_sub1_write)
  528. # define AO_char_fetch_and_sub1_release_write(addr) \
  529. AO_char_fetch_and_sub1_write(addr)
  530. # define AO_HAVE_char_fetch_and_sub1_release_write
  531. #endif
  532. #if !defined(AO_HAVE_char_fetch_and_sub1_release_write) \
  533. && defined(AO_HAVE_char_fetch_and_sub1_release)
  534. # define AO_char_fetch_and_sub1_release_write(addr) \
  535. AO_char_fetch_and_sub1_release(addr)
  536. # define AO_HAVE_char_fetch_and_sub1_release_write
  537. #endif
  538. #if !defined(AO_HAVE_char_fetch_and_sub1_acquire_read) \
  539. && defined(AO_HAVE_char_fetch_and_sub1_read)
  540. # define AO_char_fetch_and_sub1_acquire_read(addr) \
  541. AO_char_fetch_and_sub1_read(addr)
  542. # define AO_HAVE_char_fetch_and_sub1_acquire_read
  543. #endif
  544. #if !defined(AO_HAVE_char_fetch_and_sub1_acquire_read) \
  545. && defined(AO_HAVE_char_fetch_and_sub1_acquire)
  546. # define AO_char_fetch_and_sub1_acquire_read(addr) \
  547. AO_char_fetch_and_sub1_acquire(addr)
  548. # define AO_HAVE_char_fetch_and_sub1_acquire_read
  549. #endif
  550. #ifdef AO_NO_DD_ORDERING
  551. # if defined(AO_HAVE_char_fetch_and_sub1_acquire_read)
  552. # define AO_char_fetch_and_sub1_dd_acquire_read(addr) \
  553. AO_char_fetch_and_sub1_acquire_read(addr)
  554. # define AO_HAVE_char_fetch_and_sub1_dd_acquire_read
  555. # endif
  556. #else
  557. # if defined(AO_HAVE_char_fetch_and_sub1)
  558. # define AO_char_fetch_and_sub1_dd_acquire_read(addr) \
  559. AO_char_fetch_and_sub1(addr)
  560. # define AO_HAVE_char_fetch_and_sub1_dd_acquire_read
  561. # endif
  562. #endif /* !AO_NO_DD_ORDERING */
  563. /* char_and */
  564. #if defined(AO_HAVE_char_compare_and_swap_full) \
  565. && !defined(AO_HAVE_char_and_full)
  566. AO_INLINE void
  567. AO_char_and_full(volatile unsigned/**/char *addr, unsigned/**/char value)
  568. {
  569. unsigned/**/char old;
  570. do
  571. {
  572. old = *(unsigned/**/char *)addr;
  573. }
  574. while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_full(addr, old,
  575. old & value)));
  576. }
  577. # define AO_HAVE_char_and_full
  578. #endif
  579. #if defined(AO_HAVE_char_and_full)
  580. # if !defined(AO_HAVE_char_and_release)
  581. # define AO_char_and_release(addr, val) AO_char_and_full(addr, val)
  582. # define AO_HAVE_char_and_release
  583. # endif
  584. # if !defined(AO_HAVE_char_and_acquire)
  585. # define AO_char_and_acquire(addr, val) AO_char_and_full(addr, val)
  586. # define AO_HAVE_char_and_acquire
  587. # endif
  588. # if !defined(AO_HAVE_char_and_write)
  589. # define AO_char_and_write(addr, val) AO_char_and_full(addr, val)
  590. # define AO_HAVE_char_and_write
  591. # endif
  592. # if !defined(AO_HAVE_char_and_read)
  593. # define AO_char_and_read(addr, val) AO_char_and_full(addr, val)
  594. # define AO_HAVE_char_and_read
  595. # endif
  596. #endif /* AO_HAVE_char_and_full */
  597. #if !defined(AO_HAVE_char_and) && defined(AO_HAVE_char_and_release)
  598. # define AO_char_and(addr, val) AO_char_and_release(addr, val)
  599. # define AO_HAVE_char_and
  600. #endif
  601. #if !defined(AO_HAVE_char_and) && defined(AO_HAVE_char_and_acquire)
  602. # define AO_char_and(addr, val) AO_char_and_acquire(addr, val)
  603. # define AO_HAVE_char_and
  604. #endif
  605. #if !defined(AO_HAVE_char_and) && defined(AO_HAVE_char_and_write)
  606. # define AO_char_and(addr, val) AO_char_and_write(addr, val)
  607. # define AO_HAVE_char_and
  608. #endif
  609. #if !defined(AO_HAVE_char_and) && defined(AO_HAVE_char_and_read)
  610. # define AO_char_and(addr, val) AO_char_and_read(addr, val)
  611. # define AO_HAVE_char_and
  612. #endif
  613. #if defined(AO_HAVE_char_and_acquire) && defined(AO_HAVE_nop_full) \
  614. && !defined(AO_HAVE_char_and_full)
  615. # define AO_char_and_full(addr, val) \
  616. (AO_nop_full(), AO_char_and_acquire(addr, val))
  617. # define AO_HAVE_char_and_full
  618. #endif
  619. #if !defined(AO_HAVE_char_and_release_write) \
  620. && defined(AO_HAVE_char_and_write)
  621. # define AO_char_and_release_write(addr, val) AO_char_and_write(addr, val)
  622. # define AO_HAVE_char_and_release_write
  623. #endif
  624. #if !defined(AO_HAVE_char_and_release_write) \
  625. && defined(AO_HAVE_char_and_release)
  626. # define AO_char_and_release_write(addr, val) AO_char_and_release(addr, val)
  627. # define AO_HAVE_char_and_release_write
  628. #endif
  629. #if !defined(AO_HAVE_char_and_acquire_read) \
  630. && defined(AO_HAVE_char_and_read)
  631. # define AO_char_and_acquire_read(addr, val) AO_char_and_read(addr, val)
  632. # define AO_HAVE_char_and_acquire_read
  633. #endif
  634. #if !defined(AO_HAVE_char_and_acquire_read) \
  635. && defined(AO_HAVE_char_and_acquire)
  636. # define AO_char_and_acquire_read(addr, val) AO_char_and_acquire(addr, val)
  637. # define AO_HAVE_char_and_acquire_read
  638. #endif
  639. /* char_or */
  640. #if defined(AO_HAVE_char_compare_and_swap_full) \
  641. && !defined(AO_HAVE_char_or_full)
  642. AO_INLINE void
  643. AO_char_or_full(volatile unsigned/**/char *addr, unsigned/**/char value)
  644. {
  645. unsigned/**/char old;
  646. do
  647. {
  648. old = *(unsigned/**/char *)addr;
  649. }
  650. while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_full(addr, old,
  651. old | value)));
  652. }
  653. # define AO_HAVE_char_or_full
  654. #endif
  655. #if defined(AO_HAVE_char_or_full)
  656. # if !defined(AO_HAVE_char_or_release)
  657. # define AO_char_or_release(addr, val) AO_char_or_full(addr, val)
  658. # define AO_HAVE_char_or_release
  659. # endif
  660. # if !defined(AO_HAVE_char_or_acquire)
  661. # define AO_char_or_acquire(addr, val) AO_char_or_full(addr, val)
  662. # define AO_HAVE_char_or_acquire
  663. # endif
  664. # if !defined(AO_HAVE_char_or_write)
  665. # define AO_char_or_write(addr, val) AO_char_or_full(addr, val)
  666. # define AO_HAVE_char_or_write
  667. # endif
  668. # if !defined(AO_HAVE_char_or_read)
  669. # define AO_char_or_read(addr, val) AO_char_or_full(addr, val)
  670. # define AO_HAVE_char_or_read
  671. # endif
  672. #endif /* AO_HAVE_char_or_full */
  673. #if !defined(AO_HAVE_char_or) && defined(AO_HAVE_char_or_release)
  674. # define AO_char_or(addr, val) AO_char_or_release(addr, val)
  675. # define AO_HAVE_char_or
  676. #endif
  677. #if !defined(AO_HAVE_char_or) && defined(AO_HAVE_char_or_acquire)
  678. # define AO_char_or(addr, val) AO_char_or_acquire(addr, val)
  679. # define AO_HAVE_char_or
  680. #endif
  681. #if !defined(AO_HAVE_char_or) && defined(AO_HAVE_char_or_write)
  682. # define AO_char_or(addr, val) AO_char_or_write(addr, val)
  683. # define AO_HAVE_char_or
  684. #endif
  685. #if !defined(AO_HAVE_char_or) && defined(AO_HAVE_char_or_read)
  686. # define AO_char_or(addr, val) AO_char_or_read(addr, val)
  687. # define AO_HAVE_char_or
  688. #endif
  689. #if defined(AO_HAVE_char_or_acquire) && defined(AO_HAVE_nop_full) \
  690. && !defined(AO_HAVE_char_or_full)
  691. # define AO_char_or_full(addr, val) \
  692. (AO_nop_full(), AO_char_or_acquire(addr, val))
  693. # define AO_HAVE_char_or_full
  694. #endif
  695. #if !defined(AO_HAVE_char_or_release_write) \
  696. && defined(AO_HAVE_char_or_write)
  697. # define AO_char_or_release_write(addr, val) AO_char_or_write(addr, val)
  698. # define AO_HAVE_char_or_release_write
  699. #endif
  700. #if !defined(AO_HAVE_char_or_release_write) \
  701. && defined(AO_HAVE_char_or_release)
  702. # define AO_char_or_release_write(addr, val) AO_char_or_release(addr, val)
  703. # define AO_HAVE_char_or_release_write
  704. #endif
  705. #if !defined(AO_HAVE_char_or_acquire_read) && defined(AO_HAVE_char_or_read)
  706. # define AO_char_or_acquire_read(addr, val) AO_char_or_read(addr, val)
  707. # define AO_HAVE_char_or_acquire_read
  708. #endif
  709. #if !defined(AO_HAVE_char_or_acquire_read) \
  710. && defined(AO_HAVE_char_or_acquire)
  711. # define AO_char_or_acquire_read(addr, val) AO_char_or_acquire(addr, val)
  712. # define AO_HAVE_char_or_acquire_read
  713. #endif
  714. /* char_xor */
  715. #if defined(AO_HAVE_char_compare_and_swap_full) \
  716. && !defined(AO_HAVE_char_xor_full)
  717. AO_INLINE void
  718. AO_char_xor_full(volatile unsigned/**/char *addr, unsigned/**/char value)
  719. {
  720. unsigned/**/char old;
  721. do
  722. {
  723. old = *(unsigned/**/char *)addr;
  724. }
  725. while (AO_EXPECT_FALSE(!AO_char_compare_and_swap_full(addr, old,
  726. old ^ value)));
  727. }
  728. # define AO_HAVE_char_xor_full
  729. #endif
  730. #if defined(AO_HAVE_char_xor_full)
  731. # if !defined(AO_HAVE_char_xor_release)
  732. # define AO_char_xor_release(addr, val) AO_char_xor_full(addr, val)
  733. # define AO_HAVE_char_xor_release
  734. # endif
  735. # if !defined(AO_HAVE_char_xor_acquire)
  736. # define AO_char_xor_acquire(addr, val) AO_char_xor_full(addr, val)
  737. # define AO_HAVE_char_xor_acquire
  738. # endif
  739. # if !defined(AO_HAVE_char_xor_write)
  740. # define AO_char_xor_write(addr, val) AO_char_xor_full(addr, val)
  741. # define AO_HAVE_char_xor_write
  742. # endif
  743. # if !defined(AO_HAVE_char_xor_read)
  744. # define AO_char_xor_read(addr, val) AO_char_xor_full(addr, val)
  745. # define AO_HAVE_char_xor_read
  746. # endif
  747. #endif /* AO_HAVE_char_xor_full */
  748. #if !defined(AO_HAVE_char_xor) && defined(AO_HAVE_char_xor_release)
  749. # define AO_char_xor(addr, val) AO_char_xor_release(addr, val)
  750. # define AO_HAVE_char_xor
  751. #endif
  752. #if !defined(AO_HAVE_char_xor) && defined(AO_HAVE_char_xor_acquire)
  753. # define AO_char_xor(addr, val) AO_char_xor_acquire(addr, val)
  754. # define AO_HAVE_char_xor
  755. #endif
  756. #if !defined(AO_HAVE_char_xor) && defined(AO_HAVE_char_xor_write)
  757. # define AO_char_xor(addr, val) AO_char_xor_write(addr, val)
  758. # define AO_HAVE_char_xor
  759. #endif
  760. #if !defined(AO_HAVE_char_xor) && defined(AO_HAVE_char_xor_read)
  761. # define AO_char_xor(addr, val) AO_char_xor_read(addr, val)
  762. # define AO_HAVE_char_xor
  763. #endif
  764. #if defined(AO_HAVE_char_xor_acquire) && defined(AO_HAVE_nop_full) \
  765. && !defined(AO_HAVE_char_xor_full)
  766. # define AO_char_xor_full(addr, val) \
  767. (AO_nop_full(), AO_char_xor_acquire(addr, val))
  768. # define AO_HAVE_char_xor_full
  769. #endif
  770. #if !defined(AO_HAVE_char_xor_release_write) \
  771. && defined(AO_HAVE_char_xor_write)
  772. # define AO_char_xor_release_write(addr, val) AO_char_xor_write(addr, val)
  773. # define AO_HAVE_char_xor_release_write
  774. #endif
  775. #if !defined(AO_HAVE_char_xor_release_write) \
  776. && defined(AO_HAVE_char_xor_release)
  777. # define AO_char_xor_release_write(addr, val) AO_char_xor_release(addr, val)
  778. # define AO_HAVE_char_xor_release_write
  779. #endif
  780. #if !defined(AO_HAVE_char_xor_acquire_read) \
  781. && defined(AO_HAVE_char_xor_read)
  782. # define AO_char_xor_acquire_read(addr, val) AO_char_xor_read(addr, val)
  783. # define AO_HAVE_char_xor_acquire_read
  784. #endif
  785. #if !defined(AO_HAVE_char_xor_acquire_read) \
  786. && defined(AO_HAVE_char_xor_acquire)
  787. # define AO_char_xor_acquire_read(addr, val) AO_char_xor_acquire(addr, val)
  788. # define AO_HAVE_char_xor_acquire_read
  789. #endif
  790. /* char_and/or/xor_dd_acquire_read are meaningless. */
  791. /*
  792. * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
  793. *
  794. * Permission is hereby granted, free of charge, to any person obtaining a copy
  795. * of this software and associated documentation files (the "Software"), to deal
  796. * in the Software without restriction, including without limitation the rights
  797. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  798. * copies of the Software, and to permit persons to whom the Software is
  799. * furnished to do so, subject to the following conditions:
  800. *
  801. * The above copyright notice and this permission notice shall be included in
  802. * all copies or substantial portions of the Software.
  803. *
  804. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  805. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  806. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  807. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  808. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  809. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  810. * SOFTWARE.
  811. */
  812. /* short_compare_and_swap (based on fetch_compare_and_swap) */
  813. #if defined(AO_HAVE_short_fetch_compare_and_swap_full) \
  814. && !defined(AO_HAVE_short_compare_and_swap_full)
  815. AO_INLINE int
  816. AO_short_compare_and_swap_full(volatile unsigned/**/short *addr, unsigned/**/short old_val,
  817. unsigned/**/short new_val)
  818. {
  819. return AO_short_fetch_compare_and_swap_full(addr, old_val, new_val)
  820. == old_val;
  821. }
  822. # define AO_HAVE_short_compare_and_swap_full
  823. #endif
  824. #if defined(AO_HAVE_short_fetch_compare_and_swap_acquire) \
  825. && !defined(AO_HAVE_short_compare_and_swap_acquire)
  826. AO_INLINE int
  827. AO_short_compare_and_swap_acquire(volatile unsigned/**/short *addr, unsigned/**/short old_val,
  828. unsigned/**/short new_val)
  829. {
  830. return AO_short_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  831. == old_val;
  832. }
  833. # define AO_HAVE_short_compare_and_swap_acquire
  834. #endif
  835. #if defined(AO_HAVE_short_fetch_compare_and_swap_release) \
  836. && !defined(AO_HAVE_short_compare_and_swap_release)
  837. AO_INLINE int
  838. AO_short_compare_and_swap_release(volatile unsigned/**/short *addr, unsigned/**/short old_val,
  839. unsigned/**/short new_val)
  840. {
  841. return AO_short_fetch_compare_and_swap_release(addr, old_val, new_val)
  842. == old_val;
  843. }
  844. # define AO_HAVE_short_compare_and_swap_release
  845. #endif
  846. #if defined(AO_HAVE_short_fetch_compare_and_swap_write) \
  847. && !defined(AO_HAVE_short_compare_and_swap_write)
  848. AO_INLINE int
  849. AO_short_compare_and_swap_write(volatile unsigned/**/short *addr, unsigned/**/short old_val,
  850. unsigned/**/short new_val)
  851. {
  852. return AO_short_fetch_compare_and_swap_write(addr, old_val, new_val)
  853. == old_val;
  854. }
  855. # define AO_HAVE_short_compare_and_swap_write
  856. #endif
  857. #if defined(AO_HAVE_short_fetch_compare_and_swap_read) \
  858. && !defined(AO_HAVE_short_compare_and_swap_read)
  859. AO_INLINE int
  860. AO_short_compare_and_swap_read(volatile unsigned/**/short *addr, unsigned/**/short old_val,
  861. unsigned/**/short new_val)
  862. {
  863. return AO_short_fetch_compare_and_swap_read(addr, old_val, new_val)
  864. == old_val;
  865. }
  866. # define AO_HAVE_short_compare_and_swap_read
  867. #endif
  868. #if defined(AO_HAVE_short_fetch_compare_and_swap) \
  869. && !defined(AO_HAVE_short_compare_and_swap)
  870. AO_INLINE int
  871. AO_short_compare_and_swap(volatile unsigned/**/short *addr, unsigned/**/short old_val,
  872. unsigned/**/short new_val)
  873. {
  874. return AO_short_fetch_compare_and_swap(addr, old_val, new_val) == old_val;
  875. }
  876. # define AO_HAVE_short_compare_and_swap
  877. #endif
  878. #if defined(AO_HAVE_short_fetch_compare_and_swap_release_write) \
  879. && !defined(AO_HAVE_short_compare_and_swap_release_write)
  880. AO_INLINE int
  881. AO_short_compare_and_swap_release_write(volatile unsigned/**/short *addr,
  882. unsigned/**/short old_val, unsigned/**/short new_val)
  883. {
  884. return AO_short_fetch_compare_and_swap_release_write(addr, old_val,
  885. new_val) == old_val;
  886. }
  887. # define AO_HAVE_short_compare_and_swap_release_write
  888. #endif
  889. #if defined(AO_HAVE_short_fetch_compare_and_swap_acquire_read) \
  890. && !defined(AO_HAVE_short_compare_and_swap_acquire_read)
  891. AO_INLINE int
  892. AO_short_compare_and_swap_acquire_read(volatile unsigned/**/short *addr,
  893. unsigned/**/short old_val, unsigned/**/short new_val)
  894. {
  895. return AO_short_fetch_compare_and_swap_acquire_read(addr, old_val,
  896. new_val) == old_val;
  897. }
  898. # define AO_HAVE_short_compare_and_swap_acquire_read
  899. #endif
  900. #if defined(AO_HAVE_short_fetch_compare_and_swap_dd_acquire_read) \
  901. && !defined(AO_HAVE_short_compare_and_swap_dd_acquire_read)
  902. AO_INLINE int
  903. AO_short_compare_and_swap_dd_acquire_read(volatile unsigned/**/short *addr,
  904. unsigned/**/short old_val, unsigned/**/short new_val)
  905. {
  906. return AO_short_fetch_compare_and_swap_dd_acquire_read(addr, old_val,
  907. new_val) == old_val;
  908. }
  909. # define AO_HAVE_short_compare_and_swap_dd_acquire_read
  910. #endif
  911. /* short_fetch_and_add */
  912. /* We first try to implement fetch_and_add variants in terms of the */
  913. /* corresponding compare_and_swap variants to minimize adding barriers. */
  914. #if defined(AO_HAVE_short_compare_and_swap_full) \
  915. && !defined(AO_HAVE_short_fetch_and_add_full)
  916. AO_INLINE unsigned/**/short
  917. AO_short_fetch_and_add_full(volatile unsigned/**/short *addr, unsigned/**/short incr)
  918. {
  919. unsigned/**/short old;
  920. do
  921. {
  922. old = *(unsigned/**/short *)addr;
  923. }
  924. while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_full(addr, old,
  925. old + incr)));
  926. return old;
  927. }
  928. # define AO_HAVE_short_fetch_and_add_full
  929. #endif
  930. #if defined(AO_HAVE_short_compare_and_swap_acquire) \
  931. && !defined(AO_HAVE_short_fetch_and_add_acquire)
  932. AO_INLINE unsigned/**/short
  933. AO_short_fetch_and_add_acquire(volatile unsigned/**/short *addr, unsigned/**/short incr)
  934. {
  935. unsigned/**/short old;
  936. do
  937. {
  938. old = *(unsigned/**/short *)addr;
  939. }
  940. while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_acquire(addr, old,
  941. old + incr)));
  942. return old;
  943. }
  944. # define AO_HAVE_short_fetch_and_add_acquire
  945. #endif
  946. #if defined(AO_HAVE_short_compare_and_swap_release) \
  947. && !defined(AO_HAVE_short_fetch_and_add_release)
  948. AO_INLINE unsigned/**/short
  949. AO_short_fetch_and_add_release(volatile unsigned/**/short *addr, unsigned/**/short incr)
  950. {
  951. unsigned/**/short old;
  952. do
  953. {
  954. old = *(unsigned/**/short *)addr;
  955. }
  956. while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_release(addr, old,
  957. old + incr)));
  958. return old;
  959. }
  960. # define AO_HAVE_short_fetch_and_add_release
  961. #endif
  962. #if defined(AO_HAVE_short_compare_and_swap) \
  963. && !defined(AO_HAVE_short_fetch_and_add)
  964. AO_INLINE unsigned/**/short
  965. AO_short_fetch_and_add(volatile unsigned/**/short *addr, unsigned/**/short incr)
  966. {
  967. unsigned/**/short old;
  968. do
  969. {
  970. old = *(unsigned/**/short *)addr;
  971. }
  972. while (AO_EXPECT_FALSE(!AO_short_compare_and_swap(addr, old,
  973. old + incr)));
  974. return old;
  975. }
  976. # define AO_HAVE_short_fetch_and_add
  977. #endif
  978. #if defined(AO_HAVE_short_fetch_and_add_full)
  979. # if !defined(AO_HAVE_short_fetch_and_add_release)
  980. # define AO_short_fetch_and_add_release(addr, val) \
  981. AO_short_fetch_and_add_full(addr, val)
  982. # define AO_HAVE_short_fetch_and_add_release
  983. # endif
  984. # if !defined(AO_HAVE_short_fetch_and_add_acquire)
  985. # define AO_short_fetch_and_add_acquire(addr, val) \
  986. AO_short_fetch_and_add_full(addr, val)
  987. # define AO_HAVE_short_fetch_and_add_acquire
  988. # endif
  989. # if !defined(AO_HAVE_short_fetch_and_add_write)
  990. # define AO_short_fetch_and_add_write(addr, val) \
  991. AO_short_fetch_and_add_full(addr, val)
  992. # define AO_HAVE_short_fetch_and_add_write
  993. # endif
  994. # if !defined(AO_HAVE_short_fetch_and_add_read)
  995. # define AO_short_fetch_and_add_read(addr, val) \
  996. AO_short_fetch_and_add_full(addr, val)
  997. # define AO_HAVE_short_fetch_and_add_read
  998. # endif
  999. #endif /* AO_HAVE_short_fetch_and_add_full */
  1000. #if defined(AO_HAVE_short_fetch_and_add) && defined(AO_HAVE_nop_full) \
  1001. && !defined(AO_HAVE_short_fetch_and_add_acquire)
  1002. AO_INLINE unsigned/**/short
  1003. AO_short_fetch_and_add_acquire(volatile unsigned/**/short *addr, unsigned/**/short incr)
  1004. {
  1005. unsigned/**/short result = AO_short_fetch_and_add(addr, incr);
  1006. AO_nop_full();
  1007. return result;
  1008. }
  1009. # define AO_HAVE_short_fetch_and_add_acquire
  1010. #endif
  1011. #if defined(AO_HAVE_short_fetch_and_add) && defined(AO_HAVE_nop_full) \
  1012. && !defined(AO_HAVE_short_fetch_and_add_release)
  1013. # define AO_short_fetch_and_add_release(addr, incr) \
  1014. (AO_nop_full(), AO_short_fetch_and_add(addr, incr))
  1015. # define AO_HAVE_short_fetch_and_add_release
  1016. #endif
  1017. #if !defined(AO_HAVE_short_fetch_and_add) \
  1018. && defined(AO_HAVE_short_fetch_and_add_release)
  1019. # define AO_short_fetch_and_add(addr, val) \
  1020. AO_short_fetch_and_add_release(addr, val)
  1021. # define AO_HAVE_short_fetch_and_add
  1022. #endif
  1023. #if !defined(AO_HAVE_short_fetch_and_add) \
  1024. && defined(AO_HAVE_short_fetch_and_add_acquire)
  1025. # define AO_short_fetch_and_add(addr, val) \
  1026. AO_short_fetch_and_add_acquire(addr, val)
  1027. # define AO_HAVE_short_fetch_and_add
  1028. #endif
  1029. #if !defined(AO_HAVE_short_fetch_and_add) \
  1030. && defined(AO_HAVE_short_fetch_and_add_write)
  1031. # define AO_short_fetch_and_add(addr, val) \
  1032. AO_short_fetch_and_add_write(addr, val)
  1033. # define AO_HAVE_short_fetch_and_add
  1034. #endif
  1035. #if !defined(AO_HAVE_short_fetch_and_add) \
  1036. && defined(AO_HAVE_short_fetch_and_add_read)
  1037. # define AO_short_fetch_and_add(addr, val) \
  1038. AO_short_fetch_and_add_read(addr, val)
  1039. # define AO_HAVE_short_fetch_and_add
  1040. #endif
  1041. #if defined(AO_HAVE_short_fetch_and_add_acquire) \
  1042. && defined(AO_HAVE_nop_full) && !defined(AO_HAVE_short_fetch_and_add_full)
  1043. # define AO_short_fetch_and_add_full(addr, val) \
  1044. (AO_nop_full(), AO_short_fetch_and_add_acquire(addr, val))
  1045. # define AO_HAVE_short_fetch_and_add_full
  1046. #endif
  1047. #if !defined(AO_HAVE_short_fetch_and_add_release_write) \
  1048. && defined(AO_HAVE_short_fetch_and_add_write)
  1049. # define AO_short_fetch_and_add_release_write(addr, val) \
  1050. AO_short_fetch_and_add_write(addr, val)
  1051. # define AO_HAVE_short_fetch_and_add_release_write
  1052. #endif
  1053. #if !defined(AO_HAVE_short_fetch_and_add_release_write) \
  1054. && defined(AO_HAVE_short_fetch_and_add_release)
  1055. # define AO_short_fetch_and_add_release_write(addr, val) \
  1056. AO_short_fetch_and_add_release(addr, val)
  1057. # define AO_HAVE_short_fetch_and_add_release_write
  1058. #endif
  1059. #if !defined(AO_HAVE_short_fetch_and_add_acquire_read) \
  1060. && defined(AO_HAVE_short_fetch_and_add_read)
  1061. # define AO_short_fetch_and_add_acquire_read(addr, val) \
  1062. AO_short_fetch_and_add_read(addr, val)
  1063. # define AO_HAVE_short_fetch_and_add_acquire_read
  1064. #endif
  1065. #if !defined(AO_HAVE_short_fetch_and_add_acquire_read) \
  1066. && defined(AO_HAVE_short_fetch_and_add_acquire)
  1067. # define AO_short_fetch_and_add_acquire_read(addr, val) \
  1068. AO_short_fetch_and_add_acquire(addr, val)
  1069. # define AO_HAVE_short_fetch_and_add_acquire_read
  1070. #endif
  1071. #ifdef AO_NO_DD_ORDERING
  1072. # if defined(AO_HAVE_short_fetch_and_add_acquire_read)
  1073. # define AO_short_fetch_and_add_dd_acquire_read(addr, val) \
  1074. AO_short_fetch_and_add_acquire_read(addr, val)
  1075. # define AO_HAVE_short_fetch_and_add_dd_acquire_read
  1076. # endif
  1077. #else
  1078. # if defined(AO_HAVE_short_fetch_and_add)
  1079. # define AO_short_fetch_and_add_dd_acquire_read(addr, val) \
  1080. AO_short_fetch_and_add(addr, val)
  1081. # define AO_HAVE_short_fetch_and_add_dd_acquire_read
  1082. # endif
  1083. #endif /* !AO_NO_DD_ORDERING */
  1084. /* short_fetch_and_add1 */
  1085. #if defined(AO_HAVE_short_fetch_and_add_full) \
  1086. && !defined(AO_HAVE_short_fetch_and_add1_full)
  1087. # define AO_short_fetch_and_add1_full(addr) \
  1088. AO_short_fetch_and_add_full(addr, 1)
  1089. # define AO_HAVE_short_fetch_and_add1_full
  1090. #endif
  1091. #if defined(AO_HAVE_short_fetch_and_add_release) \
  1092. && !defined(AO_HAVE_short_fetch_and_add1_release)
  1093. # define AO_short_fetch_and_add1_release(addr) \
  1094. AO_short_fetch_and_add_release(addr, 1)
  1095. # define AO_HAVE_short_fetch_and_add1_release
  1096. #endif
  1097. #if defined(AO_HAVE_short_fetch_and_add_acquire) \
  1098. && !defined(AO_HAVE_short_fetch_and_add1_acquire)
  1099. # define AO_short_fetch_and_add1_acquire(addr) \
  1100. AO_short_fetch_and_add_acquire(addr, 1)
  1101. # define AO_HAVE_short_fetch_and_add1_acquire
  1102. #endif
  1103. #if defined(AO_HAVE_short_fetch_and_add_write) \
  1104. && !defined(AO_HAVE_short_fetch_and_add1_write)
  1105. # define AO_short_fetch_and_add1_write(addr) \
  1106. AO_short_fetch_and_add_write(addr, 1)
  1107. # define AO_HAVE_short_fetch_and_add1_write
  1108. #endif
  1109. #if defined(AO_HAVE_short_fetch_and_add_read) \
  1110. && !defined(AO_HAVE_short_fetch_and_add1_read)
  1111. # define AO_short_fetch_and_add1_read(addr) \
  1112. AO_short_fetch_and_add_read(addr, 1)
  1113. # define AO_HAVE_short_fetch_and_add1_read
  1114. #endif
  1115. #if defined(AO_HAVE_short_fetch_and_add_release_write) \
  1116. && !defined(AO_HAVE_short_fetch_and_add1_release_write)
  1117. # define AO_short_fetch_and_add1_release_write(addr) \
  1118. AO_short_fetch_and_add_release_write(addr, 1)
  1119. # define AO_HAVE_short_fetch_and_add1_release_write
  1120. #endif
  1121. #if defined(AO_HAVE_short_fetch_and_add_acquire_read) \
  1122. && !defined(AO_HAVE_short_fetch_and_add1_acquire_read)
  1123. # define AO_short_fetch_and_add1_acquire_read(addr) \
  1124. AO_short_fetch_and_add_acquire_read(addr, 1)
  1125. # define AO_HAVE_short_fetch_and_add1_acquire_read
  1126. #endif
  1127. #if defined(AO_HAVE_short_fetch_and_add) \
  1128. && !defined(AO_HAVE_short_fetch_and_add1)
  1129. # define AO_short_fetch_and_add1(addr) AO_short_fetch_and_add(addr, 1)
  1130. # define AO_HAVE_short_fetch_and_add1
  1131. #endif
  1132. #if defined(AO_HAVE_short_fetch_and_add1_full)
  1133. # if !defined(AO_HAVE_short_fetch_and_add1_release)
  1134. # define AO_short_fetch_and_add1_release(addr) \
  1135. AO_short_fetch_and_add1_full(addr)
  1136. # define AO_HAVE_short_fetch_and_add1_release
  1137. # endif
  1138. # if !defined(AO_HAVE_short_fetch_and_add1_acquire)
  1139. # define AO_short_fetch_and_add1_acquire(addr) \
  1140. AO_short_fetch_and_add1_full(addr)
  1141. # define AO_HAVE_short_fetch_and_add1_acquire
  1142. # endif
  1143. # if !defined(AO_HAVE_short_fetch_and_add1_write)
  1144. # define AO_short_fetch_and_add1_write(addr) \
  1145. AO_short_fetch_and_add1_full(addr)
  1146. # define AO_HAVE_short_fetch_and_add1_write
  1147. # endif
  1148. # if !defined(AO_HAVE_short_fetch_and_add1_read)
  1149. # define AO_short_fetch_and_add1_read(addr) \
  1150. AO_short_fetch_and_add1_full(addr)
  1151. # define AO_HAVE_short_fetch_and_add1_read
  1152. # endif
  1153. #endif /* AO_HAVE_short_fetch_and_add1_full */
  1154. #if !defined(AO_HAVE_short_fetch_and_add1) \
  1155. && defined(AO_HAVE_short_fetch_and_add1_release)
  1156. # define AO_short_fetch_and_add1(addr) AO_short_fetch_and_add1_release(addr)
  1157. # define AO_HAVE_short_fetch_and_add1
  1158. #endif
  1159. #if !defined(AO_HAVE_short_fetch_and_add1) \
  1160. && defined(AO_HAVE_short_fetch_and_add1_acquire)
  1161. # define AO_short_fetch_and_add1(addr) AO_short_fetch_and_add1_acquire(addr)
  1162. # define AO_HAVE_short_fetch_and_add1
  1163. #endif
  1164. #if !defined(AO_HAVE_short_fetch_and_add1) \
  1165. && defined(AO_HAVE_short_fetch_and_add1_write)
  1166. # define AO_short_fetch_and_add1(addr) AO_short_fetch_and_add1_write(addr)
  1167. # define AO_HAVE_short_fetch_and_add1
  1168. #endif
  1169. #if !defined(AO_HAVE_short_fetch_and_add1) \
  1170. && defined(AO_HAVE_short_fetch_and_add1_read)
  1171. # define AO_short_fetch_and_add1(addr) AO_short_fetch_and_add1_read(addr)
  1172. # define AO_HAVE_short_fetch_and_add1
  1173. #endif
  1174. #if defined(AO_HAVE_short_fetch_and_add1_acquire) \
  1175. && defined(AO_HAVE_nop_full) \
  1176. && !defined(AO_HAVE_short_fetch_and_add1_full)
  1177. # define AO_short_fetch_and_add1_full(addr) \
  1178. (AO_nop_full(), AO_short_fetch_and_add1_acquire(addr))
  1179. # define AO_HAVE_short_fetch_and_add1_full
  1180. #endif
  1181. #if !defined(AO_HAVE_short_fetch_and_add1_release_write) \
  1182. && defined(AO_HAVE_short_fetch_and_add1_write)
  1183. # define AO_short_fetch_and_add1_release_write(addr) \
  1184. AO_short_fetch_and_add1_write(addr)
  1185. # define AO_HAVE_short_fetch_and_add1_release_write
  1186. #endif
  1187. #if !defined(AO_HAVE_short_fetch_and_add1_release_write) \
  1188. && defined(AO_HAVE_short_fetch_and_add1_release)
  1189. # define AO_short_fetch_and_add1_release_write(addr) \
  1190. AO_short_fetch_and_add1_release(addr)
  1191. # define AO_HAVE_short_fetch_and_add1_release_write
  1192. #endif
  1193. #if !defined(AO_HAVE_short_fetch_and_add1_acquire_read) \
  1194. && defined(AO_HAVE_short_fetch_and_add1_read)
  1195. # define AO_short_fetch_and_add1_acquire_read(addr) \
  1196. AO_short_fetch_and_add1_read(addr)
  1197. # define AO_HAVE_short_fetch_and_add1_acquire_read
  1198. #endif
  1199. #if !defined(AO_HAVE_short_fetch_and_add1_acquire_read) \
  1200. && defined(AO_HAVE_short_fetch_and_add1_acquire)
  1201. # define AO_short_fetch_and_add1_acquire_read(addr) \
  1202. AO_short_fetch_and_add1_acquire(addr)
  1203. # define AO_HAVE_short_fetch_and_add1_acquire_read
  1204. #endif
  1205. #ifdef AO_NO_DD_ORDERING
  1206. # if defined(AO_HAVE_short_fetch_and_add1_acquire_read)
  1207. # define AO_short_fetch_and_add1_dd_acquire_read(addr) \
  1208. AO_short_fetch_and_add1_acquire_read(addr)
  1209. # define AO_HAVE_short_fetch_and_add1_dd_acquire_read
  1210. # endif
  1211. #else
  1212. # if defined(AO_HAVE_short_fetch_and_add1)
  1213. # define AO_short_fetch_and_add1_dd_acquire_read(addr) \
  1214. AO_short_fetch_and_add1(addr)
  1215. # define AO_HAVE_short_fetch_and_add1_dd_acquire_read
  1216. # endif
  1217. #endif /* !AO_NO_DD_ORDERING */
  1218. /* short_fetch_and_sub1 */
  1219. #if defined(AO_HAVE_short_fetch_and_add_full) \
  1220. && !defined(AO_HAVE_short_fetch_and_sub1_full)
  1221. # define AO_short_fetch_and_sub1_full(addr) \
  1222. AO_short_fetch_and_add_full(addr, (unsigned/**/short)(-1))
  1223. # define AO_HAVE_short_fetch_and_sub1_full
  1224. #endif
  1225. #if defined(AO_HAVE_short_fetch_and_add_release) \
  1226. && !defined(AO_HAVE_short_fetch_and_sub1_release)
  1227. # define AO_short_fetch_and_sub1_release(addr) \
  1228. AO_short_fetch_and_add_release(addr, (unsigned/**/short)(-1))
  1229. # define AO_HAVE_short_fetch_and_sub1_release
  1230. #endif
  1231. #if defined(AO_HAVE_short_fetch_and_add_acquire) \
  1232. && !defined(AO_HAVE_short_fetch_and_sub1_acquire)
  1233. # define AO_short_fetch_and_sub1_acquire(addr) \
  1234. AO_short_fetch_and_add_acquire(addr, (unsigned/**/short)(-1))
  1235. # define AO_HAVE_short_fetch_and_sub1_acquire
  1236. #endif
  1237. #if defined(AO_HAVE_short_fetch_and_add_write) \
  1238. && !defined(AO_HAVE_short_fetch_and_sub1_write)
  1239. # define AO_short_fetch_and_sub1_write(addr) \
  1240. AO_short_fetch_and_add_write(addr, (unsigned/**/short)(-1))
  1241. # define AO_HAVE_short_fetch_and_sub1_write
  1242. #endif
  1243. #if defined(AO_HAVE_short_fetch_and_add_read) \
  1244. && !defined(AO_HAVE_short_fetch_and_sub1_read)
  1245. # define AO_short_fetch_and_sub1_read(addr) \
  1246. AO_short_fetch_and_add_read(addr, (unsigned/**/short)(-1))
  1247. # define AO_HAVE_short_fetch_and_sub1_read
  1248. #endif
  1249. #if defined(AO_HAVE_short_fetch_and_add_release_write) \
  1250. && !defined(AO_HAVE_short_fetch_and_sub1_release_write)
  1251. # define AO_short_fetch_and_sub1_release_write(addr) \
  1252. AO_short_fetch_and_add_release_write(addr, (unsigned/**/short)(-1))
  1253. # define AO_HAVE_short_fetch_and_sub1_release_write
  1254. #endif
  1255. #if defined(AO_HAVE_short_fetch_and_add_acquire_read) \
  1256. && !defined(AO_HAVE_short_fetch_and_sub1_acquire_read)
  1257. # define AO_short_fetch_and_sub1_acquire_read(addr) \
  1258. AO_short_fetch_and_add_acquire_read(addr, (unsigned/**/short)(-1))
  1259. # define AO_HAVE_short_fetch_and_sub1_acquire_read
  1260. #endif
  1261. #if defined(AO_HAVE_short_fetch_and_add) \
  1262. && !defined(AO_HAVE_short_fetch_and_sub1)
  1263. # define AO_short_fetch_and_sub1(addr) \
  1264. AO_short_fetch_and_add(addr, (unsigned/**/short)(-1))
  1265. # define AO_HAVE_short_fetch_and_sub1
  1266. #endif
  1267. #if defined(AO_HAVE_short_fetch_and_sub1_full)
  1268. # if !defined(AO_HAVE_short_fetch_and_sub1_release)
  1269. # define AO_short_fetch_and_sub1_release(addr) \
  1270. AO_short_fetch_and_sub1_full(addr)
  1271. # define AO_HAVE_short_fetch_and_sub1_release
  1272. # endif
  1273. # if !defined(AO_HAVE_short_fetch_and_sub1_acquire)
  1274. # define AO_short_fetch_and_sub1_acquire(addr) \
  1275. AO_short_fetch_and_sub1_full(addr)
  1276. # define AO_HAVE_short_fetch_and_sub1_acquire
  1277. # endif
  1278. # if !defined(AO_HAVE_short_fetch_and_sub1_write)
  1279. # define AO_short_fetch_and_sub1_write(addr) \
  1280. AO_short_fetch_and_sub1_full(addr)
  1281. # define AO_HAVE_short_fetch_and_sub1_write
  1282. # endif
  1283. # if !defined(AO_HAVE_short_fetch_and_sub1_read)
  1284. # define AO_short_fetch_and_sub1_read(addr) \
  1285. AO_short_fetch_and_sub1_full(addr)
  1286. # define AO_HAVE_short_fetch_and_sub1_read
  1287. # endif
  1288. #endif /* AO_HAVE_short_fetch_and_sub1_full */
  1289. #if !defined(AO_HAVE_short_fetch_and_sub1) \
  1290. && defined(AO_HAVE_short_fetch_and_sub1_release)
  1291. # define AO_short_fetch_and_sub1(addr) AO_short_fetch_and_sub1_release(addr)
  1292. # define AO_HAVE_short_fetch_and_sub1
  1293. #endif
  1294. #if !defined(AO_HAVE_short_fetch_and_sub1) \
  1295. && defined(AO_HAVE_short_fetch_and_sub1_acquire)
  1296. # define AO_short_fetch_and_sub1(addr) AO_short_fetch_and_sub1_acquire(addr)
  1297. # define AO_HAVE_short_fetch_and_sub1
  1298. #endif
  1299. #if !defined(AO_HAVE_short_fetch_and_sub1) \
  1300. && defined(AO_HAVE_short_fetch_and_sub1_write)
  1301. # define AO_short_fetch_and_sub1(addr) AO_short_fetch_and_sub1_write(addr)
  1302. # define AO_HAVE_short_fetch_and_sub1
  1303. #endif
  1304. #if !defined(AO_HAVE_short_fetch_and_sub1) \
  1305. && defined(AO_HAVE_short_fetch_and_sub1_read)
  1306. # define AO_short_fetch_and_sub1(addr) AO_short_fetch_and_sub1_read(addr)
  1307. # define AO_HAVE_short_fetch_and_sub1
  1308. #endif
  1309. #if defined(AO_HAVE_short_fetch_and_sub1_acquire) \
  1310. && defined(AO_HAVE_nop_full) \
  1311. && !defined(AO_HAVE_short_fetch_and_sub1_full)
  1312. # define AO_short_fetch_and_sub1_full(addr) \
  1313. (AO_nop_full(), AO_short_fetch_and_sub1_acquire(addr))
  1314. # define AO_HAVE_short_fetch_and_sub1_full
  1315. #endif
  1316. #if !defined(AO_HAVE_short_fetch_and_sub1_release_write) \
  1317. && defined(AO_HAVE_short_fetch_and_sub1_write)
  1318. # define AO_short_fetch_and_sub1_release_write(addr) \
  1319. AO_short_fetch_and_sub1_write(addr)
  1320. # define AO_HAVE_short_fetch_and_sub1_release_write
  1321. #endif
  1322. #if !defined(AO_HAVE_short_fetch_and_sub1_release_write) \
  1323. && defined(AO_HAVE_short_fetch_and_sub1_release)
  1324. # define AO_short_fetch_and_sub1_release_write(addr) \
  1325. AO_short_fetch_and_sub1_release(addr)
  1326. # define AO_HAVE_short_fetch_and_sub1_release_write
  1327. #endif
  1328. #if !defined(AO_HAVE_short_fetch_and_sub1_acquire_read) \
  1329. && defined(AO_HAVE_short_fetch_and_sub1_read)
  1330. # define AO_short_fetch_and_sub1_acquire_read(addr) \
  1331. AO_short_fetch_and_sub1_read(addr)
  1332. # define AO_HAVE_short_fetch_and_sub1_acquire_read
  1333. #endif
  1334. #if !defined(AO_HAVE_short_fetch_and_sub1_acquire_read) \
  1335. && defined(AO_HAVE_short_fetch_and_sub1_acquire)
  1336. # define AO_short_fetch_and_sub1_acquire_read(addr) \
  1337. AO_short_fetch_and_sub1_acquire(addr)
  1338. # define AO_HAVE_short_fetch_and_sub1_acquire_read
  1339. #endif
  1340. #ifdef AO_NO_DD_ORDERING
  1341. # if defined(AO_HAVE_short_fetch_and_sub1_acquire_read)
  1342. # define AO_short_fetch_and_sub1_dd_acquire_read(addr) \
  1343. AO_short_fetch_and_sub1_acquire_read(addr)
  1344. # define AO_HAVE_short_fetch_and_sub1_dd_acquire_read
  1345. # endif
  1346. #else
  1347. # if defined(AO_HAVE_short_fetch_and_sub1)
  1348. # define AO_short_fetch_and_sub1_dd_acquire_read(addr) \
  1349. AO_short_fetch_and_sub1(addr)
  1350. # define AO_HAVE_short_fetch_and_sub1_dd_acquire_read
  1351. # endif
  1352. #endif /* !AO_NO_DD_ORDERING */
  1353. /* short_and */
  1354. #if defined(AO_HAVE_short_compare_and_swap_full) \
  1355. && !defined(AO_HAVE_short_and_full)
  1356. AO_INLINE void
  1357. AO_short_and_full(volatile unsigned/**/short *addr, unsigned/**/short value)
  1358. {
  1359. unsigned/**/short old;
  1360. do
  1361. {
  1362. old = *(unsigned/**/short *)addr;
  1363. }
  1364. while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_full(addr, old,
  1365. old & value)));
  1366. }
  1367. # define AO_HAVE_short_and_full
  1368. #endif
  1369. #if defined(AO_HAVE_short_and_full)
  1370. # if !defined(AO_HAVE_short_and_release)
  1371. # define AO_short_and_release(addr, val) AO_short_and_full(addr, val)
  1372. # define AO_HAVE_short_and_release
  1373. # endif
  1374. # if !defined(AO_HAVE_short_and_acquire)
  1375. # define AO_short_and_acquire(addr, val) AO_short_and_full(addr, val)
  1376. # define AO_HAVE_short_and_acquire
  1377. # endif
  1378. # if !defined(AO_HAVE_short_and_write)
  1379. # define AO_short_and_write(addr, val) AO_short_and_full(addr, val)
  1380. # define AO_HAVE_short_and_write
  1381. # endif
  1382. # if !defined(AO_HAVE_short_and_read)
  1383. # define AO_short_and_read(addr, val) AO_short_and_full(addr, val)
  1384. # define AO_HAVE_short_and_read
  1385. # endif
  1386. #endif /* AO_HAVE_short_and_full */
  1387. #if !defined(AO_HAVE_short_and) && defined(AO_HAVE_short_and_release)
  1388. # define AO_short_and(addr, val) AO_short_and_release(addr, val)
  1389. # define AO_HAVE_short_and
  1390. #endif
  1391. #if !defined(AO_HAVE_short_and) && defined(AO_HAVE_short_and_acquire)
  1392. # define AO_short_and(addr, val) AO_short_and_acquire(addr, val)
  1393. # define AO_HAVE_short_and
  1394. #endif
  1395. #if !defined(AO_HAVE_short_and) && defined(AO_HAVE_short_and_write)
  1396. # define AO_short_and(addr, val) AO_short_and_write(addr, val)
  1397. # define AO_HAVE_short_and
  1398. #endif
  1399. #if !defined(AO_HAVE_short_and) && defined(AO_HAVE_short_and_read)
  1400. # define AO_short_and(addr, val) AO_short_and_read(addr, val)
  1401. # define AO_HAVE_short_and
  1402. #endif
  1403. #if defined(AO_HAVE_short_and_acquire) && defined(AO_HAVE_nop_full) \
  1404. && !defined(AO_HAVE_short_and_full)
  1405. # define AO_short_and_full(addr, val) \
  1406. (AO_nop_full(), AO_short_and_acquire(addr, val))
  1407. # define AO_HAVE_short_and_full
  1408. #endif
  1409. #if !defined(AO_HAVE_short_and_release_write) \
  1410. && defined(AO_HAVE_short_and_write)
  1411. # define AO_short_and_release_write(addr, val) AO_short_and_write(addr, val)
  1412. # define AO_HAVE_short_and_release_write
  1413. #endif
  1414. #if !defined(AO_HAVE_short_and_release_write) \
  1415. && defined(AO_HAVE_short_and_release)
  1416. # define AO_short_and_release_write(addr, val) AO_short_and_release(addr, val)
  1417. # define AO_HAVE_short_and_release_write
  1418. #endif
  1419. #if !defined(AO_HAVE_short_and_acquire_read) \
  1420. && defined(AO_HAVE_short_and_read)
  1421. # define AO_short_and_acquire_read(addr, val) AO_short_and_read(addr, val)
  1422. # define AO_HAVE_short_and_acquire_read
  1423. #endif
  1424. #if !defined(AO_HAVE_short_and_acquire_read) \
  1425. && defined(AO_HAVE_short_and_acquire)
  1426. # define AO_short_and_acquire_read(addr, val) AO_short_and_acquire(addr, val)
  1427. # define AO_HAVE_short_and_acquire_read
  1428. #endif
  1429. /* short_or */
  1430. #if defined(AO_HAVE_short_compare_and_swap_full) \
  1431. && !defined(AO_HAVE_short_or_full)
  1432. AO_INLINE void
  1433. AO_short_or_full(volatile unsigned/**/short *addr, unsigned/**/short value)
  1434. {
  1435. unsigned/**/short old;
  1436. do
  1437. {
  1438. old = *(unsigned/**/short *)addr;
  1439. }
  1440. while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_full(addr, old,
  1441. old | value)));
  1442. }
  1443. # define AO_HAVE_short_or_full
  1444. #endif
  1445. #if defined(AO_HAVE_short_or_full)
  1446. # if !defined(AO_HAVE_short_or_release)
  1447. # define AO_short_or_release(addr, val) AO_short_or_full(addr, val)
  1448. # define AO_HAVE_short_or_release
  1449. # endif
  1450. # if !defined(AO_HAVE_short_or_acquire)
  1451. # define AO_short_or_acquire(addr, val) AO_short_or_full(addr, val)
  1452. # define AO_HAVE_short_or_acquire
  1453. # endif
  1454. # if !defined(AO_HAVE_short_or_write)
  1455. # define AO_short_or_write(addr, val) AO_short_or_full(addr, val)
  1456. # define AO_HAVE_short_or_write
  1457. # endif
  1458. # if !defined(AO_HAVE_short_or_read)
  1459. # define AO_short_or_read(addr, val) AO_short_or_full(addr, val)
  1460. # define AO_HAVE_short_or_read
  1461. # endif
  1462. #endif /* AO_HAVE_short_or_full */
  1463. #if !defined(AO_HAVE_short_or) && defined(AO_HAVE_short_or_release)
  1464. # define AO_short_or(addr, val) AO_short_or_release(addr, val)
  1465. # define AO_HAVE_short_or
  1466. #endif
  1467. #if !defined(AO_HAVE_short_or) && defined(AO_HAVE_short_or_acquire)
  1468. # define AO_short_or(addr, val) AO_short_or_acquire(addr, val)
  1469. # define AO_HAVE_short_or
  1470. #endif
  1471. #if !defined(AO_HAVE_short_or) && defined(AO_HAVE_short_or_write)
  1472. # define AO_short_or(addr, val) AO_short_or_write(addr, val)
  1473. # define AO_HAVE_short_or
  1474. #endif
  1475. #if !defined(AO_HAVE_short_or) && defined(AO_HAVE_short_or_read)
  1476. # define AO_short_or(addr, val) AO_short_or_read(addr, val)
  1477. # define AO_HAVE_short_or
  1478. #endif
  1479. #if defined(AO_HAVE_short_or_acquire) && defined(AO_HAVE_nop_full) \
  1480. && !defined(AO_HAVE_short_or_full)
  1481. # define AO_short_or_full(addr, val) \
  1482. (AO_nop_full(), AO_short_or_acquire(addr, val))
  1483. # define AO_HAVE_short_or_full
  1484. #endif
  1485. #if !defined(AO_HAVE_short_or_release_write) \
  1486. && defined(AO_HAVE_short_or_write)
  1487. # define AO_short_or_release_write(addr, val) AO_short_or_write(addr, val)
  1488. # define AO_HAVE_short_or_release_write
  1489. #endif
  1490. #if !defined(AO_HAVE_short_or_release_write) \
  1491. && defined(AO_HAVE_short_or_release)
  1492. # define AO_short_or_release_write(addr, val) AO_short_or_release(addr, val)
  1493. # define AO_HAVE_short_or_release_write
  1494. #endif
  1495. #if !defined(AO_HAVE_short_or_acquire_read) && defined(AO_HAVE_short_or_read)
  1496. # define AO_short_or_acquire_read(addr, val) AO_short_or_read(addr, val)
  1497. # define AO_HAVE_short_or_acquire_read
  1498. #endif
  1499. #if !defined(AO_HAVE_short_or_acquire_read) \
  1500. && defined(AO_HAVE_short_or_acquire)
  1501. # define AO_short_or_acquire_read(addr, val) AO_short_or_acquire(addr, val)
  1502. # define AO_HAVE_short_or_acquire_read
  1503. #endif
  1504. /* short_xor */
  1505. #if defined(AO_HAVE_short_compare_and_swap_full) \
  1506. && !defined(AO_HAVE_short_xor_full)
  1507. AO_INLINE void
  1508. AO_short_xor_full(volatile unsigned/**/short *addr, unsigned/**/short value)
  1509. {
  1510. unsigned/**/short old;
  1511. do
  1512. {
  1513. old = *(unsigned/**/short *)addr;
  1514. }
  1515. while (AO_EXPECT_FALSE(!AO_short_compare_and_swap_full(addr, old,
  1516. old ^ value)));
  1517. }
  1518. # define AO_HAVE_short_xor_full
  1519. #endif
  1520. #if defined(AO_HAVE_short_xor_full)
  1521. # if !defined(AO_HAVE_short_xor_release)
  1522. # define AO_short_xor_release(addr, val) AO_short_xor_full(addr, val)
  1523. # define AO_HAVE_short_xor_release
  1524. # endif
  1525. # if !defined(AO_HAVE_short_xor_acquire)
  1526. # define AO_short_xor_acquire(addr, val) AO_short_xor_full(addr, val)
  1527. # define AO_HAVE_short_xor_acquire
  1528. # endif
  1529. # if !defined(AO_HAVE_short_xor_write)
  1530. # define AO_short_xor_write(addr, val) AO_short_xor_full(addr, val)
  1531. # define AO_HAVE_short_xor_write
  1532. # endif
  1533. # if !defined(AO_HAVE_short_xor_read)
  1534. # define AO_short_xor_read(addr, val) AO_short_xor_full(addr, val)
  1535. # define AO_HAVE_short_xor_read
  1536. # endif
  1537. #endif /* AO_HAVE_short_xor_full */
  1538. #if !defined(AO_HAVE_short_xor) && defined(AO_HAVE_short_xor_release)
  1539. # define AO_short_xor(addr, val) AO_short_xor_release(addr, val)
  1540. # define AO_HAVE_short_xor
  1541. #endif
  1542. #if !defined(AO_HAVE_short_xor) && defined(AO_HAVE_short_xor_acquire)
  1543. # define AO_short_xor(addr, val) AO_short_xor_acquire(addr, val)
  1544. # define AO_HAVE_short_xor
  1545. #endif
  1546. #if !defined(AO_HAVE_short_xor) && defined(AO_HAVE_short_xor_write)
  1547. # define AO_short_xor(addr, val) AO_short_xor_write(addr, val)
  1548. # define AO_HAVE_short_xor
  1549. #endif
  1550. #if !defined(AO_HAVE_short_xor) && defined(AO_HAVE_short_xor_read)
  1551. # define AO_short_xor(addr, val) AO_short_xor_read(addr, val)
  1552. # define AO_HAVE_short_xor
  1553. #endif
  1554. #if defined(AO_HAVE_short_xor_acquire) && defined(AO_HAVE_nop_full) \
  1555. && !defined(AO_HAVE_short_xor_full)
  1556. # define AO_short_xor_full(addr, val) \
  1557. (AO_nop_full(), AO_short_xor_acquire(addr, val))
  1558. # define AO_HAVE_short_xor_full
  1559. #endif
  1560. #if !defined(AO_HAVE_short_xor_release_write) \
  1561. && defined(AO_HAVE_short_xor_write)
  1562. # define AO_short_xor_release_write(addr, val) AO_short_xor_write(addr, val)
  1563. # define AO_HAVE_short_xor_release_write
  1564. #endif
  1565. #if !defined(AO_HAVE_short_xor_release_write) \
  1566. && defined(AO_HAVE_short_xor_release)
  1567. # define AO_short_xor_release_write(addr, val) AO_short_xor_release(addr, val)
  1568. # define AO_HAVE_short_xor_release_write
  1569. #endif
  1570. #if !defined(AO_HAVE_short_xor_acquire_read) \
  1571. && defined(AO_HAVE_short_xor_read)
  1572. # define AO_short_xor_acquire_read(addr, val) AO_short_xor_read(addr, val)
  1573. # define AO_HAVE_short_xor_acquire_read
  1574. #endif
  1575. #if !defined(AO_HAVE_short_xor_acquire_read) \
  1576. && defined(AO_HAVE_short_xor_acquire)
  1577. # define AO_short_xor_acquire_read(addr, val) AO_short_xor_acquire(addr, val)
  1578. # define AO_HAVE_short_xor_acquire_read
  1579. #endif
  1580. /* short_and/or/xor_dd_acquire_read are meaningless. */
  1581. /*
  1582. * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
  1583. *
  1584. * Permission is hereby granted, free of charge, to any person obtaining a copy
  1585. * of this software and associated documentation files (the "Software"), to deal
  1586. * in the Software without restriction, including without limitation the rights
  1587. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  1588. * copies of the Software, and to permit persons to whom the Software is
  1589. * furnished to do so, subject to the following conditions:
  1590. *
  1591. * The above copyright notice and this permission notice shall be included in
  1592. * all copies or substantial portions of the Software.
  1593. *
  1594. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1595. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1596. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  1597. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1598. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  1599. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  1600. * SOFTWARE.
  1601. */
  1602. /* int_compare_and_swap (based on fetch_compare_and_swap) */
  1603. #if defined(AO_HAVE_int_fetch_compare_and_swap_full) \
  1604. && !defined(AO_HAVE_int_compare_and_swap_full)
  1605. AO_INLINE int
  1606. AO_int_compare_and_swap_full(volatile unsigned *addr, unsigned old_val,
  1607. unsigned new_val)
  1608. {
  1609. return AO_int_fetch_compare_and_swap_full(addr, old_val, new_val)
  1610. == old_val;
  1611. }
  1612. # define AO_HAVE_int_compare_and_swap_full
  1613. #endif
  1614. #if defined(AO_HAVE_int_fetch_compare_and_swap_acquire) \
  1615. && !defined(AO_HAVE_int_compare_and_swap_acquire)
  1616. AO_INLINE int
  1617. AO_int_compare_and_swap_acquire(volatile unsigned *addr, unsigned old_val,
  1618. unsigned new_val)
  1619. {
  1620. return AO_int_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  1621. == old_val;
  1622. }
  1623. # define AO_HAVE_int_compare_and_swap_acquire
  1624. #endif
  1625. #if defined(AO_HAVE_int_fetch_compare_and_swap_release) \
  1626. && !defined(AO_HAVE_int_compare_and_swap_release)
  1627. AO_INLINE int
  1628. AO_int_compare_and_swap_release(volatile unsigned *addr, unsigned old_val,
  1629. unsigned new_val)
  1630. {
  1631. return AO_int_fetch_compare_and_swap_release(addr, old_val, new_val)
  1632. == old_val;
  1633. }
  1634. # define AO_HAVE_int_compare_and_swap_release
  1635. #endif
  1636. #if defined(AO_HAVE_int_fetch_compare_and_swap_write) \
  1637. && !defined(AO_HAVE_int_compare_and_swap_write)
  1638. AO_INLINE int
  1639. AO_int_compare_and_swap_write(volatile unsigned *addr, unsigned old_val,
  1640. unsigned new_val)
  1641. {
  1642. return AO_int_fetch_compare_and_swap_write(addr, old_val, new_val)
  1643. == old_val;
  1644. }
  1645. # define AO_HAVE_int_compare_and_swap_write
  1646. #endif
  1647. #if defined(AO_HAVE_int_fetch_compare_and_swap_read) \
  1648. && !defined(AO_HAVE_int_compare_and_swap_read)
  1649. AO_INLINE int
  1650. AO_int_compare_and_swap_read(volatile unsigned *addr, unsigned old_val,
  1651. unsigned new_val)
  1652. {
  1653. return AO_int_fetch_compare_and_swap_read(addr, old_val, new_val)
  1654. == old_val;
  1655. }
  1656. # define AO_HAVE_int_compare_and_swap_read
  1657. #endif
  1658. #if defined(AO_HAVE_int_fetch_compare_and_swap) \
  1659. && !defined(AO_HAVE_int_compare_and_swap)
  1660. AO_INLINE int
  1661. AO_int_compare_and_swap(volatile unsigned *addr, unsigned old_val,
  1662. unsigned new_val)
  1663. {
  1664. return AO_int_fetch_compare_and_swap(addr, old_val, new_val) == old_val;
  1665. }
  1666. # define AO_HAVE_int_compare_and_swap
  1667. #endif
  1668. #if defined(AO_HAVE_int_fetch_compare_and_swap_release_write) \
  1669. && !defined(AO_HAVE_int_compare_and_swap_release_write)
  1670. AO_INLINE int
  1671. AO_int_compare_and_swap_release_write(volatile unsigned *addr,
  1672. unsigned old_val, unsigned new_val)
  1673. {
  1674. return AO_int_fetch_compare_and_swap_release_write(addr, old_val,
  1675. new_val) == old_val;
  1676. }
  1677. # define AO_HAVE_int_compare_and_swap_release_write
  1678. #endif
  1679. #if defined(AO_HAVE_int_fetch_compare_and_swap_acquire_read) \
  1680. && !defined(AO_HAVE_int_compare_and_swap_acquire_read)
  1681. AO_INLINE int
  1682. AO_int_compare_and_swap_acquire_read(volatile unsigned *addr,
  1683. unsigned old_val, unsigned new_val)
  1684. {
  1685. return AO_int_fetch_compare_and_swap_acquire_read(addr, old_val,
  1686. new_val) == old_val;
  1687. }
  1688. # define AO_HAVE_int_compare_and_swap_acquire_read
  1689. #endif
  1690. #if defined(AO_HAVE_int_fetch_compare_and_swap_dd_acquire_read) \
  1691. && !defined(AO_HAVE_int_compare_and_swap_dd_acquire_read)
  1692. AO_INLINE int
  1693. AO_int_compare_and_swap_dd_acquire_read(volatile unsigned *addr,
  1694. unsigned old_val, unsigned new_val)
  1695. {
  1696. return AO_int_fetch_compare_and_swap_dd_acquire_read(addr, old_val,
  1697. new_val) == old_val;
  1698. }
  1699. # define AO_HAVE_int_compare_and_swap_dd_acquire_read
  1700. #endif
  1701. /* int_fetch_and_add */
  1702. /* We first try to implement fetch_and_add variants in terms of the */
  1703. /* corresponding compare_and_swap variants to minimize adding barriers. */
  1704. #if defined(AO_HAVE_int_compare_and_swap_full) \
  1705. && !defined(AO_HAVE_int_fetch_and_add_full)
  1706. AO_INLINE unsigned
  1707. AO_int_fetch_and_add_full(volatile unsigned *addr, unsigned incr)
  1708. {
  1709. unsigned old;
  1710. do
  1711. {
  1712. old = *(unsigned *)addr;
  1713. }
  1714. while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_full(addr, old,
  1715. old + incr)));
  1716. return old;
  1717. }
  1718. # define AO_HAVE_int_fetch_and_add_full
  1719. #endif
  1720. #if defined(AO_HAVE_int_compare_and_swap_acquire) \
  1721. && !defined(AO_HAVE_int_fetch_and_add_acquire)
  1722. AO_INLINE unsigned
  1723. AO_int_fetch_and_add_acquire(volatile unsigned *addr, unsigned incr)
  1724. {
  1725. unsigned old;
  1726. do
  1727. {
  1728. old = *(unsigned *)addr;
  1729. }
  1730. while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_acquire(addr, old,
  1731. old + incr)));
  1732. return old;
  1733. }
  1734. # define AO_HAVE_int_fetch_and_add_acquire
  1735. #endif
  1736. #if defined(AO_HAVE_int_compare_and_swap_release) \
  1737. && !defined(AO_HAVE_int_fetch_and_add_release)
  1738. AO_INLINE unsigned
  1739. AO_int_fetch_and_add_release(volatile unsigned *addr, unsigned incr)
  1740. {
  1741. unsigned old;
  1742. do
  1743. {
  1744. old = *(unsigned *)addr;
  1745. }
  1746. while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_release(addr, old,
  1747. old + incr)));
  1748. return old;
  1749. }
  1750. # define AO_HAVE_int_fetch_and_add_release
  1751. #endif
  1752. #if defined(AO_HAVE_int_compare_and_swap) \
  1753. && !defined(AO_HAVE_int_fetch_and_add)
  1754. AO_INLINE unsigned
  1755. AO_int_fetch_and_add(volatile unsigned *addr, unsigned incr)
  1756. {
  1757. unsigned old;
  1758. do
  1759. {
  1760. old = *(unsigned *)addr;
  1761. }
  1762. while (AO_EXPECT_FALSE(!AO_int_compare_and_swap(addr, old,
  1763. old + incr)));
  1764. return old;
  1765. }
  1766. # define AO_HAVE_int_fetch_and_add
  1767. #endif
  1768. #if defined(AO_HAVE_int_fetch_and_add_full)
  1769. # if !defined(AO_HAVE_int_fetch_and_add_release)
  1770. # define AO_int_fetch_and_add_release(addr, val) \
  1771. AO_int_fetch_and_add_full(addr, val)
  1772. # define AO_HAVE_int_fetch_and_add_release
  1773. # endif
  1774. # if !defined(AO_HAVE_int_fetch_and_add_acquire)
  1775. # define AO_int_fetch_and_add_acquire(addr, val) \
  1776. AO_int_fetch_and_add_full(addr, val)
  1777. # define AO_HAVE_int_fetch_and_add_acquire
  1778. # endif
  1779. # if !defined(AO_HAVE_int_fetch_and_add_write)
  1780. # define AO_int_fetch_and_add_write(addr, val) \
  1781. AO_int_fetch_and_add_full(addr, val)
  1782. # define AO_HAVE_int_fetch_and_add_write
  1783. # endif
  1784. # if !defined(AO_HAVE_int_fetch_and_add_read)
  1785. # define AO_int_fetch_and_add_read(addr, val) \
  1786. AO_int_fetch_and_add_full(addr, val)
  1787. # define AO_HAVE_int_fetch_and_add_read
  1788. # endif
  1789. #endif /* AO_HAVE_int_fetch_and_add_full */
  1790. #if defined(AO_HAVE_int_fetch_and_add) && defined(AO_HAVE_nop_full) \
  1791. && !defined(AO_HAVE_int_fetch_and_add_acquire)
  1792. AO_INLINE unsigned
  1793. AO_int_fetch_and_add_acquire(volatile unsigned *addr, unsigned incr)
  1794. {
  1795. unsigned result = AO_int_fetch_and_add(addr, incr);
  1796. AO_nop_full();
  1797. return result;
  1798. }
  1799. # define AO_HAVE_int_fetch_and_add_acquire
  1800. #endif
  1801. #if defined(AO_HAVE_int_fetch_and_add) && defined(AO_HAVE_nop_full) \
  1802. && !defined(AO_HAVE_int_fetch_and_add_release)
  1803. # define AO_int_fetch_and_add_release(addr, incr) \
  1804. (AO_nop_full(), AO_int_fetch_and_add(addr, incr))
  1805. # define AO_HAVE_int_fetch_and_add_release
  1806. #endif
  1807. #if !defined(AO_HAVE_int_fetch_and_add) \
  1808. && defined(AO_HAVE_int_fetch_and_add_release)
  1809. # define AO_int_fetch_and_add(addr, val) \
  1810. AO_int_fetch_and_add_release(addr, val)
  1811. # define AO_HAVE_int_fetch_and_add
  1812. #endif
  1813. #if !defined(AO_HAVE_int_fetch_and_add) \
  1814. && defined(AO_HAVE_int_fetch_and_add_acquire)
  1815. # define AO_int_fetch_and_add(addr, val) \
  1816. AO_int_fetch_and_add_acquire(addr, val)
  1817. # define AO_HAVE_int_fetch_and_add
  1818. #endif
  1819. #if !defined(AO_HAVE_int_fetch_and_add) \
  1820. && defined(AO_HAVE_int_fetch_and_add_write)
  1821. # define AO_int_fetch_and_add(addr, val) \
  1822. AO_int_fetch_and_add_write(addr, val)
  1823. # define AO_HAVE_int_fetch_and_add
  1824. #endif
  1825. #if !defined(AO_HAVE_int_fetch_and_add) \
  1826. && defined(AO_HAVE_int_fetch_and_add_read)
  1827. # define AO_int_fetch_and_add(addr, val) \
  1828. AO_int_fetch_and_add_read(addr, val)
  1829. # define AO_HAVE_int_fetch_and_add
  1830. #endif
  1831. #if defined(AO_HAVE_int_fetch_and_add_acquire) \
  1832. && defined(AO_HAVE_nop_full) && !defined(AO_HAVE_int_fetch_and_add_full)
  1833. # define AO_int_fetch_and_add_full(addr, val) \
  1834. (AO_nop_full(), AO_int_fetch_and_add_acquire(addr, val))
  1835. # define AO_HAVE_int_fetch_and_add_full
  1836. #endif
  1837. #if !defined(AO_HAVE_int_fetch_and_add_release_write) \
  1838. && defined(AO_HAVE_int_fetch_and_add_write)
  1839. # define AO_int_fetch_and_add_release_write(addr, val) \
  1840. AO_int_fetch_and_add_write(addr, val)
  1841. # define AO_HAVE_int_fetch_and_add_release_write
  1842. #endif
  1843. #if !defined(AO_HAVE_int_fetch_and_add_release_write) \
  1844. && defined(AO_HAVE_int_fetch_and_add_release)
  1845. # define AO_int_fetch_and_add_release_write(addr, val) \
  1846. AO_int_fetch_and_add_release(addr, val)
  1847. # define AO_HAVE_int_fetch_and_add_release_write
  1848. #endif
  1849. #if !defined(AO_HAVE_int_fetch_and_add_acquire_read) \
  1850. && defined(AO_HAVE_int_fetch_and_add_read)
  1851. # define AO_int_fetch_and_add_acquire_read(addr, val) \
  1852. AO_int_fetch_and_add_read(addr, val)
  1853. # define AO_HAVE_int_fetch_and_add_acquire_read
  1854. #endif
  1855. #if !defined(AO_HAVE_int_fetch_and_add_acquire_read) \
  1856. && defined(AO_HAVE_int_fetch_and_add_acquire)
  1857. # define AO_int_fetch_and_add_acquire_read(addr, val) \
  1858. AO_int_fetch_and_add_acquire(addr, val)
  1859. # define AO_HAVE_int_fetch_and_add_acquire_read
  1860. #endif
  1861. #ifdef AO_NO_DD_ORDERING
  1862. # if defined(AO_HAVE_int_fetch_and_add_acquire_read)
  1863. # define AO_int_fetch_and_add_dd_acquire_read(addr, val) \
  1864. AO_int_fetch_and_add_acquire_read(addr, val)
  1865. # define AO_HAVE_int_fetch_and_add_dd_acquire_read
  1866. # endif
  1867. #else
  1868. # if defined(AO_HAVE_int_fetch_and_add)
  1869. # define AO_int_fetch_and_add_dd_acquire_read(addr, val) \
  1870. AO_int_fetch_and_add(addr, val)
  1871. # define AO_HAVE_int_fetch_and_add_dd_acquire_read
  1872. # endif
  1873. #endif /* !AO_NO_DD_ORDERING */
  1874. /* int_fetch_and_add1 */
  1875. #if defined(AO_HAVE_int_fetch_and_add_full) \
  1876. && !defined(AO_HAVE_int_fetch_and_add1_full)
  1877. # define AO_int_fetch_and_add1_full(addr) \
  1878. AO_int_fetch_and_add_full(addr, 1)
  1879. # define AO_HAVE_int_fetch_and_add1_full
  1880. #endif
  1881. #if defined(AO_HAVE_int_fetch_and_add_release) \
  1882. && !defined(AO_HAVE_int_fetch_and_add1_release)
  1883. # define AO_int_fetch_and_add1_release(addr) \
  1884. AO_int_fetch_and_add_release(addr, 1)
  1885. # define AO_HAVE_int_fetch_and_add1_release
  1886. #endif
  1887. #if defined(AO_HAVE_int_fetch_and_add_acquire) \
  1888. && !defined(AO_HAVE_int_fetch_and_add1_acquire)
  1889. # define AO_int_fetch_and_add1_acquire(addr) \
  1890. AO_int_fetch_and_add_acquire(addr, 1)
  1891. # define AO_HAVE_int_fetch_and_add1_acquire
  1892. #endif
  1893. #if defined(AO_HAVE_int_fetch_and_add_write) \
  1894. && !defined(AO_HAVE_int_fetch_and_add1_write)
  1895. # define AO_int_fetch_and_add1_write(addr) \
  1896. AO_int_fetch_and_add_write(addr, 1)
  1897. # define AO_HAVE_int_fetch_and_add1_write
  1898. #endif
  1899. #if defined(AO_HAVE_int_fetch_and_add_read) \
  1900. && !defined(AO_HAVE_int_fetch_and_add1_read)
  1901. # define AO_int_fetch_and_add1_read(addr) \
  1902. AO_int_fetch_and_add_read(addr, 1)
  1903. # define AO_HAVE_int_fetch_and_add1_read
  1904. #endif
  1905. #if defined(AO_HAVE_int_fetch_and_add_release_write) \
  1906. && !defined(AO_HAVE_int_fetch_and_add1_release_write)
  1907. # define AO_int_fetch_and_add1_release_write(addr) \
  1908. AO_int_fetch_and_add_release_write(addr, 1)
  1909. # define AO_HAVE_int_fetch_and_add1_release_write
  1910. #endif
  1911. #if defined(AO_HAVE_int_fetch_and_add_acquire_read) \
  1912. && !defined(AO_HAVE_int_fetch_and_add1_acquire_read)
  1913. # define AO_int_fetch_and_add1_acquire_read(addr) \
  1914. AO_int_fetch_and_add_acquire_read(addr, 1)
  1915. # define AO_HAVE_int_fetch_and_add1_acquire_read
  1916. #endif
  1917. #if defined(AO_HAVE_int_fetch_and_add) \
  1918. && !defined(AO_HAVE_int_fetch_and_add1)
  1919. # define AO_int_fetch_and_add1(addr) AO_int_fetch_and_add(addr, 1)
  1920. # define AO_HAVE_int_fetch_and_add1
  1921. #endif
  1922. #if defined(AO_HAVE_int_fetch_and_add1_full)
  1923. # if !defined(AO_HAVE_int_fetch_and_add1_release)
  1924. # define AO_int_fetch_and_add1_release(addr) \
  1925. AO_int_fetch_and_add1_full(addr)
  1926. # define AO_HAVE_int_fetch_and_add1_release
  1927. # endif
  1928. # if !defined(AO_HAVE_int_fetch_and_add1_acquire)
  1929. # define AO_int_fetch_and_add1_acquire(addr) \
  1930. AO_int_fetch_and_add1_full(addr)
  1931. # define AO_HAVE_int_fetch_and_add1_acquire
  1932. # endif
  1933. # if !defined(AO_HAVE_int_fetch_and_add1_write)
  1934. # define AO_int_fetch_and_add1_write(addr) \
  1935. AO_int_fetch_and_add1_full(addr)
  1936. # define AO_HAVE_int_fetch_and_add1_write
  1937. # endif
  1938. # if !defined(AO_HAVE_int_fetch_and_add1_read)
  1939. # define AO_int_fetch_and_add1_read(addr) \
  1940. AO_int_fetch_and_add1_full(addr)
  1941. # define AO_HAVE_int_fetch_and_add1_read
  1942. # endif
  1943. #endif /* AO_HAVE_int_fetch_and_add1_full */
  1944. #if !defined(AO_HAVE_int_fetch_and_add1) \
  1945. && defined(AO_HAVE_int_fetch_and_add1_release)
  1946. # define AO_int_fetch_and_add1(addr) AO_int_fetch_and_add1_release(addr)
  1947. # define AO_HAVE_int_fetch_and_add1
  1948. #endif
  1949. #if !defined(AO_HAVE_int_fetch_and_add1) \
  1950. && defined(AO_HAVE_int_fetch_and_add1_acquire)
  1951. # define AO_int_fetch_and_add1(addr) AO_int_fetch_and_add1_acquire(addr)
  1952. # define AO_HAVE_int_fetch_and_add1
  1953. #endif
  1954. #if !defined(AO_HAVE_int_fetch_and_add1) \
  1955. && defined(AO_HAVE_int_fetch_and_add1_write)
  1956. # define AO_int_fetch_and_add1(addr) AO_int_fetch_and_add1_write(addr)
  1957. # define AO_HAVE_int_fetch_and_add1
  1958. #endif
  1959. #if !defined(AO_HAVE_int_fetch_and_add1) \
  1960. && defined(AO_HAVE_int_fetch_and_add1_read)
  1961. # define AO_int_fetch_and_add1(addr) AO_int_fetch_and_add1_read(addr)
  1962. # define AO_HAVE_int_fetch_and_add1
  1963. #endif
  1964. #if defined(AO_HAVE_int_fetch_and_add1_acquire) \
  1965. && defined(AO_HAVE_nop_full) \
  1966. && !defined(AO_HAVE_int_fetch_and_add1_full)
  1967. # define AO_int_fetch_and_add1_full(addr) \
  1968. (AO_nop_full(), AO_int_fetch_and_add1_acquire(addr))
  1969. # define AO_HAVE_int_fetch_and_add1_full
  1970. #endif
  1971. #if !defined(AO_HAVE_int_fetch_and_add1_release_write) \
  1972. && defined(AO_HAVE_int_fetch_and_add1_write)
  1973. # define AO_int_fetch_and_add1_release_write(addr) \
  1974. AO_int_fetch_and_add1_write(addr)
  1975. # define AO_HAVE_int_fetch_and_add1_release_write
  1976. #endif
  1977. #if !defined(AO_HAVE_int_fetch_and_add1_release_write) \
  1978. && defined(AO_HAVE_int_fetch_and_add1_release)
  1979. # define AO_int_fetch_and_add1_release_write(addr) \
  1980. AO_int_fetch_and_add1_release(addr)
  1981. # define AO_HAVE_int_fetch_and_add1_release_write
  1982. #endif
  1983. #if !defined(AO_HAVE_int_fetch_and_add1_acquire_read) \
  1984. && defined(AO_HAVE_int_fetch_and_add1_read)
  1985. # define AO_int_fetch_and_add1_acquire_read(addr) \
  1986. AO_int_fetch_and_add1_read(addr)
  1987. # define AO_HAVE_int_fetch_and_add1_acquire_read
  1988. #endif
  1989. #if !defined(AO_HAVE_int_fetch_and_add1_acquire_read) \
  1990. && defined(AO_HAVE_int_fetch_and_add1_acquire)
  1991. # define AO_int_fetch_and_add1_acquire_read(addr) \
  1992. AO_int_fetch_and_add1_acquire(addr)
  1993. # define AO_HAVE_int_fetch_and_add1_acquire_read
  1994. #endif
  1995. #ifdef AO_NO_DD_ORDERING
  1996. # if defined(AO_HAVE_int_fetch_and_add1_acquire_read)
  1997. # define AO_int_fetch_and_add1_dd_acquire_read(addr) \
  1998. AO_int_fetch_and_add1_acquire_read(addr)
  1999. # define AO_HAVE_int_fetch_and_add1_dd_acquire_read
  2000. # endif
  2001. #else
  2002. # if defined(AO_HAVE_int_fetch_and_add1)
  2003. # define AO_int_fetch_and_add1_dd_acquire_read(addr) \
  2004. AO_int_fetch_and_add1(addr)
  2005. # define AO_HAVE_int_fetch_and_add1_dd_acquire_read
  2006. # endif
  2007. #endif /* !AO_NO_DD_ORDERING */
  2008. /* int_fetch_and_sub1 */
  2009. #if defined(AO_HAVE_int_fetch_and_add_full) \
  2010. && !defined(AO_HAVE_int_fetch_and_sub1_full)
  2011. # define AO_int_fetch_and_sub1_full(addr) \
  2012. AO_int_fetch_and_add_full(addr, (unsigned)(-1))
  2013. # define AO_HAVE_int_fetch_and_sub1_full
  2014. #endif
  2015. #if defined(AO_HAVE_int_fetch_and_add_release) \
  2016. && !defined(AO_HAVE_int_fetch_and_sub1_release)
  2017. # define AO_int_fetch_and_sub1_release(addr) \
  2018. AO_int_fetch_and_add_release(addr, (unsigned)(-1))
  2019. # define AO_HAVE_int_fetch_and_sub1_release
  2020. #endif
  2021. #if defined(AO_HAVE_int_fetch_and_add_acquire) \
  2022. && !defined(AO_HAVE_int_fetch_and_sub1_acquire)
  2023. # define AO_int_fetch_and_sub1_acquire(addr) \
  2024. AO_int_fetch_and_add_acquire(addr, (unsigned)(-1))
  2025. # define AO_HAVE_int_fetch_and_sub1_acquire
  2026. #endif
  2027. #if defined(AO_HAVE_int_fetch_and_add_write) \
  2028. && !defined(AO_HAVE_int_fetch_and_sub1_write)
  2029. # define AO_int_fetch_and_sub1_write(addr) \
  2030. AO_int_fetch_and_add_write(addr, (unsigned)(-1))
  2031. # define AO_HAVE_int_fetch_and_sub1_write
  2032. #endif
  2033. #if defined(AO_HAVE_int_fetch_and_add_read) \
  2034. && !defined(AO_HAVE_int_fetch_and_sub1_read)
  2035. # define AO_int_fetch_and_sub1_read(addr) \
  2036. AO_int_fetch_and_add_read(addr, (unsigned)(-1))
  2037. # define AO_HAVE_int_fetch_and_sub1_read
  2038. #endif
  2039. #if defined(AO_HAVE_int_fetch_and_add_release_write) \
  2040. && !defined(AO_HAVE_int_fetch_and_sub1_release_write)
  2041. # define AO_int_fetch_and_sub1_release_write(addr) \
  2042. AO_int_fetch_and_add_release_write(addr, (unsigned)(-1))
  2043. # define AO_HAVE_int_fetch_and_sub1_release_write
  2044. #endif
  2045. #if defined(AO_HAVE_int_fetch_and_add_acquire_read) \
  2046. && !defined(AO_HAVE_int_fetch_and_sub1_acquire_read)
  2047. # define AO_int_fetch_and_sub1_acquire_read(addr) \
  2048. AO_int_fetch_and_add_acquire_read(addr, (unsigned)(-1))
  2049. # define AO_HAVE_int_fetch_and_sub1_acquire_read
  2050. #endif
  2051. #if defined(AO_HAVE_int_fetch_and_add) \
  2052. && !defined(AO_HAVE_int_fetch_and_sub1)
  2053. # define AO_int_fetch_and_sub1(addr) \
  2054. AO_int_fetch_and_add(addr, (unsigned)(-1))
  2055. # define AO_HAVE_int_fetch_and_sub1
  2056. #endif
  2057. #if defined(AO_HAVE_int_fetch_and_sub1_full)
  2058. # if !defined(AO_HAVE_int_fetch_and_sub1_release)
  2059. # define AO_int_fetch_and_sub1_release(addr) \
  2060. AO_int_fetch_and_sub1_full(addr)
  2061. # define AO_HAVE_int_fetch_and_sub1_release
  2062. # endif
  2063. # if !defined(AO_HAVE_int_fetch_and_sub1_acquire)
  2064. # define AO_int_fetch_and_sub1_acquire(addr) \
  2065. AO_int_fetch_and_sub1_full(addr)
  2066. # define AO_HAVE_int_fetch_and_sub1_acquire
  2067. # endif
  2068. # if !defined(AO_HAVE_int_fetch_and_sub1_write)
  2069. # define AO_int_fetch_and_sub1_write(addr) \
  2070. AO_int_fetch_and_sub1_full(addr)
  2071. # define AO_HAVE_int_fetch_and_sub1_write
  2072. # endif
  2073. # if !defined(AO_HAVE_int_fetch_and_sub1_read)
  2074. # define AO_int_fetch_and_sub1_read(addr) \
  2075. AO_int_fetch_and_sub1_full(addr)
  2076. # define AO_HAVE_int_fetch_and_sub1_read
  2077. # endif
  2078. #endif /* AO_HAVE_int_fetch_and_sub1_full */
  2079. #if !defined(AO_HAVE_int_fetch_and_sub1) \
  2080. && defined(AO_HAVE_int_fetch_and_sub1_release)
  2081. # define AO_int_fetch_and_sub1(addr) AO_int_fetch_and_sub1_release(addr)
  2082. # define AO_HAVE_int_fetch_and_sub1
  2083. #endif
  2084. #if !defined(AO_HAVE_int_fetch_and_sub1) \
  2085. && defined(AO_HAVE_int_fetch_and_sub1_acquire)
  2086. # define AO_int_fetch_and_sub1(addr) AO_int_fetch_and_sub1_acquire(addr)
  2087. # define AO_HAVE_int_fetch_and_sub1
  2088. #endif
  2089. #if !defined(AO_HAVE_int_fetch_and_sub1) \
  2090. && defined(AO_HAVE_int_fetch_and_sub1_write)
  2091. # define AO_int_fetch_and_sub1(addr) AO_int_fetch_and_sub1_write(addr)
  2092. # define AO_HAVE_int_fetch_and_sub1
  2093. #endif
  2094. #if !defined(AO_HAVE_int_fetch_and_sub1) \
  2095. && defined(AO_HAVE_int_fetch_and_sub1_read)
  2096. # define AO_int_fetch_and_sub1(addr) AO_int_fetch_and_sub1_read(addr)
  2097. # define AO_HAVE_int_fetch_and_sub1
  2098. #endif
  2099. #if defined(AO_HAVE_int_fetch_and_sub1_acquire) \
  2100. && defined(AO_HAVE_nop_full) \
  2101. && !defined(AO_HAVE_int_fetch_and_sub1_full)
  2102. # define AO_int_fetch_and_sub1_full(addr) \
  2103. (AO_nop_full(), AO_int_fetch_and_sub1_acquire(addr))
  2104. # define AO_HAVE_int_fetch_and_sub1_full
  2105. #endif
  2106. #if !defined(AO_HAVE_int_fetch_and_sub1_release_write) \
  2107. && defined(AO_HAVE_int_fetch_and_sub1_write)
  2108. # define AO_int_fetch_and_sub1_release_write(addr) \
  2109. AO_int_fetch_and_sub1_write(addr)
  2110. # define AO_HAVE_int_fetch_and_sub1_release_write
  2111. #endif
  2112. #if !defined(AO_HAVE_int_fetch_and_sub1_release_write) \
  2113. && defined(AO_HAVE_int_fetch_and_sub1_release)
  2114. # define AO_int_fetch_and_sub1_release_write(addr) \
  2115. AO_int_fetch_and_sub1_release(addr)
  2116. # define AO_HAVE_int_fetch_and_sub1_release_write
  2117. #endif
  2118. #if !defined(AO_HAVE_int_fetch_and_sub1_acquire_read) \
  2119. && defined(AO_HAVE_int_fetch_and_sub1_read)
  2120. # define AO_int_fetch_and_sub1_acquire_read(addr) \
  2121. AO_int_fetch_and_sub1_read(addr)
  2122. # define AO_HAVE_int_fetch_and_sub1_acquire_read
  2123. #endif
  2124. #if !defined(AO_HAVE_int_fetch_and_sub1_acquire_read) \
  2125. && defined(AO_HAVE_int_fetch_and_sub1_acquire)
  2126. # define AO_int_fetch_and_sub1_acquire_read(addr) \
  2127. AO_int_fetch_and_sub1_acquire(addr)
  2128. # define AO_HAVE_int_fetch_and_sub1_acquire_read
  2129. #endif
  2130. #ifdef AO_NO_DD_ORDERING
  2131. # if defined(AO_HAVE_int_fetch_and_sub1_acquire_read)
  2132. # define AO_int_fetch_and_sub1_dd_acquire_read(addr) \
  2133. AO_int_fetch_and_sub1_acquire_read(addr)
  2134. # define AO_HAVE_int_fetch_and_sub1_dd_acquire_read
  2135. # endif
  2136. #else
  2137. # if defined(AO_HAVE_int_fetch_and_sub1)
  2138. # define AO_int_fetch_and_sub1_dd_acquire_read(addr) \
  2139. AO_int_fetch_and_sub1(addr)
  2140. # define AO_HAVE_int_fetch_and_sub1_dd_acquire_read
  2141. # endif
  2142. #endif /* !AO_NO_DD_ORDERING */
  2143. /* int_and */
  2144. #if defined(AO_HAVE_int_compare_and_swap_full) \
  2145. && !defined(AO_HAVE_int_and_full)
  2146. AO_INLINE void
  2147. AO_int_and_full(volatile unsigned *addr, unsigned value)
  2148. {
  2149. unsigned old;
  2150. do
  2151. {
  2152. old = *(unsigned *)addr;
  2153. }
  2154. while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_full(addr, old,
  2155. old & value)));
  2156. }
  2157. # define AO_HAVE_int_and_full
  2158. #endif
  2159. #if defined(AO_HAVE_int_and_full)
  2160. # if !defined(AO_HAVE_int_and_release)
  2161. # define AO_int_and_release(addr, val) AO_int_and_full(addr, val)
  2162. # define AO_HAVE_int_and_release
  2163. # endif
  2164. # if !defined(AO_HAVE_int_and_acquire)
  2165. # define AO_int_and_acquire(addr, val) AO_int_and_full(addr, val)
  2166. # define AO_HAVE_int_and_acquire
  2167. # endif
  2168. # if !defined(AO_HAVE_int_and_write)
  2169. # define AO_int_and_write(addr, val) AO_int_and_full(addr, val)
  2170. # define AO_HAVE_int_and_write
  2171. # endif
  2172. # if !defined(AO_HAVE_int_and_read)
  2173. # define AO_int_and_read(addr, val) AO_int_and_full(addr, val)
  2174. # define AO_HAVE_int_and_read
  2175. # endif
  2176. #endif /* AO_HAVE_int_and_full */
  2177. #if !defined(AO_HAVE_int_and) && defined(AO_HAVE_int_and_release)
  2178. # define AO_int_and(addr, val) AO_int_and_release(addr, val)
  2179. # define AO_HAVE_int_and
  2180. #endif
  2181. #if !defined(AO_HAVE_int_and) && defined(AO_HAVE_int_and_acquire)
  2182. # define AO_int_and(addr, val) AO_int_and_acquire(addr, val)
  2183. # define AO_HAVE_int_and
  2184. #endif
  2185. #if !defined(AO_HAVE_int_and) && defined(AO_HAVE_int_and_write)
  2186. # define AO_int_and(addr, val) AO_int_and_write(addr, val)
  2187. # define AO_HAVE_int_and
  2188. #endif
  2189. #if !defined(AO_HAVE_int_and) && defined(AO_HAVE_int_and_read)
  2190. # define AO_int_and(addr, val) AO_int_and_read(addr, val)
  2191. # define AO_HAVE_int_and
  2192. #endif
  2193. #if defined(AO_HAVE_int_and_acquire) && defined(AO_HAVE_nop_full) \
  2194. && !defined(AO_HAVE_int_and_full)
  2195. # define AO_int_and_full(addr, val) \
  2196. (AO_nop_full(), AO_int_and_acquire(addr, val))
  2197. # define AO_HAVE_int_and_full
  2198. #endif
  2199. #if !defined(AO_HAVE_int_and_release_write) \
  2200. && defined(AO_HAVE_int_and_write)
  2201. # define AO_int_and_release_write(addr, val) AO_int_and_write(addr, val)
  2202. # define AO_HAVE_int_and_release_write
  2203. #endif
  2204. #if !defined(AO_HAVE_int_and_release_write) \
  2205. && defined(AO_HAVE_int_and_release)
  2206. # define AO_int_and_release_write(addr, val) AO_int_and_release(addr, val)
  2207. # define AO_HAVE_int_and_release_write
  2208. #endif
  2209. #if !defined(AO_HAVE_int_and_acquire_read) \
  2210. && defined(AO_HAVE_int_and_read)
  2211. # define AO_int_and_acquire_read(addr, val) AO_int_and_read(addr, val)
  2212. # define AO_HAVE_int_and_acquire_read
  2213. #endif
  2214. #if !defined(AO_HAVE_int_and_acquire_read) \
  2215. && defined(AO_HAVE_int_and_acquire)
  2216. # define AO_int_and_acquire_read(addr, val) AO_int_and_acquire(addr, val)
  2217. # define AO_HAVE_int_and_acquire_read
  2218. #endif
  2219. /* int_or */
  2220. #if defined(AO_HAVE_int_compare_and_swap_full) \
  2221. && !defined(AO_HAVE_int_or_full)
  2222. AO_INLINE void
  2223. AO_int_or_full(volatile unsigned *addr, unsigned value)
  2224. {
  2225. unsigned old;
  2226. do
  2227. {
  2228. old = *(unsigned *)addr;
  2229. }
  2230. while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_full(addr, old,
  2231. old | value)));
  2232. }
  2233. # define AO_HAVE_int_or_full
  2234. #endif
  2235. #if defined(AO_HAVE_int_or_full)
  2236. # if !defined(AO_HAVE_int_or_release)
  2237. # define AO_int_or_release(addr, val) AO_int_or_full(addr, val)
  2238. # define AO_HAVE_int_or_release
  2239. # endif
  2240. # if !defined(AO_HAVE_int_or_acquire)
  2241. # define AO_int_or_acquire(addr, val) AO_int_or_full(addr, val)
  2242. # define AO_HAVE_int_or_acquire
  2243. # endif
  2244. # if !defined(AO_HAVE_int_or_write)
  2245. # define AO_int_or_write(addr, val) AO_int_or_full(addr, val)
  2246. # define AO_HAVE_int_or_write
  2247. # endif
  2248. # if !defined(AO_HAVE_int_or_read)
  2249. # define AO_int_or_read(addr, val) AO_int_or_full(addr, val)
  2250. # define AO_HAVE_int_or_read
  2251. # endif
  2252. #endif /* AO_HAVE_int_or_full */
  2253. #if !defined(AO_HAVE_int_or) && defined(AO_HAVE_int_or_release)
  2254. # define AO_int_or(addr, val) AO_int_or_release(addr, val)
  2255. # define AO_HAVE_int_or
  2256. #endif
  2257. #if !defined(AO_HAVE_int_or) && defined(AO_HAVE_int_or_acquire)
  2258. # define AO_int_or(addr, val) AO_int_or_acquire(addr, val)
  2259. # define AO_HAVE_int_or
  2260. #endif
  2261. #if !defined(AO_HAVE_int_or) && defined(AO_HAVE_int_or_write)
  2262. # define AO_int_or(addr, val) AO_int_or_write(addr, val)
  2263. # define AO_HAVE_int_or
  2264. #endif
  2265. #if !defined(AO_HAVE_int_or) && defined(AO_HAVE_int_or_read)
  2266. # define AO_int_or(addr, val) AO_int_or_read(addr, val)
  2267. # define AO_HAVE_int_or
  2268. #endif
  2269. #if defined(AO_HAVE_int_or_acquire) && defined(AO_HAVE_nop_full) \
  2270. && !defined(AO_HAVE_int_or_full)
  2271. # define AO_int_or_full(addr, val) \
  2272. (AO_nop_full(), AO_int_or_acquire(addr, val))
  2273. # define AO_HAVE_int_or_full
  2274. #endif
  2275. #if !defined(AO_HAVE_int_or_release_write) \
  2276. && defined(AO_HAVE_int_or_write)
  2277. # define AO_int_or_release_write(addr, val) AO_int_or_write(addr, val)
  2278. # define AO_HAVE_int_or_release_write
  2279. #endif
  2280. #if !defined(AO_HAVE_int_or_release_write) \
  2281. && defined(AO_HAVE_int_or_release)
  2282. # define AO_int_or_release_write(addr, val) AO_int_or_release(addr, val)
  2283. # define AO_HAVE_int_or_release_write
  2284. #endif
  2285. #if !defined(AO_HAVE_int_or_acquire_read) && defined(AO_HAVE_int_or_read)
  2286. # define AO_int_or_acquire_read(addr, val) AO_int_or_read(addr, val)
  2287. # define AO_HAVE_int_or_acquire_read
  2288. #endif
  2289. #if !defined(AO_HAVE_int_or_acquire_read) \
  2290. && defined(AO_HAVE_int_or_acquire)
  2291. # define AO_int_or_acquire_read(addr, val) AO_int_or_acquire(addr, val)
  2292. # define AO_HAVE_int_or_acquire_read
  2293. #endif
  2294. /* int_xor */
  2295. #if defined(AO_HAVE_int_compare_and_swap_full) \
  2296. && !defined(AO_HAVE_int_xor_full)
  2297. AO_INLINE void
  2298. AO_int_xor_full(volatile unsigned *addr, unsigned value)
  2299. {
  2300. unsigned old;
  2301. do
  2302. {
  2303. old = *(unsigned *)addr;
  2304. }
  2305. while (AO_EXPECT_FALSE(!AO_int_compare_and_swap_full(addr, old,
  2306. old ^ value)));
  2307. }
  2308. # define AO_HAVE_int_xor_full
  2309. #endif
  2310. #if defined(AO_HAVE_int_xor_full)
  2311. # if !defined(AO_HAVE_int_xor_release)
  2312. # define AO_int_xor_release(addr, val) AO_int_xor_full(addr, val)
  2313. # define AO_HAVE_int_xor_release
  2314. # endif
  2315. # if !defined(AO_HAVE_int_xor_acquire)
  2316. # define AO_int_xor_acquire(addr, val) AO_int_xor_full(addr, val)
  2317. # define AO_HAVE_int_xor_acquire
  2318. # endif
  2319. # if !defined(AO_HAVE_int_xor_write)
  2320. # define AO_int_xor_write(addr, val) AO_int_xor_full(addr, val)
  2321. # define AO_HAVE_int_xor_write
  2322. # endif
  2323. # if !defined(AO_HAVE_int_xor_read)
  2324. # define AO_int_xor_read(addr, val) AO_int_xor_full(addr, val)
  2325. # define AO_HAVE_int_xor_read
  2326. # endif
  2327. #endif /* AO_HAVE_int_xor_full */
  2328. #if !defined(AO_HAVE_int_xor) && defined(AO_HAVE_int_xor_release)
  2329. # define AO_int_xor(addr, val) AO_int_xor_release(addr, val)
  2330. # define AO_HAVE_int_xor
  2331. #endif
  2332. #if !defined(AO_HAVE_int_xor) && defined(AO_HAVE_int_xor_acquire)
  2333. # define AO_int_xor(addr, val) AO_int_xor_acquire(addr, val)
  2334. # define AO_HAVE_int_xor
  2335. #endif
  2336. #if !defined(AO_HAVE_int_xor) && defined(AO_HAVE_int_xor_write)
  2337. # define AO_int_xor(addr, val) AO_int_xor_write(addr, val)
  2338. # define AO_HAVE_int_xor
  2339. #endif
  2340. #if !defined(AO_HAVE_int_xor) && defined(AO_HAVE_int_xor_read)
  2341. # define AO_int_xor(addr, val) AO_int_xor_read(addr, val)
  2342. # define AO_HAVE_int_xor
  2343. #endif
  2344. #if defined(AO_HAVE_int_xor_acquire) && defined(AO_HAVE_nop_full) \
  2345. && !defined(AO_HAVE_int_xor_full)
  2346. # define AO_int_xor_full(addr, val) \
  2347. (AO_nop_full(), AO_int_xor_acquire(addr, val))
  2348. # define AO_HAVE_int_xor_full
  2349. #endif
  2350. #if !defined(AO_HAVE_int_xor_release_write) \
  2351. && defined(AO_HAVE_int_xor_write)
  2352. # define AO_int_xor_release_write(addr, val) AO_int_xor_write(addr, val)
  2353. # define AO_HAVE_int_xor_release_write
  2354. #endif
  2355. #if !defined(AO_HAVE_int_xor_release_write) \
  2356. && defined(AO_HAVE_int_xor_release)
  2357. # define AO_int_xor_release_write(addr, val) AO_int_xor_release(addr, val)
  2358. # define AO_HAVE_int_xor_release_write
  2359. #endif
  2360. #if !defined(AO_HAVE_int_xor_acquire_read) \
  2361. && defined(AO_HAVE_int_xor_read)
  2362. # define AO_int_xor_acquire_read(addr, val) AO_int_xor_read(addr, val)
  2363. # define AO_HAVE_int_xor_acquire_read
  2364. #endif
  2365. #if !defined(AO_HAVE_int_xor_acquire_read) \
  2366. && defined(AO_HAVE_int_xor_acquire)
  2367. # define AO_int_xor_acquire_read(addr, val) AO_int_xor_acquire(addr, val)
  2368. # define AO_HAVE_int_xor_acquire_read
  2369. #endif
  2370. /* int_and/or/xor_dd_acquire_read are meaningless. */
  2371. /*
  2372. * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P.
  2373. *
  2374. * Permission is hereby granted, free of charge, to any person obtaining a copy
  2375. * of this software and associated documentation files (the "Software"), to deal
  2376. * in the Software without restriction, including without limitation the rights
  2377. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  2378. * copies of the Software, and to permit persons to whom the Software is
  2379. * furnished to do so, subject to the following conditions:
  2380. *
  2381. * The above copyright notice and this permission notice shall be included in
  2382. * all copies or substantial portions of the Software.
  2383. *
  2384. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2385. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2386. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2387. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  2388. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2389. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2390. * SOFTWARE.
  2391. */
  2392. /* compare_and_swap (based on fetch_compare_and_swap) */
  2393. #if defined(AO_HAVE_fetch_compare_and_swap_full) \
  2394. && !defined(AO_HAVE_compare_and_swap_full)
  2395. AO_INLINE int
  2396. AO_compare_and_swap_full(volatile AO_t *addr, AO_t old_val,
  2397. AO_t new_val)
  2398. {
  2399. return AO_fetch_compare_and_swap_full(addr, old_val, new_val)
  2400. == old_val;
  2401. }
  2402. # define AO_HAVE_compare_and_swap_full
  2403. #endif
  2404. #if defined(AO_HAVE_fetch_compare_and_swap_acquire) \
  2405. && !defined(AO_HAVE_compare_and_swap_acquire)
  2406. AO_INLINE int
  2407. AO_compare_and_swap_acquire(volatile AO_t *addr, AO_t old_val,
  2408. AO_t new_val)
  2409. {
  2410. return AO_fetch_compare_and_swap_acquire(addr, old_val, new_val)
  2411. == old_val;
  2412. }
  2413. # define AO_HAVE_compare_and_swap_acquire
  2414. #endif
  2415. #if defined(AO_HAVE_fetch_compare_and_swap_release) \
  2416. && !defined(AO_HAVE_compare_and_swap_release)
  2417. AO_INLINE int
  2418. AO_compare_and_swap_release(volatile AO_t *addr, AO_t old_val,
  2419. AO_t new_val)
  2420. {
  2421. return AO_fetch_compare_and_swap_release(addr, old_val, new_val)
  2422. == old_val;
  2423. }
  2424. # define AO_HAVE_compare_and_swap_release
  2425. #endif
  2426. #if defined(AO_HAVE_fetch_compare_and_swap_write) \
  2427. && !defined(AO_HAVE_compare_and_swap_write)
  2428. AO_INLINE int
  2429. AO_compare_and_swap_write(volatile AO_t *addr, AO_t old_val,
  2430. AO_t new_val)
  2431. {
  2432. return AO_fetch_compare_and_swap_write(addr, old_val, new_val)
  2433. == old_val;
  2434. }
  2435. # define AO_HAVE_compare_and_swap_write
  2436. #endif
  2437. #if defined(AO_HAVE_fetch_compare_and_swap_read) \
  2438. && !defined(AO_HAVE_compare_and_swap_read)
  2439. AO_INLINE int
  2440. AO_compare_and_swap_read(volatile AO_t *addr, AO_t old_val,
  2441. AO_t new_val)
  2442. {
  2443. return AO_fetch_compare_and_swap_read(addr, old_val, new_val)
  2444. == old_val;
  2445. }
  2446. # define AO_HAVE_compare_and_swap_read
  2447. #endif
  2448. #if defined(AO_HAVE_fetch_compare_and_swap) \
  2449. && !defined(AO_HAVE_compare_and_swap)
  2450. AO_INLINE int
  2451. AO_compare_and_swap(volatile AO_t *addr, AO_t old_val,
  2452. AO_t new_val)
  2453. {
  2454. return AO_fetch_compare_and_swap(addr, old_val, new_val) == old_val;
  2455. }
  2456. # define AO_HAVE_compare_and_swap
  2457. #endif
  2458. #if defined(AO_HAVE_fetch_compare_and_swap_release_write) \
  2459. && !defined(AO_HAVE_compare_and_swap_release_write)
  2460. AO_INLINE int
  2461. AO_compare_and_swap_release_write(volatile AO_t *addr,
  2462. AO_t old_val, AO_t new_val)
  2463. {
  2464. return AO_fetch_compare_and_swap_release_write(addr, old_val,
  2465. new_val) == old_val;
  2466. }
  2467. # define AO_HAVE_compare_and_swap_release_write
  2468. #endif
  2469. #if defined(AO_HAVE_fetch_compare_and_swap_acquire_read) \
  2470. && !defined(AO_HAVE_compare_and_swap_acquire_read)
  2471. AO_INLINE int
  2472. AO_compare_and_swap_acquire_read(volatile AO_t *addr,
  2473. AO_t old_val, AO_t new_val)
  2474. {
  2475. return AO_fetch_compare_and_swap_acquire_read(addr, old_val,
  2476. new_val) == old_val;
  2477. }
  2478. # define AO_HAVE_compare_and_swap_acquire_read
  2479. #endif
  2480. #if defined(AO_HAVE_fetch_compare_and_swap_dd_acquire_read) \
  2481. && !defined(AO_HAVE_compare_and_swap_dd_acquire_read)
  2482. AO_INLINE int
  2483. AO_compare_and_swap_dd_acquire_read(volatile AO_t *addr,
  2484. AO_t old_val, AO_t new_val)
  2485. {
  2486. return AO_fetch_compare_and_swap_dd_acquire_read(addr, old_val,
  2487. new_val) == old_val;
  2488. }
  2489. # define AO_HAVE_compare_and_swap_dd_acquire_read
  2490. #endif
  2491. /* fetch_and_add */
  2492. /* We first try to implement fetch_and_add variants in terms of the */
  2493. /* corresponding compare_and_swap variants to minimize adding barriers. */
  2494. #if defined(AO_HAVE_compare_and_swap_full) \
  2495. && !defined(AO_HAVE_fetch_and_add_full)
  2496. AO_INLINE AO_t
  2497. AO_fetch_and_add_full(volatile AO_t *addr, AO_t incr)
  2498. {
  2499. AO_t old;
  2500. do
  2501. {
  2502. old = *(AO_t *)addr;
  2503. }
  2504. while (AO_EXPECT_FALSE(!AO_compare_and_swap_full(addr, old,
  2505. old + incr)));
  2506. return old;
  2507. }
  2508. # define AO_HAVE_fetch_and_add_full
  2509. #endif
  2510. #if defined(AO_HAVE_compare_and_swap_acquire) \
  2511. && !defined(AO_HAVE_fetch_and_add_acquire)
  2512. AO_INLINE AO_t
  2513. AO_fetch_and_add_acquire(volatile AO_t *addr, AO_t incr)
  2514. {
  2515. AO_t old;
  2516. do
  2517. {
  2518. old = *(AO_t *)addr;
  2519. }
  2520. while (AO_EXPECT_FALSE(!AO_compare_and_swap_acquire(addr, old,
  2521. old + incr)));
  2522. return old;
  2523. }
  2524. # define AO_HAVE_fetch_and_add_acquire
  2525. #endif
  2526. #if defined(AO_HAVE_compare_and_swap_release) \
  2527. && !defined(AO_HAVE_fetch_and_add_release)
  2528. AO_INLINE AO_t
  2529. AO_fetch_and_add_release(volatile AO_t *addr, AO_t incr)
  2530. {
  2531. AO_t old;
  2532. do
  2533. {
  2534. old = *(AO_t *)addr;
  2535. }
  2536. while (AO_EXPECT_FALSE(!AO_compare_and_swap_release(addr, old,
  2537. old + incr)));
  2538. return old;
  2539. }
  2540. # define AO_HAVE_fetch_and_add_release
  2541. #endif
  2542. #if defined(AO_HAVE_compare_and_swap) \
  2543. && !defined(AO_HAVE_fetch_and_add)
  2544. AO_INLINE AO_t
  2545. AO_fetch_and_add(volatile AO_t *addr, AO_t incr)
  2546. {
  2547. AO_t old;
  2548. do
  2549. {
  2550. old = *(AO_t *)addr;
  2551. }
  2552. while (AO_EXPECT_FALSE(!AO_compare_and_swap(addr, old,
  2553. old + incr)));
  2554. return old;
  2555. }
  2556. # define AO_HAVE_fetch_and_add
  2557. #endif
  2558. #if defined(AO_HAVE_fetch_and_add_full)
  2559. # if !defined(AO_HAVE_fetch_and_add_release)
  2560. # define AO_fetch_and_add_release(addr, val) \
  2561. AO_fetch_and_add_full(addr, val)
  2562. # define AO_HAVE_fetch_and_add_release
  2563. # endif
  2564. # if !defined(AO_HAVE_fetch_and_add_acquire)
  2565. # define AO_fetch_and_add_acquire(addr, val) \
  2566. AO_fetch_and_add_full(addr, val)
  2567. # define AO_HAVE_fetch_and_add_acquire
  2568. # endif
  2569. # if !defined(AO_HAVE_fetch_and_add_write)
  2570. # define AO_fetch_and_add_write(addr, val) \
  2571. AO_fetch_and_add_full(addr, val)
  2572. # define AO_HAVE_fetch_and_add_write
  2573. # endif
  2574. # if !defined(AO_HAVE_fetch_and_add_read)
  2575. # define AO_fetch_and_add_read(addr, val) \
  2576. AO_fetch_and_add_full(addr, val)
  2577. # define AO_HAVE_fetch_and_add_read
  2578. # endif
  2579. #endif /* AO_HAVE_fetch_and_add_full */
  2580. #if defined(AO_HAVE_fetch_and_add) && defined(AO_HAVE_nop_full) \
  2581. && !defined(AO_HAVE_fetch_and_add_acquire)
  2582. AO_INLINE AO_t
  2583. AO_fetch_and_add_acquire(volatile AO_t *addr, AO_t incr)
  2584. {
  2585. AO_t result = AO_fetch_and_add(addr, incr);
  2586. AO_nop_full();
  2587. return result;
  2588. }
  2589. # define AO_HAVE_fetch_and_add_acquire
  2590. #endif
  2591. #if defined(AO_HAVE_fetch_and_add) && defined(AO_HAVE_nop_full) \
  2592. && !defined(AO_HAVE_fetch_and_add_release)
  2593. # define AO_fetch_and_add_release(addr, incr) \
  2594. (AO_nop_full(), AO_fetch_and_add(addr, incr))
  2595. # define AO_HAVE_fetch_and_add_release
  2596. #endif
  2597. #if !defined(AO_HAVE_fetch_and_add) \
  2598. && defined(AO_HAVE_fetch_and_add_release)
  2599. # define AO_fetch_and_add(addr, val) \
  2600. AO_fetch_and_add_release(addr, val)
  2601. # define AO_HAVE_fetch_and_add
  2602. #endif
  2603. #if !defined(AO_HAVE_fetch_and_add) \
  2604. && defined(AO_HAVE_fetch_and_add_acquire)
  2605. # define AO_fetch_and_add(addr, val) \
  2606. AO_fetch_and_add_acquire(addr, val)
  2607. # define AO_HAVE_fetch_and_add
  2608. #endif
  2609. #if !defined(AO_HAVE_fetch_and_add) \
  2610. && defined(AO_HAVE_fetch_and_add_write)
  2611. # define AO_fetch_and_add(addr, val) \
  2612. AO_fetch_and_add_write(addr, val)
  2613. # define AO_HAVE_fetch_and_add
  2614. #endif
  2615. #if !defined(AO_HAVE_fetch_and_add) \
  2616. && defined(AO_HAVE_fetch_and_add_read)
  2617. # define AO_fetch_and_add(addr, val) \
  2618. AO_fetch_and_add_read(addr, val)
  2619. # define AO_HAVE_fetch_and_add
  2620. #endif
  2621. #if defined(AO_HAVE_fetch_and_add_acquire) \
  2622. && defined(AO_HAVE_nop_full) && !defined(AO_HAVE_fetch_and_add_full)
  2623. # define AO_fetch_and_add_full(addr, val) \
  2624. (AO_nop_full(), AO_fetch_and_add_acquire(addr, val))
  2625. # define AO_HAVE_fetch_and_add_full
  2626. #endif
  2627. #if !defined(AO_HAVE_fetch_and_add_release_write) \
  2628. && defined(AO_HAVE_fetch_and_add_write)
  2629. # define AO_fetch_and_add_release_write(addr, val) \
  2630. AO_fetch_and_add_write(addr, val)
  2631. # define AO_HAVE_fetch_and_add_release_write
  2632. #endif
  2633. #if !defined(AO_HAVE_fetch_and_add_release_write) \
  2634. && defined(AO_HAVE_fetch_and_add_release)
  2635. # define AO_fetch_and_add_release_write(addr, val) \
  2636. AO_fetch_and_add_release(addr, val)
  2637. # define AO_HAVE_fetch_and_add_release_write
  2638. #endif
  2639. #if !defined(AO_HAVE_fetch_and_add_acquire_read) \
  2640. && defined(AO_HAVE_fetch_and_add_read)
  2641. # define AO_fetch_and_add_acquire_read(addr, val) \
  2642. AO_fetch_and_add_read(addr, val)
  2643. # define AO_HAVE_fetch_and_add_acquire_read
  2644. #endif
  2645. #if !defined(AO_HAVE_fetch_and_add_acquire_read) \
  2646. && defined(AO_HAVE_fetch_and_add_acquire)
  2647. # define AO_fetch_and_add_acquire_read(addr, val) \
  2648. AO_fetch_and_add_acquire(addr, val)
  2649. # define AO_HAVE_fetch_and_add_acquire_read
  2650. #endif
  2651. #ifdef AO_NO_DD_ORDERING
  2652. # if defined(AO_HAVE_fetch_and_add_acquire_read)
  2653. # define AO_fetch_and_add_dd_acquire_read(addr, val) \
  2654. AO_fetch_and_add_acquire_read(addr, val)
  2655. # define AO_HAVE_fetch_and_add_dd_acquire_read
  2656. # endif
  2657. #else
  2658. # if defined(AO_HAVE_fetch_and_add)
  2659. # define AO_fetch_and_add_dd_acquire_read(addr, val) \
  2660. AO_fetch_and_add(addr, val)
  2661. # define AO_HAVE_fetch_and_add_dd_acquire_read
  2662. # endif
  2663. #endif /* !AO_NO_DD_ORDERING */
  2664. /* fetch_and_add1 */
  2665. #if defined(AO_HAVE_fetch_and_add_full) \
  2666. && !defined(AO_HAVE_fetch_and_add1_full)
  2667. # define AO_fetch_and_add1_full(addr) \
  2668. AO_fetch_and_add_full(addr, 1)
  2669. # define AO_HAVE_fetch_and_add1_full
  2670. #endif
  2671. #if defined(AO_HAVE_fetch_and_add_release) \
  2672. && !defined(AO_HAVE_fetch_and_add1_release)
  2673. # define AO_fetch_and_add1_release(addr) \
  2674. AO_fetch_and_add_release(addr, 1)
  2675. # define AO_HAVE_fetch_and_add1_release
  2676. #endif
  2677. #if defined(AO_HAVE_fetch_and_add_acquire) \
  2678. && !defined(AO_HAVE_fetch_and_add1_acquire)
  2679. # define AO_fetch_and_add1_acquire(addr) \
  2680. AO_fetch_and_add_acquire(addr, 1)
  2681. # define AO_HAVE_fetch_and_add1_acquire
  2682. #endif
  2683. #if defined(AO_HAVE_fetch_and_add_write) \
  2684. && !defined(AO_HAVE_fetch_and_add1_write)
  2685. # define AO_fetch_and_add1_write(addr) \
  2686. AO_fetch_and_add_write(addr, 1)
  2687. # define AO_HAVE_fetch_and_add1_write
  2688. #endif
  2689. #if defined(AO_HAVE_fetch_and_add_read) \
  2690. && !defined(AO_HAVE_fetch_and_add1_read)
  2691. # define AO_fetch_and_add1_read(addr) \
  2692. AO_fetch_and_add_read(addr, 1)
  2693. # define AO_HAVE_fetch_and_add1_read
  2694. #endif
  2695. #if defined(AO_HAVE_fetch_and_add_release_write) \
  2696. && !defined(AO_HAVE_fetch_and_add1_release_write)
  2697. # define AO_fetch_and_add1_release_write(addr) \
  2698. AO_fetch_and_add_release_write(addr, 1)
  2699. # define AO_HAVE_fetch_and_add1_release_write
  2700. #endif
  2701. #if defined(AO_HAVE_fetch_and_add_acquire_read) \
  2702. && !defined(AO_HAVE_fetch_and_add1_acquire_read)
  2703. # define AO_fetch_and_add1_acquire_read(addr) \
  2704. AO_fetch_and_add_acquire_read(addr, 1)
  2705. # define AO_HAVE_fetch_and_add1_acquire_read
  2706. #endif
  2707. #if defined(AO_HAVE_fetch_and_add) \
  2708. && !defined(AO_HAVE_fetch_and_add1)
  2709. # define AO_fetch_and_add1(addr) AO_fetch_and_add(addr, 1)
  2710. # define AO_HAVE_fetch_and_add1
  2711. #endif
  2712. #if defined(AO_HAVE_fetch_and_add1_full)
  2713. # if !defined(AO_HAVE_fetch_and_add1_release)
  2714. # define AO_fetch_and_add1_release(addr) \
  2715. AO_fetch_and_add1_full(addr)
  2716. # define AO_HAVE_fetch_and_add1_release
  2717. # endif
  2718. # if !defined(AO_HAVE_fetch_and_add1_acquire)
  2719. # define AO_fetch_and_add1_acquire(addr) \
  2720. AO_fetch_and_add1_full(addr)
  2721. # define AO_HAVE_fetch_and_add1_acquire
  2722. # endif
  2723. # if !defined(AO_HAVE_fetch_and_add1_write)
  2724. # define AO_fetch_and_add1_write(addr) \
  2725. AO_fetch_and_add1_full(addr)
  2726. # define AO_HAVE_fetch_and_add1_write
  2727. # endif
  2728. # if !defined(AO_HAVE_fetch_and_add1_read)
  2729. # define AO_fetch_and_add1_read(addr) \
  2730. AO_fetch_and_add1_full(addr)
  2731. # define AO_HAVE_fetch_and_add1_read
  2732. # endif
  2733. #endif /* AO_HAVE_fetch_and_add1_full */
  2734. #if !defined(AO_HAVE_fetch_and_add1) \
  2735. && defined(AO_HAVE_fetch_and_add1_release)
  2736. # define AO_fetch_and_add1(addr) AO_fetch_and_add1_release(addr)
  2737. # define AO_HAVE_fetch_and_add1
  2738. #endif
  2739. #if !defined(AO_HAVE_fetch_and_add1) \
  2740. && defined(AO_HAVE_fetch_and_add1_acquire)
  2741. # define AO_fetch_and_add1(addr) AO_fetch_and_add1_acquire(addr)
  2742. # define AO_HAVE_fetch_and_add1
  2743. #endif
  2744. #if !defined(AO_HAVE_fetch_and_add1) \
  2745. && defined(AO_HAVE_fetch_and_add1_write)
  2746. # define AO_fetch_and_add1(addr) AO_fetch_and_add1_write(addr)
  2747. # define AO_HAVE_fetch_and_add1
  2748. #endif
  2749. #if !defined(AO_HAVE_fetch_and_add1) \
  2750. && defined(AO_HAVE_fetch_and_add1_read)
  2751. # define AO_fetch_and_add1(addr) AO_fetch_and_add1_read(addr)
  2752. # define AO_HAVE_fetch_and_add1
  2753. #endif
  2754. #if defined(AO_HAVE_fetch_and_add1_acquire) \
  2755. && defined(AO_HAVE_nop_full) \
  2756. && !defined(AO_HAVE_fetch_and_add1_full)
  2757. # define AO_fetch_and_add1_full(addr) \
  2758. (AO_nop_full(), AO_fetch_and_add1_acquire(addr))
  2759. # define AO_HAVE_fetch_and_add1_full
  2760. #endif
  2761. #if !defined(AO_HAVE_fetch_and_add1_release_write) \
  2762. && defined(AO_HAVE_fetch_and_add1_write)
  2763. # define AO_fetch_and_add1_release_write(addr) \
  2764. AO_fetch_and_add1_write(addr)
  2765. # define AO_HAVE_fetch_and_add1_release_write
  2766. #endif
  2767. #if !defined(AO_HAVE_fetch_and_add1_release_write) \
  2768. && defined(AO_HAVE_fetch_and_add1_release)
  2769. # define AO_fetch_and_add1_release_write(addr) \
  2770. AO_fetch_and_add1_release(addr)
  2771. # define AO_HAVE_fetch_and_add1_release_write
  2772. #endif
  2773. #if !defined(AO_HAVE_fetch_and_add1_acquire_read) \
  2774. && defined(AO_HAVE_fetch_and_add1_read)
  2775. # define AO_fetch_and_add1_acquire_read(addr) \
  2776. AO_fetch_and_add1_read(addr)
  2777. # define AO_HAVE_fetch_and_add1_acquire_read
  2778. #endif
  2779. #if !defined(AO_HAVE_fetch_and_add1_acquire_read) \
  2780. && defined(AO_HAVE_fetch_and_add1_acquire)
  2781. # define AO_fetch_and_add1_acquire_read(addr) \
  2782. AO_fetch_and_add1_acquire(addr)
  2783. # define AO_HAVE_fetch_and_add1_acquire_read
  2784. #endif
  2785. #ifdef AO_NO_DD_ORDERING
  2786. # if defined(AO_HAVE_fetch_and_add1_acquire_read)
  2787. # define AO_fetch_and_add1_dd_acquire_read(addr) \
  2788. AO_fetch_and_add1_acquire_read(addr)
  2789. # define AO_HAVE_fetch_and_add1_dd_acquire_read
  2790. # endif
  2791. #else
  2792. # if defined(AO_HAVE_fetch_and_add1)
  2793. # define AO_fetch_and_add1_dd_acquire_read(addr) \
  2794. AO_fetch_and_add1(addr)
  2795. # define AO_HAVE_fetch_and_add1_dd_acquire_read
  2796. # endif
  2797. #endif /* !AO_NO_DD_ORDERING */
  2798. /* fetch_and_sub1 */
  2799. #if defined(AO_HAVE_fetch_and_add_full) \
  2800. && !defined(AO_HAVE_fetch_and_sub1_full)
  2801. # define AO_fetch_and_sub1_full(addr) \
  2802. AO_fetch_and_add_full(addr, (AO_t)(-1))
  2803. # define AO_HAVE_fetch_and_sub1_full
  2804. #endif
  2805. #if defined(AO_HAVE_fetch_and_add_release) \
  2806. && !defined(AO_HAVE_fetch_and_sub1_release)
  2807. # define AO_fetch_and_sub1_release(addr) \
  2808. AO_fetch_and_add_release(addr, (AO_t)(-1))
  2809. # define AO_HAVE_fetch_and_sub1_release
  2810. #endif
  2811. #if defined(AO_HAVE_fetch_and_add_acquire) \
  2812. && !defined(AO_HAVE_fetch_and_sub1_acquire)
  2813. # define AO_fetch_and_sub1_acquire(addr) \
  2814. AO_fetch_and_add_acquire(addr, (AO_t)(-1))
  2815. # define AO_HAVE_fetch_and_sub1_acquire
  2816. #endif
  2817. #if defined(AO_HAVE_fetch_and_add_write) \
  2818. && !defined(AO_HAVE_fetch_and_sub1_write)
  2819. # define AO_fetch_and_sub1_write(addr) \
  2820. AO_fetch_and_add_write(addr, (AO_t)(-1))
  2821. # define AO_HAVE_fetch_and_sub1_write
  2822. #endif
  2823. #if defined(AO_HAVE_fetch_and_add_read) \
  2824. && !defined(AO_HAVE_fetch_and_sub1_read)
  2825. # define AO_fetch_and_sub1_read(addr) \
  2826. AO_fetch_and_add_read(addr, (AO_t)(-1))
  2827. # define AO_HAVE_fetch_and_sub1_read
  2828. #endif
  2829. #if defined(AO_HAVE_fetch_and_add_release_write) \
  2830. && !defined(AO_HAVE_fetch_and_sub1_release_write)
  2831. # define AO_fetch_and_sub1_release_write(addr) \
  2832. AO_fetch_and_add_release_write(addr, (AO_t)(-1))
  2833. # define AO_HAVE_fetch_and_sub1_release_write
  2834. #endif
  2835. #if defined(AO_HAVE_fetch_and_add_acquire_read) \
  2836. && !defined(AO_HAVE_fetch_and_sub1_acquire_read)
  2837. # define AO_fetch_and_sub1_acquire_read(addr) \
  2838. AO_fetch_and_add_acquire_read(addr, (AO_t)(-1))
  2839. # define AO_HAVE_fetch_and_sub1_acquire_read
  2840. #endif
  2841. #if defined(AO_HAVE_fetch_and_add) \
  2842. && !defined(AO_HAVE_fetch_and_sub1)
  2843. # define AO_fetch_and_sub1(addr) \
  2844. AO_fetch_and_add(addr, (AO_t)(-1))
  2845. # define AO_HAVE_fetch_and_sub1
  2846. #endif
  2847. #if defined(AO_HAVE_fetch_and_sub1_full)
  2848. # if !defined(AO_HAVE_fetch_and_sub1_release)
  2849. # define AO_fetch_and_sub1_release(addr) \
  2850. AO_fetch_and_sub1_full(addr)
  2851. # define AO_HAVE_fetch_and_sub1_release
  2852. # endif
  2853. # if !defined(AO_HAVE_fetch_and_sub1_acquire)
  2854. # define AO_fetch_and_sub1_acquire(addr) \
  2855. AO_fetch_and_sub1_full(addr)
  2856. # define AO_HAVE_fetch_and_sub1_acquire
  2857. # endif
  2858. # if !defined(AO_HAVE_fetch_and_sub1_write)
  2859. # define AO_fetch_and_sub1_write(addr) \
  2860. AO_fetch_and_sub1_full(addr)
  2861. # define AO_HAVE_fetch_and_sub1_write
  2862. # endif
  2863. # if !defined(AO_HAVE_fetch_and_sub1_read)
  2864. # define AO_fetch_and_sub1_read(addr) \
  2865. AO_fetch_and_sub1_full(addr)
  2866. # define AO_HAVE_fetch_and_sub1_read
  2867. # endif
  2868. #endif /* AO_HAVE_fetch_and_sub1_full */
  2869. #if !defined(AO_HAVE_fetch_and_sub1) \
  2870. && defined(AO_HAVE_fetch_and_sub1_release)
  2871. # define AO_fetch_and_sub1(addr) AO_fetch_and_sub1_release(addr)
  2872. # define AO_HAVE_fetch_and_sub1
  2873. #endif
  2874. #if !defined(AO_HAVE_fetch_and_sub1) \
  2875. && defined(AO_HAVE_fetch_and_sub1_acquire)
  2876. # define AO_fetch_and_sub1(addr) AO_fetch_and_sub1_acquire(addr)
  2877. # define AO_HAVE_fetch_and_sub1
  2878. #endif
  2879. #if !defined(AO_HAVE_fetch_and_sub1) \
  2880. && defined(AO_HAVE_fetch_and_sub1_write)
  2881. # define AO_fetch_and_sub1(addr) AO_fetch_and_sub1_write(addr)
  2882. # define AO_HAVE_fetch_and_sub1
  2883. #endif
  2884. #if !defined(AO_HAVE_fetch_and_sub1) \
  2885. && defined(AO_HAVE_fetch_and_sub1_read)
  2886. # define AO_fetch_and_sub1(addr) AO_fetch_and_sub1_read(addr)
  2887. # define AO_HAVE_fetch_and_sub1
  2888. #endif
  2889. #if defined(AO_HAVE_fetch_and_sub1_acquire) \
  2890. && defined(AO_HAVE_nop_full) \
  2891. && !defined(AO_HAVE_fetch_and_sub1_full)
  2892. # define AO_fetch_and_sub1_full(addr) \
  2893. (AO_nop_full(), AO_fetch_and_sub1_acquire(addr))
  2894. # define AO_HAVE_fetch_and_sub1_full
  2895. #endif
  2896. #if !defined(AO_HAVE_fetch_and_sub1_release_write) \
  2897. && defined(AO_HAVE_fetch_and_sub1_write)
  2898. # define AO_fetch_and_sub1_release_write(addr) \
  2899. AO_fetch_and_sub1_write(addr)
  2900. # define AO_HAVE_fetch_and_sub1_release_write
  2901. #endif
  2902. #if !defined(AO_HAVE_fetch_and_sub1_release_write) \
  2903. && defined(AO_HAVE_fetch_and_sub1_release)
  2904. # define AO_fetch_and_sub1_release_write(addr) \
  2905. AO_fetch_and_sub1_release(addr)
  2906. # define AO_HAVE_fetch_and_sub1_release_write
  2907. #endif
  2908. #if !defined(AO_HAVE_fetch_and_sub1_acquire_read) \
  2909. && defined(AO_HAVE_fetch_and_sub1_read)
  2910. # define AO_fetch_and_sub1_acquire_read(addr) \
  2911. AO_fetch_and_sub1_read(addr)
  2912. # define AO_HAVE_fetch_and_sub1_acquire_read
  2913. #endif
  2914. #if !defined(AO_HAVE_fetch_and_sub1_acquire_read) \
  2915. && defined(AO_HAVE_fetch_and_sub1_acquire)
  2916. # define AO_fetch_and_sub1_acquire_read(addr) \
  2917. AO_fetch_and_sub1_acquire(addr)
  2918. # define AO_HAVE_fetch_and_sub1_acquire_read
  2919. #endif
  2920. #ifdef AO_NO_DD_ORDERING
  2921. # if defined(AO_HAVE_fetch_and_sub1_acquire_read)
  2922. # define AO_fetch_and_sub1_dd_acquire_read(addr) \
  2923. AO_fetch_and_sub1_acquire_read(addr)
  2924. # define AO_HAVE_fetch_and_sub1_dd_acquire_read
  2925. # endif
  2926. #else
  2927. # if defined(AO_HAVE_fetch_and_sub1)
  2928. # define AO_fetch_and_sub1_dd_acquire_read(addr) \
  2929. AO_fetch_and_sub1(addr)
  2930. # define AO_HAVE_fetch_and_sub1_dd_acquire_read
  2931. # endif
  2932. #endif /* !AO_NO_DD_ORDERING */
  2933. /* and */
  2934. #if defined(AO_HAVE_compare_and_swap_full) \
  2935. && !defined(AO_HAVE_and_full)
  2936. AO_INLINE void
  2937. AO_and_full(volatile AO_t *addr, AO_t value)
  2938. {
  2939. AO_t old;
  2940. do
  2941. {
  2942. old = *(AO_t *)addr;
  2943. }
  2944. while (AO_EXPECT_FALSE(!AO_compare_and_swap_full(addr, old,
  2945. old & value)));
  2946. }
  2947. # define AO_HAVE_and_full
  2948. #endif
  2949. #if defined(AO_HAVE_and_full)
  2950. # if !defined(AO_HAVE_and_release)
  2951. # define AO_and_release(addr, val) AO_and_full(addr, val)
  2952. # define AO_HAVE_and_release
  2953. # endif
  2954. # if !defined(AO_HAVE_and_acquire)
  2955. # define AO_and_acquire(addr, val) AO_and_full(addr, val)
  2956. # define AO_HAVE_and_acquire
  2957. # endif
  2958. # if !defined(AO_HAVE_and_write)
  2959. # define AO_and_write(addr, val) AO_and_full(addr, val)
  2960. # define AO_HAVE_and_write
  2961. # endif
  2962. # if !defined(AO_HAVE_and_read)
  2963. # define AO_and_read(addr, val) AO_and_full(addr, val)
  2964. # define AO_HAVE_and_read
  2965. # endif
  2966. #endif /* AO_HAVE_and_full */
  2967. #if !defined(AO_HAVE_and) && defined(AO_HAVE_and_release)
  2968. # define AO_and(addr, val) AO_and_release(addr, val)
  2969. # define AO_HAVE_and
  2970. #endif
  2971. #if !defined(AO_HAVE_and) && defined(AO_HAVE_and_acquire)
  2972. # define AO_and(addr, val) AO_and_acquire(addr, val)
  2973. # define AO_HAVE_and
  2974. #endif
  2975. #if !defined(AO_HAVE_and) && defined(AO_HAVE_and_write)
  2976. # define AO_and(addr, val) AO_and_write(addr, val)
  2977. # define AO_HAVE_and
  2978. #endif
  2979. #if !defined(AO_HAVE_and) && defined(AO_HAVE_and_read)
  2980. # define AO_and(addr, val) AO_and_read(addr, val)
  2981. # define AO_HAVE_and
  2982. #endif
  2983. #if defined(AO_HAVE_and_acquire) && defined(AO_HAVE_nop_full) \
  2984. && !defined(AO_HAVE_and_full)
  2985. # define AO_and_full(addr, val) \
  2986. (AO_nop_full(), AO_and_acquire(addr, val))
  2987. # define AO_HAVE_and_full
  2988. #endif
  2989. #if !defined(AO_HAVE_and_release_write) \
  2990. && defined(AO_HAVE_and_write)
  2991. # define AO_and_release_write(addr, val) AO_and_write(addr, val)
  2992. # define AO_HAVE_and_release_write
  2993. #endif
  2994. #if !defined(AO_HAVE_and_release_write) \
  2995. && defined(AO_HAVE_and_release)
  2996. # define AO_and_release_write(addr, val) AO_and_release(addr, val)
  2997. # define AO_HAVE_and_release_write
  2998. #endif
  2999. #if !defined(AO_HAVE_and_acquire_read) \
  3000. && defined(AO_HAVE_and_read)
  3001. # define AO_and_acquire_read(addr, val) AO_and_read(addr, val)
  3002. # define AO_HAVE_and_acquire_read
  3003. #endif
  3004. #if !defined(AO_HAVE_and_acquire_read) \
  3005. && defined(AO_HAVE_and_acquire)
  3006. # define AO_and_acquire_read(addr, val) AO_and_acquire(addr, val)
  3007. # define AO_HAVE_and_acquire_read
  3008. #endif
  3009. /* or */
  3010. #if defined(AO_HAVE_compare_and_swap_full) \
  3011. && !defined(AO_HAVE_or_full)
  3012. AO_INLINE void
  3013. AO_or_full(volatile AO_t *addr, AO_t value)
  3014. {
  3015. AO_t old;
  3016. do
  3017. {
  3018. old = *(AO_t *)addr;
  3019. }
  3020. while (AO_EXPECT_FALSE(!AO_compare_and_swap_full(addr, old,
  3021. old | value)));
  3022. }
  3023. # define AO_HAVE_or_full
  3024. #endif
  3025. #if defined(AO_HAVE_or_full)
  3026. # if !defined(AO_HAVE_or_release)
  3027. # define AO_or_release(addr, val) AO_or_full(addr, val)
  3028. # define AO_HAVE_or_release
  3029. # endif
  3030. # if !defined(AO_HAVE_or_acquire)
  3031. # define AO_or_acquire(addr, val) AO_or_full(addr, val)
  3032. # define AO_HAVE_or_acquire
  3033. # endif
  3034. # if !defined(AO_HAVE_or_write)
  3035. # define AO_or_write(addr, val) AO_or_full(addr, val)
  3036. # define AO_HAVE_or_write
  3037. # endif
  3038. # if !defined(AO_HAVE_or_read)
  3039. # define AO_or_read(addr, val) AO_or_full(addr, val)
  3040. # define AO_HAVE_or_read
  3041. # endif
  3042. #endif /* AO_HAVE_or_full */
  3043. #if !defined(AO_HAVE_or) && defined(AO_HAVE_or_release)
  3044. # define AO_or(addr, val) AO_or_release(addr, val)
  3045. # define AO_HAVE_or
  3046. #endif
  3047. #if !defined(AO_HAVE_or) && defined(AO_HAVE_or_acquire)
  3048. # define AO_or(addr, val) AO_or_acquire(addr, val)
  3049. # define AO_HAVE_or
  3050. #endif
  3051. #if !defined(AO_HAVE_or) && defined(AO_HAVE_or_write)
  3052. # define AO_or(addr, val) AO_or_write(addr, val)
  3053. # define AO_HAVE_or
  3054. #endif
  3055. #if !defined(AO_HAVE_or) && defined(AO_HAVE_or_read)
  3056. # define AO_or(addr, val) AO_or_read(addr, val)
  3057. # define AO_HAVE_or
  3058. #endif
  3059. #if defined(AO_HAVE_or_acquire) && defined(AO_HAVE_nop_full) \
  3060. && !defined(AO_HAVE_or_full)
  3061. # define AO_or_full(addr, val) \
  3062. (AO_nop_full(), AO_or_acquire(addr, val))
  3063. # define AO_HAVE_or_full
  3064. #endif
  3065. #if !defined(AO_HAVE_or_release_write) \
  3066. && defined(AO_HAVE_or_write)
  3067. # define AO_or_release_write(addr, val) AO_or_write(addr, val)
  3068. # define AO_HAVE_or_release_write
  3069. #endif
  3070. #if !defined(AO_HAVE_or_release_write) \
  3071. && defined(AO_HAVE_or_release)
  3072. # define AO_or_release_write(addr, val) AO_or_release(addr, val)
  3073. # define AO_HAVE_or_release_write
  3074. #endif
  3075. #if !defined(AO_HAVE_or_acquire_read) && defined(AO_HAVE_or_read)
  3076. # define AO_or_acquire_read(addr, val) AO_or_read(addr, val)
  3077. # define AO_HAVE_or_acquire_read
  3078. #endif
  3079. #if !defined(AO_HAVE_or_acquire_read) \
  3080. && defined(AO_HAVE_or_acquire)
  3081. # define AO_or_acquire_read(addr, val) AO_or_acquire(addr, val)
  3082. # define AO_HAVE_or_acquire_read
  3083. #endif
  3084. /* xor */
  3085. #if defined(AO_HAVE_compare_and_swap_full) \
  3086. && !defined(AO_HAVE_xor_full)
  3087. AO_INLINE void
  3088. AO_xor_full(volatile AO_t *addr, AO_t value)
  3089. {
  3090. AO_t old;
  3091. do
  3092. {
  3093. old = *(AO_t *)addr;
  3094. }
  3095. while (AO_EXPECT_FALSE(!AO_compare_and_swap_full(addr, old,
  3096. old ^ value)));
  3097. }
  3098. # define AO_HAVE_xor_full
  3099. #endif
  3100. #if defined(AO_HAVE_xor_full)
  3101. # if !defined(AO_HAVE_xor_release)
  3102. # define AO_xor_release(addr, val) AO_xor_full(addr, val)
  3103. # define AO_HAVE_xor_release
  3104. # endif
  3105. # if !defined(AO_HAVE_xor_acquire)
  3106. # define AO_xor_acquire(addr, val) AO_xor_full(addr, val)
  3107. # define AO_HAVE_xor_acquire
  3108. # endif
  3109. # if !defined(AO_HAVE_xor_write)
  3110. # define AO_xor_write(addr, val) AO_xor_full(addr, val)
  3111. # define AO_HAVE_xor_write
  3112. # endif
  3113. # if !defined(AO_HAVE_xor_read)
  3114. # define AO_xor_read(addr, val) AO_xor_full(addr, val)
  3115. # define AO_HAVE_xor_read
  3116. # endif
  3117. #endif /* AO_HAVE_xor_full */
  3118. #if !defined(AO_HAVE_xor) && defined(AO_HAVE_xor_release)
  3119. # define AO_xor(addr, val) AO_xor_release(addr, val)
  3120. # define AO_HAVE_xor
  3121. #endif
  3122. #if !defined(AO_HAVE_xor) && defined(AO_HAVE_xor_acquire)
  3123. # define AO_xor(addr, val) AO_xor_acquire(addr, val)
  3124. # define AO_HAVE_xor
  3125. #endif
  3126. #if !defined(AO_HAVE_xor) && defined(AO_HAVE_xor_write)
  3127. # define AO_xor(addr, val) AO_xor_write(addr, val)
  3128. # define AO_HAVE_xor
  3129. #endif
  3130. #if !defined(AO_HAVE_xor) && defined(AO_HAVE_xor_read)
  3131. # define AO_xor(addr, val) AO_xor_read(addr, val)
  3132. # define AO_HAVE_xor
  3133. #endif
  3134. #if defined(AO_HAVE_xor_acquire) && defined(AO_HAVE_nop_full) \
  3135. && !defined(AO_HAVE_xor_full)
  3136. # define AO_xor_full(addr, val) \
  3137. (AO_nop_full(), AO_xor_acquire(addr, val))
  3138. # define AO_HAVE_xor_full
  3139. #endif
  3140. #if !defined(AO_HAVE_xor_release_write) \
  3141. && defined(AO_HAVE_xor_write)
  3142. # define AO_xor_release_write(addr, val) AO_xor_write(addr, val)
  3143. # define AO_HAVE_xor_release_write
  3144. #endif
  3145. #if !defined(AO_HAVE_xor_release_write) \
  3146. && defined(AO_HAVE_xor_release)
  3147. # define AO_xor_release_write(addr, val) AO_xor_release(addr, val)
  3148. # define AO_HAVE_xor_release_write
  3149. #endif
  3150. #if !defined(AO_HAVE_xor_acquire_read) \
  3151. && defined(AO_HAVE_xor_read)
  3152. # define AO_xor_acquire_read(addr, val) AO_xor_read(addr, val)
  3153. # define AO_HAVE_xor_acquire_read
  3154. #endif
  3155. #if !defined(AO_HAVE_xor_acquire_read) \
  3156. && defined(AO_HAVE_xor_acquire)
  3157. # define AO_xor_acquire_read(addr, val) AO_xor_acquire(addr, val)
  3158. # define AO_HAVE_xor_acquire_read
  3159. #endif
  3160. /* and/or/xor_dd_acquire_read are meaningless. */