Skip to content

Commit 0267cf2

Browse files
author
Matt Godbolt
committed
Images; x86 101
1 parent 7433853 commit 0267cf2

File tree

6 files changed

+140
-38
lines changed

6 files changed

+140
-38
lines changed

images/6502_z80.jpg

1.27 MB
Loading
File renamed without changes.

images/google.png

4.97 KB
Loading

images/profactor.jpg

14.3 KB
Loading

images/red_dog.png

143 KB
Loading

index.html

Lines changed: 140 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,47 @@
1010
<link rel="stylesheet" href="drw.css">
1111

1212
<style>
13-
td.reg {
14-
background-color: #333;
15-
text-align: center !important
13+
.faded {
14+
opacity: 0.7;
1615
}
1716

18-
.replaceable {
19-
position: absolute !important;
20-
width: 800px;
17+
div.footnote {
18+
margin-top: 4em;
19+
font-size: smaller;
20+
font-style: italic;
2121
}
2222

23-
.replacecontainer {
24-
position: relative;
23+
#registers th {
24+
font-size: smaller;
25+
text-align: center;
2526
}
2627

27-
.faded {
28-
opacity: 0.7;
28+
#registers td {
29+
text-align: center;
30+
}
31+
32+
#registers td.register {
33+
border: 1px solid black;
34+
}
35+
36+
#registers td.rax {
37+
background: rgb(141, 211, 199);
38+
}
39+
40+
#registers td.eax {
41+
background: rgb(255, 255, 179);
42+
}
43+
44+
#registers td.ax {
45+
background: rgb(190, 186, 218);
46+
}
47+
48+
#registers td.ah {
49+
background: rgb(251, 128, 114);
50+
}
51+
52+
#registers td.al {
53+
background: rgb(128, 177, 211);
2954
}
3055
</style>
3156

@@ -44,7 +69,7 @@
4469
<!-- TODO compile all with -Wall -Wextra -->
4570
<!-- TODO unify indentation -->
4671
<section class="slides">
47-
<section id="intro">
72+
<section id="title">
4873
<em>September 2017</em>
4974
<!-- TODO, better title format -->
5075
<h3>Unbolting the Compiler's Lid:</h3>
@@ -71,7 +96,15 @@ <h3>Why am I here?</h3>
7196
</section>
7297
<section>
7398
<h3>My background</h3>
74-
<!-- TODO z80 and 6502 pics -->
99+
<div class="fragment">
100+
<img src="images/6502_z80.jpg" width="200">
101+
<img src="images/red_dog.png" width="200">
102+
</div>
103+
<div class="fragment">
104+
<img src="images/profactor.jpg" width="100">
105+
<img src="images/google.png" width="100">
106+
<img src="images/DRWSmallLogo.png" width="100">
107+
</div>
75108
<aside class="notes">
76109
<h4>Potted history:</h4>
77110
<ul>
@@ -118,6 +151,7 @@ <h3>Backstory</h3>
118151
for (int x : v) result += x;
119152
return result;
120153
}</code></pre>
154+
<div class="fragment">Which is better? Check the compiler output!</div>
121155
<aside class="notes">
122156
<ul>
123157
<li>love performance</li>
@@ -151,15 +185,70 @@ <h3>WARNING</h3>
151185
<!-- reference "just enough asm to be dangerous talk -->
152186
<section>
153187
<h3>x86 Assembly 101</h3>
154-
<h5>Registers</h5>
155188
</section>
156189
<section>
157-
<h3>x86 Assembly 101</h3>
158-
<h5>Calling convention</h5>
190+
<h3>Registers</h3>
191+
<ul>
192+
<li>rax, rbx, rcx, rdx, rsp, rbp, rsi, rdi, r8-r15</li>
193+
<li>xmm0-15, ymm0-15, zmm0-15</li>
194+
<li>cs, ds, ss, es, fs, gs</li>
195+
<li>flags</li>
196+
</ul>
159197
</section>
160198
<section>
161-
<h3>x86 Assembly 101</h3>
162-
<h5>Instructions</h5>
199+
<h3>Registers</h3>
200+
<table id="registers">
201+
<thead>
202+
<tr>
203+
<th>63...56</th>
204+
<th>55...48</th>
205+
<th>47...40</th>
206+
<th>39...32</th>
207+
<th>31...24</th>
208+
<th>23...16</th>
209+
<th>15...8</th>
210+
<th>7...0</th>
211+
</tr>
212+
</thead>
213+
<tbody>
214+
<tr>
215+
<td colspan="8" class="register rax">rax</td>
216+
</tr>
217+
<tr>
218+
<td colspan="4">(zeroed out)</td>
219+
<td colspan="4" class="register eax">eax</td>
220+
</tr>
221+
<tr>
222+
<td colspan="6"></td>
223+
<td colspan="2" class="register ax">ax</td>
224+
</tr>
225+
<tr>
226+
<td colspan="6"></td>
227+
<td colspan="1" class="register ah">ah</td>
228+
<td colspan="1"></td>
229+
</tr>
230+
<tr>
231+
<td colspan="7"></td>
232+
<td colspan="1" class="register al">al</td>
233+
</tr>
234+
</tbody>
235+
</table>
236+
</section>
237+
<section>
238+
<h3>Calling convention</h3>
239+
<pre><code class="cpp">long func(int a, short b, char c);</code></pre>
240+
<ul class="fragment">
241+
<li>Params: rdi, rsi, rdx, rcx, r8, r9; xmm0-7</li>
242+
<li>Return: eax / xmm0</li>
243+
<li>Callee-save: rbp, rbx, r12–r15</li>
244+
</ul>
245+
<div class="fragment">
246+
<pre><code class="cpp">rax func(edi a, si b, dl c);</code></pre>
247+
</div>
248+
<div class="footnote">(System V AMD64 ABI)</div>
249+
</section>
250+
<section>
251+
<h3>Instructions</h3>
163252
<pre><code data-trim class="x86asm">
164253
mov eax, 1234 ; eax = 1234
165254
mov ecx, 5678 ; ecx = 5678
@@ -169,20 +258,27 @@ <h5>Instructions</h5>
169258
</code></pre>
170259
</section>
171260
<section>
172-
<h3>x86 Assembly 101</h3>
173-
<h5>Instructions</h5>
261+
<h3>Instructions</h3>
174262
<pre><code data-trim class="x86asm">
175-
mov eax, DWORD PTR [r14] ; eax = *(int32_t *)rdi
176-
mov eax, DWORD PTR [r14 + 4] ; eax = *(int32_t *)(rdi + 4)
263+
mov eax, DWORD PTR [r14] ; eax = *(uint32_t *)rdi
264+
mov eax, DWORD PTR [r14 + 4] ; eax = *(uint32_t *)(rdi + 4)
177265
mov eax, DWORD PTR [r14 + 4 * rbx]
178-
; eax = *(int32_t *)(rdi + 4 * rbx)
179-
lea eax, [r14 + 4 * rbx]
180-
; eax = (rdi + 4 * rbx)
181-
</code></pre>
266+
; eax = *(uint32_t *)(rdi + 4 * rbx)
267+
lea rax, [r14 + 4 * rbx] ; eax = (rdi + 4 * rbx)
268+
</code></pre>
269+
<pre class="fragment"><code data-trim class="cpp">
270+
int eax = *r14; // int *r14;
271+
int eax = r14[1];
272+
int eax = r14[rbx];
273+
int *rax = &r14[rbx];
274+
</code></pre>
182275
</section>
183276
<section>
184-
<h3>Miscellaneous</h3>
277+
<h3>Instructions</h3>
185278
<pre><code data-trim class="x86asm">
279+
sub eax, edi
280+
movsx rax, di
281+
push rax
186282
vpaddd ymm0, ymm0, ymmword ptr [rax]
187283
popcnt rax
188284
bsf rax
@@ -211,15 +307,11 @@ <h3>Where were we?</h3>
211307
}</code></pre>
212308
</section>
213309
<section>
214-
<h3>CE v1</h3>
310+
<h3>Compiler Explorer v0.1</h3>
215311
<pre><code data-noescape data-trim class="bash">
216312
$ g++ /tmp/test.cc -O1 -c -S -o -masm=intel -
217-
<span class="fragment" data-fragment-index="3">| c++filt</span>
218-
<span class="fragment" data-fragment-index="4">| grep -vE '\s+\.'</span>
219313
</code></pre>
220-
<div class="replacecontainer">
221-
<pre class="fragment current-visible replaceable" data-fragment-index="2"><code class="x86asm"
222-
data-trim>
314+
<pre class="fragment"><code class="x86asm" data-trim>
223315
.file "test.cc"
224316
.text
225317
.globl _Z3sumRKSt6vectorIiSaIiEE
@@ -231,8 +323,13 @@ <h3>CE v1</h3>
231323
mov rax, QWORD PTR 8[rdi]
232324
sub rax, rcx
233325
...</code></pre>
234-
<pre class="fragment current-visible replaceable" data-fragment-index="3"><code class="x86asm"
235-
data-trim>
326+
</section>
327+
<section>
328+
<h3>Compiler Explorer v0.1</h3>
329+
<pre><code data-noescape data-trim class="bash">
330+
$ g++ /tmp/test.cc -O1 -c -S -o -masm=intel - | c++filt
331+
</code></pre>
332+
<pre><code class="x86asm" data-trim>
236333
.file "test.cc"
237334
.text
238335
.globl sum(std::vector&lt;int, std::allocator&lt;int> > const&)
@@ -244,8 +341,14 @@ <h3>CE v1</h3>
244341
mov rax, QWORD PTR 8[rdi]
245342
sub rax, rcx
246343
...</code></pre>
247-
<pre class="fragment current-visible replaceable" data-fragment-index="4"><code class="x86asm"
248-
data-trim>
344+
</section>
345+
<section>
346+
<h3>Compiler Explorer v0.1</h3>
347+
<pre><code data-noescape data-trim class="bash">
348+
$ g++ /tmp/test.cc -O1 -c -S -o -masm=intel - | c++filt \
349+
| grep -vE '\s+\.'
350+
</code></pre>
351+
<pre><code class="x86asm" data-trim>
249352
sum(std::vector&lt;int, std::allocator&lt;int> > const&):
250353
.LFB786:
251354
mov rcx, QWORD PTR [rdi]
@@ -257,7 +360,6 @@ <h3>CE v1</h3>
257360
mov edx, 0
258361
mov eax, 0
259362
...</code></pre>
260-
</div>
261363
</section>
262364
</section>
263365

@@ -1127,7 +1229,7 @@ <h3>Variant</h3>
11271229

11281230
<div class="footer">
11291231
<hr>
1130-
<img src="DRWSmallLogo.png" width="50" height="16">
1232+
<img src="images/DRWSmallLogo.png" width="50" height="16">
11311233
</div>
11321234
</section>
11331235
</div>

0 commit comments

Comments
 (0)