Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 243 lines (189 sloc) 6.953 kB
a3e1b1c @ko1 * Merge YARV
ko1 authored
1 /**********************************************************************
2
3 insnhelper.h - helper macros to implement each instructions
4
5 $Author$
6 created at: 04/01/01 15:50:34 JST
7
d907cbc @ko1 * blockinlining.c, compile.c, compile.h, debug.c, debug.h,
ko1 authored
8 Copyright (C) 2004-2007 Koichi Sasada
a3e1b1c @ko1 * Merge YARV
ko1 authored
9
10 **********************************************************************/
11
8a9993d @nobu * eval_intern.h, insnhelper.h, thread_pthread.h, vm_core.h, vm_opts.h:
nobu authored
12 #ifndef RUBY_INSNHELPER_H
13 #define RUBY_INSNHELPER_H
a3e1b1c @ko1 * Merge YARV
ko1 authored
14
8cd252a @ko1 * common.mk: clean up
ko1 authored
15 /**
16 * VM Debug Level
17 *
18 * debug level:
19 * 0: no debug output
20 * 1: show instruction name
21 * 2: show stack frame when control stack frame is changed
22 * 3: show stack status
23 * 4: show register
24 * 5:
25 * 10: gc check
26 */
27
28 #ifndef VMDEBUG
29 #define VMDEBUG 0
30 #endif
31
32 #if 0
33 #undef VMDEBUG
34 #define VMDEBUG 3
35 #endif
36
7215c9a @ko1 * vm.c, vm_insnhelper.h (ruby_vm_redefined_flag): apply optimization
ko1 authored
37 enum {
38 BOP_PLUS,
39 BOP_MINUS,
40 BOP_MULT,
41 BOP_DIV,
42 BOP_MOD,
43 BOP_EQ,
8e8e343 @ko1 * insns.def, vm.c, vm_insnhelper.c, vm_insnhelper.h: check
ko1 authored
44 BOP_EQQ,
7215c9a @ko1 * vm.c, vm_insnhelper.h (ruby_vm_redefined_flag): apply optimization
ko1 authored
45 BOP_LT,
46 BOP_LE,
47 BOP_LTLT,
48 BOP_AREF,
49 BOP_ASET,
50 BOP_LENGTH,
f825d84 @ko1 * compile.c (iseq_specialized_instruction), insns.def (opt_size):
ko1 authored
51 BOP_SIZE,
7215c9a @ko1 * vm.c, vm_insnhelper.h (ruby_vm_redefined_flag): apply optimization
ko1 authored
52 BOP_SUCC,
53 BOP_GT,
54 BOP_GE,
55 BOP_NOT,
56 BOP_NEQ,
57
fe867f4 @nobu * cont.c (fiber_status), template/insns.inc.tmpl (ruby_vminsn_type),
nobu authored
58 BOP_LAST_
7215c9a @ko1 * vm.c, vm_insnhelper.h (ruby_vm_redefined_flag): apply optimization
ko1 authored
59 };
60
61 extern char ruby_vm_redefined_flag[BOP_LAST_];
a3a45fa @ko1 * vm.c (rb_vm_inc_const_missing_count, ruby_vm_const_missing_count):
ko1 authored
62 extern VALUE ruby_vm_const_missing_count;
8cd252a @ko1 * common.mk: clean up
ko1 authored
63
a3e1b1c @ko1 * Merge YARV
ko1 authored
64
65 /**********************************************************/
66 /* deal with stack */
67 /**********************************************************/
68
69 #define PUSH(x) (SET_SV(x), INC_SP(1))
70 #define TOPN(n) (*(GET_SP()-(n)-1))
5f05c26 @unak * insnhelper.h, insns.def (DEC_SP): shoudn't use unary minus operator
unak authored
71 #define POPN(n) (DEC_SP(n))
72 #define POP() (DEC_SP(1))
6287295 @unak * insnhelper.h (INC_SP): shouldn't cast ``x'' to unsigned type because
unak authored
73 #define STACK_ADDR_FROM_TOP(n) (GET_SP()-(n))
a3e1b1c @ko1 * Merge YARV
ko1 authored
74
75 #define GET_TOS() (tos) /* dummy */
76
77 /**********************************************************/
78 /* deal with registers */
79 /**********************************************************/
80
81 #define REG_CFP (reg_cfp)
82 #define REG_PC (REG_CFP->pc)
83 #define REG_SP (REG_CFP->sp)
0a71db8 @ko1 * vm_core.h: remove lfp (local frame pointer) and rename
ko1 authored
84 #define REG_EP (REG_CFP->ep)
a3e1b1c @ko1 * Merge YARV
ko1 authored
85
59202b7 @ko1 * insnhelper.h (RESTORE_REGS): add do/while(0) around macro.
ko1 authored
86 #define RESTORE_REGS() do { \
a3e1b1c @ko1 * Merge YARV
ko1 authored
87 REG_CFP = th->cfp; \
59202b7 @ko1 * insnhelper.h (RESTORE_REGS): add do/while(0) around macro.
ko1 authored
88 } while (0)
a3e1b1c @ko1 * Merge YARV
ko1 authored
89
90 #define REG_A reg_a
91 #define REG_B reg_b
92
0a71db8 @ko1 * vm_core.h: remove lfp (local frame pointer) and rename
ko1 authored
93 enum vm_regan_regtype {
94 VM_REGAN_PC = 0,
95 VM_REGAN_SP = 1,
96 VM_REGAN_EP = 2,
97 VM_REGAN_CFP = 3,
98 VM_REGAN_SELF = 4,
99 VM_REGAN_ISEQ = 5,
100 };
101 enum vm_regan_acttype {
102 VM_REGAN_ACT_GET = 0,
103 VM_REGAN_ACT_SET = 1,
104 };
105
a3e1b1c @ko1 * Merge YARV
ko1 authored
106 #ifdef COLLECT_USAGE_ANALYSIS
107 #define USAGE_ANALYSIS_REGISTER_HELPER(a, b, v) \
0a71db8 @ko1 * vm_core.h: remove lfp (local frame pointer) and rename
ko1 authored
108 (USAGE_ANALYSIS_REGISTER((VM_REGAN_#a), (VM_REGAN_ACT_#b)), (v))
a3e1b1c @ko1 * Merge YARV
ko1 authored
109 #else
061cce6 @ko1 * insnhelper.h, vm.h: some refactoring.
ko1 authored
110 #define USAGE_ANALYSIS_REGISTER_HELPER(a, b, v) (v)
a3e1b1c @ko1 * Merge YARV
ko1 authored
111 #endif
112
113 /* PC */
0a71db8 @ko1 * vm_core.h: remove lfp (local frame pointer) and rename
ko1 authored
114 #define GET_PC() (USAGE_ANALYSIS_REGISTER_HELPER(PC, GET, REG_PC))
115 #define SET_PC(x) (REG_PC = (USAGE_ANALYSIS_REGISTER_HELPER(PC, SET, (x))))
a3e1b1c @ko1 * Merge YARV
ko1 authored
116 #define GET_CURRENT_INSN() (*GET_PC())
117 #define GET_OPERAND(n) (GET_PC()[(n)])
118 #define ADD_PC(n) (SET_PC(REG_PC + (n)))
119
14c3aa5 @ko1 * proc.c (Init_Proc), eval.c (Init_eval), eval_intern.h: move
ko1 authored
120 #define GET_PC_COUNT() (REG_PC - GET_ISEQ()->iseq_encoded)
a3e1b1c @ko1 * Merge YARV
ko1 authored
121 #define JUMP(dst) (REG_PC += (dst))
122
0a71db8 @ko1 * vm_core.h: remove lfp (local frame pointer) and rename
ko1 authored
123 /* frame pointer, environment pointer */
124 #define GET_CFP() (USAGE_ANALYSIS_REGISTER_HELPER(CFP, GET, REG_CFP))
125 #define GET_EP() (USAGE_ANALYSIS_REGISTER_HELPER(EP, GET, REG_EP))
126 #define SET_EP(x) (REG_EP = (USAGE_ANALYSIS_REGISTER_HELPER(EP, SET, (x))))
127 #define GET_LEP() (VM_EP_LEP(GET_EP()))
a3e1b1c @ko1 * Merge YARV
ko1 authored
128
129 /* SP */
0a71db8 @ko1 * vm_core.h: remove lfp (local frame pointer) and rename
ko1 authored
130 #define GET_SP() (USAGE_ANALYSIS_REGISTER_HELPER(SP, GET, REG_SP))
131 #define SET_SP(x) (REG_SP = (USAGE_ANALYSIS_REGISTER_HELPER(SP, SET, (x))))
132 #define INC_SP(x) (REG_SP += (USAGE_ANALYSIS_REGISTER_HELPER(SP, SET, (x))))
133 #define DEC_SP(x) (REG_SP -= (USAGE_ANALYSIS_REGISTER_HELPER(SP, SET, (x))))
a3e1b1c @ko1 * Merge YARV
ko1 authored
134 #define SET_SV(x) (*GET_SP() = (x))
135 /* set current stack value as x */
136
137 #define GET_SP_COUNT() (REG_SP - th->stack)
138
139 /* instruction sequence C struct */
140 #define GET_ISEQ() (GET_CFP()->iseq)
141
142 /**********************************************************/
143 /* deal with variables */
144 /**********************************************************/
145
0a71db8 @ko1 * vm_core.h: remove lfp (local frame pointer) and rename
ko1 authored
146 #define GET_PREV_EP(ep) ((VALUE *)((ep)[0] & ~0x03))
a3e1b1c @ko1 * Merge YARV
ko1 authored
147
c11a4d8 @akr * vm_insnhelper.h: parenthesize macro arguments.
akr authored
148 #define GET_GLOBAL(entry) rb_gvar_get((struct rb_global_entry*)(entry))
149 #define SET_GLOBAL(entry, val) rb_gvar_set((struct rb_global_entry*)(entry), (val))
a3e1b1c @ko1 * Merge YARV
ko1 authored
150
0ac93a1 @ko1 * insns.def, vm_insnhelper.c (getinstancevariable):
ko1 authored
151 #define GET_CONST_INLINE_CACHE(dst) ((IC) * (GET_PC() + (dst) + 2))
27013e7 @ko1 * yarvcore.h, compile.c, insnhelper.ci, iseq.c, vm.c:
ko1 authored
152
a3e1b1c @ko1 * Merge YARV
ko1 authored
153 /**********************************************************/
154 /* deal with values */
155 /**********************************************************/
156
157 #define GET_SELF() (USAGE_ANALYSIS_REGISTER_HELPER(5, 0, GET_CFP()->self))
158
159 /**********************************************************/
160 /* deal with control flow 2: method/iterator */
161 /**********************************************************/
162
061cce6 @ko1 * insnhelper.h, vm.h: some refactoring.
ko1 authored
163 #define COPY_CREF(c1, c2) do { \
a3e1b1c @ko1 * Merge YARV
ko1 authored
164 NODE *__tmp_c2 = (c2); \
c11a4d8 @akr * vm_insnhelper.h: parenthesize macro arguments.
akr authored
165 (c1)->nd_clss = __tmp_c2->nd_clss; \
166 (c1)->nd_visi = __tmp_c2->nd_visi;\
167 (c1)->nd_next = __tmp_c2->nd_next; \
3b20c21 @shugo * vm_insnhelper.h (COPY_CREF): should copy
shugo authored
168 if (__tmp_c2->flags & NODE_FL_CREF_PUSHED_BY_EVAL) { \
169 (c1)->flags |= NODE_FL_CREF_PUSHED_BY_EVAL; \
170 } \
061cce6 @ko1 * insnhelper.h, vm.h: some refactoring.
ko1 authored
171 } while (0)
172
c330876 @ko1 * method.h, vm_core.h: add rb_method_entry_t. Remove nodes around
ko1 authored
173 #define CALL_METHOD(num, blockptr, flag, id, me, recv) do { \
c11a4d8 @akr * vm_insnhelper.h: parenthesize macro arguments.
akr authored
174 VALUE v = vm_call_method(th, GET_CFP(), (num), (blockptr), (flag), (id), (me), (recv)); \
061cce6 @ko1 * insnhelper.h, vm.h: some refactoring.
ko1 authored
175 if (v == Qundef) { \
176 RESTORE_REGS(); \
177 NEXT_INSN(); \
178 } \
179 else { \
180 val = v; \
181 } \
182 } while (0)
a3e1b1c @ko1 * Merge YARV
ko1 authored
183
0a71db8 @ko1 * vm_core.h: remove lfp (local frame pointer) and rename
ko1 authored
184 #define GET_BLOCK_PTR() ((rb_block_t *)(GC_GUARDED_PTR_REF(GET_LEP()[0])))
a3e1b1c @ko1 * Merge YARV
ko1 authored
185
186 /**********************************************************/
187 /* deal with control flow 3: exception */
188 /**********************************************************/
189
190
191 /**********************************************************/
192 /* others */
193 /**********************************************************/
194
195 /* optimize insn */
beb26e1 @ko1 * vm_insnhelper.h, vm_insnhelper.c, vm.c, vm_method.c, insns.def:
ko1 authored
196 #define FIXNUM_REDEFINED_OP_FLAG (1 << 0)
197 #define FLOAT_REDEFINED_OP_FLAG (1 << 1)
198 #define STRING_REDEFINED_OP_FLAG (1 << 2)
199 #define ARRAY_REDEFINED_OP_FLAG (1 << 3)
200 #define HASH_REDEFINED_OP_FLAG (1 << 4)
201 #define BIGNUM_REDEFINED_OP_FLAG (1 << 5)
202 #define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
203 #define TIME_REDEFINED_OP_FLAG (1 << 7)
204
a3e1b1c @ko1 * Merge YARV
ko1 authored
205 #define FIXNUM_2_P(a, b) ((a) & (b) & 1)
beb26e1 @ko1 * vm_insnhelper.h, vm_insnhelper.c, vm.c, vm_method.c, insns.def:
ko1 authored
206 #define BASIC_OP_UNREDEFINED_P(op, klass) (LIKELY((ruby_vm_redefined_flag[(op)]&(klass)) == 0))
a3e1b1c @ko1 * Merge YARV
ko1 authored
207 #define HEAP_CLASS_OF(obj) RBASIC(obj)->klass
208
b82db52 @ko1 * insns.def (opt_*): add IC operands.
ko1 authored
209 #ifndef USE_IC_FOR_SPECIALIZED_METHOD
210 #define USE_IC_FOR_SPECIALIZED_METHOD 1
211 #endif
212
213 #if USE_IC_FOR_SPECIALIZED_METHOD
214
62deb7d @ko1 * insn_send.ci: removed.
ko1 authored
215 #define CALL_SIMPLE_METHOD(num, id, recv) do { \
216 VALUE klass = CLASS_OF(recv); \
c11a4d8 @akr * vm_insnhelper.h: parenthesize macro arguments.
akr authored
217 CALL_METHOD((num), 0, 0, (id), vm_method_search((id), klass, ic), (recv)); \
62deb7d @ko1 * insn_send.ci: removed.
ko1 authored
218 } while (0)
219
b82db52 @ko1 * insns.def (opt_*): add IC operands.
ko1 authored
220 #else
221
222 #define CALL_SIMPLE_METHOD(num, id, recv) do { \
f1e9808 @ko1 * vm_insnhelper.h (CALL_SIMPLE_METHOD_IC): make a macro
ko1 authored
223 VALUE klass = CLASS_OF(recv); \
c11a4d8 @akr * vm_insnhelper.h: parenthesize macro arguments.
akr authored
224 CALL_METHOD((num), 0, 0, (id), rb_method_entry(klass, (id)), (recv)); \
f1e9808 @ko1 * vm_insnhelper.h (CALL_SIMPLE_METHOD_IC): make a macro
ko1 authored
225 } while (0)
226
b82db52 @ko1 * insns.def (opt_*): add IC operands.
ko1 authored
227 #endif
228
038ef3f @ko1 * vm_core.h, vm_insnhelper.h: move decl. of
ko1 authored
229 static VALUE ruby_vm_global_state_version = 1;
230
231 #define GET_VM_STATE_VERSION() (ruby_vm_global_state_version)
232 #define INC_VM_STATE_VERSION() do { \
233 ruby_vm_global_state_version = (ruby_vm_global_state_version + 1); \
234 if (ruby_vm_global_state_version == 0) vm_clear_all_cache(); \
235 } while (0)
236 static void vm_clear_all_cache(void);
237
171c708 @znz fix typos
znz authored
238 static VALUE make_no_method_exception(VALUE exc, const char *format,
89fef02 @nobu * vm_eval.c (make_no_method_execption): extract from
nobu authored
239 VALUE obj, int argc, const VALUE *argv);
240
241
8a9993d @nobu * eval_intern.h, insnhelper.h, thread_pthread.h, vm_core.h, vm_opts.h:
nobu authored
242 #endif /* RUBY_INSNHELPER_H */
Something went wrong with that request. Please try again.