class BOAST::Set
Attributes
return_type[R]
source[R]
Public Class Methods
new(source, return_type)
click to toggle source
# File lib/BOAST/Language/Operators.rb, line 393 def initialize(source, return_type) @source = source @return_type = return_type.to_var end
Public Instance Methods
pr()
click to toggle source
# 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_s()
click to toggle source
# File lib/BOAST/Language/Operators.rb, line 461 def to_s return to_var.to_s end
to_var()
click to toggle source
# 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
type()
click to toggle source
# File lib/BOAST/Language/Operators.rb, line 398 def type return @return_type.type end