From 4d99345b9e6fbd53fd78c3e5c86c6fd75f29c53f Mon Sep 17 00:00:00 2001 From: reisen <2863896505@qq.com> Date: Thu, 19 Oct 2023 23:26:17 +0800 Subject: [PATCH] Fix Bugs --- LAB1/README | 267 +++++++++++++++++++++++++++++++----------------------------- LAB1/bits.c | 39 +++++---- README.md | 8 +- 3 files changed, 164 insertions(+), 150 deletions(-) diff --git a/LAB1/README b/LAB1/README index e73d37f..d16dd6b 100644 --- a/LAB1/README +++ b/LAB1/README @@ -1,140 +1,153 @@ -*********************** -The CS:APP Data Lab -Directions to Students -*********************** +1. bitXor思路 -Your goal is to modify your copy of bits.c so that it passes all the -tests in btest without violating any of the coding guidelines. +根据德摩根定律,A^B = (A&~B)|(~A&B) +2. tmin思路 -********* -0. Files: -********* +最小的INT类即首位1,末31位全为0,故TMIN = 0x1<<31 -Makefile - Makes btest, fshow, and ishow -README - This file -bits.c - The file you will be modifying and handing in -bits.h - Header file -btest.c - The main btest program - btest.h - Used to build btest - decl.c - Used to build btest - tests.c - Used to build btest - tests-header.c- Used to build btest -dlc* - Rule checking compiler binary (data lab compiler) -driver.pl* - Driver program that uses btest and dlc to autograde bits.c -Driverhdrs.pm - Header file for optional "Beat the Prof" contest -fshow.c - Utility for examining floating-point representations -ishow.c - Utility for examining integer representations +3. isTmax思路 -*********************************************************** -1. Modifying bits.c and checking it for compliance with dlc -*********************************************************** +设置掩码y = 0x7fffffff +构造掩码方式为 y = (0x7f<<24)+(0xff<<16)+(0xff<<8)+0xff +x^y只有在x = Tmax时才为0,其余情况非0 +取反返回即可 -IMPORTANT: Carefully read the instructions in the bits.c file before -you start. These give the coding rules that you will need to follow if -you want full credit. +4. allOddBits思路 -Use the dlc compiler (./dlc) to automatically check your version of -bits.c for compliance with the coding guidelines: +设置掩码y = 0xaaaaaaaa +构造掩码方式为 y = (0xaa<<24)+(0xaa<<16)+(0xaa<<8)+0xaa +由于只看奇数次幂 +故得过滤掉偶数次幂,即x&y使得偶数次幂均为0,奇数次幂不变 +随后 (x&y)^y即可 +只有奇数次幂全为1才可输出为0,其余非0 +取反返回即可 - unix> ./dlc bits.c +5. negate思路 -dlc returns silently if there are no problems with your code. -Otherwise it prints messages that flag any problems. Running dlc with -the -e switch: +补码规则 负数取反加一即可 - unix> ./dlc -e bits.c - -causes dlc to print counts of the number of operators used by each function. - -Once you have a legal solution, you can test it for correctness using -the ./btest program. - -********************* -2. Testing with btest -********************* - -The Makefile in this directory compiles your version of bits.c with -additional code to create a program (or test harness) named btest. - -To compile and run the btest program, type: - - unix> make btest - unix> ./btest [optional cmd line args] - -You will need to recompile btest each time you change your bits.c -program. When moving from one platform to another, you will want to -get rid of the old version of btest and generate a new one. Use the -commands: - - unix> make clean - unix> make btest - -Btest tests your code for correctness by running millions of test -cases on each function. It tests wide swaths around well known corner -cases such as Tmin and zero for integer puzzles, and zero, inf, and -the boundary between denormalized and normalized numbers for floating -point puzzles. When btest detects an error in one of your functions, -it prints out the test that failed, the incorrect result, and the -expected result, and then terminates the testing for that function. - -Here are the command line options for btest: - - unix> ./btest -h - Usage: ./btest [-hg] [-r ] [-f [-1|-2|-3 ]*] [-T