Blame src/string/ntapi_tt_aligned_memcpy_utf16.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
766a63
__attr_protected__
dd89bb
wchar16_t * __cdecl __ntapi_tt_aligned_memcpy_utf16(
dd89bb
	__in	uintptr_t *	dst,
dd89bb
	__in	uintptr_t *	src,
dd89bb
	__in	size_t		bytes)
dd89bb
{
dd89bb
	size_t 		aligned_block;
dd89bb
	size_t		copied;
dd89bb
dd89bb
	wchar16_t *	wch_src;
dd89bb
	wchar16_t *	wch_dst;
dd89bb
dd89bb
	#if defined (__X86_64_MODEL)
dd89bb
	uint32_t *	uint32_src;
dd89bb
	uint32_t *	uint32_dst;
dd89bb
	#endif
dd89bb
dd89bb
	aligned_block = bytes;
dd89bb
	aligned_block /= sizeof(uintptr_t);
dd89bb
	aligned_block *= sizeof(uintptr_t);
dd89bb
dd89bb
	copied = 0;
dd89bb
dd89bb
	while (copied < aligned_block) {
dd89bb
		*dst = *src;
dd89bb
		src++;
dd89bb
		dst++;
dd89bb
		copied += sizeof(uintptr_t);
dd89bb
	}
dd89bb
dd89bb
	#if defined (__X86_64_MODEL)
dd89bb
		switch (bytes % sizeof(uintptr_t)) {
dd89bb
			case 6:
dd89bb
				uint32_src = (uint32_t *)src;
dd89bb
				uint32_dst = (uint32_t *)dst;
dd89bb
				*uint32_dst = *uint32_src;
dd89bb
dd89bb
				uint32_src++;
dd89bb
				uint32_dst++;
dd89bb
dd89bb
				/* make the compiler happy */
dd89bb
				wch_src = (wchar16_t *)uint32_src;
dd89bb
				wch_dst = (wchar16_t *)uint32_dst;
dd89bb
				*wch_dst = *wch_src;
dd89bb
				break;
dd89bb
dd89bb
			case 4:
dd89bb
				uint32_src = (uint32_t *)src;
dd89bb
				uint32_dst = (uint32_t *)dst;
dd89bb
				*uint32_dst = *uint32_src;
dd89bb
				break;
dd89bb
		}
dd89bb
	#endif
dd89bb
dd89bb
	if (bytes % sizeof(uintptr_t)) {
dd89bb
		/* the remainder must be 2 */
dd89bb
		wch_src = (wchar16_t *)src;
dd89bb
		wch_dst = (wchar16_t *)dst;
dd89bb
		*wch_dst = *wch_src;
dd89bb
	}
dd89bb
dd89bb
	return (wchar16_t *)dst;
dd89bb
}