Inxhinieri i Intel, Noah Goldstein, optimizoi funksionin memset() në bibliotekën glibc. Kjo optimizim ofron një rritje të performancës prej rreth 7.5% në versionet desktop të procesorëve me arkitekturë Skylake-X dhe Ice Lake. Në versionet server, rritja e performancës është pak më e ulët, kryesisht për shkak të performancës më të ulët të bërthamës së vetme.
Në realizimin e mëparshëm të funksionit memset() përdorej instruksioni assembler rep stosb. Deri kohët e fundit, ky instrukcion punonte mjaft shpejt, falë optimizimit të brendshëm zero-over-zero writeback. Megjithatë, në këtë optimizim u zgjodh një vulnerabilitet potencial, i cili mund të çojë në një sulm përmes kanaleve anësore. Si rezultat, optimizimi zero-over-zero writeback u anulua, çka çoi në një rënie të performancës së rep stosb. Në versionin e ri të memset(), instruksioni rep stosb akoma përdoret, por nën kushte më strikte.
ĂfarĂ« saktĂ«sisht ka ndryshuar mund tĂ« kuptohet nga ndryshimi i komentit tĂ« mĂ«poshtĂ«m nĂ« kod, i cili pĂ«rshkruan detajet e zbatimit tĂ« memset()
Versioni i mëparshëm i përshkrimit:
/* memset is implemented as: 1. Use overlapping store to avoid branch. 2. If size is less than VEC, use integer register stores. 3. If size is from VEC_SIZE to 2 * VEC_SIZE, use 2 VEC stores. 4. If size is from 2 * VEC_SIZE to 4 * VEC_SIZE, use 4 VEC stores. 5. On machines ERMS feature, if size is greater or equal than __x86_rep_stosb_threshold then REP STOSB will be used. 6. If size is more to 4 * VEC_SIZE, align to 4 * VEC_SIZE with 4 VEC stores and store 4 * VEC at a time until done. */
Versioni i ri i përshkrimit:
/* memset is implemented as: 1. Use overlapping store to avoid branch. 2. If size is less than VEC, use integer register stores. 3. If size is from VEC_SIZE to 2 * VEC_SIZE, use 2 VEC stores. 4. If size is from 2 * VEC_SIZE to 4 * VEC_SIZE, use 4 VEC stores. 5. If size is more to 4 * VEC_SIZE, align to 1 * VEC_SIZE with 4 VEC stores and store 4 * VEC at a time until done. 6. On machines ERMS feature, if size is range [__x86_rep_stosb_threshold, __x86_memset_non_temporal_threshold) then REP STOSB will be used. 7. If size >= __x86_memset_non_temporal_threshold, use a non-temporal stores. */
Burimi: linux.org.ru
