Reconfigurable Computing (EN2911X, Fall07) : Lab 2 Presentations
Reconfigurable Computing (EN2911X, Fall07) : Lab 2 Presentations
Lab 2 presentations
Prof. Sherief Reda Division of Engineering, Brown University http://ic.engin.brown.edu
Palindrome Checker
Unsolved things
Our running time now depends on the way that we extract digits from the number Some ideas to improve?
Using shift register Using non-blocking instructions
Setup
Two-cycle fixed length custom instruction Operates on 20 numbers at a time Returns total palindromes in that 20number block
Process
Combinatorial conversion from binary to BCD Check number of digits Compare digits based on length Total up number of valid palindromes
assign digCount = digits[9] != 0?10: digits[8] != 0?9: digits[7] != 0?8: digits[6] != 0?7: digits[5] != 0?6: digits[4] != 0?5: digits[3] != 0?4: digits[2] != 0?3: digits[1] != 0?2: 1; assign result = digCount == 1 || digCount == 2 && (digits[0] == digits[1]) || digCount == 3 && (digits[0] == digits[2]) || digCount == 4 && (digits[0] == digits[3] && digits[1] == digits[2]) || digCount == 5 && (digits[0] == digits[4] && digits[1] == digits[3]) || digCount == 6 && (digits[0] == digits[5] && digits[1] == digits[4] && digits[2] == digits[3]) || digCount == 7 && (digits[0] == digits[6] && digits[1] == digits[5] && digits[2] == digits[4]) || digCount == 8 && (digits[0] == digits[7] && digits[1] == digits[6] && digits[2] == digits[5] && digits[3] == digits[4]) || digCount == 9 && (digits[0] == digits[8] && digits[1] == digits[7] && digits[2] == digits[6] && digits[3] == digits[5]); endmodule
Yossi
: : : : : : : : 0))))))));
Inherently sequential
Early false detection: quit the computation if we find two digits that do not match.
Brings down expected # divide operations to less than 2.2
Reconfigurable Computing S. Reda, Brown University
Algorithm: find one LSD after another, compare with MSDs, quit early if not a palindrome. Runs in 8 seconds on laptop
Reconfigurable Computing S. Reda, Brown University
On NIOS, division is really expensive Division free algorithm: Dont test the MSD, find it with binary search
floor[ n * ((231+2)/10) * 1/231 ] = floor [ n/10 + 2*n/(10*231) ] n < 230 implies: 2*n < 231 < 1/10
= floor(n/10)
Divide by Constant
Similarly, to divide n by a constant C, we need to find P and R such that:
2P + R = 0 mod C. R*n < 2P
Found the constants to all powers of 10 needed. Algorithm worst register to register delay: 25 ns.
Reconfigurable Computing S. Reda, Brown University
Checking a palindrome
All combinational logic! Step 1: Convert 30-bit integer to 37-bit binary-coded decimal (BCD) format Step 2: Detect the length of decimal number Step 3: Compare pairs of digits with XOR
Nios Software
Results
Original C program: 49.59s/billion Unoptimized Nios C program: 7842s/100million Final result: 4.2s/billion (420000036 cycles @ 100MHz)
Total logic elements: 23,039 / 33,216 (69%)