How to use the pyrtl.concat function in pyrtl

To help you get started, we’ve selected a few pyrtl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github UCSBarchlab / PyRTL / tests / test_estimate.py View on Github external
def test_area_est_unchanged_with_rom(self):
        a = pyrtl.Const(2, 8)
        b = pyrtl.Const(85, 8)
        zero = pyrtl.Const(0, 1)
        reg = pyrtl.Register(8)
        mem = pyrtl.RomBlock(8, 8, romdata=list(range(0,256)))
        out = pyrtl.Output(8)
        nota, aLSB, athenb, aORb, aANDb, aNANDb, \
        aXORb, aequalsb, altb, agtb, aselectb, \
        aplusb, bminusa, atimesb, memread = [pyrtl.Output() for i in range(15)]
        out <<= zero
        nota <<= ~a
        aLSB <<= a[0]
        athenb <<= pyrtl.concat(a, b)
        aORb <<= a | b
        aANDb <<= a & b
        aNANDb <<= a.nand(b)
        aXORb <<= a ^ b
        aequalsb <<= a==b
        altb <<= a < b
        agtb <<= a > b
        aselectb <<= pyrtl.select(zero, a, b)
        reg.next <<= a
        aplusb <<= a + b
        bminusa <<= a - b
        atimesb <<= a*b
        memread <<= mem[reg]
        self.assertEquals(estimate.area_estimation(), (0.00734386752, 0.001879779717361501))
github UCSBarchlab / PyRTL / firrtl_tests / example2-counter.py View on Github external
def ripple_add(a, b, carry_in=0):
    a, b = pyrtl.match_bitwidth(a, b)
    # this function is a function that allows us to match the bitwidth of multiple
    # different wires. By default, it zero extends the shorter bits
    if len(a) == 1:
        sumbits, carry_out = one_bit_add(a, b, carry_in)
    else:
        lsbit, ripplecarry = one_bit_add(a[0], b[0], carry_in)
        msbits, carry_out = ripple_add(a[1:], b[1:], ripplecarry)
        sumbits = pyrtl.concat(msbits, lsbit)
    return sumbits, carry_out
github UCSBarchlab / PyRTL / pyrtl / rtllib / adders.py View on Github external
def cla_adder(a, b, cin=0, la_unit_len=4):
    """
    Carry Lookahead Adder
    :param int la_unit_len: the length of input that every unit processes

    A Carry LookAhead Adder is an adder that is faster than
    a ripple carry adder, as it calculates the carry bits faster.
    It is not as fast as a Kogge-Stone adder, but uses less area.
    """
    a, b = pyrtl.match_bitwidth(a, b)
    if len(a) <= la_unit_len:
        sum, cout = _cla_adder_unit(a, b, cin)
        return pyrtl.concat(cout, sum)
    else:
        sum, cout = _cla_adder_unit(a[0:la_unit_len], b[0:la_unit_len], cin)
        msbits = cla_adder(a[la_unit_len:], b[la_unit_len:], cout, la_unit_len)
        return pyrtl.concat(msbits, sum)
github UCSBarchlab / PyRTL / research / aes / aes_encryption.py View on Github external
b2_w31 <<= shifted_w31[16:24]
	b3_w31 <<= shifted_w31[8:16]
	b4_w31 <<= shifted_w31[0:8]

	c1_w31 = pyrtl.WireVector(8, 'c1_w31')
	c2_w31 = pyrtl.WireVector(8, 'c2_w31')
	c3_w31 = pyrtl.WireVector(8, 'c3_w31')
	c4_w31 = pyrtl.WireVector(8, 'c4_w31')

	c1_w31 <<= sbox[b1_w31]
	c2_w31 <<= sbox[b2_w31]
	c3_w31 <<= sbox[b3_w31]
	c4_w31 <<= sbox[b4_w31]

	substituted_w31 = pyrtl.WireVector(32, 'substituted_w31')
	substituted_w31 <<= pyrtl.concat(c1_w31, c2_w31, c3_w31, c4_w31)

	# STEP 3: XOR substituted bytes with round constant.
	xor_w31 = pyrtl.WireVector(bitwidth=32, name='xor_w31')
	rc1_w31 = pyrtl.WireVector(bitwidth=8, name='rc1_w31')
	rc2_w31 = pyrtl.WireVector(bitwidth=8, name='rc2_w31')
	rc3_w31 = pyrtl.WireVector(bitwidth=8, name='rc3_w31')
	rc4_w31 = pyrtl.WireVector(bitwidth=8, name='rc4_w31')

	rc1_w31 <<= rcon[8]
	rc2_w31 <<= 0x00
	rc3_w31 <<= 0x00
	rc4_w31<<= 0x00

	concat_w31 = pyrtl.WireVector(32, 'concat_w31')
	concat_w31 <<= pyrtl.concat(rc1_w31, rc2_w31, rc3_w31, rc4_w31)
	xor_w31 <<= concat_w31 ^ substituted_w31
github UCSBarchlab / PyRTL / research / aes / aes_decryption.py View on Github external
def g_w23(word):
	# STEP 1: One-byte left circular rotation.
	a1_w23 = pyrtl.WireVector(8, 'a1_w23')
	a2_w23 = pyrtl.WireVector(8, 'a2_w23')
	a3_w23 = pyrtl.WireVector(8, 'a3_w23')
	a4_w23 = pyrtl.WireVector(8, 'a4_w23')

	a1_w23 <<= word[24:32]
	a2_w23 <<= word[16:24]
	a3_w23 <<= word[8:16]
	a4_w23 <<= word[0:8]

	shifted_w23 = pyrtl.WireVector(32, 'shifted_w23')
	shifted_w23 <<= pyrtl.concat(a2_w23, a3_w23, a4_w23, a1_w23)

	# STEP 2: Substitution of each byte of shifted word.
	b1_w23 = pyrtl.WireVector(8, 'b1_w23')
	b2_w23 = pyrtl.WireVector(8, 'b2_w23')
	b3_w23 = pyrtl.WireVector(8, 'b3_w23')
	b4_w23 = pyrtl.WireVector(8, 'b4_w23')

	b1_w23 <<= shifted_w23[24:32]
	b2_w23 <<= shifted_w23[16:24]
	b3_w23 <<= shifted_w23[8:16]
	b4_w23 <<= shifted_w23[0:8]

	c1_w23 = pyrtl.WireVector(8, 'c1_w23')
	c2_w23 = pyrtl.WireVector(8, 'c2_w23')
	c3_w23 = pyrtl.WireVector(8, 'c3_w23')
	c4_w23 = pyrtl.WireVector(8, 'c4_w23')
github UCSBarchlab / PyRTL / research / aes / aes_decryption.py View on Github external
b2_w19 <<= shifted_w19[16:24]
	b3_w19 <<= shifted_w19[8:16]
	b4_w19 <<= shifted_w19[0:8]

	c1_w19 = pyrtl.WireVector(8, 'c1_w19')
	c2_w19 = pyrtl.WireVector(8, 'c2_w19')
	c3_w19 = pyrtl.WireVector(8, 'c3_w19')
	c4_w19 = pyrtl.WireVector(8, 'c4_w19')

	c1_w19 <<= sbox[b1_w19]
	c2_w19 <<= sbox[b2_w19]
	c3_w19 <<= sbox[b3_w19]
	c4_w19 <<= sbox[b4_w19]

	substituted_w19 = pyrtl.WireVector(32, 'substituted_w19')
	substituted_w19 <<= pyrtl.concat(c1_w19, c2_w19, c3_w19, c4_w19)

	# STEP 3: XOR substituted bytes with round constant.
	xor_w19 = pyrtl.WireVector(bitwidth=32, name='xor_w19')
	rc1_w19 = pyrtl.WireVector(bitwidth=8, name='rc1_w19')
	rc2_w19 = pyrtl.WireVector(bitwidth=8, name='rc2_w19')
	rc3_w19 = pyrtl.WireVector(bitwidth=8, name='rc3_w19')
	rc4_w19 = pyrtl.WireVector(bitwidth=8, name='rc4_w19')

	rc1_w19 <<= rcon[5]
	rc2_w19 <<= 0x00
	rc3_w19 <<= 0x00
	rc4_w19<<= 0x00

	concat_w19 = pyrtl.WireVector(32, 'concat_w19')
	concat_w19 <<= pyrtl.concat(rc1_w19, rc2_w19, rc3_w19, rc4_w19)
	xor_w19 <<= concat_w19 ^ substituted_w19
github UCSBarchlab / PyRTL / research / aes / aes_decryption.py View on Github external
b2_w23 <<= shifted_w23[16:24]
	b3_w23 <<= shifted_w23[8:16]
	b4_w23 <<= shifted_w23[0:8]

	c1_w23 = pyrtl.WireVector(8, 'c1_w23')
	c2_w23 = pyrtl.WireVector(8, 'c2_w23')
	c3_w23 = pyrtl.WireVector(8, 'c3_w23')
	c4_w23 = pyrtl.WireVector(8, 'c4_w23')

	c1_w23 <<= sbox[b1_w23]
	c2_w23 <<= sbox[b2_w23]
	c3_w23 <<= sbox[b3_w23]
	c4_w23 <<= sbox[b4_w23]

	substituted_w23 = pyrtl.WireVector(32, 'substituted_w23')
	substituted_w23 <<= pyrtl.concat(c1_w23, c2_w23, c3_w23, c4_w23)

	# STEP 3: XOR substituted bytes with round constant.
	xor_w23 = pyrtl.WireVector(bitwidth=32, name='xor_w23')
	rc1_w23 = pyrtl.WireVector(bitwidth=8, name='rc1_w23')
	rc2_w23 = pyrtl.WireVector(bitwidth=8, name='rc2_w23')
	rc3_w23 = pyrtl.WireVector(bitwidth=8, name='rc3_w23')
	rc4_w23 = pyrtl.WireVector(bitwidth=8, name='rc4_w23')

	rc1_w23 <<= rcon[6]
	rc2_w23 <<= 0x00
	rc3_w23 <<= 0x00
	rc4_w23<<= 0x00

	concat_w23 = pyrtl.WireVector(32, 'concat_w23')
	concat_w23 <<= pyrtl.concat(rc1_w23, rc2_w23, rc3_w23, rc4_w23)
	xor_w23 <<= concat_w23 ^ substituted_w23
github UCSBarchlab / PyRTL / research / aes / aes_encryption.py View on Github external
b2_w19 <<= shifted_w19[16:24]
	b3_w19 <<= shifted_w19[8:16]
	b4_w19 <<= shifted_w19[0:8]

	c1_w19 = pyrtl.WireVector(8, 'c1_w19')
	c2_w19 = pyrtl.WireVector(8, 'c2_w19')
	c3_w19 = pyrtl.WireVector(8, 'c3_w19')
	c4_w19 = pyrtl.WireVector(8, 'c4_w19')

	c1_w19 <<= sbox[b1_w19]
	c2_w19 <<= sbox[b2_w19]
	c3_w19 <<= sbox[b3_w19]
	c4_w19 <<= sbox[b4_w19]

	substituted_w19 = pyrtl.WireVector(32, 'substituted_w19')
	substituted_w19 <<= pyrtl.concat(c1_w19, c2_w19, c3_w19, c4_w19)

	# STEP 3: XOR substituted bytes with round constant.
	xor_w19 = pyrtl.WireVector(bitwidth=32, name='xor_w19')
	rc1_w19 = pyrtl.WireVector(bitwidth=8, name='rc1_w19')
	rc2_w19 = pyrtl.WireVector(bitwidth=8, name='rc2_w19')
	rc3_w19 = pyrtl.WireVector(bitwidth=8, name='rc3_w19')
	rc4_w19 = pyrtl.WireVector(bitwidth=8, name='rc4_w19')

	rc1_w19 <<= rcon[5]
	rc2_w19 <<= 0x00
	rc3_w19 <<= 0x00
	rc4_w19<<= 0x00

	concat_w19 = pyrtl.WireVector(32, 'concat_w19')
	concat_w19 <<= pyrtl.concat(rc1_w19, rc2_w19, rc3_w19, rc4_w19)
	xor_w19 <<= concat_w19 ^ substituted_w19
github UCSBarchlab / RaceLogic / racetrees / flat_racetree.py View on Github external
def shift_reg(din, n):
    """
        Use a shift register to create delay-coded thresholds.
    """
    sr = pyrtl.Register(bitwidth = n)
    sr.next <<= pyrtl.concat(sr[:-1], din)
    return sr
github UCSBarchlab / PyRTL / research / aes / aes_decryption.py View on Github external
def g_w27(word):
	# STEP 1: One-byte left circular rotation.
	a1_w27 = pyrtl.WireVector(8, 'a1_w27')
	a2_w27 = pyrtl.WireVector(8, 'a2_w27')
	a3_w27 = pyrtl.WireVector(8, 'a3_w27')
	a4_w27 = pyrtl.WireVector(8, 'a4_w27')

	a1_w27 <<= word[24:32]
	a2_w27 <<= word[16:24]
	a3_w27 <<= word[8:16]
	a4_w27 <<= word[0:8]

	shifted_w27 = pyrtl.WireVector(32, 'shifted_w27')
	shifted_w27 <<= pyrtl.concat(a2_w27, a3_w27, a4_w27, a1_w27)

	# STEP 2: Substitution of each byte of shifted word.
	b1_w27 = pyrtl.WireVector(8, 'b1_w27')
	b2_w27 = pyrtl.WireVector(8, 'b2_w27')
	b3_w27 = pyrtl.WireVector(8, 'b3_w27')
	b4_w27 = pyrtl.WireVector(8, 'b4_w27')

	b1_w27 <<= shifted_w27[24:32]
	b2_w27 <<= shifted_w27[16:24]
	b3_w27 <<= shifted_w27[8:16]
	b4_w27 <<= shifted_w27[0:8]

	c1_w27 = pyrtl.WireVector(8, 'c1_w27')
	c2_w27 = pyrtl.WireVector(8, 'c2_w27')
	c3_w27 = pyrtl.WireVector(8, 'c3_w27')
	c4_w27 = pyrtl.WireVector(8, 'c4_w27')