Class: RubyHDL::High::Binary
- Inherits:
-
Expression
- Object
- Expression
- RubyHDL::High::Binary
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes the software implementation of an binary operation.
Instance Attribute Summary
Attributes inherited from Expression
Instance Method Summary collapse
-
#initialize(type, operator, left, right) ⇒ Binary
constructor
Create a new binary operation with +type+ data type, operator +operator+ and operands +left+ and +right+.
-
#to_c ⇒ Object
Convert to C code.
-
#to_python(l = "") ⇒ Object
Convert to Python code.
-
#to_ruby ⇒ Object
Convert to Ruby code.
-
#to_tf(l = "") ⇒ Object
Convert to TensorFlow code.
Methods inherited from Expression
#<=, #[], #heach, #mux, #sdownto, #seach, #stimes, #supto, #to_expr, #to_value
Methods included from HEnumerable
#hall?, #hany?, #hchain, #hchunk, #hchunk_while, #hcompact, #hcount, #hcycle, #hdrop, #hdrop_while, #heach_cons, #heach_entry, #heach_range, #heach_slice, #heach_with_index, #heach_with_object, #hfind, #hfind_index, #hfirst, #hflat_map, #hgrep, #hgrep_v, #hgroup_by, #hinclude?, #hinject, #hlazy, #hmap, #hmax, #hmax_by, #hmin, #hmin_by, #hminmax, #hminmax_by, #hnone?, #hone?, #hpartition, #hreduce, #hreject, #hreverse_each, #hselect, #hslice_after, #hslice_before, #hslice_when, #hsort, #hsort_by, #hsum, #htake, #htake_while, #htally, #hto_a, #hto_h, #huniq, #hzip
Constructor Details
#initialize(type, operator, left, right) ⇒ Binary
Create a new binary operation with +type+ data type, operator +operator+ and operands +left+ and +right+.
2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2461 def initialize(type,operator,left,right) super(type) @operator = operator.to_sym @left = left.to_expr @right = right.to_expr # Compute the mask for fixing the bit width. @mask = (2 ** @type.width)-1 # puts "@type=#{@type} name=#{@type.name} @type.width=#{@type.width} @mask=#{@mask}" # Compute xor mask for handling the sign. # Make it as a string so that no addition computation is required # if no sign is required. @sign_fix = "" if type.signed? then @sign_fix = " ^ #{2**(@type.width-1)}" end end |
Instance Method Details
#to_c ⇒ Object
Convert to C code.
2486 2487 2488 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2486 def to_c return C_OPERATOR[@operator] % [ @left.to_c, @right.to_c ] end |
#to_python(l = "") ⇒ Object
Convert to Python code.
2491 2492 2493 2494 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2491 def to_python(l = "") return PYTHON_OPERATOR[@operator] % { l: @left.to_python, r: @right.to_python, m: @mask, s: @sign_fix } end |
#to_ruby ⇒ Object
Convert to Ruby code.
2479 2480 2481 2482 2483 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2479 def to_ruby # return RUBY_OPERATOR[@operator] % [ @left.to_ruby, @right.to_ruby ] return RUBY_OPERATOR[@operator] % { l: @left.to_ruby, r: @right.to_ruby, m: @mask, s: @sign_fix } end |
#to_tf(l = "") ⇒ Object
Convert to TensorFlow code.
2497 2498 2499 2500 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2497 def to_tf(l = "") return TF_OPERATOR[@operator] % { l: @left.to_tf, r: @right.to_tf, m: @mask, s: @sign_fix } end |