The memcpy routine is courtesy of SuperH, with some tweaks by me. XXX: There is room for further optimisation in some of these routines.