URL
https://opencores.org/ocsvn/forwardcom/forwardcom/trunk
Subversion Repositories forwardcom
[/] [forwardcom/] [libraries/] [memcpy.as] - Rev 106
Go to most recent revision | Compare with Previous | Blame | View Log
/********************************* memcpy.as ********************************* Author: Agner Fog* date created: 2018-03-25* Last modified: 2021-04-25* Version: 1.11* Project: ForwardCom library libc.li* Description: memcpy and memmove functions. Copy memory block* C declaration: void *memcpy (void *dest, const void *src, uint64_t n)* C declaration: void *memmove(void *dest, const void *src, uint64_t n)** Copyright 2018-2021 GNU General Public License http://www.gnu.org/licenses*****************************************************************************/// ! To do: Make vector read and write aligned for better performancepublic _memcpy: function, reguse = 0x1F, 1public _memmove: function, reguse = 0x1F, 1code section execute align = 4// r0 = destination// r1 = source// r2 = n_memcpy function_memmove:int64 r3 = r0 - r1if (uint64 r3 >= r2) {// destination will not overwrite source. copy forwardsint64 r3 = r0 + r2 // end of destinationint64 r4 = r1 + r2 // end of source// vector loop. count down r2for (int8 v0 in [r3-r2]) {int8 v0 = [r4-r2, length = r2] // read from sourceint8 [r3-r2, length = r2] = v0 // write to destination}}else {// destination overlaps source. copy backwardspush (r0) // save destinationint8 v0 = set_len(v0, r2) // length = min(n,maxlen)int64 r3 = get_len(v0) // this will be the block sizeint64 r0 = r0 + r2 - r3 // last block of destinationint64 r1 = r1 + r2 - r3 // last block of sourceint64 r4 = r3 // current block sizewhile (uint64 r2 > 0) { // loop counting down remaining bytesint8 v0 = [r1, length = r4] // read from sourceint8 [r0, length = r4] = v0 // write to destinationint64 r2 -= r4 // subtract block size from remaining sizeuint64 r4 = min_u(r2, r3) // block size = minimum of remaining bytes and maxlenint64 r0 -= r4 // subtract next block size from destinationint64 r1 -= r4 // subtract next block size from source}pop (r0) // restore destination}return // return dest in r0 unchanged_memcpy endcode end
Go to most recent revision | Compare with Previous | Blame | View Log
