Class: Kumi::Core::LIR::Emit

Inherits:
Object
  • Object
show all
Defined in:
lib/kumi/core/lir/emit.rb

Instance Method Summary collapse

Constructor Details

#initialize(registry:, ids:, ops:) ⇒ Emit

Returns a new instance of Emit.



5
6
7
8
9
# File 'lib/kumi/core/lir/emit.rb', line 5

def initialize(registry:, ids:, ops:)
  (@registry = registry
   @ids = ids
   @ops = ops)
end

Instance Method Details

#add_i(a, b) ⇒ Object

Integer arithmetic via canonical ids



21
# File 'lib/kumi/core/lir/emit.rb', line 21

def add_i(a, b) = k_id("core.add", [a, b], out: :integer)

#and_(a, b) ⇒ Object



28
# File 'lib/kumi/core/lir/emit.rb', line 28

def and_(a, b) = k_id("core.and", [a, b], out: :boolean)

#clamp(x, lo, hi, out:) ⇒ Object

Clamp via canonical id



31
# File 'lib/kumi/core/lir/emit.rb', line 31

def clamp(x, lo, hi, out:) = k_id("core.clamp", [x, lo, hi], out:)

#clamp_index(j, nlen) ⇒ Object



48
49
50
51
# File 'lib/kumi/core/lir/emit.rb', line 48

def clamp_index(j, nlen)
  hi = add_i(nlen, iconst(-1))
  clamp(j, iconst(0), hi, out: :integer)
end

#const(value, dtype) ⇒ Object



37
38
39
# File 'lib/kumi/core/lir/emit.rb', line 37

def const(value, dtype)
  push(Build.constant(value: value, dtype: dtype, ids: @ids))
end

#gather(arr, i, dt) ⇒ Object



34
# File 'lib/kumi/core/lir/emit.rb', line 34

def gather(arr, i, dt) = push(Build.gather(collection_register: arr, index_register: i, dtype: dt, ids: @ids))

#ge(a, b) ⇒ Object



27
# File 'lib/kumi/core/lir/emit.rb', line 27

def ge(a, b)   = k_id("core.gte", [a, b], out: :boolean)

#gt(a, b) ⇒ Object



25
# File 'lib/kumi/core/lir/emit.rb', line 25

def gt(a, b)    = k_id("core.gt",  [a, b], out: :boolean)

#iconst(v) ⇒ Object



11
# File 'lib/kumi/core/lir/emit.rb', line 11

def iconst(v) = push(Build.constant(value: Integer(v), dtype: :integer, ids: @ids))

#k_id(fn_id, args, out:) ⇒ Object

Kernel bridge with explicit function ids



14
15
16
17
18
# File 'lib/kumi/core/lir/emit.rb', line 14

def k_id(fn_id, args, out:)
  ins = Build.kernel_call(function: @registry.resolve_function(fn_id),
                          args:, out_dtype: out, ids: @ids)
  push(ins)
end

#le(a, b) ⇒ Object



26
# File 'lib/kumi/core/lir/emit.rb', line 26

def le(a, b)   = k_id("core.lte", [a, b], out: :boolean)

#length(coll) ⇒ Object



33
# File 'lib/kumi/core/lir/emit.rb', line 33

def length(coll) = push(Build.length(collection_register: coll, ids: @ids))

#lt(a, b) ⇒ Object



24
# File 'lib/kumi/core/lir/emit.rb', line 24

def lt(a, b)    = k_id("core.lt",  [a, b], out: :boolean)

#mod_i(a, b) ⇒ Object



23
# File 'lib/kumi/core/lir/emit.rb', line 23

def mod_i(a, b) = k_id("core.mod", [a, b], out: :integer)

#select(c, t, f, dt) ⇒ Object



35
# File 'lib/kumi/core/lir/emit.rb', line 35

def select(c, t, f, dt) = push(Build.select(cond: c, on_true: t, on_false: f, out_dtype: dt, ids: @ids))

#sub_i(a, b) ⇒ Object



22
# File 'lib/kumi/core/lir/emit.rb', line 22

def sub_i(a, b) = k_id("core.sub", [a, b], out: :integer)

#wrap_index(i, off, nlen) ⇒ Object



41
42
43
44
45
46
# File 'lib/kumi/core/lir/emit.rb', line 41

def wrap_index(i, off, nlen)
  i_plus = add_i(i, iconst(off))
  m1     = mod_i(i_plus, nlen)
  p2     = add_i(m1, nlen)
  mod_i(p2, nlen)
end