<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">unaligned variable may cause split cache line load/store;<div class=""><br class=""></div><div class="">Which can be fetch by perf event: <span class="" style="font-family: Menlo; font-size: 14px;">mem_inst_retired.split_loads,mem_inst_retired.split_stores</span></div><div class=""><span class="" style="font-family: Menlo; font-size: 14px;"><br class=""></span></div><div class=""><font face="Menlo" class=""><span class="" style="font-size: 14px;">Is gcc has some compile time option can control variable allocated on stack will aligned?</span></font></div><div class=""><font face="Menlo" class=""><span class="" style="font-size: 14px;"><br class=""></span></font></div><div class=""><font face="Menlo" class=""><span class="" style="font-size: 14px;">I use this code snippet tested that both default gcc and clang can’t promise this:</span></font></div><div class=""><font face="Menlo" class=""><span class="" style="font-size: 14px;"><br class=""></span></font></div><div class=""><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#include <stdio.h></span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">unsigned long rbp = 0;</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">int main() {</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">    asm("movq %%rbp,%0": "=r"(rbp):);</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">    char a='c';</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">    int  b=1;</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">    char e='b';</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">    long c=20;</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">    printf("%lu\n%lu, %d\n%lu, %d \n%lu, %d\n%lu, %d", rbp, &a, sizeof(a), &b, sizeof(b), &e, sizeof(e), &c, sizeof(c));</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">}</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><div class="" style="margin: 0px; font-stretch: normal; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">$./a.out </span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">140733249436400</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">140733249436159, 1</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">140733249436152, 4 </span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">140733249436151, 1</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">140733249436136, 8</span></div></div></body></html>