aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/utils
AgeCommit message (Collapse)Author
2017-11-07Strengthen tests of definition of specific instructionsBjörn Gustavsson
Don't allow defining an specific operation more than once with the exact same operands. Don't allow a specific operation to be defined with different arities.
2017-11-06Remove redundant built-in macro $IS_PACKED()Björn Gustavsson
It can easily be implemented as $OPERAND_POSITION($Operand) == 0.
2017-11-06Warn when $REFRESH_GEN_DEST() is not used after a GCBjörn Gustavsson
It is easy to to forget to use $REFRESH_GEN_DEST() in an instruction that has a general destionation ('d'). Add a heuristic that should catch most if not all such problems.
2017-11-06Add the built-in macro $IF() to handle conditionalsBjörn Gustavsson
Add an $IF() macro to conditionally expand macros. Use it like this: $IF(Expression, IfTrue, IfFalse) Expression is a Perl expression that can be evaulated at macro expansion time. If the expression evaluates to 0, the result will be IfFalse, otherwise IfTrue.
2017-11-06Rename the built-in macro ARG_SIZE() to OPERAND_SIZE()Björn Gustavsson
Although the terminology "arguments" is used in the comments for beam_makeops, the documentation in beam_makeops.md consistenly use the term "operand". Since the name of the macro is user-facing, it should be consistent with the documentation.
2017-11-06Clean up definition of built-in macrosBjörn Gustavsson
Make it easier to define new macros.
2017-11-01beam_makeops: Strengthen the checking of transformationsBjörn Gustavsson
Any type that is a lower-case letter is allowed in a transformation, even though some of them don't make sense, could cause compilation errors when building the emulator, or crash at runtime. For example, the type 'z' is emitted by the compiler, but eaten by the loader before the transform engine can see it. Another example is the 'q' type, which would crash the emulator if it was used on the right side of a transformation rule. In beam_makeops, define explicitly which types that are allowed in patterns (on the left side) and in construction (on the right side). Using that information, check the transformation rules thoroughly and reject operands that don't make sense. While we are it, also correct some misleading comments.
2017-10-09Merge branch 'bjorn/erts/pack-with-opcode/OTP-14325'Björn Gustavsson
OTP-14327 OTP-14340 * bjorn/erts/pack-with-opcode/OTP-14325: Pack operands for combined instructions into the instruction word beam_makeops: Use named arguments for the code generation functions Optimize packing for "optional use" operands beam_makeops: Print the instruction name for fatal packing errors Introduce a syntax for marking operands as "optional use" beam_makeops: Refactor parsing of specific instructions Optimize instruction prefetch Pack operands into the instruction word Use 32-bits pointers to C code Move LD flags for hipe from Makefile.in to configure.in beam_disasm: Correct printing of y registers ops.tab: Slightly optimize badmatch on a Y register macros.tab: Fix assertion in SET_I_REL()
2017-10-09Pack operands for combined instructions into the instruction wordBjörn Gustavsson
The operands for the first part of a combined instruction (the entry point following the OpCase() label) can safely be packed into the instruction word. This commit will make each of the following instructions one word shorter: bs_context_to_binary_x i_band_xcjtd i_bs_get_binary_all_reuse_xft i_bs_get_integer_imm_xWtftx i_bs_get_integer_small_imm_xWftx i_bs_init_bits_fail_xjtx i_bs_init_bits_fail_yjtx i_bs_init_bits_fail_heap_sIjtx i_bs_init_bits_heap_WItx i_bs_init_fail_xjtx i_bs_init_fail_yjtx i_bs_init_fail_heap_sIjtx i_bs_init_heap_WItx i_bs_start_match2_xfttx i_bs_start_match2_yfttx i_element_xjsd i_element_yjsd i_fast_element_xjId i_fast_element_yjId i_increment_xWtd i_increment_yWtd i_jump_on_val_xfIW i_jump_on_val_yfIW i_jump_on_val_zero_xfI i_jump_on_val_zero_yfI i_minus_xxjtd i_plus_xxjtd i_plus_xyjtd i_put_tuple_xI i_put_tuple_yI i_rem_xxjtd i_select_tuple_arity_xfI i_select_tuple_arity_yfI i_select_tuple_arity2_xfAA i_select_tuple_arity2_yfAA i_select_val2_xfcc i_select_val2_yfcc i_select_val_bins_xfI i_select_val_bins_yfI i_select_val_lins_xfI i_select_val_lins_yfI
2017-10-09beam_makeops: Use named arguments for the code generation functionsBjörn Gustavsson
The number of arguments has become unwieldy.
2017-10-05Merge branch 'lukas/erts/beam-emu-vars'Lukas Larsson
* lukas/erts/beam-emu-vars: erts: Add makefile target to check emu register allocation
2017-10-05Optimize packing for "optional use" operandsBjörn Gustavsson
Operands that are marked with a "?" are not always used when an instruction is executed. Enhance the packing algorithm to place optional use operands into the instruction word even they are not the first operand (as long as the total instruction size stays the same). Here are the instructions that will be packed differently because of this change: allocate_heap t I t? allocate_heap_zero t I t? test_heap I t? i_bs_get_integer_8 x f? x i_bs_get_integer_16 x f? x i_bs_get_integer_32 x f? x
2017-10-05beam_makeops: Print the instruction name for fatal packing errorsBjörn Gustavsson
Having the instruction name available in the functions that implement packing also simplifies debugging.
2017-10-05Introduce a syntax for marking operands as "optional use"Björn Gustavsson
Introduce a syntax to mark an operand that is not always used when an instrution is executed. Example of such operands are the fail label for is_nil or the number of live registers for an allocate instruction. Use a question mark to annotate optional use: is_nil f? xy allocate t t?
2017-10-05beam_makeops: Refactor parsing of specific instructionsBjörn Gustavsson
2017-10-05Optimize instruction prefetchBjörn Gustavsson
2017-10-05Pack operands into the instruction wordBjörn Gustavsson
On 64-bit machines where the C code is always at address below 4Gb, pack one or more operands into the instruction word.
2017-10-02Merge branch 'bjorn/erts/improve-beam-ops'Björn Gustavsson
* bjorn/erts/improve-beam-ops: Move out variables from the head of combined instructions Change operand from 'P' to 'Q' for i_apply_last and i_apply_fun_last Add CHECK_ALIGNED() for testing storage destinations instrs.tab: Add missing -no_next directives beam_load.c: Generalize the 'P' operator in the packing engine Break out most of the initialization from process_main() Eliminate the OpCode() macro Eliminate unnecessary and inconsistent casts Refactor macros for accessing Beam instructions beam_emu: Make order of macros consistent beam_SUITE: Strengthen test of packed registers
2017-10-01Eliminate unnecessary and inconsistent castsBjörn Gustavsson
Consider the types in the code below: BeamInstr* I; . . . BeamInstr* next; next = (BeamInstr *) *I; Goto(next); This is illogical. If 'I' points to a BeamInstr, then 'next' should be a BeamInstr, not a pointer to a BeamInstr. The Goto() macros does not require a pointer, because it will cast its argument to a void* anyway. Therefore, this code example can be simplified to: BeamInstr* I; . . . BeamInstr next; next = *I; Goto(next); Similarly, we can remove the casts in the macros when NO_JUMP_TABLE is defined.
2017-09-30Point out the correct line number in stack tracesBjörn Gustavsson
Sometimes the line number in a stack trace could be wrong, for example for this code: t() -> Res = id(x), %<== Wrong line number. Res + 1. id(I) -> I. The line number pointed out in the stack trace would be the line before the line where the exception occurred. The reason is the way the increment instruction instruction is implemented: OpCase(i_increment_rWtd): { increment_reg_val = r(0); } I -= 1; goto increment__execute; OpCase(i_increment_xWtd): { increment_reg_val = xb(I[1]); } goto increment__execute; increment__execute: /* Common code for increment */ . . . (The implementation in OTP 20 is similar, but hand-coded directly in beam_emu.c instead of generated.) The instruction i_increment_rWtd decrements the instruction pointer (I) before jumping to the common code. That means that I points *before* the 'increment' instruction. If there is a 'line' instruction directly before the 'increment' instruction (as there is in this example), the instruction pointer will point before that line. Thus the previous line will be picked up instead. To eliminate this bug, we must never decrement the instruction pointer. Instead, we can increment the other (longer) instructions in the same group of combined instructions: OpCase(i_increment_rWtd): { increment_reg_val = r(0); } goto increment__execute; OpCase(i_increment_xWtd): { increment_reg_val = xb(I[1]); } I += 1; goto increment__execute; increment__execute: /* Common code for increment */ . . . Also fix a bug that was only a potential bug when ddaed7774eb0a introduced relative jumps, but is now a real bug. See the added comment for SET_I_REL() in macros.tab.
2017-09-27erts: Add makefile target to check emu register allocationLukas Larsson
2017-09-15Merge branch 'bjorn/erts/pack-combined'Björn Gustavsson
* bjorn/erts/pack-combined: Pack combined instructions beam_makeops: Refactor code generation Correct disassembly of select instructions
2017-09-15Merge branch 'lukas/erts/remove-dirty-scheduler-defines/OTP-14613'Lukas Larsson
* lukas/erts/remove-dirty-scheduler-defines/OTP-14613: erts: Remove possibility to disable dirty schedulers
2017-09-14Pack combined instructionsBjörn Gustavsson
2017-09-14beam_makeops: Refactor code generationBjörn Gustavsson
The refactoring will simplify packing of combined instructions.
2017-09-14Merge branch 'bjorn/erts/relative-jumps'Björn Gustavsson
* bjorn/erts/relative-jumps: Pack failure labels in i_select_val2 and i_select_tuple_arity2 Optimize i_select_tuple_arity2 and is_select_lins Rewrite select_val_bins so that its labels can be packed Pack sequences of trailing 'f' operands Implement packing of 'f' and 'j' Make sure that mask literals are 64 bits Use relative failure labels Add information about offset to common group start position Remove JUMP_OFFSET Refactor instructions to support relative jumps Introduce a new trace_jump/1 instruction for tracing Avoid using $Src more than once
2017-09-14Implement packing of 'f' and 'j'Björn Gustavsson
2017-09-14Make sure that mask literals are 64 bitsBjörn Gustavsson
Use the "ull" suffix for the mask literals instead of "ul" to ensure that the literals are 64 bits also on Windows.
2017-09-14Add information about offset to common group start positionBjörn Gustavsson
2017-09-13Add built-in macros $ARG_POSITION() and $IS_PACKED()Björn Gustavsson
2017-09-11erts: Remove possibility to disable dirty schedulersLukas Larsson
2017-09-11Check the right side of a transformation betterBjörn Gustavsson
The right side of a transformation must be either a single call to a transformation function OR a list of instructions. Mixing them like this is not supported: some_instruction A B C => gen_something(A) | other B C Unfortunately, beam_makeops would silenty ignore anything after the function call, basically handling it in the same way as: some_instruction A B C => gen_something(A) Add a sanity check to reject such mixed right-hand sides.
2017-09-04Try to avoid generating unecessary do/while wrappersBjörn Gustavsson
Make the generated code easier to read.
2017-08-31Introduce '%warm' and beam_warm.hBjörn Gustavsson
The bit syntax instructions are mixed among other instructions in beam_hot.h and beam_cold.h. Introduce a new hotness level called '%warm' with is associated file beam_warm.h. Mark all bit syntax instructions as '%warm'.
2017-08-23beam_makeops: Stop using the Arg() macroBjörn Gustavsson
Generated code uses 'I' explicitly in other places, so it can as well use 'I' when accessing the operands for instructions.
2017-08-23Eliminate the beam_instrs.h fileBjörn Gustavsson
The beam_instrs.h file serves no useful purpose. Put the instructions in beam_hot.h instead.
2017-08-23Add the 'S' type for a register sourceBjörn Gustavsson
The type 'd' could be used both for destination registers and source register. Restrict the 'd' type to only be used for destinations, and introduce the new 'S' type to be used when a source must be a register.
2017-08-23Pack cold instructions tooBjörn Gustavsson
Cold instructions used to be cooler (less frequently executed), so it did not seem worthwhile to pack their operands. Now bit syntax instructions are included among the cold instructions, and they are frequently used.
2017-08-23Pack instructions using 'q', 'c', and 's'Björn Gustavsson
Update the pack engine to safely push literal operands to the pack stack and to safely pop them back to another code address. That will allow packing of more instructions.
2017-08-23beam_makeops: Rewrite the packer, fixing several bugsBjörn Gustavsson
The packer had several bugs and limitations. For instance, on a 32-bit Erlang virtual machine it would gladly pack three 't' values into one word even though it would be not safe. The rewritten version will be more careful how much it packs into each word. It will also be able to do packing for more instructions.
2017-08-23beam_makeops: Introduce the new type 'W' (machine word)Björn Gustavsson
As a preparation for potentially improving packing in the future, we will need to make sure that packable types have a defined maximum size. The packer algorithm assumes that two 'I' operands can be packed into one 64-bit word, but there are instructions that use an 'I' operand to store a pointer. It only works because those instructions are not packed for other reasons. Introduce the 'W' type and use it for operands that don't fit in 32 bits.
2017-08-23beam_makeops: Remove the unused aliases 'N' and 'U'Björn Gustavsson
I don't remember what they were used for, but they are certainly no longer used.
2017-08-23beam_makeops: Add an additional sanity checkBjörn Gustavsson
If a type has a size in %arg_size, it should also have a defined pattern in %bit_type.
2017-08-23beam_makeops: Prevent truncation when packing 'I' valuesBjörn Gustavsson
BEAM_WIDE_MASK covered the 16 right-most bits, instead of the 32 right-most bits. This bug will bite us when we'll do more packing in the future. This bug has been harmless in the past. It has been used in test_heap and allocate instructions for the number of heap words needed. It would be theoretically possible to construct a program that would need 65536 or more heap words, but it is hard to imagine a practical use for such a program. (The program would have to build a tuple or list with at least one variable and the rest of the elements being literals.)
2017-08-22beam_makeops: Remove unused subroutine save_c_codeBjörn Gustavsson
2017-08-08beam_makeops: Pretty-print the generated codeBjörn Gustavsson
2017-08-08beam_makeops: Define ARCH_32 and ARCH_64Björn Gustavsson
2017-08-08Introduce micro instructionsBjörn Gustavsson
beam_makeops will place all micro instructions in a block and generate goto instructions from one micro instruction to the next. It will also add adjustments of 'I' if necessary (if the micro instructions have different length).
2017-08-08Simplify specifying implementation of instructionsBjörn Gustavsson
Eliminate the need to write pre-processor macros for each instruction. Instead allow the implementation of instruction to be written in C directly in the .tab files. Rewrite all existing macros in this way and remove the %macro directive.
2017-06-14Update copyright yearHans Nilsson