Scoreboard for the Data Lab "Beat the Prof" Contest Warning: The instructor (Tiger) must submit an entry before the results of the contest can be displayed.
To submit your instructor's entry: linux> ./src/driver.pl -u "The Prof"
这时候我们需要在后台执行提示的命令:
1 2
[root@VM-4-8-centos lab1]# ./src/driver.pl -u "The Prof" -bash: ./src/driver.pl: Permission denied
报错显示需要加权限:
1 2
cd /root/Lab/lab1/src chmod +x *.pl
之后再次报错:
1 2 3
[root@VM-4-8-centos lab1]# ./src/driver.pl -u "The Prof" Can't locate Driverlib.pm in @INC (you may need to install the Driverlib module) (@INC contains: . /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at ./src/driver.pl line 19. BEGIN failed--compilation aborted at ./src/driver.pl line 19.
[root@VM-4-8-centos lab1]# ./src/driver.pl -u "The Prof" Can't locate Driverhdrs.pm in @INC (you may need to install the Driverhdrs module) (@INC contains: . /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at /usr/lib64/perl5/Driverlib.pm line 13. BEGIN failed--compilation aborted at /usr/lib64/perl5/Driverlib.pm line 13. Compilation failed in require at ./src/driver.pl line 20. BEGIN failed--compilation aborted at ./src/driver.pl line 20.
Driverhdrs.pm文件与上面的Driverlib.pm文件同理,再次执行:
1 2
[root@VM-4-8-centos lab1]# ./src/driver.pl -u "The Prof" ./src/driver.pl: ERROR: No executable dlc binary.
[root@VM-4-8-centos dlcdir]# make bison -y -dv ANSI-C.y ANSI-C.y:653.15-16: error: $$ for the midrule at $4 of ‘declaring.list’ has no declared type $$ = AppendDecl($1, $3, Redecl); ^^ ANSI-C.y:708.15-16: error: $$ for the midrule at $4 of ‘default.declaring.list’ has no declared type { $$ = AppendDecl($1, $3, NoRedecl); } ^^ ANSI-C.y:1408.14-15: error: $$ for the midrule at $3 of ‘labeled.statement’ has no declared type { $$ = BuildLabel($1, NULL); } ^^ make: *** [Makefile:40: y.tab.h] Error 1
[root@VM-4-8-centos dlcdir]# bison -V bison (GNU Bison) 3.0.4 Written by Robert Corbett and Richard Stallman.
Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the sourcefor copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
heap.h:69:21: warning: inline function ‘HeapAllocate’ declared but never defined GLOBAL inline void *HeapAllocate(int number, int size); ... /root/Lab/lab1/src/dlcdir/check.c:339: undefined reference to `MakeConstSlong' /root/Lab/lab1/src/dlcdir/check.c:339: undefined reference to `MakeReturnCoord' collect2: error: ld returned 1 exit status make: *** [Makefile:36: dlc] Error 1
make clean make liuzhenlong@debian:~/Lab_new/lab1-handout$ file dlc dlc: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=ec898c28449afe1d16254e2cbe67617c1874b026, with debug_info, not stripped
/* * lsbZero - set 0 to the least significant bit of x * Example: lsbZero(0x87654321) = 0x87654320 * Legal ops: ! ~ & ^ | + << >> * Max ops: 5 * Rating: 1 */
// 法1(标准答案-9') /* 移位取指定字节,异或,两次取逻辑非 */ intbyteXor(int x, int y, int n){ int shift = n << 3; int xs = x >> shift; int ys = y >> shift; int cmp = (xs & 0xFF) ^ (ys & 0xFF); return !!cmp & 1 ; }
// 法2(目前最佳答案-8') /* 法1最后的&1是多余的操作 */ intbyteXor(int x, int y, int n){ int shift = n << 3; int xs = x >> shift; int ys = y >> shift; int cmp = (xs & 0xFF) ^ (ys & 0xFF); return !!cmp; }
/* * rotateLeft - Rotate x to the left by n * Can assume that 0 <= n <= 31 * Examples: rotateLeft(0x87654321,4) = 0x76543218 * Legal ops: ~ & ^ | + << >> ! * Max ops: 25 * Rating: 3 */
// 法1(标准答案-16') /* */ introtateLeft(int x, int n){ /* Create mask for n = 0 */ int zmask = (~!n)+1; int left = x << n; /* Arithmetic shift right by 32-n */ int right = x >> (33 + ~n); /* Mask off upper 1's */ int lmask = ~0 << n; right &= ~lmask; return (zmask&x) | (~zmask&(left|right)); }
// 法2(其他方法-10’) /* 先构造y为高(32-n)位为0的y,再与x右移(32-n)的x相与,相当于储存了x的高n位数,最后再与x左移n位相加即可。 */ introtateLeft(int x, int n){ int y; y=~((~0)<<n); x=(x<<n)+((x>>(32+(~n+1)))&y); return x; }
3.7 float_abs.c
注释:
1 2 3 4 5 6 7 8 9 10 11
/* * float_abs - Return bit-level equivalent of absolute value of f for * floating point argument f. * Both the argument and result are passed as unsigned int's, but * they are to be interpreted as the bit-level representations of * single-precision floating point values. * When argument is NaN, return argument.. * Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while * Max ops: 10 * Rating: 2 */
题目:
给予⼀个无符号整数表示的浮点数 uf (你可以认为 uf 具有浮点数的比特级结构) ,函数返回它的绝对值,即 |uf| (返回的结果也是⼀个无符号整数表示的浮点数),如果这个数是 NaN ,请返回它本身。
/* * float_f2i - Return bit-level equivalent of expression (int) f * for floating point argument f. * Argument is passed as unsigned int, but * it is to be interpreted as the bit-level representation of a * single-precision floating point value. * Anything out of range (including NaN and infinity) should return * 0x80000000u. * Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while * Max ops: 30 * Rating: 4 */
2. Compiling and running './btest -g' to determine correctness score. gcc -O -Wall -m32 -lm -o btest bits.c btest.c decl.c tests.c btest.c: In function ‘test_function’: btest.c:332:23: warning: ‘arg_test_range[1]’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (arg_test_range[1] < 1) ~~~~~~~~~~~~~~^~~
3. Running './dlc -Z' to identify operator count violations.
4. Compiling and running './btest -g -r 2' to determine performance score. gcc -O -Wall -m32 -lm -o btest bits.c btest.c decl.c tests.c btest.c: In function ‘test_function’: btest.c:332:23: warning: ‘arg_test_range[1]’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (arg_test_range[1] < 1) ~~~~~~~~~~~~~~^~~
5. Running './dlc -e' to get operator count of each function.