Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit moves ruby_basic_operators and the unredefined macros out of vm_core.h and into basic_operators.h so that we can use them more broadly in places where we currently use a method look up via `rb_method_basic_definition_p` (e.g. object.c, numeric.c, complex.c, enum.c, but also in internal/compar.h after introducing BOP_CMP and elsewhere if we introduce more BOPs) The most controversial part of this change is probably moving redefined_flag out of rb_vm_t. [vm_opt_method_def_table and vm_opt_mid_table](https://github.com/ruby/ruby/blob/9da2a5204f32a4f2ce135fddde2abb6e07d647e9/vm.c) are not part of rb_vm_t either, and I think this fits well with those. But more significantly it seems to result in one fewer instruction. For example: Before: ``` (lldb) disassemble -n vm_opt_str_freeze miniruby`vm_exec_core: miniruby[0x10028233e] <+14558>: movq 0x11a86b(%rip), %rax ; ruby_current_vm_ptr miniruby[0x100282345] <+14565>: testb $0x4, 0x242c(%rax) ``` After: ``` (lldb) disassemble -n vm_opt_str_freeze ruby`vm_exec_core: ruby[0x100280ebe] <+14510>: testb $0x4, 0x120147(%rip) ; ruby_vm_redefined_flag + 43 ``` Co-authored-by: John Hawthorn <jhawthorn@github.com>
- Loading branch information
1 parent
9d4483f
commit c43951e
Showing
4 changed files
with
95 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#ifndef INTERNAL_BOP_H /*-*-C-*-vi:se ft=c:*/ | ||
#define INTERNAL_BOP_H | ||
|
||
#include "internal.h" | ||
#include "ruby/internal/dllexport.h" | ||
|
||
enum ruby_basic_operators { | ||
BOP_PLUS, | ||
BOP_MINUS, | ||
BOP_MULT, | ||
BOP_DIV, | ||
BOP_MOD, | ||
BOP_EQ, | ||
BOP_EQQ, | ||
BOP_LT, | ||
BOP_LE, | ||
BOP_LTLT, | ||
BOP_AREF, | ||
BOP_ASET, | ||
BOP_LENGTH, | ||
BOP_SIZE, | ||
BOP_EMPTY_P, | ||
BOP_NIL_P, | ||
BOP_SUCC, | ||
BOP_GT, | ||
BOP_GE, | ||
BOP_NOT, | ||
BOP_NEQ, | ||
BOP_MATCH, | ||
BOP_FREEZE, | ||
BOP_UMINUS, | ||
BOP_MAX, | ||
BOP_MIN, | ||
BOP_CALL, | ||
BOP_AND, | ||
BOP_OR, | ||
|
||
BOP_LAST_ | ||
}; | ||
|
||
MJIT_SYMBOL_EXPORT_BEGIN | ||
RUBY_EXTERN short ruby_vm_redefined_flag[BOP_LAST_]; | ||
MJIT_SYMBOL_EXPORT_END | ||
|
||
/* optimize insn */ | ||
#define INTEGER_REDEFINED_OP_FLAG (1 << 0) | ||
#define FLOAT_REDEFINED_OP_FLAG (1 << 1) | ||
#define STRING_REDEFINED_OP_FLAG (1 << 2) | ||
#define ARRAY_REDEFINED_OP_FLAG (1 << 3) | ||
#define HASH_REDEFINED_OP_FLAG (1 << 4) | ||
/* #define BIGNUM_REDEFINED_OP_FLAG (1 << 5) */ | ||
#define SYMBOL_REDEFINED_OP_FLAG (1 << 6) | ||
#define TIME_REDEFINED_OP_FLAG (1 << 7) | ||
#define REGEXP_REDEFINED_OP_FLAG (1 << 8) | ||
#define NIL_REDEFINED_OP_FLAG (1 << 9) | ||
#define TRUE_REDEFINED_OP_FLAG (1 << 10) | ||
#define FALSE_REDEFINED_OP_FLAG (1 << 11) | ||
#define PROC_REDEFINED_OP_FLAG (1 << 12) | ||
|
||
#define BASIC_OP_UNREDEFINED_P(op, klass) (LIKELY(ruby_vm_redefined_flag[(op)]&(klass)) == 0) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters