ytljit 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/ext/memory.c CHANGED
@@ -10,8 +10,8 @@ VALUE ytl_cArena;
10
10
  void
11
11
  ytl_arena_mark(struct ArenaHeader *arenah)
12
12
  {
13
- VALUE *base;
14
13
  VALUE *start;
14
+ VALUE *end;
15
15
  struct ArenaBody *bodyptr;
16
16
  struct ArenaBody *next_bodyptr;
17
17
  struct ArenaBody *lastbodyptr;
@@ -36,8 +36,8 @@ ytl_arena_mark(struct ArenaHeader *arenah)
36
36
  continue;
37
37
  }
38
38
 
39
- base = bodyptr->body + (bodyptr->size / sizeof(VALUE));
40
- for (bodyeleptr = start; bodyeleptr < base; bodyeleptr++) {
39
+ end = bodyptr->body + (bodyptr->size / sizeof(VALUE));
40
+ for (bodyeleptr = start; bodyeleptr <= end; bodyeleptr++) {
41
41
  rb_gc_mark_maybe(*bodyeleptr);
42
42
  }
43
43
  next_bodyptr = bodyptr->next;
@@ -158,7 +158,7 @@ ytl_arena_ref(VALUE self, VALUE offset)
158
158
  int raw_offset;
159
159
 
160
160
  Data_Get_Struct(self, struct ArenaHeader, arenah);
161
- raw_offset = FIX2INT(offset);
161
+ raw_offset = (arenah->body->size / sizeof(VALUE)) - FIX2INT(offset);
162
162
 
163
163
  return ULONG2NUM(arenah->body->body[raw_offset]);
164
164
  }
@@ -169,11 +169,17 @@ ytl_arena_emit(VALUE self, VALUE offset, VALUE src)
169
169
  struct ArenaHeader *arenah;
170
170
 
171
171
  int raw_offset;
172
+ int newsize;
173
+ VALUE *newlastptr;
172
174
 
173
175
  Data_Get_Struct(self, struct ArenaHeader, arenah);
174
- raw_offset = NUM2ULONG(offset);
176
+ raw_offset = (arenah->body->size / sizeof(VALUE)) - NUM2ULONG(offset);
175
177
 
176
178
  arenah->body->body[raw_offset] = FIX2INT(src);
179
+ newlastptr = arenah->body->body + raw_offset;
180
+ if (newlastptr < arenah->lastptr) {
181
+ arenah->lastptr = newlastptr;
182
+ }
177
183
 
178
184
  return src;
179
185
  }
data/ext/ytljit.c CHANGED
@@ -424,6 +424,43 @@ body(uintptr_t *regbuf)
424
424
  rb_funcall2(ytl_eStepHandler, ytl_v_step_handler_id, NUMREGS + 1, argv);
425
425
  }
426
426
 
427
+ void
428
+ ytl_backtrace(VALUE rip,
429
+ VALUE rax, VALUE rcx, VALUE rdx, VALUE rbx,
430
+ VALUE rbp, VALUE rsp, VALUE rdi, VALUE rsi,
431
+ VALUE r8, VALUE r9, VALUE r10, VALUE r11,
432
+ VALUE r12, VALUE r13, VALUE r14, VALUE r15)
433
+ {
434
+ VALUE *argv;
435
+ uintptr_t sp;
436
+ int i;
437
+
438
+ argv = ALLOCA_N(VALUE, NUMREGS + 1);
439
+
440
+ argv[0] = ULONG2NUM(rax);
441
+ argv[1] = ULONG2NUM(rip);
442
+ argv[2] = ULONG2NUM(rcx);
443
+ argv[3] = ULONG2NUM(rdx);
444
+ argv[4] = ULONG2NUM(rbx);
445
+ argv[5] = ULONG2NUM(rbp);
446
+ argv[6] = ULONG2NUM(rdi);
447
+ argv[7] = ULONG2NUM(rsi);
448
+ argv[8] = ULONG2NUM(r8);
449
+ argv[9] = ULONG2NUM(r9);
450
+ argv[10] = ULONG2NUM(r10);
451
+ argv[11] = ULONG2NUM(r11);
452
+ argv[12] = ULONG2NUM(r12);
453
+ argv[13] = ULONG2NUM(r13);
454
+ argv[14] = ULONG2NUM(r14);
455
+ argv[15] = ULONG2NUM(r15);
456
+ sp = (uintptr_t)rsp;
457
+ sp += NUMREGS * sizeof(uintptr_t); /* reg save area */
458
+ sp += sizeof(uintptr_t); /* stored pc by call instruction */
459
+ argv[NUMREGS] = ULONG2NUM(sp);
460
+
461
+ rb_funcall2(ytl_eStepHandler, ytl_v_step_handler_id, NUMREGS + 1, argv);
462
+ }
463
+
427
464
  static uintptr_t * __attribute__ ((noinline, optimize("omit-frame-pointer")))
428
465
  pushall(void)
429
466
  {
@@ -76,7 +76,12 @@ module YTLJit
76
76
  File.popen(objdump_cmd, "r") {|fp|
77
77
  fp.readlines.each do |lin|
78
78
  if /([0-9a-f]*):(\t[0-9a-f ]+? *\t.*)/ =~ lin then
79
- @@disasm_cache[$1] = $2
79
+ src = $2
80
+ addr = $1
81
+ $symbol_table.each do |val, sym|
82
+ src.gsub!(val.to_s(16), "#{sym} (#{val})")
83
+ end
84
+ @@disasm_cache[addr] = src
80
85
  end
81
86
  end
82
87
  }
@@ -797,6 +797,23 @@ module YTLJit
797
797
  return nosupported_addressing_mode(inst, dst, src)
798
798
  end
799
799
  end
800
+
801
+ def common_cvt2(dst, src, op0, op1, inst)
802
+ if (src.is_a?(OpRegXMM) or
803
+ src.is_a?(OpIndirect)) and
804
+ (dst.is_a?(OpReg32) or
805
+ dst.is_a?(OpReg64)) then
806
+ rexseq, rexfmt = rex(dst, src)
807
+ modseq, modfmt = modrm(inst, dst, src, dst, src)
808
+ if op0 then
809
+ ([op0] + rexseq + [0x0F, op1] + modseq).pack("C#{rexfmt}C2#{modfmt}")
810
+ else
811
+ (rexseq + [0x0F, op1] + modseq).pack("#{rexfmt}C2#{modfmt}")
812
+ end
813
+ else
814
+ return nosupported_addressing_mode(inst, dst, src)
815
+ end
816
+ end
800
817
  end
801
818
 
802
819
  class GeneratorIABinary<Generator
@@ -1392,6 +1409,22 @@ module YTLJit
1392
1409
  common_cvt(dst, src, 0xf3, 0x2a, :cvtsi2ss)
1393
1410
  end
1394
1411
 
1412
+ def cvtsd2si(dst, src)
1413
+ common_cvt2(dst, src, 0xf2, 0x2d, :cvtsd2si)
1414
+ end
1415
+
1416
+ def cvttsd2si(dst, src)
1417
+ common_cvt2(dst, src, 0xf2, 0x2c, :cvttsd2si)
1418
+ end
1419
+
1420
+ def cvtss2si(dst, src)
1421
+ common_cvt2(dst, src, 0xf3, 0x2d, :cvtss2si)
1422
+ end
1423
+
1424
+ def cvttss2si(dst, src)
1425
+ common_cvt2(dst, src, 0xf3, 0x2c, :cvttss2si)
1426
+ end
1427
+
1395
1428
  def int3
1396
1429
  [0xcc].pack("C")
1397
1430
  end
data/lib/ytljit/util.rb CHANGED
@@ -127,4 +127,5 @@ class Float
127
127
  end
128
128
  end
129
129
 
130
+ $symbol_table = {}
130
131