Comp 40, Summer 2009 Lab Assignment L1: Manipulating Bits Extra Credit Assignment Assigned: June 4 2009, Due: June 11, 2009
Introduction
This is completely optional and is worth 5 extra credit points. Extra credits will be used at the end of the semester when determining the grades.
Error Correcting Codes
Parity has the disadvantage that it can only be used to detect a change in odd number of bits. Further, it cannot be used to correct the error. This is because a single bit cannot encode the position of the error. Error correcting codes have been developed to both detect and correct errors. There are many different types of error correcting codes, Hamming and Solomon-Reed being two of the widely used ones. The idea behind such codes is the same. By adding more parity bits and arranging them such that errors in different bit positions of the data produce different error results, the bad bits can be identified. For example, in an 8-bit piece of data D = d 7d6d5d4d3d2d1d0, there are eight possible single bit errors, so four error control bits or “ecc bits” could potentially specify not only that an error occurred but also which data bit caused the error. Each ecc bit is generated by computing parity across some selected data bits. With 4 ecc bits, we can also detect if the error was in one of the ecc bits. Since we have a total of 8 data + 4 ecc = 12 bits, we need 4 bits to encode this. However, double bit errors are not distinguishable. Adding one more parity bit gives the code the ability to detect and correct a single bit error and also detect (but not correct) a double bit error. This is referred to as SEC-DED (Single Error Correct Double Error Detect). Thus we need 5 ecc bits to protect 8 bits of data. That is a lot of wasted space which is why parity is often used for 8 bits. However SEC-DED is most commonly used for 64-bits of data where it requires 8 ecc bits. In this lab, you will be using the Hamming code ECC algorithm developed by Hsiao of IBM [1]. You will be using the following rule from this paper to encode and decode ecc for 32 bits of data (an integer). This width is chosen so that you can use some of the functions you have already written. • Table 1 shows which data bits are used to compute each ecc bit. For example: C0 = d0 ^ d1 ^ d2 ^ d3 ^ d4 ^ d5 ^ d6 ^ d7 ^ d14 ^ d19 ^ d22 ^ d24 ^ d30 ^ d31 C1 = d4 ^ d7 ^ d8 ^ d9 ^ d10 ^ d11 ^ d12 ^ d13 ^ d14 ^ d15 ^ d18 ^ d21 ^ d24 ^ d29 etc. This is what you will be doing in the ecc_encode() function. When checking ecc in ecc_decode(), you will compute the ecc bits for the data. Then you will compare it with the given ecc bits. The resulting bit pattern showing the difference is called syndrome. • If they differ in bit positions (0,5,6), we know the problem is in data bit d0. • If they differ in bit positions (0,4,6), we know the problem is in data bit d1. • and so on....
•
• • • •
If they differ in bit position (0), then we know the problem is in ecc bit c0. If they differ in bit position (1), then we know the problem is in ecc bit c1. and so on... If the mismatch is a different bit pattern, then it is a double bit or multi bit error, also called uncorrectible error. We cannot detect which bits flipped.
Table 1: (39,32) SEC-DED code from [1]
DATA 0 1 S0 1 1 S1 S2 S3 S4 S5 1 S6 1 1 0 0 5 4 6 6 0 4 3 1 0 2 6 1 0 1 6 0 4 5 0 3 5 0 1 4 1 1 1 1 1 1 1 1 1 1 1 1 5 6 1 1 4 6 1 1 3 6 1 1 2 6 1 4 5 1 3 5 1 0 5 1 3 4 2 3 5 1 1 1 1 1 1 2 1 3 1 4 1 1 5 1 6 1 7 1 1 1 1 1 1 1 1 1 1 1 1 1 2 6 5 2 1 5 2 0 5 2 4 5 2 1 4 2 0 4 1 1 1 1 8 9 1 0 1 1 1 2 1 3 1 4 1 1 1 1 1 1 1 1 2 4 6 3 0 1 1 3 4 6 3 2 4 1 3 2 6 3 4 5 3 1 2 3 0 2 1 1 1 1 1 1 1 1 1 5 1 6 1 7 1 8 1 9 1 1 1 1 1 1 1 1 2 0 2 1 2 2 1 2 3 2 4 1 1 1 1 1 1 1 1 1 1 1 3 1 6 1 1 1 1 1 1 2 5 2 6 2 7 2 8 2 9 3 0 1 3 1 1 ECC C C C C C C C 0 1 2 3 4 5 6 1 1 1 1 1 1 1
Write the following functions: • int ecc_encode (int data) : a function which returns the 7-bit ecc of the input 32-bit data computed according to the above table. • ecc_decode (int *data, int *ecc, int *error, int *uncorr, int *pos): a procedure which takes as input the 32-bit data and its corresponding ecc. It then computes (i) if there is an error, (ii) if the error is uncorrectible (not single-bit) and (iii) the position of the error in case it was a single bit error. Thus, we have the following possibilities. (Note that this table makes a good informative comment to put in your code) error uncorr no error single bit error double bit error 0 1 1 0 0 1 pos don't care error bit position 0-38 don't care
Further, in case there is a single bit error, ecc_decode() returns the corrected data or ecc. • Test your code. Describe the test cases you used.
Handin
• • All the code you wrote to implement and test SEC-DED. If not obvious from the code, hand in a description of your test strategy, including the input vectors you used.
References
[1] M. Y. Hsiao, A Class of Optimal Minimum Odd-weight-column SEC-DED Codes, IBM J. Res. Develop., July 1970.