Module: YTLJit::VM::ArithmeticOperationUtil

Constant Summary

Constants included from AbsArch

AbsArch::AL, AbsArch::BL, AbsArch::CL, AbsArch::DL, AbsArch::FUNC_ARG, AbsArch::FUNC_ARG_YTL, AbsArch::FUNC_FLOAT_ARG, AbsArch::FUNC_FLOAT_ARG_YTL, AbsArch::INDIRECT_BPR, AbsArch::INDIRECT_RETR, AbsArch::INDIRECT_SPR, AbsArch::INDIRECT_TMPR, AbsArch::INDIRECT_TMPR2, AbsArch::INDIRECT_TMPR3

Constants included from SSE

SSE::XMM0, SSE::XMM1, SSE::XMM2, SSE::XMM3, SSE::XMM4, SSE::XMM5, SSE::XMM6, SSE::XMM7

Instance Method Summary collapse

Instance Method Details

#gen_arithmetic_operation(context, inst, tempreg, resreg) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/ytljit/vm_inline_method.rb', line 91

def gen_arithmetic_operation(context, inst, tempreg, resreg)
  context.start_using_reg(tempreg)
  context = gen_eval_self(context)
  context.ret_node.type = nil
  rtype = context.ret_node.decide_type_once(context.to_signature)
  context = rtype.gen_unboxing(context)
  gen_inst_with_conversion(context, tempreg, :mov)
  context.set_reg_content(tempreg, context.ret_node)
  
  # @argunents[1] is block
  # @argunents[2] is self
  # @arguments[3] is other
  aele = @arguments[3]
  context = aele.compile(context)
  context.ret_node.type = nil
  rtype = context.ret_node.decide_type_once(context.to_signature)
  context = rtype.gen_unboxing(context)

  if block_given? then
    yield(context)
  else
    # default code
    gen_inst_with_conversion(context, tempreg, inst)
    asm = context.assembler
    asm.with_retry do
      asm.mov(resreg, tempreg)
    end
  end

  context.end_using_reg(tempreg)

  context.ret_node = self
  context.ret_reg = resreg
  
  decide_type_once(context.to_signature)
  if @type.boxed then
    context = @type.to_unbox.gen_boxing(context)
  end
  
  context
end

#gen_inst_with_conversion(context, dst, inst) ⇒ Object

def decide_type_core_local(tlist, sig, local_cache = {})

  tlist = tlist.select {|e| e.class != RubyType::DefaultType0 }
  if tlist.size < 2 then
    return decide_type_core(tlist, local_cache)
  end
  aele = @arguments[3].decide_type_once(sig)
  if tlist.include?(aele) then
    aele
  else
    RubyType::DefaultType0.new
  end
end

def decide_type_once(sig, local_cache = {})
  if local_cache[self] then
    return local_cache[self] 
  end

  if @type.equal?(nil) or @type.is_a?(RubyType::DefaultType0) then
    tlist = type_list(sig).flatten.uniq
    @type = decide_type_core_local(tlist, sig, local_cache)
  else
    @type
  end

  @type
end


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ytljit/vm_inline_method.rb', line 35

def gen_inst_with_conversion(context, dst, inst)
  asm = context.assembler
  src = context.ret_reg
  if dst.is_a?(OpRegXMM) then
    # Float
    if src.is_a?(OpRegistor) and
        !src.is_a?(OpRegXMM) then
      asm.with_retry do
        asm.cvtsi2sd(XMM0, src)
      end
      context.end_using_reg(src)
      asm.with_retry do
        asm.send(inst, dst, XMM0)
      end
    elsif src.using(dst) then
      asm.with_retry do
        asm.mov(XMM0, src)
      end
      context.end_using_reg(src)
      asm.with_retry do
        asm.send(inst, dst, XMM0)
      end
    elsif src.is_a?(OpImmidiateMachineWord) then
      asm.with_retry do
        asm.mov(TMPR, src)
      end
      context.end_using_reg(src)
      asm.with_retry do
        asm.cvtsi2sd(XMM0, TMPR)
        asm.send(inst, dst, XMM0)
      end
    else
      asm.with_retry do
        asm.send(inst, dst, src)
      end
      context.end_using_reg(src)
    end
  else
    # Fixnum
    if src.using(dst) then
      asm.with_retry do
        asm.mov(TMPR, src)
      end
      context.end_using_reg(src)
      asm.with_retry do
        asm.send(inst, dst, TMPR)
      end
    else
      asm.with_retry do
        asm.send(inst, dst, src)
      end
      context.end_using_reg(src)
    end
  end
end