ytljit 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/code_alloc.c +39 -17
- data/ext/memory.c +170 -22
- data/ext/ytljit.c +57 -2
- data/ext/ytljit.h +15 -2
- data/lib/ytljit/asm.rb +21 -0
- data/lib/ytljit/asmext_x64.rb +1 -1
- data/lib/ytljit/asmutil.rb +1 -0
- data/lib/ytljit/instruction.rb +6 -0
- data/lib/ytljit/instruction_ia.rb +31 -2
- data/lib/ytljit/util.rb +5 -4
- data/lib/ytljit/vm.rb +771 -182
- data/lib/ytljit/vm_codegen.rb +76 -25
- data/lib/ytljit/vm_cruby_obj.rb +34 -13
- data/lib/ytljit/vm_inline_method.rb +154 -32
- data/lib/ytljit/vm_sendnode.rb +597 -112
- data/lib/ytljit/vm_trans.rb +148 -35
- data/lib/ytljit/vm_type.rb +5 -1
- data/lib/ytljit/vm_type_gen.rb +224 -51
- data/lib/ytljit.rb +5 -0
- data/test/test_assemble2.rb +35 -5
- metadata +3 -3
data/lib/ytljit/vm_type_gen.rb
CHANGED
@@ -13,6 +13,11 @@ module YTLJit
|
|
13
13
|
false
|
14
14
|
end
|
15
15
|
|
16
|
+
# Can represent nil by this format
|
17
|
+
def include_nil?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
16
21
|
def gen_boxing(context)
|
17
22
|
context
|
18
23
|
end
|
@@ -28,12 +33,21 @@ module YTLJit
|
|
28
33
|
def inspect
|
29
34
|
"{ #{boxed ? "BOXED" : "UNBOXED"} #{@ruby_type}}"
|
30
35
|
end
|
36
|
+
|
37
|
+
def copy_type
|
38
|
+
# Do not copy. It is immutable
|
39
|
+
self
|
40
|
+
end
|
31
41
|
end
|
32
42
|
|
33
43
|
module FixnumTypeUnboxedCodeGen
|
34
44
|
include AbsArch
|
35
45
|
include CommonCodeGen
|
36
46
|
|
47
|
+
def include_nil?
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
37
51
|
def gen_boxing(context)
|
38
52
|
asm = context.assembler
|
39
53
|
val = context.ret_reg
|
@@ -74,6 +88,7 @@ module YTLJit
|
|
74
88
|
end
|
75
89
|
asm.sar(TMPR)
|
76
90
|
end
|
91
|
+
|
77
92
|
context.set_reg_content(TMPR, vnode)
|
78
93
|
context.ret_reg = TMPR
|
79
94
|
context
|
@@ -111,16 +126,21 @@ module YTLJit
|
|
111
126
|
context.start_using_reg(TMPR2)
|
112
127
|
context.start_arg_reg(FUNC_FLOAT_ARG)
|
113
128
|
context.start_arg_reg
|
114
|
-
|
129
|
+
addr = lambda {
|
130
|
+
address_of("rb_float_new")
|
131
|
+
}
|
132
|
+
rbfloatnew = OpVarMemAddress.new(addr)
|
115
133
|
=begin
|
116
134
|
# This is sample of backtrace
|
117
135
|
sh = OpMemAddress.new(address_of("ytl_step_handler"))
|
136
|
+
context = gen_save_thepr(context)
|
118
137
|
context = gen_call(context, sh, 0, vnode)
|
119
138
|
=end
|
120
139
|
asm.with_retry do
|
121
140
|
asm.mov(FUNC_FLOAT_ARG[0], val)
|
122
141
|
end
|
123
142
|
context.set_reg_content(FUNC_FLOAT_ARG[0].dst_opecode, vnode)
|
143
|
+
context = gen_save_thepr(context)
|
124
144
|
context = gen_call(context, rbfloatnew, 1, vnode)
|
125
145
|
context.end_arg_reg
|
126
146
|
context.end_arg_reg(FUNC_FLOAT_ARG)
|
@@ -130,14 +150,65 @@ module YTLJit
|
|
130
150
|
context
|
131
151
|
end
|
132
152
|
|
153
|
+
def include_nil?
|
154
|
+
false
|
155
|
+
end
|
156
|
+
|
133
157
|
def gen_unboxing(context)
|
134
158
|
context
|
135
159
|
end
|
136
160
|
end
|
137
161
|
|
162
|
+
module ArrayTypeCommonCodeGen
|
163
|
+
def init
|
164
|
+
@element_type = nil
|
165
|
+
end
|
166
|
+
|
167
|
+
attr_accessor :element_type
|
168
|
+
|
169
|
+
def have_element?
|
170
|
+
true
|
171
|
+
end
|
172
|
+
|
173
|
+
def ==(other)
|
174
|
+
if other then
|
175
|
+
oc = other.ruby_type
|
176
|
+
sc = self.ruby_type
|
177
|
+
sc == oc and
|
178
|
+
((other.element_type == nil and
|
179
|
+
@element_type == nil) or
|
180
|
+
(other.element_type and @element_type and
|
181
|
+
@element_type[nil] == other.element_type[nil])) and
|
182
|
+
boxed == other.boxed
|
183
|
+
else
|
184
|
+
false
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
=begin
|
189
|
+
def eql?(other)
|
190
|
+
if other then
|
191
|
+
oc = other.ruby_type
|
192
|
+
sc = self.ruby_type
|
193
|
+
|
194
|
+
sc == oc and
|
195
|
+
boxed == other.boxed
|
196
|
+
else
|
197
|
+
false
|
198
|
+
end
|
199
|
+
end
|
200
|
+
=end
|
201
|
+
|
202
|
+
def inspect
|
203
|
+
etype = @element_type.inspect
|
204
|
+
"{ #{boxed ? "BOXED" : "UNBOXED"} #{@ruby_type} (#{etype})}"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
138
208
|
module ArrayTypeBoxedCodeGen
|
139
209
|
include AbsArch
|
140
210
|
include CommonCodeGen
|
211
|
+
include ArrayTypeCommonCodeGen
|
141
212
|
|
142
213
|
def instance
|
143
214
|
ni = self.dup
|
@@ -146,49 +217,112 @@ module YTLJit
|
|
146
217
|
ni
|
147
218
|
end
|
148
219
|
|
149
|
-
def init
|
150
|
-
@element_type = nil
|
151
|
-
end
|
152
|
-
|
153
|
-
attr_accessor :element_type
|
154
|
-
|
155
|
-
def have_element?
|
156
|
-
true
|
157
|
-
end
|
158
|
-
|
159
220
|
def gen_copy(context)
|
160
221
|
asm = context.assembler
|
161
222
|
val = context.ret_reg
|
162
223
|
vnode = context.ret_node
|
163
|
-
context.start_using_reg(TMPR3)
|
164
224
|
context.start_arg_reg
|
165
|
-
|
225
|
+
addr = lambda {
|
226
|
+
address_of("rb_ary_dup")
|
227
|
+
}
|
228
|
+
rbarydup = OpVarMemAddress.new(addr)
|
166
229
|
asm.with_retry do
|
167
230
|
asm.mov(FUNC_ARG[0], val)
|
168
231
|
end
|
169
232
|
context.set_reg_content(FUNC_ARG[0].dst_opecode, vnode)
|
233
|
+
context = gen_save_thepr(context)
|
170
234
|
context = gen_call(context, rbarydup, 1, vnode)
|
171
235
|
context.end_arg_reg
|
172
|
-
context.end_using_reg(TMPR3)
|
173
236
|
context.ret_reg = RETR
|
174
237
|
|
175
238
|
context
|
176
239
|
end
|
177
240
|
|
178
|
-
def
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
241
|
+
def copy_type
|
242
|
+
dao = self.class.from_ruby_class(@ruby_type)
|
243
|
+
dao = dao.to_box
|
244
|
+
dao.element_type = @element_type
|
245
|
+
dao
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
module ArrayTypeUnboxedCodeGen
|
250
|
+
include ArrayTypeCommonCodeGen
|
251
|
+
include SendNodeCodeGen
|
252
|
+
|
253
|
+
def instance
|
254
|
+
ni = self.dup
|
255
|
+
ni.instance_eval { extend ArrayTypeUnboxedCodeGen }
|
256
|
+
ni.init
|
257
|
+
ni
|
258
|
+
end
|
259
|
+
|
260
|
+
def gen_boxing(context)
|
261
|
+
# raise "foo"
|
262
|
+
# return context
|
263
|
+
cursig = context.to_signature
|
264
|
+
asm = context.assembler
|
265
|
+
val = context.ret_reg
|
266
|
+
vnode = context.ret_node
|
267
|
+
etypel = []
|
268
|
+
vnode.element_node_list[1..-1].each do |a|
|
269
|
+
if a[3] then
|
270
|
+
curidx = a[3][0]
|
271
|
+
if etypel[curidx] == nil then
|
272
|
+
etypel[curidx] = a[2].decide_type_once(a[1])
|
273
|
+
end
|
274
|
+
end
|
186
275
|
end
|
276
|
+
siz = etypel.size
|
277
|
+
|
278
|
+
context.start_using_reg(TMPR3)
|
279
|
+
context.start_using_reg(TMPR2)
|
280
|
+
asm.with_retry do
|
281
|
+
asm.mov(TMPR3, val)
|
282
|
+
end
|
283
|
+
|
284
|
+
argcomp = lambda {|context, arg, idx|
|
285
|
+
eleacc = OpIndirect.new(TMPR3, idx * AsmType::MACHINE_WORD.size)
|
286
|
+
asm.with_retry do
|
287
|
+
asm.mov(TMPR2, eleacc)
|
288
|
+
end
|
289
|
+
context.ret_reg = TMPR2
|
290
|
+
arg
|
291
|
+
}
|
292
|
+
|
293
|
+
context = gen_make_argv(context, etypel, argcomp) do |context, rarg|
|
294
|
+
context.start_arg_reg
|
295
|
+
context.cpustack_pushn(2 * AsmType::MACHINE_WORD.size)
|
296
|
+
|
297
|
+
addr = lambda {
|
298
|
+
address_of("rb_ary_new4")
|
299
|
+
}
|
300
|
+
rbarynew = OpVarMemAddress.new(addr)
|
301
|
+
asm.with_retry do
|
302
|
+
asm.mov(FUNC_ARG[0], siz)
|
303
|
+
asm.mov(FUNC_ARG[1], TMPR2)
|
304
|
+
end
|
305
|
+
|
306
|
+
context = gen_save_thepr(context)
|
307
|
+
context = gen_call(context, rbarynew, 2, vnode)
|
308
|
+
context.cpustack_popn(2 * AsmType::MACHINE_WORD.size)
|
309
|
+
context.end_arg_reg
|
310
|
+
context.ret_reg = RETR
|
311
|
+
context.set_reg_content(context.ret_reg, vnode)
|
312
|
+
context
|
313
|
+
end
|
314
|
+
|
315
|
+
context.end_using_reg(TMPR2)
|
316
|
+
context.end_using_reg(TMPR3)
|
317
|
+
context
|
187
318
|
end
|
188
319
|
|
189
|
-
|
190
|
-
|
191
|
-
|
320
|
+
|
321
|
+
def copy_type
|
322
|
+
dao = self.class.from_ruby_class(@ruby_type)
|
323
|
+
dao = dao.to_unbox
|
324
|
+
dao.element_type = @element_type
|
325
|
+
dao
|
192
326
|
end
|
193
327
|
end
|
194
328
|
|
@@ -200,25 +334,71 @@ module YTLJit
|
|
200
334
|
asm = context.assembler
|
201
335
|
val = context.ret_reg
|
202
336
|
vnode = context.ret_node
|
203
|
-
context.start_using_reg(TMPR2)
|
204
337
|
context.start_arg_reg
|
205
|
-
|
338
|
+
addr = lambda {
|
339
|
+
address_of("rb_str_dup")
|
340
|
+
}
|
341
|
+
rbstrdup = OpVarMemAddress.new(addr)
|
206
342
|
asm.with_retry do
|
207
343
|
asm.mov(FUNC_ARG[0], val)
|
208
344
|
end
|
209
345
|
context.set_reg_content(FUNC_ARG[0].dst_opecode, vnode)
|
210
|
-
context =
|
346
|
+
context = gen_save_thepr(context)
|
347
|
+
context = gen_call(context, rbstrdup, 1, vnode)
|
211
348
|
context.end_arg_reg
|
212
|
-
context.end_using_reg(TMPR2)
|
213
349
|
context.ret_reg = RETR
|
214
|
-
|
350
|
+
|
215
351
|
context
|
216
352
|
end
|
217
353
|
end
|
218
354
|
|
355
|
+
module RangeTypeCommonCodeGen
|
356
|
+
def init
|
357
|
+
@args = nil
|
358
|
+
@element_type = nil
|
359
|
+
end
|
360
|
+
|
361
|
+
attr_accessor :args
|
362
|
+
attr_accessor :element_type
|
363
|
+
|
364
|
+
def have_element?
|
365
|
+
true
|
366
|
+
end
|
367
|
+
|
368
|
+
def inspect
|
369
|
+
"{ #{boxed ? "BOXED" : "UNBOXED"} #{@ruby_type} (#{@element_type.inspect})}"
|
370
|
+
end
|
371
|
+
|
372
|
+
def ==(other)
|
373
|
+
self.class == other.class and
|
374
|
+
# @args == other.args and
|
375
|
+
boxed == other.boxed
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
module RangeTypeBoxedCodeGen
|
380
|
+
include RangeTypeCommonCodeGen
|
381
|
+
|
382
|
+
def instance
|
383
|
+
ni = self.dup
|
384
|
+
ni.instance_eval { extend RangeTypeBoxedCodeGen }
|
385
|
+
ni.init
|
386
|
+
ni
|
387
|
+
end
|
388
|
+
|
389
|
+
def copy_type
|
390
|
+
dro = self.class.from_ruby_class(@ruby_type)
|
391
|
+
dro = dro.to_box
|
392
|
+
dro.element_type = @element_type
|
393
|
+
dro.args = @args
|
394
|
+
dro
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
219
398
|
module RangeTypeUnboxedCodeGen
|
220
399
|
include AbsArch
|
221
400
|
include CommonCodeGen
|
401
|
+
include RangeTypeCommonCodeGen
|
222
402
|
|
223
403
|
def instance
|
224
404
|
ni = self.dup
|
@@ -227,17 +407,15 @@ module YTLJit
|
|
227
407
|
ni
|
228
408
|
end
|
229
409
|
|
230
|
-
def init
|
231
|
-
@args = nil
|
232
|
-
end
|
233
|
-
|
234
|
-
attr_accessor :args
|
235
|
-
|
236
410
|
def gen_boxing(context)
|
237
|
-
rtype = args[0].decide_type_once(context.to_signature)
|
411
|
+
rtype = @args[0].decide_type_once(context.to_signature)
|
238
412
|
|
413
|
+
vnode = context.ret_node
|
239
414
|
base = context.ret_reg
|
240
|
-
|
415
|
+
addr = lambda {
|
416
|
+
address_of("rb_range_new")
|
417
|
+
}
|
418
|
+
rbrangenew = OpVarMemAddress.new(addr)
|
241
419
|
begoff = OpIndirect.new(TMPR2, 0)
|
242
420
|
endoff = OpIndirect.new(TMPR2, AsmType::MACHINE_WORD.size)
|
243
421
|
excoff = OpIndirect.new(TMPR2, AsmType::MACHINE_WORD.size * 2)
|
@@ -263,27 +441,22 @@ module YTLJit
|
|
263
441
|
|
264
442
|
asm.with_retry do
|
265
443
|
asm.mov(FUNC_ARG[2], excoff)
|
266
|
-
asm.call_with_arg(rbrangenew, 3)
|
267
444
|
end
|
445
|
+
context = gen_save_thepr(context)
|
446
|
+
context = gen_call(context, rbrangenew, 3, vnode)
|
268
447
|
|
269
448
|
context.end_arg_reg
|
270
449
|
context.end_using_reg(TMPR2)
|
271
450
|
context.ret_reg = RETR
|
272
451
|
context
|
273
452
|
end
|
274
|
-
|
275
|
-
def ==(other)
|
276
|
-
self.class == other.class and
|
277
|
-
@args == other.args
|
278
|
-
end
|
279
|
-
end
|
280
453
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
454
|
+
def copy_type
|
455
|
+
dro = self.class.from_ruby_class(@ruby_type)
|
456
|
+
dro = dro.to_unbox
|
457
|
+
dro.element_type = @element_type
|
458
|
+
dro.args = @args
|
459
|
+
dro
|
287
460
|
end
|
288
461
|
end
|
289
462
|
end
|
data/lib/ytljit.rb
CHANGED
data/test/test_assemble2.rb
CHANGED
@@ -17,18 +17,18 @@ class InstructionTests < Test::Unit::TestCase
|
|
17
17
|
@cs = CodeSpace.new
|
18
18
|
@asm = Assembler.new(@cs, GeneratorExtend)
|
19
19
|
@asout = ""
|
20
|
-
|
20
|
+
@regs = [EAX, ECX, EDX, EBX, EBP, EDI, ESI, ESP]
|
21
21
|
@regs8 = [AL, CL, DL, BL]
|
22
|
-
@regs = [RAX, RCX, RDX, RBX, RBP, RDI, RSI, RSP, R8, R9, R10,
|
23
|
-
R11, R12, R13, R14, R15]
|
22
|
+
# @regs = [RAX, RCX, RDX, RBX, RBP, RDI, RSI, RSP, R8, R9, R10,
|
23
|
+
# R11, R12, R13, R14, R15]
|
24
24
|
|
25
25
|
@xmmregs = [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7]
|
26
26
|
@lits = [OpImmidiate32.new(0x0), OpImmidiate32.new(0x92),
|
27
27
|
OpImmidiate32.new(0x8212), OpImmidiate32.new(0x12345678),
|
28
28
|
0, 0x92, 0x8212, 0x12345678]# , 0xffffffff]
|
29
29
|
@indirects = []
|
30
|
-
|
31
|
-
[RBP, RDI, RSI, RSP, R8, R9, R10, R11, R12].each do |reg|
|
30
|
+
[EBP, EDI, ESI, ESP].each do |reg|
|
31
|
+
# [RBP, RDI, RSI, RSP, R8, R9, R10, R11, R12].each do |reg|
|
32
32
|
[
|
33
33
|
# -65535, -8192, -256, -255, -80, -12, -8,
|
34
34
|
-80, -8, 0, 8,
|
@@ -279,6 +279,36 @@ class InstructionTests < Test::Unit::TestCase
|
|
279
279
|
end
|
280
280
|
end
|
281
281
|
|
282
|
+
def test_xmm_cvt
|
283
|
+
[:cvtsi2sd, :cvtsi2ss].each do |mnm|
|
284
|
+
|
285
|
+
# Pattern xmmreg, reg
|
286
|
+
@xmmregs.each do |reg|
|
287
|
+
@regs.each do |src|
|
288
|
+
asm_ytljit(mnm, reg, src)
|
289
|
+
asm_gas(mnm, reg, src)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
# Pattern xmmreg, indirect
|
294
|
+
@indirects.each do |src|
|
295
|
+
@xmmregs.each do |dst|
|
296
|
+
asm_ytljit(mnm, dst, src)
|
297
|
+
asm_gas(mnm, dst, src)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
ytlres = disasm_ytljit(@cs)
|
302
|
+
gasres = disasm_gas(@cs)
|
303
|
+
# print @asout
|
304
|
+
ytlres.each_with_index do |lin, i|
|
305
|
+
assert_equal(gasres[i], lin)
|
306
|
+
end
|
307
|
+
@cs.reset
|
308
|
+
@asout = ""
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
282
312
|
def test_xmm_arith
|
283
313
|
[:addss, :addsd, :subss, :subsd,
|
284
314
|
:mulss, :mulsd, :divss, :divsd,
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 7
|
9
|
+
version: 0.0.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Hideki Miura
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-05-06 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|