Fills up a complete array in memory setting bytes 2-by-2, in chuncks of 64 bytes. Size of the array must be multiple of 64.
void cpct_memset_f64 (void* array, u16 value, u16 size);
(2B HL) array | Pointer to the first byte of the array to be filled up (starting point in memory) |
(2B DE) value | 16-bit value to be set (Pair of bytes) |
(2B BC) size | Number of bytes to be set (>= 64, multiple of 64) |
call cpct_memset_f64_asm
Sets all pairs of bytes of an array in memory to the same given value. This is the same operation as std memset from standard C library, but with the added advantage of being faster and letting the user define the contents 16-bits-by-16-bits instead of 8. The technique used by this function is as follows:
1 | It saves the value of SP to recover it at the end of the function |
2 | It places SP at the last 2-bytes of the array |
3 | It uses PUSH instructions to set bytes 2-by-2, in chuncks of 64 bytes, until the entire array is set |
This function works for array sizes from 64 to 65472. However, it is recommended that you use it for values much greater than 64.
AF, BC, DE, HL
C-binding | 72 bytes |
ASM-binding | 67 bytes |
Case | microSecs (us) | CPU Cycles | ---------------------------------------------------------- Any | 47 + 132CH + 3CHHH | 188 + 528*CH + 12CHHH | ---------------------------------------------------------- CH%256 = 0 | +1 | +4 | ---------------------------------------------------------- Asm saving | -16 | -64 | ----------------------------------------------------------
BC = array size (Number of total bytes to set) CH = BC \ 64 (number of chuncks, 1 chunck = 64 bytes) CHHH = CH \ 256 - 1 \ = integer division