Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
bensampson5 committed May 26, 2024
1 parent 7a73df6 commit 4202c4c
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 26 deletions.
9 changes: 6 additions & 3 deletions libsv/coders/bcd_decoder.sv
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ module bcd_decoder #(
logic [4*N-1:0] temp; // create temp vector as wide as i_bcd to hold intermediate values
always_comb begin
temp = i_bcd; // initialize with input vector
for (i = 0; i < 4 * (N - 1); i = i + 1) // iterate on structure depth
for (j = 0; j < N - i / 4 - 1; j = j + 1) // iterate on structure width
if (temp[4+i+4*j-:4] > 7) // if > 7
for (i = 0; i < 4 * (N - 1); i = i + 1) begin // iterate on structure depth
for (j = 0; j < N - i / 4 - 1; j = j + 1) begin // iterate on structure width
if (temp[4+i+4*j-:4] > 7) begin // if > 7
temp[4+i+4*j-:4] = temp[4+i+4*j-:4] - 4'd3; // subtract three
end
end
end
o_bin = temp[3*N+(N+2)/3-1:0]; // truncate final result in temp vector to get o_bin
end

Expand Down
9 changes: 6 additions & 3 deletions libsv/coders/bcd_encoder.sv
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ module bcd_encoder #(

always_comb begin
o_bcd = {{(N - 4) / 3 + 1{1'b0}}, i_bin}; // initialize with input vector in lower bits
for (i = 0; i <= N - 4; i = i + 1) // iterate on structure depth
for (j = 0; j <= i / 3; j = j + 1) // iterate on structure width
if (o_bcd[N-i+4*j-:4] > 4) // if > 4
for (i = 0; i <= N - 4; i = i + 1) begin // iterate on structure depth
for (j = 0; j <= i / 3; j = j + 1) begin // iterate on structure width
if (o_bcd[N-i+4*j-:4] > 4) begin // if > 4
o_bcd[N-i+4*j-:4] = o_bcd[N-i+4*j-:4] + 4'd3; // add 3
end
end
end
end

endmodule
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pytest = "^6.2.5"
Sphinx = "^4.2.0"
sphinx-rtd-theme = "^1.0.0"
flake8 = "^4.0.1"
black = "^21.9b0"
black = "^22.3.0"
click = "^8.0.3"
colorama = "^0.4.4"
cocotb-test = "^0.2.1"
Expand Down
6 changes: 3 additions & 3 deletions tests/arbiters/test_ring_arbiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ async def cocotb_test_ring_arbiter(dut):
dut.i_aresetn.value = 1

# setup i_data
i_data_array = [i & (2 ** data_width - 1) for i in range(ports)]
i_data_array = [i & (2**data_width - 1) for i in range(ports)]
i_data = 0
for i in range(ports):
i_data |= i << (data_width * i)
log.info("i_data = 0x" + format(i_data, f"0{ports*data_width//4}x"))
log.info(f"i_data_array = {i_data_array}")
dut.i_data.value = i_data
dut.i_input_valid.value = 2 ** ports - 1
dut.i_input_valid.value = 2**ports - 1

# Scenario 1: Have all ports have data ready for the arbiter and
# have output interface be ready to receive data from arbiter. This
Expand All @@ -50,7 +50,7 @@ async def cocotb_test_ring_arbiter(dut):

# Scenario 2: Have a port drop out but still maintain max throughput
# of output interface
dut.i_input_valid.value = 2 ** ports - 2 # port 0 drops out
dut.i_input_valid.value = 2**ports - 2 # port 0 drops out
i_data_array_s2 = i_data_array[1:]
for i in range(4 * (ports - 1)):
await FallingEdge(dut.i_clock)
Expand Down
6 changes: 3 additions & 3 deletions tests/bit_ops/test_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ async def cocotb_test_rotate(dut):
data_width = int(dut.DATA_WIDTH.value)
amt_bits = len(dut.i_amt.value)

for value in range(2 ** data_width):
for value in range(2**data_width):

for amt in range(2 ** amt_bits):
for amt in range(2**amt_bits):

dut.i_data.value = value
dut.i_amt.value = amt
Expand All @@ -45,7 +45,7 @@ async def cocotb_test_rotate(dut):


def do_rotate(value: int, amt: int, data_width: int):
data_width_mask = 2 ** data_width - 1
data_width_mask = 2**data_width - 1
adj_amt = amt % data_width # adjust amount if greater than data_width
return ((value << adj_amt) & data_width_mask) | (
(value >> (data_width - adj_amt)) & data_width_mask
Expand Down
2 changes: 1 addition & 1 deletion tests/coders/test_bcd_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def cocotb_test_bcd_decoder(dut):

n = int(dut.N)

for i in range(10 ** n):
for i in range(10**n):
dut.i_bcd.value = int(str(int(i)), 16)
await Timer(1)
assert dut.o_bin == i
2 changes: 1 addition & 1 deletion tests/coders/test_bcd_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def cocotb_test_bcd_encoder(dut):

n = int(dut.N)

for i in range(2 ** n):
for i in range(2**n):
dut.i_bin.value = i
await Timer(1)
assert dut.o_bcd == int(str(int(dut.i_bin)), 16)
2 changes: 1 addition & 1 deletion tests/coders/test_decoder_8b10b.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ async def cocotb_test_decoder_8b10b(dut):
# Test 8b/10b decoding look-up table
dut.i_reset_n.value = 1
dut.i_en.value = 1
for i in range(2 ** 11):
for i in range(2**11):

# Parse out input values
i_10b = i & 0x3FF
Expand Down
2 changes: 1 addition & 1 deletion tests/coders/test_encoder_8b10b.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ async def cocotb_test_encoder_8b10b(dut):
# Test 8b/10b encoding look-up table
dut.i_reset_n.value = 1
dut.i_en.value = 1
for i in range(2 ** 10):
for i in range(2**10):

# Parse out input values
i_8b = i & 0xFF
Expand Down
2 changes: 1 addition & 1 deletion tests/coders/test_gray_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def cocotb_test_gray_decoder(dut):

data_width = int(dut.DATA_WIDTH)

for i in range(2 ** data_width):
for i in range(2**data_width):

dut.i_gray.value = i
await Timer(1)
Expand Down
2 changes: 1 addition & 1 deletion tests/coders/test_gray_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def cocotb_test_gray_encoder(dut):

data_width = int(dut.DATA_WIDTH)

for i in range(2 ** data_width):
for i in range(2**data_width):
dut.i_bin.value = i
await Timer(1)

Expand Down
2 changes: 1 addition & 1 deletion tests/coders/test_onehot_priority_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def cocotb_test_onehot_priority_encoder(dut):

data_width = int(dut.DATA_WIDTH)

for i in range(2 ** data_width):
for i in range(2**data_width):
dut.i_data.value = i # drive input

await Timer(1)
Expand Down
2 changes: 1 addition & 1 deletion tests/coders/test_priority_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def cocotb_test_priority_encoder(dut):

data_width = int(dut.DATA_WIDTH)

for i in range(2 ** data_width):
for i in range(2**data_width):
dut.i_data.value = i # drive input

await Timer(1)
Expand Down
2 changes: 1 addition & 1 deletion tests/counters/test_binary_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def cocotb_test_binary_counter(dut):
dut.aresetn.value = 1

# increment through all possible counter states
for i in range(2 ** n):
for i in range(2**n):
await RisingEdge(dut.clk)
assert int(dut.q) == i

Expand Down
4 changes: 2 additions & 2 deletions tests/fifos/test_skid_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def cocotb_test_skid_buffer(dut):
await FallingEdge(dut.i_clock)
o_data = i_data
assert int(dut.o_data.value) == o_data # check output data
i_data = (i_data + 1) % (2 ** data_width)
i_data = (i_data + 1) % (2**data_width)
dut.i_data.value = i_data # drive next input data

# disable output ready so that skid buffer gets full
Expand All @@ -62,7 +62,7 @@ async def cocotb_test_skid_buffer(dut):
await FallingEdge(dut.i_clock)
o_data = i_data
assert int(dut.o_data.value) == o_data # check output data
i_data = (i_data + 1) % (2 ** data_width)
i_data = (i_data + 1) % (2**data_width)
dut.i_data.value = i_data # drive next input data

await FallingEdge(dut.i_clock)
2 changes: 1 addition & 1 deletion tests/math/test_full_adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_full_adder(pytestconfig):
async def cocotb_test_full_adder(dut):
"""Full adder test"""

for i in range(2 ** 3):
for i in range(2**3):
i_a = i & 1
i_b = (i >> 1) & 1
i_carry = (i >> 2) & 1
Expand Down
2 changes: 1 addition & 1 deletion tests/math/test_half_adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_half_adder(pytestconfig):
async def cocotb_test_half_adder(dut):
"""Half adder test"""

for i in range(2 ** 2):
for i in range(2**2):
i_a = i & 1
i_b = (i >> 1) & 1
o_sum = i_a ^ i_b
Expand Down

0 comments on commit 4202c4c

Please sign in to comment.