Skip to content

Commit

Permalink
Merge branch 'slides-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Apr 26, 2024
2 parents fba65ee + 312dcae commit 9c5e446
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
Binary file modified docs/slides/YOMM2.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/slides/deck/03-ast.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ struct RPNVisitor : Node::Visitor {
string result;
};
string to_rpn(Node& node) {
string to_rpn(const Node& node) {
RPNVisitor viz;
node.visit(viz);
return viz.result;
Expand Down
23 changes: 12 additions & 11 deletions docs/slides/deck/04-open-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@



## Open Methods
## YOMM2 Open Methods

```c++
struct Node {
virtual string to_rpn(/*const Node* this*/) const = 0;
virtual string to_rpn(/* const Node* */) const = 0;
};
```
Expand All @@ -33,7 +33,7 @@ declare_method(string, to_rpn, (virtual_<const Node&>));

```c++
struct Plus : Node {
string to_rpn(/*const Node* this*/) const override {
string to_rpn(/* const Node* this */) const override {
return left.to_rpn() + " " + right.to_rpn() + " +";
}
};
Expand All @@ -54,8 +54,6 @@ define_method(string, to_rpn, (const Plus& expr)) {
```C++
#include <yorel/yomm2/keywords.hpp>

register_classes(Node, Number, Plus, Times);

declare_method(string, to_rpn, (virtual_<const Node&>));

define_method(string, to_rpn, (const Number& expr)) {
Expand All @@ -70,6 +68,8 @@ define_method(string, to_rpn, (const Times& expr)) {
return to_rpn(expr.left) + " " + to_rpn(expr.right) + " *";
}

register_classes(Node, Number, Plus, Times);

int main() {
yorel::yomm2::update();
cout << to_rpn(expr) << " = " << expr.value() << "\n";
Expand Down Expand Up @@ -102,12 +102,6 @@ define_method(int, value, (Plus& expr)) {

## Performance

* 15-30% slower than equivalent native virtual function call (but see `virtual_ptr`)

* [Optimizing Away C++ Virtual Functions May Be
Pointless](https://www.youtube.com/watch?v=i5MAXAxp_Tw) - Shachar Shemesh -
CppCon 2023

```asm
mov rax, qword ptr [rdi]
mov rdx, qword ptr [rip+fast_perfect_hash<release>::mult]
Expand All @@ -124,6 +118,13 @@ define_method(int, value, (Plus& expr)) {
jmp qword ptr [rax+8*rcx]
```

* 15-30% slower than equivalent native virtual function call (using perfect
integer hash; but see `virtual_ptr`)

* [Optimizing Away C++ Virtual Functions May Be
Pointless](https://www.youtube.com/watch?v=i5MAXAxp_Tw) - Shachar Shemesh -
CppCon 2023



## Multiple Dispatch
Expand Down
30 changes: 18 additions & 12 deletions docs/slides/deck/06-evolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ul>
<li class="fragment">goals:
<ul>
<li class="fragment">help promote adoption in the standard
<li class="fragment">help promote adoption in the language
<ul>
<li class="fragment">submit to Boost</li>
<li class="fragment">talk about it (CppCon 2018...)</li>
Expand Down Expand Up @@ -49,12 +49,6 @@

<br/>

```c++
declare_method(int, value, (virtual_ptr<Node>));
```
<br/>
```c++
int call_via_vptr(virtual_ptr<const Node> node) {
return value(node);
Expand All @@ -67,6 +61,12 @@ mov rax, qword ptr [rsi + 8*rax]
jmp rax
```

<br/>

```c++
declare_method(int, value, (virtual_ptr<Node>));
```
Expand Down Expand Up @@ -124,13 +124,15 @@ ret
## Core API

```c++
use_classes<Node, Number, Plus, Times> use_ast_classes;

struct value_id;
using value = method<value_id, int(virtual_<const Node&>)>;
```

```c++
auto result = value::fn(expr);
```

```c++
int number_value(const Number& node) {
return node.val;
}
Expand All @@ -145,6 +147,8 @@ struct binary_value {

YOMM2_STATIC(value::add_definition<binary_value<Plus, std::plus<int>>>);
YOMM2_STATIC(value::add_definition<binary_value<Times, std::multiplies<int>>>);

YOMM2_STATIC(use_classes<Node, Number, Plus, Times>);
```
Expand All @@ -157,10 +161,10 @@ YOMM2_STATIC(value::add_definition<binary_value<Times, std::multiplies<int>>>);
<li>virtual_ptr</li>
<li>core API</li>
<li class="fragment">template interop toolkit</li>
<li class="fragment">header only (+ Compiler Explorer)</li>
<li class="fragment">header only (Compiler Explorer)</li>
<li class="fragment">friendship</li>
<li class="fragment">member methods</li>
<li class="fragment">policies and facets
<li class="fragment">policies and facets (latest release)
<ul>
<li class="fragment">custom RTTI</li>
<li class="fragment">custom error handling, trace, vptr placement...</li>
Expand All @@ -177,9 +181,11 @@ YOMM2_STATIC(value::add_definition<binary_value<Times, std::multiplies<int>>>);
<ul>
<li class="fragment">goals:
<ul>
<li class="fragment">beat virtual function speed</li>
<li class="fragment">match (beat?) virtual function speed</li>
<li class="fragment">pre-calculate dispatch tables</li>
<li class="fragment">malloc-free operation</li>
<li class="fragment">dispatch on std::any</li>
<li class="fragment">(feature complete)</li>
<li class="fragment">C++20</li>
</ul>
</li>
Expand Down

0 comments on commit 9c5e446

Please sign in to comment.