@@ -569,7 +569,7 @@ <h3>Functions</h3>
569
569
< section > < h3 > Virtual methods</ h3 >
570
570
< pre > < code class ="ce ">
571
571
/// g71:-O2 -std=c++1z
572
- //setup
572
+ // setup
573
573
#include <vector>
574
574
using namespace std;
575
575
struct Coster { virtual int costFor(int x) const = 0; };
@@ -589,7 +589,7 @@ <h3>Functions</h3>
589
589
nextCost?
590
590
even this generates tons of code
591
591
592
- //setup
592
+ // setup
593
593
#include <vector>
594
594
using namespace std;
595
595
struct Coster { virtual int nextCost() = 0; };
@@ -655,19 +655,19 @@ <h3>Functions</h3>
655
655
</ aside >
656
656
</ section >
657
657
< section >
658
- < h3 > Restrict </ h3 >
658
+ < h3 > Aliasing </ h3 >
659
659
<!-- TODO - some story about compilers pessimistic? -->
660
660
< pre > < code class ="ce ">
661
- /// g71:-Ofast
662
- #include <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 <functional >
664
+ #include <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] ;
671
671
}
672
672
}
673
673
</ code > </ pre >
@@ -676,19 +676,20 @@ <h3>Restrict</h3>
676
676
< h3 > Likelihood analysis</ h3 >
677
677
<!-- TODO -->
678
678
<!--clang vs gcc difference here -->
679
+ <!-- likely doesn't work here in clang :'( -->
679
680
< pre > < code class ="ce ">
680
- /// g71:-O3 -march=haswell -std=c++1z
681
+ /// g71:-O2 -std=c++1z
681
682
// 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();
686
688
}
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();
692
693
}
693
694
</ code > </ pre >
694
695
</ section >
@@ -698,8 +699,9 @@ <h3>Helping the compiler out</h3>
698
699
/// g71:-O3 -std=c++1z -march=haswell
699
700
// setup
700
701
#include <cstddef>
701
- int testFunction(const int *input, size_t length) {
702
- input = static_cast<decltype(input)> (__builtin_assume_aligned(input, 64));
702
+ int sum(const int *input, size_t length) {
703
+ input = static_cast<decltype(input)> (
704
+ __builtin_assume_aligned(input, 64));
703
705
if (length & 63) __builtin_unreachable();
704
706
if (length == 0) __builtin_unreachable();
705
707
@@ -712,6 +714,7 @@ <h3>Helping the compiler out</h3>
712
714
</ code > </ pre >
713
715
</ section >
714
716
< section >
717
+ <!-- TODO this still? -->
715
718
< h3 > Case Study: auto copy / move / etc (Chrome copied all its images moved instead of moved..)</ h3 >
716
719
< pre > < code class ="cpp ce ">
717
720
// setup
@@ -736,7 +739,10 @@ <h3>Case Study: auto copy / move / etc (Chrome copied all its images moved inste
736
739
737
740
<!------------------------------------------------------->
738
741
< section id ="ubIsYourFriend ">
739
- <!-- TODO -->
742
+ < section >
743
+ < h3 > Undefined behaviour</ h3 >
744
+ < h5 class ="fragment "> Can be your friend</ h5 >
745
+ </ section >
740
746
< section >
741
747
< h3 > Infinite loops</ h3 >
742
748
<!-- TODO get C++ standards quote -->
@@ -763,32 +769,47 @@ <h3>Infinite loops</h3>
763
769
< section > < h3 > index signed vs unsigned</ h3 >
764
770
< pre > < code data-trim class ="cpp ce ">
765
771
/// g71:-O2 -std=c++1z
766
- // setup
772
+ // setup
767
773
#include <cstdint>
768
774
769
- int sum1000(char *a, int32_t offset) {
775
+ int sum1000(const char *a, uint32_t offset) {
770
776
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++];
773
780
return res;
774
781
}
775
782
</ code > </ pre >
776
783
< aside class ="notes ">
777
784
show it uint32_t and int32_t
785
+ TODO still weak
778
786
</ aside >
779
787
</ 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 <memory>
793
+ using namespace std;
794
+
795
+ int func() {
796
+ auto a = make_unique<int> (42);
797
+ auto b = make_unique<int> (24);
798
+ return *a + *b;
799
+ }
800
+ </ code > </ pre >
801
+ </ section >
781
802
</ section >
782
803
783
804
784
805
<!------------------------------------------------------->
785
806
< section id ="usingCE ">
786
807
<!-- TODO -->
787
808
< 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 >
792
813
< pre > < code data-trim class ="cpp ce ">
793
814
/// g71:-O2 -std=c++1z
794
815
constexpr int sumTo(int x) {
@@ -802,22 +823,22 @@ <h3>Appropriately defeating the optimizer to see what you'd expect</h3>
802
823
return sumTo(20);
803
824
}
804
825
</ 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
821
842
class Holder {
822
843
int value_{0};
823
844
public:
@@ -826,13 +847,20 @@ <h3>Classes?</h3>
826
847
}
827
848
};
828
849
</ 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 = &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-->
834
863
</ section >
835
- < section > < h3 > Templates</ h3 > </ section >
836
864
< section > < h3 > Power use demo</ h3 > </ section >
837
865
</ section >
838
866
@@ -952,15 +980,17 @@ <h3>How it works - Backend</h3>
952
980
< h3 > < code > node.js</ code > </ h3 >
953
981
< pre > < code class ="javascript " data-trim >
954
982
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
956
985
}
957
986
var webServer = express();
958
987
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);
964
994
webServer.use('/api', apiHandler);
965
995
webServer.listen(10240);
966
996
</ code > </ pre >
@@ -1037,10 +1067,6 @@ <h3>Conclusions</h3>
1037
1067
</ ul >
1038
1068
<!-- TODO -->
1039
1069
</ 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 >
1044
1070
< section >
1045
1071
< h3 > Go read some assembly!</ h3 >
1046
1072
< br >
0 commit comments