-
-
Save timshen91/23093be104015d64ee252e5b51828e1c to your computer and use it in GitHub Desktop.
atomic reordering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <atomic> | |
int a; | |
std::atomic<bool> a_meaningful { 0 }; // a is meaningful only if a_meaningful | |
int Read() { | |
if (a_meaningful.load(std::memory_order_acquire)) { | |
return a; | |
} | |
return -1; | |
} | |
int Init() { | |
a = 42; | |
a_meaningful.store(1, std::memory_order_release); | |
} | |
/* | |
.file "a.cc" | |
.machine power8 | |
.abiversion 2 | |
.section ".text" | |
.align 2 | |
.p2align 4,,15 | |
.globl _Z4Readv | |
.type _Z4Readv, @function | |
_Z4Readv: | |
.LFB342: | |
.cfi_startproc | |
.LCF0: | |
0: addis 2,12,.TOC.-.LCF0@ha | |
addi 2,2,.TOC.-.LCF0@l | |
.localentry _Z4Readv,.-_Z4Readv | |
addis 9,2,.LANCHOR0@toc@ha # gpr load fusion, type char | |
lbz 9,.LANCHOR0@toc@l(9) | |
cmpw 7,9,9 | |
bne- 7,$+4 | |
isync | |
rlwinm 9,9,0,0xff | |
cmpdi 7,9,0 | |
beq 7,.L3 | |
addis 9,2,.LANCHOR0+4@toc@ha | |
lwa 3,.LANCHOR0+4@toc@l(9) | |
blr | |
.p2align 4,,15 | |
.L3: | |
li 3,-1 | |
blr | |
.long 0 | |
.byte 0,9,0,0,0,0,0,0 | |
.cfi_endproc | |
.LFE342: | |
.size _Z4Readv,.-_Z4Readv | |
.align 2 | |
.p2align 4,,15 | |
.globl _Z4Initv | |
.type _Z4Initv, @function | |
_Z4Initv: | |
.LFB343: | |
.cfi_startproc | |
.LCF1: | |
0: addis 2,12,.TOC.-.LCF1@ha | |
addi 2,2,.TOC.-.LCF1@l | |
.localentry _Z4Initv,.-_Z4Initv | |
li 10,42 | |
addis 8,2,.LANCHOR0+4@toc@ha | |
li 9,1 | |
stw 10,.LANCHOR0+4@toc@l(8) | |
addis 10,2,.LANCHOR0@toc@ha | |
lwsync | |
stb 9,.LANCHOR0@toc@l(10) | |
blr | |
.long 0 | |
.byte 0,9,0,0,0,0,0,0 | |
.cfi_endproc | |
.LFE343: | |
.size _Z4Initv,.-_Z4Initv | |
.globl a_meaningful | |
.globl a | |
.section ".bss" | |
.align 2 | |
.set .LANCHOR0,. + 0 | |
.type a_meaningful, @object | |
.size a_meaningful, 1 | |
a_meaningful: | |
.zero 1 | |
.zero 3 | |
.type a, @object | |
.size a, 4 | |
a: | |
.zero 4 | |
.ident "GCC: (GNU) 7.0.1 20170302 (experimental)" | |
.section .note.GNU-stack,"",@progbits | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment