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

#pow2?Boolean

Tells if the value is a power of 2.

Returns:

  • (Boolean)


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

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

#sdownto(val, &ruby_block) ⇒ Object

HW downto iteration.



1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
# File 'lib/HDLRuby/std/sequencer.rb', line 1823

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.



1813
1814
1815
# File 'lib/HDLRuby/std/sequencer.rb', line 1813

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

#supto(val, &ruby_block) ⇒ Object

HW upto iteration.



1818
1819
1820
# File 'lib/HDLRuby/std/sequencer.rb', line 1818

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

#to_exprObject

Converts to a new high-level expression.



4782
4783
4784
4785
4786
4787
4788
# File 'lib/HDLRuby/hruby_high.rb', line 4782

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.



4791
4792
4793
# File 'lib/HDLRuby/hruby_high.rb', line 4791

def width
    return self.bit_length
end