Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_tools.rb,
lib/HDLRuby/hruby_verilog.rb,
lib/HDLRuby/std/sequencer.rb

Overview

Extends the Integer class for computing the bit width.

Instance Method Summary collapse

Instance Method Details

#as(typ) ⇒ Object

Cast.



5012
5013
5014
# File 'lib/HDLRuby/hruby_high.rb', line 5012

def as(typ)
    return self.to_expr.as(typ)
end

#pow2?Boolean

Tells if the value is a power of 2.

Returns:

  • (Boolean)


44
45
46
# File 'lib/HDLRuby/hruby_tools.rb', line 44

def pow2?
    return self > 0 && (self & (self - 1) == 0)
end

#sdownto(val, &ruby_block) ⇒ Object

HW downto iteration.



2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
# File 'lib/HDLRuby/std/sequencer.rb', line 2331

def sdownto(val,&ruby_block)
    # Create the hardware iterator.
    range = val..self
    hw_enum = SEnumeratorBase.new(signed[32],range.size) do |idx|
        range.last - idx
    end
    # Is there a ruby block?
    if(ruby_block) then
        # Yes, apply it.
        return hw_enum.seach(&ruby_block)
    else
        # No, return the resulting enumerator.
        return hw_enum
    end
end

#stimes(&ruby_block) ⇒ Object

HW times iteration.



2321
2322
2323
# File 'lib/HDLRuby/std/sequencer.rb', line 2321

def stimes(&ruby_block)
    return (0..self-1).seach(&ruby_block)
end

#supto(val, &ruby_block) ⇒ Object

HW upto iteration.



2326
2327
2328
# File 'lib/HDLRuby/std/sequencer.rb', line 2326

def supto(val,&ruby_block)
    return (self..val).seach(&ruby_block)
end

#to_exprObject

Converts to a new high-level expression.



4998
4999
5000
5001
5002
5003
5004
# File 'lib/HDLRuby/hruby_high.rb', line 4998

def to_expr
    if (self.bit_length <= 63) then
        return Value.new(Integer,self)
    else
        return Value.new(TypeSigned.new(:"",self.bit_length..0),self)
    end
end

#to_verilogObject

Extends the Integer class with generation of verilog text.



43
44
45
# File 'lib/HDLRuby/hruby_verilog.rb', line 43

def to_verilog
    to_s
end

#widthObject

Gets the bit width NOTE: returns infinity if the number is negative.



5007
5008
5009
# File 'lib/HDLRuby/hruby_high.rb', line 5007

def width
    return self.bit_length
end