--- tags: info2022-homework --- # 資訊科技產業專案設計 作業3 contributed by <`魏昇芷 - tissue`> ## [NVIDIA - Embedded Software Engineer](https://nvidia.wd5.myworkdayjobs.com/zh-TW/NVIDIAExternalCareerSite/job/Taiwan-Taipei/Embedded-Software-Engineer_JR1962146) ### What we need to see: * Experience in relevant domain. * Good English language skills to work effectively with global teams. * Full experience at Linux, QNX or Android. * Excellent C skills. * Experience working on embedded systems and ARM processor specific. ### 問題一 下面的程式碼是在做 str 的初始化,請問可能有什麼潛在的問題? ```c char c; char str[128]; for (c = 0; c < 128; c++) str[c] = 0; ``` > 取自 https://www.pttweb.cc/bbs/Tech_Job/M.1612848862.A.6D2 #### 試答 C 語言中的 `char` 是一個 8 bit 的有號數,其範圍為 127 ~ -128,因此這個迴圈會成為無迴圈,因為其數值永遠不會超過 128。 ### 問題二 如果硬體不支援乘法,那 x = y * 200 要怎麼改才能得到正確答案 > 取自 https://www.pttweb.cc/bbs/Tech_Job/M.1612848862.A.6D2 #### 試答 首先先將 200 轉成 2 進位,$200_{10}$ = $11001000_2$,由 2 進位可知 200 = 128 + 64 + 8。 接著我們可以反覆 y + y = 2y, 2y + 2y = 4y ...,過程中我們可以得到 8y、64y、128y,將這三個數字相加 8y + 64y + 128y 即可得到 200y。 也可以用 shift 的。 ### 問題三 實作一個 function,參數是 32-bit integer,回傳共有幾個 bits 是 1 > 取自 https://www.pttweb.cc/bbs/Tech_Job/M.1612848862.A.6D2 #### 試答 用一個 for loop 逐一走訪 32 個 bit,並計算有幾個 bit 是 1 ```c int countBit(int input) { int count = 0; for (int i = 0; i < 32; i++) { if (input & 1) count ++; input >>= 1; } return count; } ``` ### 問題四 承上題,有沒有什麼更快的做法 > 取自 https://www.pttweb.cc/bbs/Tech_Job/M.1612848862.A.6D2 #### 試答 改成一次走訪 2 個 bit,並利用建表的方式快速得知該數字有幾個 bit 是 1 ```c int countBit(int input) { int num[4] = {0, 1, 1, 2}; int count = 0; for (int i = 0; i < 16; i++) { count += num[input & 3]; input >>= 2; } return count; } ``` 另外,也可以繼續延伸成 1 次走訪 4、8、16、32 個 bit,一次走訪的 bit 數量越多,要建的表就越大,花費的記憶體資源就越多,因此必須在效能與記憶體空間之間做取捨。 #### 更佳解法 ```C int hammingWeight(uint32_t n) { n = (n & 0x55555555) + ((n & 0xaaaaaaaa) >> 1); n = (n & 0x33333333) + ((n & 0xcccccccc) >> 2); n = (n & 0x0f0f0f0f) + ((n & 0xf0f0f0f0) >> 4); n = (n & 0x00ff00ff) + ((n & 0xff00ff00) >> 8); n = (n & 0x0000ffff) + ((n & 0xffff0000) >> 16); return n; } ``` ## [GOOGLE - Software Engineer, Embedded Systems, Silicon](https://careers.google.com/jobs/results/111637298098905798/) ### Minimum qualifications: * Master's degree in Electrical Engineering, Computer Science, relevant technical field or equivalent practical experience. * Experience coding in C or C++. ### Preferred qualifications: * Experience in ARM architecture and standard interfaces, bare-metal programming, bootloader, and firmware. * Experience in Linux kernel, device drivers, and Android system programming. * Experience in software/hardware integration. * Experience in optimizing algorithms with OpenGL/OpenCL/NEON/LLVM on CPU/TPU/GPU/DSP. * Verification experience using FPGAs and/or emulation platforms. * Familiarity with computer architecture, compilers, machine learning, or image processing. ### 相關面試經驗 * [[心得] google embedded SWE 面試心得](https://www.ptt.cc/bbs/Soft_Job/M.1613548617.A.C70.html) * [2021 疫情找工作-面試分享 Google/MS/Amazon/Roku](https://richard-chang.medium.com/2021-%E7%96%AB%E6%83%85%E6%89%BE%E5%B7%A5%E4%BD%9C-%E9%9D%A2%E8%A9%A6%E5%88%86%E4%BA%AB-google-microsoft-amazon-roku-811b2db5188)