arch/openrisc/lib/memcpy.c

Source file repositories/reference/linux-study-clean/arch/openrisc/lib/memcpy.c

File Facts

System
Linux kernel
Corpus path
arch/openrisc/lib/memcpy.c
Extension
.c
Size
2641 bytes
Lines
126
Domain
Architecture Layer
Bucket
arch/openrisc
Inferred role
Architecture Layer: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

if (n & 1 << 4) {
			*dest_w++ = *src_w++;
			*dest_w++ = *src_w++;
			*dest_w++ = *src_w++;
			*dest_w++ = *src_w++;
		}

		if (n & 1 << 3) {
			*dest_w++ = *src_w++;
			*dest_w++ = *src_w++;
		}

		if (n & 1 << 2)
			*dest_w++ = *src_w++;

		d = (unsigned char *)dest_w;
		s = (unsigned char *)src_w;

	} else {
		d = (unsigned char *)dest_w;
		s = (unsigned char *)src_w;

		for (i = n >> 3; i > 0; i--) {
			*d++ = *s++;
			*d++ = *s++;
			*d++ = *s++;
			*d++ = *s++;
			*d++ = *s++;
			*d++ = *s++;
			*d++ = *s++;
			*d++ = *s++;
		}

		if (n & 1 << 2) {
			*d++ = *s++;
			*d++ = *s++;
			*d++ = *s++;
			*d++ = *s++;
		}
	}

	if (n & 1 << 1) {
		*d++ = *s++;
		*d++ = *s++;
	}

	if (n & 1)
		*d++ = *s++;

	return dest;
}
#else
/*
 * Use word copies but no loop unrolling as we cannot assume there
 * will be benefits on the archirecture
 */
void *memcpy(void *dest, __const void *src, __kernel_size_t n)
{
	unsigned char *d, *s;
	uint32_t *dest_w = (uint32_t *)dest, *src_w = (uint32_t *)src;

	/* If both source and dest are word aligned copy words */
	if (!((unsigned int)dest_w & 3) && !((unsigned int)src_w & 3)) {
		for (; n >= 4; n -= 4)
			*dest_w++ = *src_w++;
	}

	d = (unsigned char *)dest_w;
	s = (unsigned char *)src_w;

	/* For remaining or if not aligned, copy bytes */
	for (; n >= 1; n -= 1)
		*d++ = *s++;

	return dest;

}
#endif

EXPORT_SYMBOL(memcpy);

Annotation

Implementation Notes