ray90514

@ray90514

Joined on Oct 12, 2020

  • https://www.gem5.org/documentation/general_docs/cpu_models/execution_basics https://www.gem5.org/documentation/general_docs/cpu_models/O3CPU 1743621995715 gem5/src/arch/riscv/isa/templates/vector_mem.isa VlIndexMicroInitiateAcc fault = initiateMemRead(xc, EA, mem_size, memAccessFlags, byte_enable); (for o3 model) ->gem5/src/cpu/o3/dyn_inst.cc DynInst::initiateMemRead
     Like  Bookmark
  • contributed by < ray90514 > 本次的改進目標為將 Virtio-blk 引入 kvm-host ,實作參考 kvmtool 及 tinybox。virtio 基於以下規範 Virtual I/O Device (VIRTIO) Version 1.1 開發過程的程式碼在 ray90514/kvm-host TODO [x] bus [x] pci [x] virtio-pci
     Like 1 Bookmark
  • contributed by <ray90514> 測驗1 求 log2 相當於求最高位的 1 在第幾位,以 uint32_t 為例,如果某數 x 最高位的 1 在高16位,則該數會大於 0xFFFF ,最高位的 1 會在 16 + n 位,這個 n 用二分搜尋法對 x 以同樣的方法求得。因為是求 ceil 所以結果要 +1 ,對於特殊情況也就是 2 的冪則是一開始先減一處理。 這段程式碼照邏輯少了以下 r |= shift; shift = x > 0x1; r |= shift
     Like  Bookmark
  • contributed by <ray90514> 測驗一 依照程式碼,主循環如下 判斷該迴文數長度是否為偶數,如果是該數必不為質數,找出下一個長度為奇數的迴文數 判斷是否為 3 或 5 的倍數,判斷是否為質數 求出下一個迴文數 判斷 3 和 5 的倍數有比較直接的方法,判斷質數則要先產生一個質數表,然後看質數表中的質數能否被該數整除。質數表的產生使用 Sieve of Eratosthenes 搭配 bitset 產生出小於等於 $sqrt(n) 的質數$。因為偶數除了 2 一定不是質數,只要記錄奇數就好。 以 bitset 儲存的質數表第 n 位為 0 代表 2n + 1 是質數,使用時先將質數表取反搭配 __builtin_ctzll 即可快速找到質數表中的質數。
     Like  Bookmark
  • contributed by < ray90514 > 測驗1 以 GENMASK(6, 4) 為例, 0b01111111 & 0b11110000 = 0b01110000 ,也就是我們需要兩個數,一個數是最高到 h + 1 為 0 其餘為 1 ,另一個是最低位到 l - 1 為 0 其餘為 1 。可以位移全為 1 的數也就是 (~0UL) 來產生。位移的量為一個右移 63 - h 一個左移 l 。 Linux 核心的 GENMASK 實作 若依照上述想法寫出的 GENMASK 如下,也就是 Linux 核心一開始的實作 (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
     Like  Bookmark
  • contributed by <ray90514> 測驗1 #include <stdint.h> uint32_t average(uint32_t a, uint32_t b) { return (a >> 1) + (b >> 1) + (EXP1); } (a >> 1) + (b >> 1) 可以看成 a / 2 + b / 2 ,但因為最低位會被捨去,所以若 a 和 b 最低位都為 1 ,相加會進位要補上 1。 EXP1 為 a & b & 1 。
     Like  Bookmark
  • 測驗一 void *memchr_opt(const void *src_void, int c, size_t length) { const unsigned char *src = (const unsigned char *) src_void; unsigned char d = c; while (UNALIGNED(src)) { if (!length--) return NULL; if (*src == d)
     Like  Bookmark
  • contributed by <ray90514> 實驗環境 $ gcc --version gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ lscpu Architecture: x86_64
     Like  Bookmark
  • contributed by <ray90514> 題目 測驗一 void map_add(map_t *map, int key, void *data) { struct hash_key *kn = find_key(map, key); if (kn) return;
     Like  Bookmark
  • contributed by < ray90514 > 實驗環境 $ gcc --version gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ lscpu Architecture: x86_64
     Like  Bookmark