Class: RLTK::CG::ConstantVector

Inherits:
Constant show all
Defined in:
lib/rltk/cg/value.rb

Overview

A constant vector value used for SIMD instructions.

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Methods inherited from Constant

#bitcast_to, #get_element_ptr, #get_element_ptr_in_bounds

Methods included from AbstractClass

included

Methods inherited from User

#operands

Methods inherited from Value

#==, #attributes, #bitcast, #constant?, #dump, #hash, #name, #name=, #null?, #print, #trunc, #trunc_or_bitcast, #type, #undefined?, #zextend, #zextend_or_bitcast

Methods included from BindingClass

#==

Constructor Details

#initialize(size_or_values, &block) {|index| ... } ⇒ ConstantVector

Create a new constant vector value.

Examples:

Using array of values:

ConstantVector.new([Int32.new(0), Int32.new(1)])

Using size:

ConstantVector.new(2) { |i| Int32.new(i) }

Parameters:

  • size_or_values (FFI::Pointer, Array<Value>, Integer)

    Number of values or array of values.

  • block (Proc)

    Block evaluated if size is specified.

Yield Parameters:

  • index (Integer)

    Index of the value in the vector.



488
489
490
491
492
493
494
495
496
497
# File 'lib/rltk/cg/value.rb', line 488

def initialize(size_or_values, &block)
	@ptr =
	if size_or_values.is_a?(FFI::Pointer)
		size_or_values
	else
		vals_ptr = make_ptr_to_elements(size_or_values, &block)
		
		Bindings.const_vector(vals_ptr, vals_ptr.size / vals_ptr.type_size)
	end
end

Instance Method Details

#extract_element(index) ⇒ ConstExpr

Returns Extracted element.

Parameters:

  • index (Integer)

    Index of desired element.

Returns:

  • (ConstExpr)

    Extracted element.



502
503
504
# File 'lib/rltk/cg/value.rb', line 502

def extract_element(index)
	ConstExpr.new(Bindings.const_extract_element(@ptr, index))
end

#insert_element(element, index) ⇒ ConstExpr

Returns New vector representation with inserted value.

Parameters:

  • element (Value)

    Value to insert into the vector.

  • index (Integer)

    Index to insert the value at.

Returns:

  • (ConstExpr)

    New vector representation with inserted value.



510
511
512
# File 'lib/rltk/cg/value.rb', line 510

def insert_element(element, index)
	ConstExpr.new(Bindings.const_insert_element(@ptr, element, index))
end

#shuffle(other, mask) ⇒ ConstantVector

Returns New vector formed by shuffling the two vectors together using the mask.

Parameters:

Returns:

  • (ConstantVector)

    New vector formed by shuffling the two vectors together using the mask.



518
519
520
# File 'lib/rltk/cg/value.rb', line 518

def shuffle(other, mask)
	ConstantVector.new(Bindings.const_shuffle_vector(@ptr, other, mask))
end