xxHash icon indicating copy to clipboard operation
xxHash copied to clipboard

A memcpy fused version would be nice.

Open Emjayen opened this issue 1 year ago • 2 comments

As per the title: for performance reasons (single pass & overlapping writes) a version which performs xxh3 and memcpy would be nice to have. Ideally with the option for nt stores where available.

Emjayen avatar Nov 09 '23 18:11 Emjayen

What do you mean ? a "safer" memcpy() followed by a memcmp() ?

Cyan4973 avatar Nov 09 '23 21:11 Cyan4973

I have no idea what is actually asked in this issue.

But I'm just guessing "fused" function means:

memcpy(dst, data, dataSize);
xxh_update(&state, dst, dataSize);

More specific example:

uint8_t*  p     = ...;
xxh_state state = ...;

while(...) {
  // Store some data to tmp[]
  uint8_t tmp[...];
  my_magic_func(tmp, sizeof(tmp), ...);

  // LHS ("performance reason") may happen
  // - https://en.wikipedia.org/wiki/Load-Hit-Store
  // We can reverse the order of invocation in this case though.
  memcpy(p, tmp, sizeof(tmp));
  xxh_update(&state, p, sizeof(tmp));

  p += sizeof(tmp);
}

hash = xxh_digest(&state);

t-mat avatar Nov 09 '23 22:11 t-mat