Method: HDLRuby::BitString.list_add_1!

Defined in:
lib/HDLRuby/hruby_bstr.rb

.list_add_1!(l0) ⇒ Object

Adds 1 to +l0+.

NOTE:

  • l0 is contains the result.
  • The result has the same size as +l0+ (no sign extension).


1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
# File 'lib/HDLRuby/hruby_bstr.rb', line 1007

def self.list_add_1!(l0)
    c = 1 # Current carry.
    l0.each_with_index do |b0,i|
        if c == 0 then
            # The sum is b0.
            l0[i] = b0
            # The carry is unchanged.
        elsif b0 == 0 then
            # The sum is c.
            l0[i] = c
            # The carry is 0.
            c = 0
        elsif b0 == c then
            # The sum is 0.
            l0[i] = 0
            # The carry is b0.
            c = b0
        else
            # Both sum and carry are unknown
            l0[i] = BitString.new_unknown
            c = BitString.new_unknown
        end
    end
    return l0
end