Skip to content

Instantly share code, notes, and snippets.

@yuezato
Last active December 7, 2020 10:16
Show Gist options
  • Save yuezato/6092a4a0e4420cb180369bc0c69a27af to your computer and use it in GitHub Desktop.
Save yuezato/6092a4a0e4420cb180369bc0c69a27af to your computer and use it in GitHub Desktop.
typedef struct Type {
  uint32_t v[2];
} Type;

memcpy1(){
  ...
  for(...) {
    b[i].v[0] = a[i].v[0];
    b[i].v[1] = a[i].v[1];
    b[i+1].v[0] = a[i+1].v[0];
    b[i+1].v[1] = a[i+1].v[1];
  }
  ...
}

memcpy2() {
  ...
  for(...) {
    uint32_t v1 = a[i].v[0];
    uint32_t v2 = a[i].v[1];
    uint32_t v3 = a[i+1].v[0];
    uint32_t v4 = a[i+1].v[1];

    b[i].v[0] = v1;
    b[i].v[1] = v2;
    b[i+1].v[0] = v3;
    b[i+1].v[1] = v4;
  }
  ...
}    

Instrumentsを使った計測での比較

TIME time L2_RQSTS.ALL_DEMAND_MISS MEM_LOAD_RETIRED.L1_MISS MEM_LOAD_RETIRED.L2_MISS
memcpy1 5365ms 13,478,515 218,870 572,849,861
memcpy2 3604ms 1,730,475 80,561 3,698,854
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment