Giter Site home page Giter Site logo

dreamanddead / csapp-3e-solutions Goto Github PK

View Code? Open in Web Editor NEW
1.4K 26.0 305.0 4.93 MB

CSAPP 3e Solutions, migrated to github.io from gitbook.io which is being shut down.

Home Page: https://dreamanddead.github.io/CSAPP-3e-Solutions/

License: GNU General Public License v3.0

C 64.72% Makefile 2.27% C++ 0.05% Assembly 0.69% Lex 0.30% Yacc 0.22% HCL 23.23% Perl 2.83% Tcl 5.39% HTML 0.24% Dockerfile 0.06%
solution csapp gitbook

csapp-3e-solutions's Introduction

CSAPP-3e-Solutions

Computer Systems: A Programmer's Perspective Third Edition Solutions

csapp3e-cover

Build

prerequisite

  • x64 linux system
  • docker

clone code

git clone https://github.com/DreamAndDead/CSAPP-3e-Solutions.git
cd CSAPP-3e-Solutions

pull image

sudo docker pull dreamanddead/csapp-3e-solutions

compile

make

test

make test

clean

make clean

Feedback

You can

  • send an email
  • submit a PR
  • post an issue

ChangeLog

2021-03-01

  • Using hugo as website generator instead of gitbook

csapp-3e-solutions's People

Contributors

benjamindbb avatar boltma avatar bytemansion avatar dreamanddead avatar icecubewang avatar ir1d avatar liangjs avatar monque avatar timgates42 avatar vman411gamer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

csapp-3e-solutions's Issues

chapter2/code/floats/float-twice.c 中 ±∞ * 2 = -0 的错误

你的代码

  if (exp == 0) {
    /* Denormalized */
    frac <<= 1;
  } else if (exp == 0xFF - 1) {
    /* twice to oo */
    exp = 0xFF;
    frac = 0;
  } else {
    /* Normalized */
    exp += 1;
  }

当 f 是 ±∞ 时, exp = 0xFF, frac = 0x0,然后 exp += 1 --> exp = 0x100

最后 sig << 31 | exp << 23 | frac = sig << 31 | 0x80000000 | 0x0 = -0

正确的写法是


    if (exp == 0)
    {
        /* Denormalized */
        frac <<= 1;
    }
    else if (exp < 0xFE)
    {
        /* Normalized */
        exp++;
    }
    else // exp == 0xFE or 0xFF
    {
        /* twice to INF */
        exp = 0xFF;
        frac = 0;
    }

2.63 srl-sra.c bug

//当k==0
srl(x, k) != x >> k
//当k==0 && ((0x0001<<(w-1)) & x)==0x8000
sra(x, k) != x >> k

Question 2.76c second test case not appropriate

The second test case used SIZE_MAX * 2 to test the another_calloc function.
However, if I comment out the if statement that checks the overflow, the function would still run fine with the given argument. It is because the malloc function will return NULL if the provided argument is way too big. The argument SIZE_MAX * 2 on a 64-bit machine returns 18446744073709551614, which is SIZE_MAX - 1, hence malloc (SIZE_MAX *2) will return NULL even if the overflow did occur in this case.

I think it is better to test the function by using two smaller arguments, such as (2^40)+1 and 2^24, but still causing overflow.

Chapter4 exercise 4.35

请教一个问题,希望有缘人回答~
书本上练习题4.35给了个例子,关于改变Execute阶段的转发源为E_dstE。答案给的例子有一点不太明白,为什么在修改过后的版本中,条件传送源值0x123被转发到ALU的输入valA,valB正确地得到了操作数值0x321了?
我根据答案的例子绘出流水线图,对应addq %rdx, %rdx的decode阶段对应的irmovq $0x312, %rdx的write-back阶段,%rdx的值还没有写回寄存器文件,为什么答案说valB正确地得到了操作数值0x321了?

exercise 3.69

The constant CNT should be equal to 7, not 4.

7*40 + 8 = 288 = 0x120

2.88

0 00000 101
I think it's 5/2^17; 2^-14 * 5/8.....

8.12 - Update to 3rd Edition

The following code from the .pdf version:

#include <stdio.h>  
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h> 


void try() 
{
    fork();
    printf("Example\n");
    fork();
    return;
}

int main() 
{
    try(); fork();
    printf("Example\n");
    exit(0);
}

Try: https://www.programiz.com/c-programming/online-compiler/

Generates 10 lines of "example" the same when I hand ran it.
(not the 8 suggested here: https://github.com/DreamAndDead/CSAPP-3e-Solutions/blob/master/chapter8/8.12.md)

solution:
1 * fork -> 2 * "example\n" + 2 * fork -> 4 * fork -> 8 * "example\n".
= 10 * "example\n"

It seems that the solutions are from the 2nd edition and not the 3rd.

3.63中运算符优先级疑问

作者你好,3.63中

case 64:
  x = x << 4 - x;

考虑到-的优先级高于<<,这里应该改成

  x = (x << 4) - x;

才对

exercise 6.37

I don't quite understand your solutions to this exercise for sumB and sumC.

The array_t is more than a 2 multiple of the cache size (4C) and in sumB we read column by column. After the first 16 iterations of the inner loop the first quarter of the matrix will be in the cache, which means by the time we wrap around to the first row all blocks in the first quarter of the matrix will have been evicted.
sumB has a 100% miss rate, not 25%.

sumC is similar to sumB (reading columns wise) with the only diff being that we read two items out of a block once it's loaded into the cache, so we get two hits per block (per 4 ints).
sumC has a 50% miss rate, not 25%.

There is no difference between N=64 and N=60 because both will lead to a multiple of 16 and an array that is more than a 2 multiple of the cache size.

Since the stride is larger than the block size, sumB and sumC could have smaller miss rates only if the whole array_t was less than a 2 multiple of the cache size. For example, if the entire array could fit into the cache, then they would have a 25% miss rate.

5.14~16 中循环控制条件有点瑕疵

你的答案

  for (i = 0; i < length-6; i+=6) {

更好的答案

  for (i = 0; i < length-5; i+=6) {

当 length 是 6 的倍数的时候,你的答案会让下个 for 循环执行 6 次。而更好的答案就不会。

chapter2/code/floats/float-i2f.c 我的答案

/** Compute (float) f. 
*/
float_bits float_i2f(int i)
{

    // 0 是 int 中的唯一的非规格化数,单独处理
    if (i == 0)
    {
        return 0x0;
    }

    // 由于 -INT_MIN = INT_MIN
    // 后面的 M 无法正确表示,单独处理
    if (i == INT_MIN)
    {
        return 0xCF000000;
    }

    unsigned sign = i < 0 ? 1 : 0;
    unsigned M = i < 0 ? -i : i;
    unsigned E = 0;

    unsigned t = M;
    while (t > 1)
    {
        t >>= 1;
        E++;
    }

    if (E <= 23) // float 可以精确表示 int
    {
        M <<= 23 - E;
    }
    else // E > 23, 需要进行取舍
    {
        unsigned trunc_mask = (unsigned)-1 >> (32 - (E - 23));
        unsigned truncation = trunc_mask & M;
        // lsb = Least Significant Bit , 最低有效位
        unsigned lsb_is_one = (M >> (E - 23)) & 1;
        unsigned half_lsb = 1 << (E - 23 - 1);
        unsigned round_to_even = (lsb_is_one && truncation >= half_lsb) ||
                                 (!lsb_is_one && truncation > half_lsb);
        M >>= E - 23;
        M += round_to_even;
        if (M == 1 << 24)
        {
            // M >>= E - 23 后,(1<<23) <= M < (1<<24)
            // 但,M += round_to_even 有可能使得 M 的最高位进一
            // 导致 M == 1 << 24 , 例如 i = INT_MAX 就会发生这种情况
            // 为了使得 (1<<23) <= M < (1<<24)
            M >>= 1;
            E++;
        }
    }

    unsigned exp = E + 127;
    unsigned frac = M - (1 << 23);

    return sign << 31 | exp << 23 | frac;
}

3.72.md

Base on the alignment principle,the address of variable 'i' must be multiple of 8, 's1=&i-16' must be multiple of 8, 's2=s1-16x' must be multiple of 8. since p is multiple of 16 and e2=p-s2 , so e2 must be 8 or 0 rather than 15 or any other values. when e2 is 8 and n is even, e1 get it's min value 8 on 'e1+e2=16'. when e2 is 0 and n is odd, e1 get it's max value 24 on 'e1+e2=24'.

About the environment install

Hey ,After I entered "make plugin"

Following errors occured:
Error loading version latest: SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/gitbook/.gitbook/versions/3.2.3/node_modules/read-installed/node_modules/read-package-json/read-json.js:14:27)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)

TypeError: Cannot read property 'commands' of null

Could you plz tell me how to solve it?

2.63 shift 32 bits error

unsigned srl(unsigned x, int k) {
  unsigned xsra = (int) x >> k;

  int w = sizeof(int) << 3;
  //原来这句代码在k==0时会出左移32位的问题:int mask = (int) -1 << (w - k); ,改为以下这句
  int mask;
  ((k==0)&&(mask=(int)-1<<(w-k-1)<<1))||((k)&&(mask=(int)-1<<(w-k)));
  int mask = (int)-1<<(w-k
  return xsra & ~mask;
}

chapter3/3.69.md a_struct 中的 idx 可以不是 long 型。

3.69 B 的答案是

typedef struct {
    long idx,
    long x[4]
} a_struct

但是,实际上,根据对齐原则,idx 也可以是 int,short 和 char 类型。你可以修改以下 C 程序中设置,观察输出的结果。

#include <stdio.h>

#define CNT 7

typedef struct
{
    // 无论 idx 的类型为 char、short、int 或 long
    // 最后的 sizeof(b) 都是 0x128

    // char idx;
    // short idx;
    // int idx;
    long idx;
    long x[4];

} a_struct;

typedef struct
{
    int first;
    a_struct a[CNT];
    int last;
} b_struct;

int main(int argc, char const *argv[])
{
    a_struct a;
    b_struct b;
    printf("sizeof(a.idx) = %ld\n", sizeof(a.idx));
    printf("sizeof(a) = %ld\n", sizeof(a));
    printf("sizeof(b) = 0x%lX\n", sizeof(b));
    return 0;
}

Run make plugin error

When i run make plugin, got error:
`
Error loading version latest: SyntaxError: Unexpected token [
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/gitbook/.gitbook/versions/3.2.3/node_modules/read-installed/node_modules/read-package-json/read-json.js:7:16)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)

TypeError: Cannot read property 'commands' of null
`

What should i do?

chapter3/3.72.md 有一处笔误

你的答案

which e1 n s1
least 1 even n%16==1
greatest 24 odd n%16==0

正确答案

which e1 n s1
least 1 even s1%16==1
greatest 24 odd s1%16==0

2.82 E is wrong

x = INT_MIN + 1
(x >> 2) << 2 = 10000000000000000000000000000000
while x = 10000000000000000000000000000001
so E is wrong

12.21: about procedure reader

void *reader(void *vargp) {

This problem is about writer priority. So if there is a suspended writer, the while loop in reader procedure will run continuously. And it's definitely a great loss of performance. Maybe u can just implement the writer procedure just like reader procedure in textbook example if you still wanna keep the way it is.

CSAPP-3e-Solutions/chapter2/code/tsub-ok.c 中使用了 if 判断语句

/* Determine whether arguments can be substracted without overflow */
int tsub_ok(int x, int y) {
  if (y == INT_MIN) {
    return 0;
  }

  int neg_y = -y;
  int sum = x + neg_y;
  int pos_over = x > 0 && neg_y > 0 && sum < 0;
  int neg_over = x < 0 && neg_y < 0 && sum >= 0;

  return !(pos_over || neg_over);
}

可以修改为


int tsub_ok(int x, int y)
{
    int res = 1;

    (y == INT_MIN) && (res = 0);

    int sub = x - y;
    int pos_over = x > 0 && y < 0 && sub < 0;
    int neg_over = x < 0 && y > 0 && sub > 0;

    res = !(pos_over || neg_over) && res;

    return res;
}

2.64 error

Return 1 if all odd bits are ones.

int any_odd_one(unsigned x)
{
    int mask = 0xAAAAAAAA;
//extract all odd numbers of x and use ^ to compare whether all odd numbers are 1
    return !((mask & x) ^ mask);
}

chapter2/code/2.89.c 的 D,我觉得 不 总是 1 的理由如下。

理由如下

可知,-2^31 <= x,y,z < 2^31,-2^62 <= x*y < 2^62, -2^93 < x*y*z < 2^93,
而 double 类型,只可以精确地表示 [-2^53-1, 2^53+1] 中的整数。
分别结合后,可能会由于舍入而丢失精度,导致等号不成立。

C 和 D 选项的共同点是,都限制了 dx,dy,dz 的取值范围。但是,在运算过程中,C 的每一个中间过程数值都能被 double 类型精确的表示,所以,既不会溢出,也不会舍入,从而保持精度总是成立。而 D 的中间过程数值,会由于无法精确表示而产生舍入,从而丢失精度,不能总是成立。

3.70.md

there is an error in my compiler cause of operator priority,the following is Ok.

up->e2.x = *(up->e2.next->e1.p) - up->e2.next->e1.y;

Exercise 8.25

You are not uninstalling the signal handler. Here is one option:

jmp_buf tfgets_env;

void tfgets_alarm_handler () {
    longjmp(tfgets_env, 1);
}

char *tfgets (char *s, int size, FILE *stream) {
    char *res = NULL;

    Signal(SIGALRM, tfgets_alarm_handler);
    alarm(2);

    if (setjmp(tfgets_env) == 0) {
        res = fgets(s, size, stream);
    }

    alarm(0);
    Signal(SIGALRM, SIG_DFL);

    return res;
}

CSAPP-3e-Solutions/chapter2/code/threeforths.c 你的方法不大直观。

2.80

int threefourths(int x)
{

    int is_pos = ~x & INT_MIN;
    int has_remainder = x & 3;
    int fourth = x >> 2;
    // 为了保证 threefourths 向零舍入
    // fourth 必须与 向零舍入 相反
    // 所以, 正数不能整除 4 的时候, fourth++
    is_pos &&has_remainder && (fourth++);
    // 负数右移 2 位自带此效果

    return x - fourth;
}

PS: 文件名应该是 threefourths.c

10.10 md

I think that this question want to test dup2 function.

if (argc == 2) {
    int fd = Open(argv[1], O_RDONLY, 0);
    dup2(fd, STDIN_FILENO)
}
// before Rio_readinitb

problem with hugo

I use "make serve" to start the service.But it failed .Hugo report something as followed:
image
What should I do?

9.15

你的解答是
malloc(21) | 24 | 0x19

应该是
malloc(21) | 32 | 0x21

2.74有误

若x = -1, y = INT_MIN, 那么不会产生溢出, 不能因为 y 为 INT_MIN 就直接返回 0 ?

chapter3/code/good-echo/good-echo.c 无法满足任意长度的输入行

3.71 要求

你的实现应该对任意长度的输入行都能工作

但是,当输入行是以下字符串的时候,行尾的“-LOST”会丢失。

1kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk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kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkEND-LOST

the answer of 6.37 maybe wrong

N=64, sumB
The size of array is four times of cache's, that means every sixteen rows in the array are mapped to the same row in the cache, for example the row 0, 16, 32, 48 would be mapped to the first row of cache. After the first inner loop is completed, the data in cache is the first four numbers of lines 48 to 63. If search the number in lines 0 to 15, it will be missed. So the miss rate is 100%.

storre-ele.s compile error

When execute make for store-ele.s,it don't work,error:"/usr/bin/ld: store-ele.o: relocation R_X86_64_32S against symbol A can not be used when making a PIE object; recompile with -fPIC".

Fix bugs:
repalce
" movq A(,%rdx,8), %rax # t1 = (A + 8t4)"
to
"leaq A(%rip), %rax # calculate A for PIC code
movq (%rax, %rdx, 8), %rax # t1 = (A + 8t4)"

Problem 3.66

leaq 1(,%rdi,4), %r8 # t1 = n*4

Why not n*4+1 ?

My answer is
NR(n) = n*3
NC(n) = n*4+1

chapter3/code/3.70.c 答案表述错误了。

*( *(up->e2.next).e1.p )*(up->e2.next).e1.y 的表达式写错了。

因为 . 的优先级比 * 的高,所以以上写法相当于是 **p*y。即,把整型当做地址来获取值。

正确的写法是 *((*up->e2.next).e1.p)(*up->e2.next).e1.y,因为 -> 的优先级比 * 高。

还有一种更直观的写法 *(up->e2.next->e1.p)up->e2.next->e1.y,因为 ->. 的优先级一样。

void proc(union ele *up)
{
    up->e2.x = *(up->e2.next->e1.p) - up->e2.next->e1.y;
}

6.31

I believe cache access is a miss because the valid bit is 0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.