Skip to content

Commit f0e9f7e

Browse files
committed
style: split the final codeblock to 3 tabs
1 parent e2d7c26 commit f0e9f7e

File tree

1 file changed

+40
-34
lines changed
  • src/content/docs/cpp/language/basic_concepts

1 file changed

+40
-34
lines changed

src/content/docs/cpp/language/basic_concepts/as_if.mdx

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: The as-if rule
33
---
44

5+
import { Tabs, TabItem } from "@astrojs/starlight/components";
56
import { Desc, DescList } from "@components/desc-list";
67
import { RevisionBlock } from "@components/revision";
78
import DocLink from "@components/DocLink.astro";
@@ -96,40 +97,45 @@ int main() {
9697
}
9798
```
9899
99-
Output:
100-
101-
```
102-
# full code of the main() function as produced by the GCC compiler
103-
# x86 (Intel) platform:
104-
movl input(%rip), %eax # eax = input
105-
leal 3(%rax,%rax), %eax # eax = 3 + eax + eax
106-
movl %eax, result(%rip) # result = eax
107-
xorl %eax, %eax # eax = 0 (the return value of main())
108-
ret
109-
110-
# PowerPC (IBM) platform:
111-
lwz 9,LC..1(2)
112-
li 3,0 # r3 = 0 (the return value of main())
113-
lwz 11,0(9) # r11 = input;
114-
slwi 11,11,1 # r11 = r11 << 1;
115-
addi 0,11,3 # r0 = r11 + 3;
116-
stw 0,4(9) # result = r0;
117-
blr
118-
119-
# Sparc (Sun) platform:
120-
sethi %hi(result), %g2
121-
sethi %hi(input), %g1
122-
mov 0, %o0 # o0 = 0 (the return value of main)
123-
ld [%g1+%lo(input)], %g1 # g1 = input
124-
add %g1, %g1, %g1 # g1 = g1 + g1
125-
add %g1, 3, %g1 # g1 = 3 + g1
126-
st %g1, [%g2+%lo(result)] # result = g1
127-
jmp %o7+8
128-
nop
129-
130-
# in all cases, the side effects of preinc() were eliminated, and the
131-
# entire main() function was reduced to the equivalent of result = 2 * input + 3;
132-
```
100+
Full code of the `main()` function as produced by the GCC compiler, for different platforms:
101+
102+
<Tabs>
103+
<TabItem label="x86 (Intel)">
104+
```
105+
movl input(%rip), %eax # eax = input
106+
leal 3(%rax,%rax), %eax # eax = 3 + eax + eax
107+
movl %eax, result(%rip) # result = eax
108+
xorl %eax, %eax # eax = 0 (the return value of main())
109+
ret
110+
```
111+
</TabItem>
112+
<TabItem label="PowerPC (IBM)">
113+
```
114+
lwz 9,LC..1(2)
115+
li 3,0 # r3 = 0 (the return value of main())
116+
lwz 11,0(9) # r11 = input;
117+
slwi 11,11,1 # r11 = r11 << 1;
118+
addi 0,11,3 # r0 = r11 + 3;
119+
stw 0,4(9) # result = r0;
120+
blr
121+
```
122+
</TabItem>
123+
<TabItem label="Sparc (Sun)">
124+
```
125+
sethi %hi(result), %g2
126+
sethi %hi(input), %g1
127+
mov 0, %o0 # o0 = 0 (the return value of main)
128+
ld [%g1+%lo(input)], %g1 # g1 = input
129+
add %g1, %g1, %g1 # g1 = g1 + g1
130+
add %g1, 3, %g1 # g1 = 3 + g1
131+
st %g1, [%g2+%lo(result)] # result = g1
132+
jmp %o7+8
133+
nop
134+
```
135+
</TabItem>
136+
</Tabs>
137+
138+
In all cases, the side effects of `preinc()` were eliminated, and the entire `main()` function was reduced to the equivalent of `result = 2 * input + 3;`.
133139

134140
## See also
135141

0 commit comments

Comments
 (0)