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.



5000
5001
5002
# File 'lib/HDLRuby/hruby_high.rb', line 5000

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.



2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
# File 'lib/HDLRuby/std/sequencer.rb', line 2316

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.



2306
2307
2308
# File 'lib/HDLRuby/std/sequencer.rb', line 2306

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

#supto(val, &ruby_block) ⇒ Object

HW upto iteration.



2311
2312
2313
# File 'lib/HDLRuby/std/sequencer.rb', line 2311

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

#to_exprObject

Converts to a new high-level expression.



4986
4987
4988
4989
4990
4991
4992
# File 'lib/HDLRuby/hruby_high.rb', line 4986

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.



4995
4996
4997
# File 'lib/HDLRuby/hruby_high.rb', line 4995

def width
    return self.bit_length
end