Class: VectorSSE::Array

Inherits:
Array
  • Object
show all
Defined in:
lib/vector_sse.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, size = 0, val = nil) ⇒ Array

Returns a new instance of Array.



328
329
330
331
332
333
334
335
336
# File 'lib/vector_sse.rb', line 328

def initialize( type, size=0, val=nil )
   super( size, val )

   if VectorSSE::valid_type( type )
      @type = type
   else
      raise "invalid SSE vector type"
   end
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



326
327
328
# File 'lib/vector_sse.rb', line 326

def type
  @type
end

Instance Method Details

#*(other) ⇒ Object



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/vector_sse.rb', line 445

def *( other )

   unless [ Fixnum, Float ].include? other.class

      raise ArgumentError.new( "expected argument of type Float or Fixnum for argument 0" )

   end

   other  = self.class.new( @type, self.length, other )
   result = self.class.new( @type )

   case @type
   when Type::S32
      result.replace( VectorSSE::vec_mul_s32( self, other ) )
   when Type::S64
      result.replace( VectorSSE::vec_mul_s64( self, other ) )
   when Type::F32
      result.replace( VectorSSE::vec_mul_f32( self, other ) )
   when Type::F64
      result.replace( VectorSSE::vec_mul_f64( self, other ) )
   end

   result
end

#+(other) ⇒ Object

Note: This method replaces the base class implementation of ‘+’, which performs concatenation. To concatenate, see #concat.



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/vector_sse.rb', line 368

def +( other )

   if [ Fixnum, Float ].include? other.class

      other = ::Array.new( self.length, other )

   elsif other.class != self.class

      raise ArgumentError.new(
         "expect argument of type #{self.class}, Fixnum, or Float for argument 0" )

   end

   result = self.class.new( @type )

   case @type
   when Type::S32
      result.replace( VectorSSE::add_s32( self, other ) )
   when Type::S64
      result.replace( VectorSSE::add_s64( self, other ) )
   when Type::F32
      result.replace( VectorSSE::add_f32( self, other ) )
   when Type::F64
      result.replace( VectorSSE::add_f64( self, other ) )
   end

   result
end

#-(other) ⇒ Object

Note: This method replaces the base class implementation of ‘-’, which removes items that are found in ‘other’.



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/vector_sse.rb', line 401

def -( other )

   if [ Fixnum, Float ].include? other.class
      other = ::Array.new( self.length, other )
   elsif other.class != self.class
      raise ArgumentError.new(
         "expected argument of type #{self.class}, Fixnum, or Float for argument 0" )
   end

   result = self.class.new( @type )

   case @type
   when Type::S32
      result.replace( VectorSSE::sub_s32( self, other ) )
   when Type::S64
      result.replace( VectorSSE::sub_s64( self, other ) )
   when Type::F32
      result.replace( VectorSSE::sub_f32( self, other ) )
   when Type::F64
      result.replace( VectorSSE::sub_f64( self, other ) )
   end

   result
end

#<<(value) ⇒ Object



338
339
340
341
342
343
344
# File 'lib/vector_sse.rb', line 338

def <<( value )
   unless [ Fixnum, Float ].include? value.class
      raise ArgumentError.new(
         "expected argument of type Fixnum or Float for argument 0" )
   end
   super( value )
end

#[]=(index, value) ⇒ Object



356
357
358
359
360
361
362
# File 'lib/vector_sse.rb', line 356

def []=( index, value )
   unless [ Fixnum, Float ].include? value.class
      raise ArgumentError.new(
         "expected argument of type Fixnum or Float for argument 1" )
   end
   super( index, value )
end

#insert(index, *values) ⇒ Object



346
347
348
349
350
351
352
353
354
# File 'lib/vector_sse.rb', line 346

def insert( index, *values )
   values.each_with_index do |value,arg_index|
      unless [ Fixnum, Float ].include? value.class
         raise ArgumentError.new(
            "expected argument of type Fixnum or Float for argument #{arg_index}" )
      end
   end
   super( index, values )
end

#sumObject



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/vector_sse.rb', line 426

def sum
   sum_result = 0

   case @type
   when Type::S32
      sum_result = VectorSSE::sum_s32( self )
   when Type::S64
      sum_result = VectorSSE::sum_s64( self )
   when Type::F32
      sum_result = VectorSSE::sum_f32( self )
   when Type::F64
      sum_result = VectorSSE::sum_f64( self )
   else
      raise "invalid SSE vector type"
   end

   sum_result
end