Class: BOAST::Set

Inherits:
Operator show all
Extended by:
Functor
Includes:
Arithmetic, Inspectable, Intrinsics, PrivateStateAccessor
Defined in:
lib/BOAST/Language/Operators.rb

Constant Summary

Constants included from Intrinsics

Intrinsics::CONVERSIONS, Intrinsics::INTRINSICS

Constants inherited from Operator

Operator::DISCARD_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Functor

extended

Methods included from PrivateStateAccessor

private_boolean_state_accessor, private_state_accessor

Methods included from Inspectable

#inspect

Methods included from Arithmetic

#!, #!=, #*, #**, #+, #+@, #-, #-@, #/, #<, #<=, #==, #===, #>, #>=, #and, #cast, #components, #dereference, #or, #reference

Methods included from Intrinsics

get_conversion_path, get_vector_decl, get_vector_decl_ARM, get_vector_decl_X86, get_vector_name, intrinsics, intrinsics_by_vector_name, type_name_ARM, type_name_X86, vector_type_name

Methods inherited from Operator

convert, inspect

Constructor Details

#initialize(source, return_type) ⇒ Set

Returns a new instance of Set.



317
318
319
320
# File 'lib/BOAST/Language/Operators.rb', line 317

def initialize(source, return_type)
  @source = source
  @return_type = return_type
end

Instance Attribute Details

#return_typeObject (readonly)

Returns the value of attribute return_type.



315
316
317
# File 'lib/BOAST/Language/Operators.rb', line 315

def return_type
  @return_type
end

#sourceObject (readonly)

Returns the value of attribute source.



314
315
316
# File 'lib/BOAST/Language/Operators.rb', line 314

def source
  @source
end

Instance Method Details

#prObject



359
360
361
362
363
364
365
366
# File 'lib/BOAST/Language/Operators.rb', line 359

def pr
  s=""
  s += indent
  s += to_s
  s += ";" if [C, CL, CUDA].include?( lang )
  output.puts s
  return self
end

#to_sObject



355
356
357
# File 'lib/BOAST/Language/Operators.rb', line 355

def to_s
  return to_var.to_s
end

#to_varObject



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/BOAST/Language/Operators.rb', line 326

def to_var
  if lang == C or lang == CL and @return_type.type.vector_length > 1 then
    if @source.kind_of?( Array ) then
      raise OperatorError,  "Invalid array length!" unless @source.length == @return_type.type.vector_length
      return @return_type.copy("(#{@return_type.type.decl})( #{@source.join(", ")} )", DISCARD_OPTIONS) if lang == CL

      begin
        instruction = intrinsics(:SET, @return_type.type)
        return @return_type.copy("#{instruction}( #{@source.join(", ")} )",  DISCARD_OPTIONS)
      rescue IntrinsicsError
        instruction = intrinsics(:SET_LANE, @return_type.type)
        s = Set(0, @return_type).to_s
        @source.each_with_index { |v,i|
          s = "#{instruction}(#{v}, #{s}, #{i})"
        }
        return @return_type.copy(s, DISCARD_OPTIONS)
      end
    elsif @source.class != Variable or @source.type.vector_length == 1 then
      return @return_type.copy("(#{@return_type.type.decl})( #{@source} )", DISCARD_OPTIONS) if lang == CL

      instruction = intrinsics(:SET1, @return_type.type)
      return @return_type.copy("#{instruction}( #{@source} )", DISCARD_OPTIONS)
    elsif @return_type.type != @source.type
      return @return_type.copy("#{Operator.convert(@source, @return_type.type)}", DISCARD_OPTIONS)
    end
  end
  return @return_type.copy("#{@source}", DISCARD_OPTIONS)
end

#typeObject



322
323
324
# File 'lib/BOAST/Language/Operators.rb', line 322

def type
  return @return_type.type
end