From 53e841b4e09f2c715fe459a1e4a84e4de5c161fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 25 Aug 2017 10:15:25 +0200 Subject: Add annotations for likely/unlikely In a correct Erlang programs, we can expect that: * A GC test instruction (such as test_heap) is more likely not to do the GC. * A BIF is more likely to succeed than to fail. * A BIF is more likely to fail in a guard than in a body. * An apply or fun call is likely to succeed. Annotate conditions accordingly. --- erts/emulator/beam/instrs.tab | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'erts/emulator/beam/instrs.tab') diff --git a/erts/emulator/beam/instrs.tab b/erts/emulator/beam/instrs.tab index 1af01e53bd..58432cbbb4 100644 --- a/erts/emulator/beam/instrs.tab +++ b/erts/emulator/beam/instrs.tab @@ -171,7 +171,7 @@ HANDLE_APPLY_ERROR() { i_apply() { BeamInstr *next; $APPLY(NULL, 0); - if (next != NULL) { + if (ERTS_LIKELY(next != NULL)) { $i_call(next); } $HANDLE_APPLY_ERROR(); @@ -180,7 +180,7 @@ i_apply() { i_apply_last(Deallocate) { BeamInstr *next; $APPLY(I, $Deallocate); - if (next != NULL) { + if (ERTS_LIKELY(next != NULL)) { $i_call_last(next, $Deallocate); } $HANDLE_APPLY_ERROR(); @@ -189,7 +189,7 @@ i_apply_last(Deallocate) { i_apply_only() { BeamInstr *next; $APPLY(I, 0); - if (next != NULL) { + if (ERTS_LIKELY(next != NULL)) { $i_call_only(next); } $HANDLE_APPLY_ERROR(); @@ -205,7 +205,7 @@ FIXED_APPLY(Arity, I, Deallocate) { apply(Arity) { BeamInstr *next; $FIXED_APPLY($Arity, NULL, 0); - if (next != NULL) { + if (ERTS_LIKELY(next != NULL)) { $i_call(next); } $HANDLE_APPLY_ERROR(); @@ -214,7 +214,7 @@ apply(Arity) { apply_last(Arity, Deallocate) { BeamInstr *next; $FIXED_APPLY($Arity, I, $Deallocate); - if (next != NULL) { + if (ERTS_LIKELY(next != NULL)) { $i_call_last(next, $Deallocate); } $HANDLE_APPLY_ERROR(); @@ -238,7 +238,7 @@ DISPATCH_FUN(I) { i_apply_fun() { BeamInstr *next; $APPLY_FUN(); - if (next != NULL) { + if (ERTS_LIKELY(next != NULL)) { SET_CP(c_p, $NEXT_INSTRUCTION); $DISPATCH_FUN(next); } @@ -248,7 +248,7 @@ i_apply_fun() { i_apply_fun_last(Deallocate) { BeamInstr *next; $APPLY_FUN(); - if (next != NULL) { + if (ERTS_LIKELY(next != NULL)) { $deallocate($Deallocate); $DISPATCH_FUN(next); } @@ -258,7 +258,7 @@ i_apply_fun_last(Deallocate) { i_apply_fun_only() { BeamInstr *next; $APPLY_FUN(); - if (next != NULL) { + if (ERTS_LIKELY(next != NULL)) { $DISPATCH_FUN(next); } $HANDLE_APPLY_FUN_ERROR(); @@ -274,7 +274,7 @@ CALL_FUN(Fun) { i_call_fun(Fun) { BeamInstr *next; $CALL_FUN($Fun); - if (next != NULL) { + if (ERTS_LIKELY(next != NULL)) { SET_CP(c_p, $NEXT_INSTRUCTION); $DISPATCH_FUN(next); } @@ -284,7 +284,7 @@ i_call_fun(Fun) { i_call_fun_last(Fun, Deallocate) { BeamInstr *next; $CALL_FUN($Fun); - if (next != NULL) { + if (ERTS_LIKELY(next != NULL)) { $deallocate($Deallocate); $DISPATCH_FUN(next); } @@ -378,7 +378,7 @@ element_group.fetch(Src) { element_group.execute(Fail, Index, Dst) { element_index = $Index; - if (is_small(element_index) && is_tuple(element_tuple)) { + if (ERTS_LIKELY(is_small(element_index) && is_tuple(element_tuple))) { Eterm* tp = tuple_val(element_tuple); if ((signed_val(element_index) >= 1) && @@ -402,7 +402,7 @@ fast_element_group.fetch(Src) { } fast_element_group.execute(Fail, Index, Dst) { - if (is_tuple(fast_element_tuple)) { + if (ERTS_LIKELY(is_tuple(fast_element_tuple))) { Eterm* tp = tuple_val(fast_element_tuple); Eterm pos = $Index; /* Untagged integer >= 1 */ if (pos <= arityval(*tp)) { -- cgit v1.2.3 From 50da607331bc2de990828c3c74bbf4ee7efa27f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 25 Aug 2017 14:40:50 +0200 Subject: Eliminate three arguments for the apply() helper We don't need to pass x(0), x(1), and x(2) because they can already be found in the register array. --- erts/emulator/beam/instrs.tab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'erts/emulator/beam/instrs.tab') diff --git a/erts/emulator/beam/instrs.tab b/erts/emulator/beam/instrs.tab index 58432cbbb4..19219d34bd 100644 --- a/erts/emulator/beam/instrs.tab +++ b/erts/emulator/beam/instrs.tab @@ -159,7 +159,7 @@ i_move_call_ext_last(Dest, StackOffset, Src) { APPLY(I, Deallocate) { //| -no_next HEAVY_SWAPOUT; - next = apply(c_p, r(0), x(1), x(2), reg, $I, $Deallocate); + next = apply(c_p, reg, $I, $Deallocate); HEAVY_SWAPIN; } -- cgit v1.2.3 From c3b8fa5742b5fbcd262552fa1d6cad0706fa6a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 31 Aug 2017 12:48:34 +0200 Subject: Add missing -no_next directives --- erts/emulator/beam/instrs.tab | 1 + 1 file changed, 1 insertion(+) (limited to 'erts/emulator/beam/instrs.tab') diff --git a/erts/emulator/beam/instrs.tab b/erts/emulator/beam/instrs.tab index 19219d34bd..9c3e615cea 100644 --- a/erts/emulator/beam/instrs.tab +++ b/erts/emulator/beam/instrs.tab @@ -906,5 +906,6 @@ i_raise() { c_p->freason = PRIMARY_EXCEPTION(s->freason); } goto find_func_info; + //| -no_next } -- cgit v1.2.3