Free Essay

Datalab

In:

Submitted By zxfsafenZ
Words 2748
Pages 11
15-213/18-213 Fall 2012 Data Lab: Manipulating Bits Assigned: Thu, Aug 30, Due: Thu, Sep 13, 11:59PM Last Possible Time to Turn in: Sun, Sep 16, 11:59PM

For the fastest response, please contact the staff via the mailing list (15-213-staff@cs.cmu.edu) for questions about the assignment.

1 Introduction
The purpose of this assignment is to become more familiar with bit-level representations of common patterns, integers, and floating-point numbers. You’ll do this by solving a series of programming “puzzles.” Many of these puzzles are quite artificial, but you’ll find yourself thinking much more about bits in working your way through them.

2 Logistics
• This is an individual project. All handins are electronic using the Autolab service. • You should do all of your work in an Andrew directory, using either the shark machines or a Linux Andrew machine.

3 Logging in to Autolab
All 15-213 labs are being offered this term through a Web service developed by CMU students and faculty called Autolab. Before you can download your lab materials, you will need to update your Autolab account. Point your browser at the Autolab front page https://autolab.cs.cmu.edu You will be asked to authenticate via WebISO. After you authenticate this first time, Autolab will prompt you to update your account information with a nickname. Your nickname is the external name that identifies 1

you on the public scoreboards that Autolab maintains for each assignment, so pick something interesting! You can change your nickname as often as you like. Once you have updated your account information, click on “Save Changes” button, and then select the “Home” link to proceed to the main Autolab page. If you added the class late, you might not be included in Autolab’s list of valid students. In this case, you won’t see the 15-213/18-213 course listed on your Autolab home page. If this happens, just contact the staff.

4 Handout Instructions
Your lab materials are contained in a Unix tar file called datalab-handout.tar, which you can download from Autolab. After logging in to Autolab at https://autolab.cs.cmu.edu you can retrieve the datalab-handout.tar file by selecting “Data Lab − > Download handout”. Start by copying datalab-handout.tar to the Linux Andrew directory in where you plan to do your work. Then give the command linux> tar xvf datalab-handout.tar This will create a directory called datalab-handout that contains a number of files. The only file you will be modifying and handing in is bits.c. The bits.c file contains a skeleton for each of the 13 programming puzzles. Your assignment is to complete each function skeleton following a strict set of coding rules: You may use only straightline code for the integer puzzles (i.e., no loops or conditionals) and a limited number of C arithmetic and logical operators. Specifically, you are only allowed to use the following eight operators: ! ˜ & ˆ | + << >> A few of the functions further restrict this list. Also, you are not allowed to use any constants longer than 8 bits. See the comments in bits.c for detailed rules and a discussion of the coding rules for each functions. WARNING: Do not let the Windows WinZip program open up your .tar file (many Web browsers are set to do this automatically). Instead, save the file to your AFS directory and use the Linux tar program to extract the files. In general, for this class you should NEVER use any platform other than Linux to modify your files, doing so can cause loss of data (and important work!).

5 The Puzzles
This section describes the puzzles that you will be solving in bits.c.

2

5.1 Bit Manipulations
Table 1 describes a set of functions that manipulate and test sets of bits. The “Rating” field gives the difficulty rating (the number of points) for the puzzle, and the “Max ops” field gives the maximum number of operators you are allowed to use to implement each function. See the comments in bits.c for more details on the desired behavior of the functions. You may also refer to the test functions in tests.c. These are used as reference functions to express the correct behavior of your functions, although they don’t satisfy the coding rules for your functions. Name isAsciiDigit(x) anyEvenBit(x) copyLSB(x) leastBitPos(x) divpwr2(x,n) bitCount(x) Description Return 1 if 0x30 <= x <= 0x39 Return 1 if any even-numbered bit in word set to 1 Set all bits of result to least significant bit of x Determine position of the least significant 1 bit in x Compute x/2n Returns count of number of 1’s in x Table 1: Bit-Level Manipulation Functions. Rating 3 2 2 2 2 4 Max Ops 15 12 5 6 15 40

5.2 Two’s Complement Arithmetic
Table 2 describes a set of functions that make use of the two’s complement representation of integers. Again, refer to the comments in bits.c and the reference versions in tests.c for more information. Name conditional(x,y,z) isNonNegative(x) isGreater(x,y) absVal(x) isPower2(x) Description Same as x ? y : z Return 1 if x >= 0, return 0 otherwise Determine if x > y Return absolute value of x Is x a power of two? Table 2: Arithmetic Functions Rating 3 3 3 4 4 Max Ops 16 6 24 10 20

5.3 Floating-Point Operations
For this part of the assignment, you will implement some common single-precision floating-point operations. In this section, you are allowed to use standard control structures (conditionals, loops), and you may use both int and unsigned data types, including arbitrary unsigned and integer constants. You may not use any unions, structs, or arrays. Most significantly, you may not use any floating point data types, operations, or constants. Instead, any floating-point operand will be passed to the function as having type unsigned, and any returned floating-point value will be of type unsigned. Your code should perform the bit manipulations that implement the specified floating point operations. 3

Table 3 describes a set of functions that operate on the bit-level representations of floating-point numbers. Refer to the comments in bits.c and the reference versions in tests.c for more information. Name float_neg(uf) float_i2f(uf) Description Return bit-level equivalent of -f for f.p. argument f Return bit-level equivalent of expression (float) x Rating 2 4 Max Ops 10 30

Table 3: Floating-Point Functions. Value f is the floating-point number having the same bit representation as the unsigned integer uf. The included program fshow helps you understand the structure of floating point numbers. To compile fshow, switch to the handout directory and type: linux> make You can use fshow to see what an arbitrary pattern represents as a floating-point number: linux> ./fshow 2080374784 Floating point value 2.658455992e+36 Bit Representation 0x7c000000, sign = 0, exponent = f8, fraction = 000000 Normalized. 1.0000000000 X 2ˆ(121) You can also give fshow hexadecimal and floating point values, and it will decipher their bit structure: linux> ./fshow 0x15213 Floating point value 1.212781782e-40 Bit Representation 0x00015213, sign = 0, exponent = 0x00, fraction = 0x015213 Denormalized. +0.0103172064 X 2ˆ(-126) linux> ./fshow 15.213 Floating point value 15.2130003 Bit Representation 0x41736873, sign = 0, exponent = 0x82, fraction = 0x736873 Normalized. +1.9016250372 X 2ˆ(3)

6 Evaluation
Your score will be computed out of a maximum of 69 points based on the following distribution: 38 Correctness of code. 26 Performance of code, based on number of operators used in each function. 4

5 Style points, based on your instructor’s subjective evaluation of the quality of your solutions and your comments. Correctness points. The 13 puzzles you must solve have been given a difficulty rating between 1 and 4, such that their weighted sum totals to 38. We will use the the dlc compiler to check that your function follows the coding rules. We will use the BDD checker to verify that your function is correct. You will get full credit for a puzzle if it follows all of the coding rules and it passes all of the tests performed by the BDD checker, and no credit otherwise. Performance points. Our main concern at this point in the course is that you can get the right answer. However, we want to instill in you a sense of keeping things as short and simple as you can. Furthermore, some of the puzzles can be solved by brute force, but we want you to be more clever. Thus, for each function we’ve established a maximum number of operators that you are allowed to use for each function. This limit is very generous and is designed only to catch egregiously inefficient solutions. We will use the dlc compiler to verify that you’ve satisfied the operator limit. You will receive two points for each correct function that satisfies the operator limit. Style points. Finally, we’ve reserved 5 points for a subjective evaluation of the style of your solutions and your commenting. Your solutions should be as clean and straightforward as possible. Your comments should be informative, but they need not be extensive.

7 Autograding your work
We have included some handy autograding tools in the handout directory—btest, dlc, BDD checker, and driver.pl—to help you check the correctness of your work. • btest: This program checks the functional correctness of the functions in bits.c by calling them many times with many different argument values. To build and use it, type the following two commands: linux> make linux> ./btest Notice that you must rebuild btest each time you modify your bits.c file. You’ll find it very helpful to use btest to work through the functions one at a time, testing each one as you go. You can use the -f flag to instruct btest to test only a single function: linux> ./btest -f isGreater This will call your isGreater function many times with many different input values. You can feed btest specific function arguments using the option flags -1, -2, and -3: linux> ./btest -f isGreater -1 7 -2 0xf

5

This will call isGreater exactly once, using the arguments x=7 and y=15. Use this feature if you want to debug your solution by inserting printf statements; otherwise, you’ll get too much output. • dlc: This is a modified version of an ANSI C compiler from the MIT CILK group that you can use to check for compliance with the coding rules for each puzzle. The typical usage is: linux> ./dlc bits.c The program runs silently unless it detects a problem, such as an illegal operator, too many operators, or non-straightline code in the integer puzzles. Running with the -e switch: linux> ./dlc -e bits.c causes dlc to print counts of the number of operators used by each function. Type ./dlc -help for a list of command line options. • BDD checker: The code in BTEST simply tests your functions for a number of different cases. For most functions, the number of possible argument combinations far exceeds what could be tested exhaustively. To provide complete coverage, we have created a formal verification program, called cbit, that exhaustively tests your functions for all possible combinations of arguments. It does this by using a data structure known as Binary Decision Diagrams (BDDs). You do not invoke cbit directly. Instead, there is a series of Perl scripts that set up and evaluate the calls to it. Execute linux> ./bddcheck/check.pl -f fun to check function fun. Execute linux> ./bddcheck/check.pl to check all of your functions. Execute linux> ./bddcheck/check.pl -g the check all of your functions and get a compact tabular summary of the results. • driver.pl: This is a driver program that uses dlc and the BDD checker to compute the correctness and performance points for your solution. This is the same program that Autolab uses when it autogrades your handin. Execute linux> ./driver.pl to check all of your functions and to display the result in a compact tabular format.

6

8 Handin Instructions
Unlike other courses you may have taken in the past, in this course you may handin your work as often as you like until the due date of the lab. To receive credit, you will need to upload your bits.c file using the Autolab option “Handin your work.” Each time you handin your code, the server will run the driver program on your handin file and produce a grade report (it also posts the result on the scoreboard). The server archives each of your submissions and resulting grade reports, which you can view anytime using the “View handin history” option. Handin Notes: • At any point in time, your most recently uploaded file is your official handin. You may handin as often as you like. • Each time you handin, you should use the “View handin history” option to confirm that your handin was properly autograded. Manually refresh the page to see the autograded result. • You must remove any extraneous print statements from your bits.c file before handing in.

9 Advice
• You can work on this assignment using one of the class shark machines linux> ssh shark.ics.cs.cmu.edu or one of the Andrew Linux servers linux> ssh unix.andrew.cmu.edu • Test and debug your functions one at a time. Here is the sequence we recommend: – Step 1. Test and debug one function at a time using btest. To start, use the -1 and -2 arguments in conjunction with -f to call one function with one specific set of input argument(s): linux> ./btest -f isGreater -1 23 -2 0xabcd Feel free to use printf statements to display the values of intermediate variables. However, be careful to remove them after you have debugged the function. – Step 2. Use btest -f to check the correctness of your function against a large number of different input values: linux> ./btest -f isGreater If btest detects an error, it will print out the specific input argument(s) that failed. Go back to Step 1, and debug your function using those arguments – Step 3. Use dlc to check that you’ve conformed to the coding rules: 7

linux> dlc bits.c – Step 4. After your function passes all of the tests in btest, use the BDD checker to perform the definitive correctness test: linux> ./bddcheck/check.pl -f bitAdd – Step 5. Repeat Steps 1–4 for each function. At any point in time, you can compute the total number of correctness and performance points you’ve earned by running the driver program: linux> ./driver.pl • Some hints for dlc: – Don’t include the <stdio.h> header file in your bits.c file, as it confuses dlc and results in some non-intuitive error messages. You will still be able to use printf in your bits.c file for debugging without including the <stdio.h> header, although gcc will print a warning that you can ignore. – The dlc program enforces a stricter form of declarations than is the case for C++ or Java or even that is enforced by gcc. In particular, any declaration must appear in a block (what you enclose in curly braces) before any statement that is not a declaration. For example, it will complain about the following code: int foo(int x) { int a = x; a *= 3; /* This statement is not a declaration */ int b = a; /* ERROR: Declaration not allowed here */ } • Some hints for the BDD checker: – The BDD checker cannot handle functions that call other functions, including printf. You should use btest to evaluate code with debugging printf statements. Be sure to remove any of these debugging statements before handing in your code. – The BDD checker scripts are a bit picky about the formatting of your code. They expect the function to open with a line of the form: int fun (...) or unsigned fun (...) and to end with a single right brace in the leftmost column. That should be the only right brace in the leftmost column of your function. If you have any questions about this lab, the Autolab system, or the course in general, please contact the staff at 15-213-staff@cs.cmu.edu. We respond days and evenings and are very good about getting back to you fast. Remember: We’re here to help. Good luck! 8

Similar Documents

Free Essay

Cross Cultural Competence

...Životopis OSOBNE INFORMACIJE Selimović Amina Ljubina 33, 71321 Semizovac (Bosna i Hercegovina) (+387) 62 396380 aminaselimovic0601@gmail.com RADNO MJESTO NA KOJE SE PRIJAVLJUJETE Specijalist za odnose s kupcima RADNO ISKUSTVO 06/04/2015–danas Referent prodaje-anketar DataLab BiH Hamdije Čemerlića 2/XVI, 71000 Sarajevo Sarajevo (Bosna i Hercegovina) www.datalab.ba komunikacija s klijetima, direktna prodaja, izrada baza podataka, slanje dopisa, administrativni poslovi Djelatnost ili sektor Prodaja i tržišni plasman poslovno informacionog sistema Pantheon 15/01/2015–01/06/2015 Volonter - PR menadžer NVO Demokratski omladinski pokret Kemala Kapetanovića 17, 71000 Sarajevo Sarajevo (Bosna i Hercegovina) www.infozamlade.ba održavanje web stranice, izrada projekta, komunikacija s klijentima, slanje dopisa, selekcija i odabir kandidata za volontiranje, promocija Info centra za mlade Djelatnost ili sektor Nevladina organizacija 01/12/2014–26/12/2014 Studentska praksa UniCredit Bank d.d. Igmanska 60, 71320 Vogošća Sarajevo (Bosna i Hercegovina) www.unicredit.ba arhiviranje dokumentacije, slanje faksova, odgovaranje na upite klijenata Djelatnost ili sektor Bankarstvo OBRAZOVANJE I OSPOSOBLJAVANJE 10/10/2014–danas Master studij (II ciklus) Ekonomski fakultet Sarajevo Trg Alije Izetbegovića 1, 71000 Sarajevo Sarajevo (Bosna i Hercegovina) www.efsa.unsa.ba 20/09/2010–23/09/2013 VSS Bachelor menadžmenta Ekonomski fakultet Sarajevo ...

Words: 394 - Pages: 2

Premium Essay

Why Do Police Use Racial Profiling?

...Muslim or Arab American or non-American people. Of the law enforcement, racial profiling is the main function they use in order for them to do their job. In recent years, racial profiling has hit the news multiple times from police brutality. Police have killed many young black African Americans and humiliated many Arabs, but also, harassed as many Mexican and Latino Americans. Police are not the only ones who are known for racial profiling, even ordinary citizens can racially profile some because of the color of their skin or what religion they follow. It is thought to believe that the world is secretly still segregated in its own type of way. Works Cited Chalabi, Mona. "Are The Racial Disparities In Ferguson's Traffic Stops Unusual?" DataLab. 4 Mar. 2015. Web. 30 Mar. 2016. Chandrasekhar, Charu A. "Flying While Brown: Federal Civil Rights Remedies to Post-9/11 Airline Racial Profiling of South Asians." Asian American Law Journal 10.2 (2003). Print. Clarke, Rachael, and Christopher Lett. "What Happened When Michael Brown Met Officer Darren Wilson." CNN. Cable News Network, 11 Nov. 2014. Web. 31 Mar. 2016. Cronan, Bryan. "Macy's to Pay $650K, Latest Retailer to Settle over Racial Profiling."...

Words: 2317 - Pages: 10

Free Essay

Cmu 213 Ppt

...Carnegie Mellon Course Overview 15-213 /18-213: Introduction to Computer Systems 1st Lecture, Jan. 14, 2014 Instructors: Seth Copen Goldstein, Anthony Rowe, Greg Kesden The course that gives CMU its “Zip”! 1 Carnegie Mellon Overview     Course theme Five realities How the course fits into the CS/ECE curriculum Logistics 2 Carnegie Mellon Course Theme: Abstraction Is Good But Don’t Forget Reality  Most CS and CE courses emphasize abstraction  Abstract data types  Asymptotic analysis  These abstractions have limits  Especially in the presence of bugs  Need to understand details of underlying implementations  Useful outcomes from taking 213  Become more effective programmers Able to find and eliminate bugs efficiently  Able to understand and tune for program performance  Prepare for later “systems” classes in CS & ECE  Compilers, Operating Systems, Networks, Computer Architecture, Embedded Systems, Storage Systems, etc.  3 Carnegie Mellon Great Reality #1: Ints are not Integers, Floats are not Reals  Example 1: Is x2 ≥ 0?  Float’s: Yes!  Int’s:   40000 * 40000  1600000000 50000 * 50000  ?? Source: xkcd.com/571 4 Carnegie Mellon Great Reality #1: Ints are not Integers, Floats are not Reals  Example 1: Is x2 ≥ 0?  Float’s: Yes!  Int’s:   40000 * 40000  1600000000 50000 * 50000  ?? Example 2: Is (x + y) + z = x + (y + z)?  Unsigned & Signed Int’s: Yes!  Float’s: ...

Words: 2285 - Pages: 10