# 2022q1 第 8 週測驗題 ## 測驗 `1` ```c void *memchr_opt(const void *src_void, int c, size_t length) { ... if (!TOO_SMALL(length)) { ... while (length >= LBLOCKSIZE) { /* XXXXX: Your implementation should appear here */ if (!DETECT_CHAR(*asrc, mask)) { /* if not find within sizeof(long) bytes */ length -= LBLOCKSIZE; asrc += 1; } else { /* the character is within sizeof(long) bytes */ break; } } /* If there are fewer than LBLOCKSIZE characters left, then we resort to * the bytewise loop. */ src = (unsigned char *) asrc; } ... } ``` ## 測驗 `2` * `DDD`: `idx++` * `KKK`: `mask + 1` * `RRR`: `&lfr->ring[tail & mask].idx, __ATOMIC_ACQUIRE` * `HHH`: `head + actual`