Skip to content

Commit 7433853

Browse files
author
Matt Godbolt
committed
First read through. still tons TODO
1 parent e5d8d82 commit 7433853

File tree

1 file changed

+93
-67
lines changed

1 file changed

+93
-67
lines changed

index.html

Lines changed: 93 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ <h3>Functions</h3>
569569
<section><h3>Virtual methods</h3>
570570
<pre><code class="ce">
571571
/// g71:-O2 -std=c++1z
572-
//setup
572+
// setup
573573
#include &lt;vector>
574574
using namespace std;
575575
struct Coster { virtual int costFor(int x) const = 0; };
@@ -589,7 +589,7 @@ <h3>Functions</h3>
589589
nextCost?
590590
even this generates tons of code
591591
592-
//setup
592+
// setup
593593
#include &lt;vector>
594594
using namespace std;
595595
struct Coster { virtual int nextCost() = 0; };
@@ -655,19 +655,19 @@ <h3>Functions</h3>
655655
</aside>
656656
</section>
657657
<section>
658-
<h3>Restrict</h3>
658+
<h3>Aliasing</h3>
659659
<!-- TODO - some story about compilers pessimistic? -->
660660
<pre><code class="ce">
661-
/// g71:-Ofast
662-
#include &lt;functional>
663-
664-
void max(
665-
int *__restrict begin,
666-
int *__restrict end,
667-
int *__restrict out) {
668-
*out = *begin;
669-
for (auto i = begin; i != end; ++i) {
670-
*out = std::max(*i, *out);
661+
/// g71:-O2 -std=c++1z
662+
// setup
663+
#include &lt;functional>
664+
#include &lt;cstddef>
665+
666+
void sum(int *first, size_t num,
667+
int *out_sum) {
668+
*out_sum = 0;
669+
for (size_t i = 0; i < num; ++i) {
670+
*out_sum += first[i];
671671
}
672672
}
673673
</code></pre>
@@ -676,19 +676,20 @@ <h3>Restrict</h3>
676676
<h3>Likelihood analysis</h3>
677677
<!-- TODO -->
678678
<!--clang vs gcc difference here -->
679+
<!-- likely doesn't work here in clang :'( -->
679680
<pre><code class="ce">
680-
/// g71:-O3 -march=haswell -std=c++1z
681+
/// g71:-O2 -std=c++1z
681682
// setup
682-
extern void bar();
683-
void foo(int a, int b, int c) {
684-
if (a == 0 && b == 0 && c == 0) return;
685-
bar();
683+
extern void allZero();
684+
extern void notAllZero();
685+
void testZeroFirst(int a, int b, int c) {
686+
if (a == 0 && b == 0 && c == 0) allZero();
687+
else notAllZero();
686688
}
687-
void foo(int a, int b, int c, int d, int e, int f, int g, int h) {
688-
if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0
689-
&& f == 0 && g == 0 && h == 0)
690-
return;
691-
bar();
689+
690+
void testNotZeroFirst(int a, int b, int c) {
691+
if (!(a == 0 && b == 0 && c == 0)) notAllZero();
692+
else allZero();
692693
}
693694
</code></pre>
694695
</section>
@@ -698,8 +699,9 @@ <h3>Helping the compiler out</h3>
698699
/// g71:-O3 -std=c++1z -march=haswell
699700
// setup
700701
#include &lt;cstddef>
701-
int testFunction(const int *input, size_t length) {
702-
input = static_cast&lt;decltype(input)>(__builtin_assume_aligned(input, 64));
702+
int sum(const int *input, size_t length) {
703+
input = static_cast&lt;decltype(input)>(
704+
__builtin_assume_aligned(input, 64));
703705
if (length & 63) __builtin_unreachable();
704706
if (length == 0) __builtin_unreachable();
705707

@@ -712,6 +714,7 @@ <h3>Helping the compiler out</h3>
712714
</code></pre>
713715
</section>
714716
<section>
717+
<!-- TODO this still? -->
715718
<h3>Case Study: auto copy / move / etc (Chrome copied all its images moved instead of moved..)</h3>
716719
<pre><code class="cpp ce">
717720
// setup
@@ -736,7 +739,10 @@ <h3>Case Study: auto copy / move / etc (Chrome copied all its images moved inste
736739

737740
<!------------------------------------------------------->
738741
<section id="ubIsYourFriend">
739-
<!-- TODO -->
742+
<section>
743+
<h3>Undefined behaviour</h3>
744+
<h5 class="fragment">Can be your friend</h5>
745+
</section>
740746
<section>
741747
<h3>Infinite loops</h3>
742748
<!-- TODO get C++ standards quote -->
@@ -763,32 +769,47 @@ <h3>Infinite loops</h3>
763769
<section><h3>index signed vs unsigned</h3>
764770
<pre><code data-trim class="cpp ce">
765771
/// g71:-O2 -std=c++1z
766-
// setup
772+
// setup
767773
#include &lt;cstdint>
768774

769-
int sum1000(char *a, int32_t offset) {
775+
int sum1000(const char *a, uint32_t offset) {
770776
int res = 0;
771-
for (decltype(offset) i = 0; i < 1000; ++i)
772-
res += a[offset + i];
777+
auto end = offset + 1000;
778+
while (offset < end)
779+
res += a[offset++];
773780
return res;
774781
}
775782
</code></pre>
776783
<aside class="notes">
777784
show it uint32_t and int32_t
785+
TODO still weak
778786
</aside>
779787
</section>
780-
<section><h3>heap elision?</h3></section>
788+
<section><h3>Heap elision</h3>
789+
<pre><code data-trim class="cpp ce">
790+
/// g71:-O2 -std=c++1z
791+
// setup
792+
#include &lt;memory>
793+
using namespace std;
794+
795+
int func() {
796+
auto a = make_unique&lt;int>(42);
797+
auto b = make_unique&lt;int>(24);
798+
return *a + *b;
799+
}
800+
</code></pre>
801+
</section>
781802
</section>
782803

783804

784805
<!------------------------------------------------------->
785806
<section id="usingCE">
786807
<!-- TODO -->
787808
<section>
788-
<section>
789-
<h3>Appropriately defeating the optimizer to see what you'd expect</h3>
790-
</section>
791-
<section>
809+
<h3>Using Compiler Explorer</h3>
810+
</section>
811+
<section>
812+
<h3>Optimizer too clever</h3>
792813
<pre><code data-trim class="cpp ce">
793814
/// g71:-O2 -std=c++1z
794815
constexpr int sumTo(int x) {
@@ -802,22 +823,22 @@ <h3>Appropriately defeating the optimizer to see what you'd expect</h3>
802823
return sumTo(20);
803824
}
804825
</code></pre>
805-
<aside class="notes">
806-
<ul>
807-
<li>Show code</li>
808-
<li>Modify code to show how to make it depend on argc/argv</li>
809-
<li>Show clang's cleverness</li>
810-
<li>Show clang's weirdness if starting at 1 instead of 0</li>
811-
</ul>
812-
</aside>
813-
</section>
814-
<section>
815-
TODO: math bit? maybe show nice n x (n-1)
816-
</section>
817-
<section>
818-
<h3>Classes?</h3>
819-
<pre><code class="cpp ce">
820-
/// g71:-O0 -std=c++1z
826+
<aside class="notes">
827+
<ul>
828+
<li>Show code</li>
829+
<li>Modify code to show how to make it depend on argc/argv</li>
830+
<li>Show clang's cleverness</li>
831+
<li>Show clang's weirdness if starting at 1 instead of 0</li>
832+
</ul>
833+
</aside>
834+
</section>
835+
<section>
836+
TODO: math bit? maybe show nice n x (n-1)
837+
</section>
838+
<section>
839+
<h3>Classes?</h3>
840+
<pre><code class="cpp ce">
841+
/// g71:-O2 -std=c++1z
821842
class Holder {
822843
int value_{0};
823844
public:
@@ -826,13 +847,20 @@ <h3>Classes?</h3>
826847
}
827848
};
828849
</code></pre>
829-
</section>
830-
<section>
831-
<h3>Templates</h3>
832-
<!--tODO-->
833-
</section>
850+
<aside class="notes">
851+
<ul>
852+
<li>
853+
<pre>auto f = &amp;Holder::value;</pre>
854+
</li>
855+
<li>define out of line</li>
856+
<li>call from a test function</li>
857+
</ul>
858+
</aside>
859+
</section>
860+
<section>
861+
<h3>Templates</h3>
862+
<!--tODO-->
834863
</section>
835-
<section><h3>Templates</h3></section>
836864
<section><h3>Power use demo</h3></section>
837865
</section>
838866

@@ -952,15 +980,17 @@ <h3>How it works - Backend</h3>
952980
<h3><code>node.js</code></h3>
953981
<pre><code class="javascript" data-trim>
954982
function compile(req, res, next) {
955-
// exec req.compiler, feed it req.body, parse output, return via res
983+
// exec req.compiler, feed it req.body
984+
// parse output, return via res
956985
}
957986
var webServer = express();
958987
var apiHandler = express.Router();
959-
apiHandler.param('compiler', function (req, res, next, compilerName) {
960-
req.compiler = compilerName;
961-
next();
962-
};
963-
apiHandler.post('/compiler/:compiler/compile', compileHandler);
988+
apiHandler.param('compiler',
989+
function (req, res, next, compiler) {
990+
req.compiler = compiler;
991+
next();
992+
});
993+
apiHandler.post('/compiler/:compiler/compile', compile);
964994
webServer.use('/api', apiHandler);
965995
webServer.listen(10240);
966996
</code></pre>
@@ -1037,10 +1067,6 @@ <h3>Conclusions</h3>
10371067
</ul>
10381068
<!-- TODO -->
10391069
</section>
1040-
<section><h3>Conclusions and call to action!</h3></section>
1041-
<section><h3>Everyone should be using this!</h3></section>
1042-
<section><h3>Thanks to my contributors and patreon supporters</h3></section>
1043-
<section><h3>Help wanted</h3></section>
10441070
<section>
10451071
<h3>Go read some assembly!</h3>
10461072
<br>

0 commit comments

Comments
 (0)