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.



2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
# File 'lib/HDLRuby/std/sequencer.rb', line 2051

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.



2041
2042
2043
# File 'lib/HDLRuby/std/sequencer.rb', line 2041

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

#supto(val, &ruby_block) ⇒ Object

HW upto iteration.



2046
2047
2048
# File 'lib/HDLRuby/std/sequencer.rb', line 2046

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

#to_exprObject

Converts to a new high-level expression.



4800
4801
4802
4803
4804
4805
4806
# File 'lib/HDLRuby/hruby_high.rb', line 4800

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.



4809
4810
4811
# File 'lib/HDLRuby/hruby_high.rb', line 4809

def width
    return self.bit_length
end