Class: BOAST::Int

Inherits:
Object show all
Defined in:
lib/BOAST/DataTypes.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Int

Returns a new instance of Int.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/BOAST/DataTypes.rb', line 129

def initialize(hash={})
  if hash[:size] then
    @size = hash[:size]
  else
    @size = BOAST::get_default_int_size
  end
  if hash[:signed] != nil then
    @signed = hash[:signed]
  else
    @signed = BOAST::get_default_int_signed
  end
#      @getters = {}
#      @setters = {}
  if hash[:vector_length] and hash[:vector_length] > 1 then
    @vector_length = hash[:vector_length]
#        @vector_length.times{ |indx|
#          @getters["s#{indx}"] = indx
#          @setters["s#{indx}="] = indx
#        }
  else
    @vector_length = 1
  end
  @total_size = @vector_length*@size
end

Instance Attribute Details

#signedObject (readonly)

Returns the value of attribute signed.



120
121
122
# File 'lib/BOAST/DataTypes.rb', line 120

def signed
  @signed
end

#sizeObject (readonly)

Returns the value of attribute size.



119
120
121
# File 'lib/BOAST/DataTypes.rb', line 119

def size
  @size
end

#total_sizeObject (readonly)

Returns the value of attribute total_size.



122
123
124
# File 'lib/BOAST/DataTypes.rb', line 122

def total_size
  @total_size
end

#vector_lengthObject (readonly)

Returns the value of attribute vector_length.



121
122
123
# File 'lib/BOAST/DataTypes.rb', line 121

def vector_length
  @vector_length
end

Class Method Details

.parens(*args, &block) ⇒ Object



115
116
117
# File 'lib/BOAST/DataTypes.rb', line 115

def self.parens(*args,&block)
  return Variable::new(args[0], self, *args[1..-1], &block)
end

Instance Method Details

#==(t) ⇒ Object



124
125
126
127
# File 'lib/BOAST/DataTypes.rb', line 124

def ==(t)
  return true if t.class == self.class and t.signed == self.signed and t.size == self.size and t.vector_length == self.vector_length
  return false
end

#copy(options = {}) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/BOAST/DataTypes.rb', line 158

def copy(options={})
  hash = self.to_hash
  options.each { |k,v|
    hash[k] = v
  }
  return Int::new(hash)
end

#declObject



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/BOAST/DataTypes.rb', line 166

def decl
  return "integer(kind=#{@size})" if BOAST::get_lang == FORTRAN
  if BOAST::get_lang == C then
    if @vector_length == 1 then
      s = ""
      s += "u" if not @signed
      return s+"int#{8*@size}_t"
    elsif @vector_length > 1 then
      if BOAST::get_architecture == BOAST::X86 then
        return "__m#{@total_size*8}#{@total_size*8>64 ? "i" : ""}"
      elsif BOAST::get_architecture == BOAST::ARM then
        raise "Unsupported vector length in NEON: #{@total_size*8} (#{@size} x 8 x #{@vector_length})!" if @total_size * 8 != 64 and @total_size * 8 != 128
        return "#{ @signed ? "" : "u"}int#{@size*8}x#{@vector_length}_t"
      else
        raise "Unsupported architecture!"
      end
    end
  elsif BOAST::get_lang == CL then
    #char="cl_"
    char=""
    char += "u" if not @signed
    case @size
    when 1
      char += "char"
    when 2
      char += "short"
    when 4
      char += "int"
    when 8
      char += "long"
    else
      raise "Unsupported integer size!"
    end
    if @vector_length > 1 then
      char += "#{@vector_length}"
    end
    return char
  elsif BOAST::get_lang == CUDA then
    if @vector_length > 1 then
      char=""
      char += "u" if not @signed
      case @size
      when 1
        char += "char"
      when 2
        char += "short"
      when 4
        char += "int"
      when 8
        char += "longlong"
      else
        raise "Unsupported integer size!"
      end
      return char + "#{@vector_length}"
    else
      char = ""
      char += "unsigned " if not @signed
      return char += "char" if @size==1
      return char += "short" if @size==2
      return char += "int" if @size==4
      return char += "long long" if @size==8
    end
  end
end

#to_hashObject



154
155
156
# File 'lib/BOAST/DataTypes.rb', line 154

def to_hash
  return { :size => @size, :vector_length => @vector_length, :signed => @signed }
end