Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Does ?copy guarantee overlapping regions ?

newton_particle
Beginner
296 Views
Does anyone know how if ?copy has guarantees for overlapping source/target regions?

i.e. is it more memmove() than memcpy(), so that the direction of copying is factored in to prevent overruns ?

Newton
--------
0 Kudos
1 Reply
TimP
Honored Contributor III
296 Views
Quoting - newton_particle
Does anyone know how if ?copy has guarantees for overlapping source/target regions?

i.e. is it more memmove() than memcpy(), so that the direction of copying is factored in to prevent overruns ?

BLAS ?COPY has no protection against overlaps. You could build the netlib reference source code yourself, with compiler options which protect against overlap, such as ifort -assume dummy_aliases, but this is likely to be less efficient than memmove(), or copying first to a temporary region, then to the final target. It's possible to invoke memmove() directly from a Fortran compiler which supports ISO C interoperability (somewhat ugly).
Backwards copy is usually slow anyway (barring specially aligned cases) on Intel processors prior to Core i7, and AMD processors prior to Barcelona, so it's not safe to assume that an implementation of memmove() or equivalent is the most efficient one for your processor, unless you write/test it yourself. This may require fairly low level code, such as SSE intrinsics.
If you used ?COPY incorrectly, with overlapping data, it wouldn't necessarily be an over-run, but the source data would be over-written before use. memmove() likewise has no protection against over-run, should you exceed the target limits.
0 Kudos
Reply