[CakeML-dev] memcpy in wordLang?

Ramana Kumar Ramana.Kumar at cl.cam.ac.uk
Fri Mar 17 11:28:49 UTC 2017

Hi Magnus,

Thanks for the heads up. I should say that by "primitive in wordLang"
I think my language was confused: I never meant a wordLang primitive,
I mean a primitive in BVL that is implemented in wordLang.

Out of the discussion we had today, one point came up for when you
implement your ConsExtend stubs: it would be best to have a generic
memcpy (on words) that can be re-used to make an efficient memcpy on
bytes. In other words, I hope your stub won't fuse the functionality
required for ConsExtend with the basic copying primitive.

Also, Scott suggested at one point looking at how GNU libc implements
memcpy for ideas on an efficient implementation... it's a
sophisticated piece of assembly code and highly arch dependent; I
don't think we're at that level of complexity yet.. see e.g.


On 17 March 2017 at 16:48, Magnus Myreen <magnus.myreen at gmail.com> wrote:
> Hi Ramana,
> I'm on holiday at the moment, but want to write a short reply.
> I will be implementing a mem copy stub in data-to-word early next week for
> Scott's ConsExtend. That mem copy will copy word for word.
> Mem copy should not be primitive in wordlang. Having it as a primitive
> doesn't buy you anything. This also applies to byte by byte mem copy.
> For efficiency, you want to implement these copy routines as stubs in
> wordlang as opposed to stubs in higher levels like BVL, BVI or DataLang.
> Cheers,
> Magnus
> On Fri, 17 Mar 2017 at 06:07, Ramana Kumar <Ramana.Kumar at cl.cam.ac.uk>
> wrote:
>> Hi developers,
>> This question is especially for those familiar with wordLang.
>> Would it be reasonable to implement a memcpy primitive in wordLang? In
>> particular, I would want to add a primitive to BVL/BVI that given a
>> byte array, an offset, and another byte array, copies the contents of
>> the latter into the former starting at the offset.
>> The question is whether it is possible to do this efficiently in
>> wordLang even if the offset is not word aligned.
>> Obviously I can already write a byte-by-byte copying routine in BVL
>> (or even higher). I'm trying to figure out how to actually be more
>> efficient than that when implementing concatenation and
>> string/bytearray conversion primitives.
>> (Another annoying thing I noticed is that currently the only way to
>> create a byte array forces you to write some initial dummy replicated
>> value into it, even if you're going to overwrite them all right after.
>> But I don't know what a good primitive to use instead would look like
>> - some super create-and-copy-with-offsets primitive maybe, but that's
>> pretty complicated.)
>> Cheers,
>> Ramana
>> _______________________________________________
>> Developers mailing list
>> Developers at cakeml.org
>> https://lists.cakeml.org/listinfo/developers

More information about the Developers mailing list