riscv-newlib icon indicating copy to clipboard operation
riscv-newlib copied to clipboard

improve memcpy performance

Open HanKuanChen opened this issue 5 years ago • 2 comments

improve speed (memcpy32_speed.c and memcpy64_speed.c) and code size (memcpy_size.c)

HanKuanChen avatar Mar 18 '19 10:03 HanKuanChen

  1. Coding style: Could you using GNU coding style? 2 space instead of tab to indent, and using tab to replace 8 space, you could reference other files in <src>/newlib, or find clang-format file in <gcc-src>/contrib/clang-format.
  2. PREFER_SIZE_OVER_SPEED use byte-wise copy is fine, but I think __OPTIMIZE_SIZE__ use the original implementation would be better.
  3. Could you try to merge memcpy32_speed.c and memcpy64_speed.c? It seems using same algorithm to speed up.
    • Perhaps you could use unsigned long instead of magic number or uint32_t/uint64_t, e.g. sizeof (unsigned long) - 1 instead of 3 or 7.
  4. Need more comment to describe the algorithm, especially memcpy_<SIZE>_<ALIGN?> and MEMCPY_ALIGNMENT functions.
  5. Some function using #if 1/#else to comment out code like memcpy_4_2, and it seems like memcpy32_speed / memcpy64_speed using different implementation? I'd like remove all #if 1 and #else part in the code to keep it cleaner.
  6. Do you mind sharing your experimental result about that?

kito-cheng avatar Mar 18 '19 13:03 kito-cheng

Whar is the status of this patch? Do we still need it? riscv-newlib itself has been deprecated. Support for a small memcpy when optimizing for size was added a while ago, so that part of the patch is likely no longer needed. The other changes might be useful if performance data shows that they make memcpy faster.

jim-wilson avatar Apr 05 '21 23:04 jim-wilson