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

#address_size, #address_size=, #annotate, #annotate=, #annotate?, #annotate_indepth_list, #annotate_indepth_list=, #annotate_level, #annotate_level=, #annotate_list, #annotate_list=, #architecture, #architecture=, #array_start, #array_start=, #chain_code, #chain_code=, #chain_code?, #debug, #debug=, #debug?, #debug_kernel_source, #debug_kernel_source=, #debug_kernel_source?, #debug_source, #debug_source=, #debug_source?, #decl_module, #decl_module=, #decl_module?, #default_align, #default_align=, #default_int_signed, #default_int_signed=, #default_int_signed?, #default_int_size, #default_int_size=, #default_real_size, #default_real_size=, #default_type, #default_type=, #disable_openmp, #disable_openmp=, #disable_openmp?, #executable, #executable=, #executable?, #ffi, #ffi=, #ffi?, #fortran_line_length, #fortran_line_length=, #get_address_size, #get_annotate, #get_annotate_indepth_list, #get_annotate_level, #get_annotate_list, #get_architecture, #get_array_start, #get_chain_code, #get_debug, #get_debug_kernel_source, #get_debug_source, #get_decl_module, #get_default_align, #get_default_int_signed, #get_default_int_size, #get_default_real_size, #get_default_type, #get_disable_openmp, #get_executable, #get_ffi, #get_fortran_line_length, #get_indent_increment, #get_indent_level, #get_keep_temp, #get_lang, #get_model, #get_optimizer_log, #get_optimizer_log_file, #get_output, #get_replace_constants, #get_synchro, #get_use_vla, #get_verbose, #indent_increment, #indent_increment=, #indent_level, #indent_level=, #keep_temp, #keep_temp=, #keep_temp?, #lang, #lang=, #model, #model=, #optimizer_log, #optimizer_log=, #optimizer_log?, #optimizer_log_file, #optimizer_log_file=, #output, #output=, #replace_constants, #replace_constants=, #replace_constants?, #set_address_size, #set_annotate, #set_annotate_indepth_list, #set_annotate_level, #set_annotate_list, #set_architecture, #set_array_start, #set_chain_code, #set_debug, #set_debug_kernel_source, #set_debug_source, #set_decl_module, #set_default_align, #set_default_int_signed, #set_default_int_size, #set_default_real_size, #set_default_type, #set_disable_openmp, #set_executable, #set_ffi, #set_fortran_line_length, #set_indent_increment, #set_indent_level, #set_keep_temp, #set_lang, #set_model, #set_optimizer_log, #set_optimizer_log_file, #set_output, #set_replace_constants, #set_synchro, #set_use_vla, #set_verbose, #synchro, #synchro=, #use_vla, #use_vla=, #use_vla?, #verbose, #verbose=, #verbose?

Methods included from Inspectable

#inspect

Methods included from Arithmetic

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

Methods included from Intrinsics

check_coverage, generate_conversions, 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.



393
394
395
396
# File 'lib/BOAST/Language/Operators.rb', line 393

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

Instance Attribute Details

#return_typeObject (readonly)

Returns the value of attribute return_type.



391
392
393
# File 'lib/BOAST/Language/Operators.rb', line 391

def return_type
  @return_type
end

#sourceObject (readonly)

Returns the value of attribute source.



390
391
392
# File 'lib/BOAST/Language/Operators.rb', line 390

def source
  @source
end

Instance Method Details

#prObject



465
466
467
468
469
470
471
472
# File 'lib/BOAST/Language/Operators.rb', line 465

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

#to_sObject



461
462
463
# File 'lib/BOAST/Language/Operators.rb', line 461

def to_s
  return to_var.to_s
end

#to_varObject



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/BOAST/Language/Operators.rb', line 402

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
    return Set(@source.first, @return_type).to_var if @source.uniq.size == 1
      begin
        instruction = intrinsics(:SET, @return_type.type)
        raise IntrinsicsError unless instruction
        eff_srcs = @source.collect { |src|
          eff_src = nil
          eff_src = src.to_var if src.respond_to?(:to_var)
          eff_src = src unless eff_src
          eff_src
        }
        return @return_type.copy("#{instruction}( #{eff_srcs.join(", ")} )",  DISCARD_OPTIONS)
      rescue IntrinsicsError
        instruction = intrinsics(:SET_LANE, @return_type.type)
        raise IntrinsicsError, "Missing instruction for SET_LANE on #{get_architecture_name}!" unless instruction
        s = Set(0, @return_type).to_s
        @source.each_with_index { |v,i|
          eff_src = nil
          eff_src = v.to_var if v.respond_to?(:to_var)
          eff_src = v unless eff_src
          s = "#{instruction}( #{eff_src}, #{s}, #{i} )"
        }
        return @return_type.copy(s, DISCARD_OPTIONS)
      end
    elsif @source.class != Variable or @source.type.vector_length == 1 then
      eff_src = nil
      eff_src = @source.to_var if @source.respond_to?(:to_var)
      eff_src = @source unless eff_src
      if lang == CL then
        return @return_type.copy("(#{@return_type.type.decl})( #{eff_src} )", DISCARD_OPTIONS) if lang == CL
      end
      if (@source.is_a?(Numeric) and @source == 0) or (@source.instance_of? Variable and @source.constant == 0) then
        begin
          instruction = intrinsics(:SETZERO, @return_type.type)
          return @return_type.copy("#{instruction}( )", DISCARD_OPTIONS) if instruction
        rescue IntrinsicsError
        end
      end
      instruction = intrinsics(:SET1, @return_type.type)
      return @return_type.copy("#{instruction}( #{eff_src} )", DISCARD_OPTIONS)
    elsif @return_type.type != @source.type
      return @return_type.copy("#{Operator.convert(@source, @return_type.type)}", DISCARD_OPTIONS)
    end
  elsif lang == FORTRAN 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 "(/#{@source.join(", ")}/)"
    end
  end
  eff_src = nil
  eff_src = @source.to_var if @source.respond_to?(:to_var)
  eff_src = @source unless eff_src
  return @return_type.copy("#{eff_src}", DISCARD_OPTIONS)
end

#typeObject



398
399
400
# File 'lib/BOAST/Language/Operators.rb', line 398

def type
  return @return_type.type
end