Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive

memutils: memmove() / memcpy() implementation#2671

Closed
baziotis wants to merge 3 commits intodlang:masterfrom
baziotis:Dmemmove
Closed

memutils: memmove() / memcpy() implementation#2671
baziotis wants to merge 3 commits intodlang:masterfrom
baziotis:Dmemmove

Conversation

@baziotis
Copy link
Contributor

@baziotis baziotis commented Jul 9, 2019

Notes:

  1. I could not find a better way to handle both static and dynamic arrays (that includes isArray).
  2. More tests to be added.
  3. To check benchmarks, I recommend the main repo: https://github.com/baziotis/Dmemutils

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend only including memcpy in this PR and make another one for memmove

{ // There is no overlap, use memcpy.
pragma(inline, true);
Dmemcpy(d, s, n);
}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private. Also, what's the motivation for the split-up? Why can't the static array implementation call the other one?

Copy link
Contributor Author

@baziotis baziotis Jul 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most important reason is that I couldn't make (ref T[] dst, ref const T[] src) work when the arguments are !()(float[3], const(float[3])). I don't know why that is.
Edit: Yes, the static one can call the dynamic like this:

    T[] d = dst[0 .. $];
    const T[] s = src[0 .. $];
    Dmemmove(d, s);

I have to check the performance penalty although my hope is that for a serious compiler, it will be none.

}
}

unittest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs /// in order to be part of the documentation.

}

/* Can we use SIMD?
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment isn't really helpful.

}";



Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one line of whitespace between functions.

*/
version (D_SIMD)
{
import core.simd: float4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DStyle: :

version (D_SIMD)
{
import core.simd: float4;
enum useSIMD = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be private.

import gcc.builtins : __builtin_ia32_storeups, __builtin_ia32_loadups;
}

void store16f_sse(void *dest, float4 reg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private

}

/* Little SIMD library
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move into a separate module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems better to me as well. You can check point 3 in the memset PR description: #2662
I did not receive an answer and thus put them again in the same file. So, do a core/experimental/simd.d? or something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one possibility is to make core.experimental.mem a package with modules cpy, move, and simd.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better name it memory as there's core.memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm making a new PR. I have seen all the comments, I left them to be resolved in the new PR.


/* Handle dynamic sizes < 64 with forwards move. Overlap is possible.
*/
void Dmemmove_forw_lt64(void *d, const(void) *s, size_t n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private

__builtin_ia32_storeups(cast(float*) dest, reg);
}
}
float4 load16f_sse(const(void) *src)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No underscore - see the DStyle.


void memmove(T)(T *dst, const T *src)
{
void *d = cast(void*) dst;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please write void* d not void *d, this is D not C. ditto throughout.

mixin(arrayCode);
}

enum arrayCode = "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're going to use enum+mixin, please use q{} strings.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants