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.



2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
# File 'lib/HDLRuby/std/sequencer.rb', line 2302

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.



2292
2293
2294
# File 'lib/HDLRuby/std/sequencer.rb', line 2292

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

#supto(val, &ruby_block) ⇒ Object

HW upto iteration.



2297
2298
2299
# File 'lib/HDLRuby/std/sequencer.rb', line 2297

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

#to_exprObject

Converts to a new high-level expression.



4899
4900
4901
4902
4903
4904
4905
# File 'lib/HDLRuby/hruby_high.rb', line 4899

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.



4908
4909
4910
# File 'lib/HDLRuby/hruby_high.rb', line 4908

def width
    return self.bit_length
end