Speed up generic comparisons of int backed types #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
By making the small ints type known to the compiler (via the "private"
keyword) it is able to generate much better code when comparing those
values.
Example:
if v < Uint8.one then print_string "foo"
used to be compiled into (amd64 arch):
73fe5: 48 8d 05 64 47 05 00 lea 0x54764(%rip),%rax # c8750 <caml_lessthan>
73fec: e8 bf 6e 06 00 callq daeb0 <caml_c_call>
73ff1: 4c 8d 1d f0 95 0c 00 lea 0xc95f0(%rip),%r11 # 13d5e8 <caml_young_ptr>
73ff8: 4d 8b 3b mov (%r11),%r15
73ffb: 48 83 f8 01 cmp $0x1,%rax
73fff: 74 1a je ...
whereas after that change the expensive call to C is avoided:
73fd6: 48 8b 5b 10 mov 0x10(%rbx),%rbx
73fda: 48 83 e3 55 and $0x55,%rbx
73fde: 48 8b 80 10 13 00 00 mov 0x1310(%rax),%rax
73fe5: 48 39 c3 cmp %rax,%rbx
73fe8: 7d 1a jge ...
Other consequences of using the private keyword:
think is OK;
casting operator, yielding to weird values for signed types (since
those are shifted), which I think is also acceptable.