Index: boot/arch/mips32/Makefile.inc
===================================================================
--- boot/arch/mips32/Makefile.inc	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ boot/arch/mips32/Makefile.inc	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -50,4 +50,5 @@
 endif
 
+
 SOURCES = \
 	arch/$(BARCH)/src/asm.S \
Index: boot/arch/mips32/src/asm.S
===================================================================
--- boot/arch/mips32/src/asm.S	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ boot/arch/mips32/src/asm.S	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -37,6 +37,4 @@
 .global halt
 .global jump_to_kernel
-.global memset
-.global memcpy
 
 .section BOOTSTRAP
@@ -160,148 +158,2 @@
 	j $a0
 	nop
-
-memset:
-	move $v0, $a0
-	beqz $a2, 0f
-	addiu $t1, $a2, -1
-	
-	negu $t0, $a0
-	andi $t0, $t0, 0x3
-	sltu $v1, $a2, $t0
-	bnez $v1, 1f
-	andi $a1, $a1, 0xff
-	
-	7:
-		sltiu $v1, $a2, 4
-		beqz $v1, 2f
-		move $v1, $v0
-		
-		 move $t0, $a2
-	
-	3:
-		sb $a1, 0($v1)
-		addiu $v1, $v1, 1
-		subu $a3, $v1, $v0
-		sltu $a3, $a3, $t0
-		bnez $a3, 3b
-		addiu $t1, $t1, -1
-		
-		beq $a2, $t0, 0f
-		subu $a2, $a2, $t0
-	
-	8:
-		srl $a0, $a2, 0x2
-		sll $t4, $a0, 0x2
-		beqz $t4, 4f
-		sll $t2, $a1, 0x10
-		
-		sll $t3, $a1, 0x8
-		or $t3, $a1, $t3
-		sll $a3, $a1, 0x18
-		or $t3, $t3, $t2
-		or $t3, $t3, $a3
-		addu $t0, $v0, $t0
-		move $a3, $zero
-	
-	5:
-		addiu $a3, $a3, 1
-		sltu $t2, $a3, $a0
-		sw $t3, 0($t0)
-		bnez $t2, 5b
-		addiu $t0, $t0, 4
-		
-		addu $v1, $v1, $t4
-		beq $a2, $t4, 0f
-		subu $t1, $t1, $t4
-	
-	4:
-		addiu $t1, $t1, 1
-		addu $t1, $v1, $t1
-		sb $a1, 0($v1)
-	
-	6:
-		addiu $v1, $v1, 1
-		bnel $v1, $t1, 6b
-		sb $a1, 0($v1)
-	
-	0:
-		jr $ra
-		nop
-	
-	1:
-		j 7b
-		move $t0, $a2
-	
-	2:
-		bnez $t0, 3b
-		nop
-		
-		j 8b
-		subu $a2, $a2, $t0
-
-memcpy:
-	move $t2, $a0  /* save dst */
-	
-	addiu $v0, $a1, 3
-	li $v1, -4  /* 0xfffffffffffffffc */
-	and $v0, $v0, $v1
-	beq $a1, $v0, 3f
-	move $t0, $a0
-	
-	0:
-		beq $a2, $zero, 2f
-		move $a3, $zero
-	
-	1:
-		addu $v0, $a1, $a3
-		lbu $a0, 0($v0)
-		addu $v1, $t0, $a3
-		addiu $a3, $a3, 1
-		bne $a3, $a2, 1b
-		sb $a0, 0($v1)
-	
-	2:
-		jr $ra
-		move $v0, $t2
-	
-	3:
-		addiu $v0, $a0, 3
-		and $v0, $v0, $v1
-		bne $a0, $v0, 0b
-		srl $t1, $a2, 2
-		
-		beq $t1, $zero, 5f
-		move $a3, $zero
-		
-		move $a3, $zero
-		move $a0, $zero
-	
-	4:
-		addu $v0, $a1, $a0
-		lw $v1, 0($v0)
-		addiu $a3, $a3, 1
-		addu $v0, $t0, $a0
-		sw $v1, 0($v0)
-		bne $a3, $t1, 4b
-		addiu $a0, $a0, 4
-	
-	5:
-		andi $a2, $a2, 0x3
-		beq $a2, $zero, 2b
-		nop
-		
-		sll $v0, $a3, 2
-		addu $t1, $v0, $t0
-		move $a3, $zero
-		addu $t0, $v0, $a1
-	
-	6:
-		addu $v0, $t0, $a3
-		lbu $a0, 0($v0)
-		addu $v1, $t1, $a3
-		addiu $a3, $a3, 1
-		bne $a3, $a2, 6b
-		sb $a0, 0($v1)
-		
-		jr $ra
-		move $v0, $t2
Index: boot/generic/include/memstr.h
===================================================================
--- boot/generic/include/memstr.h	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ boot/generic/include/memstr.h	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -35,7 +35,6 @@
 #include <typedefs.h>
 
-#define memset(dst, val, cnt)  __builtin_memset((dst), (val), (cnt))
-#define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
-
+extern void *memcpy(void *, const void *, size_t);
+extern void *memset(void *, int, size_t);
 extern void *memmove(void *, const void *, size_t);
 
Index: boot/generic/src/memstr.c
===================================================================
--- boot/generic/src/memstr.c	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ boot/generic/src/memstr.c	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -29,4 +29,48 @@
 #include <memstr.h>
 #include <typedefs.h>
+
+/** Move memory block without overlapping.
+ *
+ * Copy cnt bytes from src address to dst address. The source
+ * and destination memory areas cannot overlap.
+ *
+ * @param dst Destination address to copy to.
+ * @param src Source address to copy from.
+ * @param cnt Number of bytes to copy.
+ *
+ * @return Destination address.
+ *
+ */
+void *memcpy(void *dst, const void *src, size_t cnt)
+{
+	uint8_t *dp = (uint8_t *) dst;
+	const uint8_t *sp = (uint8_t *) src;
+	
+	while (cnt-- != 0)
+		*dp++ = *sp++;
+	
+	return dst;
+}
+
+/** Fill block of memory.
+ *
+ * Fill cnt bytes at dst address with the value val.
+ *
+ * @param dst Destination address to fill.
+ * @param val Value to fill.
+ * @param cnt Number of bytes to fill.
+ *
+ * @return Destination address.
+ *
+ */
+void *memset(void *dst, int val, size_t cnt)
+{
+	uint8_t *dp = (uint8_t *) dst;
+	
+	while (cnt-- != 0)
+		*dp++ = val;
+	
+	return dst;
+}
 
 /** Move memory block with possible overlapping.
Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ kernel/Makefile	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -228,4 +228,5 @@
 	generic/src/lib/func.c \
 	generic/src/lib/memstr.c \
+	generic/src/lib/memfnc.c \
 	generic/src/lib/sort.c \
 	generic/src/lib/str.c \
Index: kernel/arch/amd64/src/asm.S
===================================================================
--- kernel/arch/amd64/src/asm.S	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ kernel/arch/amd64/src/asm.S	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -37,6 +37,4 @@
 .global read_efer_flag
 .global set_efer_flag
-.global memset
-.global memcpy
 .global memcpy_from_uspace
 .global memcpy_to_uspace
@@ -45,47 +43,10 @@
 .global early_putchar
 
-#define MEMSET_DST   %rdi
-#define MEMSET_VAL   %rsi
-#define MEMSET_SIZE  %rdx
-
 #define MEMCPY_DST   %rdi
 #define MEMCPY_SRC   %rsi
 #define MEMCPY_SIZE  %rdx
 
-/* Fill memory with byte pattern
- *
- * This is a conventional memset().
- *
- * @param MEMSET_DST  Destination address.
- * @param MEMSET_VAL  Value to fill.
- * @param MEMSET_SIZE Size.
- *
- * @return MEMSET_DST.
- *
- */
-memset:
-	movq MEMSET_DST, %r8    /* save %rdi */
-	
-	/* Create byte pattern */
-	movzbl %sil, %esi       /* MEMSET_VAL */
-	movabs $0x0101010101010101, %rax
-	imulq %rsi, %rax
-	
-	movq MEMSET_SIZE, %rcx
-	shrq $3, %rcx           /* size / 8 */
-	
-	rep stosq               /* store as much as possible word by word */
-	
-	movq MEMSET_SIZE, %rcx
-	andq $7, %rcx           /* size % 8 */
-	jz 0f
-	
-	rep stosb               /* store the rest byte by byte */
-	
-	0:
-		movq %r8, %rax
-		ret                 /* return MEMCPY_SRC, success */
-
-/** Copy memory from/to userspace.
+/**
+ * Copy memory from/to userspace.
  *
  * This is almost conventional memcpy().
@@ -102,5 +63,4 @@
  *
  */
-memcpy:
 memcpy_from_uspace:
 memcpy_to_uspace:
Index: kernel/arch/ia32/src/asm.S
===================================================================
--- kernel/arch/ia32/src/asm.S	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ kernel/arch/ia32/src/asm.S	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -38,6 +38,4 @@
 .global paging_on
 .global enable_l_apic_in_msr
-.global memset
-.global memcpy
 .global memcpy_from_uspace
 .global memcpy_from_uspace_failover_address
@@ -46,55 +44,7 @@
 .global early_putchar
 
-#define MEMSET_DST   4
-#define MEMSET_VAL   8
-#define MEMSET_SIZE  12
-
 #define MEMCPY_DST   4
 #define MEMCPY_SRC   8
 #define MEMCPY_SIZE  12
-
-/* Fill memory with byte pattern
- *
- * This is a conventional memset().
- *
- * @param MEMSET_DST(%esp)  Destination address.
- * @param MEMSET_VAL(%esp)  Value to fill.
- * @param MEMSET_SIZE(%esp) Size.
- *
- * @return MEMSET_DST(%esp).
- *
- */
-memset:
-	movl %edi, %edx  /* save %edi */
-	
-	movl MEMSET_DST(%esp), %edi
-	movl MEMSET_VAL(%esp), %ecx
-	
-	/* Create byte pattern */
-	movb %cl, %ch
-	movw %cx, %ax
-	shll $16, %eax
-	orw %cx, %ax
-	
-	movl MEMSET_SIZE(%esp), %ecx
-	shrl $2, %ecx  /* size / 4 */
-	
-	/* Write whole words */
-	rep stosl
-	
-	movl MEMSET_SIZE(%esp), %ecx
-	andl $3, %ecx  /* size % 4 */
-	jz 0f
-	
-	/* Copy the rest byte by byte */
-	rep stosb
-	
-	0:
-	
-		movl %edx, %edi
-		
-		/* MEMSET_DST(%esp), success */
-		movl MEMSET_DST(%esp), %eax
-		ret
 
 /** Copy memory to/from userspace.
@@ -113,5 +63,4 @@
  *
  */
-memcpy:
 memcpy_from_uspace:
 memcpy_to_uspace:
Index: kernel/arch/mips32/src/asm.S
===================================================================
--- kernel/arch/mips32/src/asm.S	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ kernel/arch/mips32/src/asm.S	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -57,91 +57,8 @@
 	nop
 
-.global memset
-.global memcpy
 .global memcpy_from_uspace
 .global memcpy_to_uspace
 .global memcpy_from_uspace_failover_address
 .global memcpy_to_uspace_failover_address
-
-memset:
-	move $v0, $a0
-	beqz $a2, 0f
-	addiu $t1, $a2, -1
-	
-	negu $t0, $a0
-	andi $t0, $t0, 0x3
-	sltu $v1, $a2, $t0
-	bnez $v1, 1f
-	andi $a1, $a1, 0xff
-	
-	7:
-		sltiu $v1, $a2, 4
-		beqz $v1, 2f
-		move $v1, $v0
-		
-		move $t0, $a2
-	
-	3:
-		sb $a1, 0($v1)
-		addiu $v1, $v1, 1
-		subu $a3, $v1, $v0
-		sltu $a3, $a3, $t0
-		bnez $a3, 3b
-		addiu $t1, $t1, -1
-		
-		beq $a2, $t0, 0f
-		subu $a2, $a2, $t0
-	
-	8:
-		srl $a0, $a2, 0x2
-		sll $t4, $a0, 0x2
-		beqz $t4, 4f
-		sll $t2, $a1, 0x10
-		
-		sll $t3, $a1, 0x8
-		or $t3, $a1, $t3
-		sll $a3, $a1, 0x18
-		or $t3, $t3, $t2
-		or $t3, $t3, $a3
-		addu $t0, $v0, $t0
-		move $a3, $zero
-	
-	5:
-		addiu $a3, $a3, 1
-		sltu $t2, $a3, $a0
-		sw $t3, 0($t0)
-		bnez $t2, 5b
-		addiu $t0, $t0, 4
-		
-		addu $v1, $v1, $t4
-		beq $a2, $t4, 0f
-		subu $t1, $t1, $t4
-	
-	4:
-		addiu $t1, $t1, 1
-		addu $t1, $v1, $t1
-		sb $a1, 0($v1)
-	
-	6:
-		addiu $v1, $v1, 1
-		bnel $v1, $t1, 6b
-		sb $a1, 0($v1)
-	
-	0:
-		jr $ra
-		nop
-	
-	1:
-		j 7b
-		move $t0, $a2
-	
-	2:
-		bnez $t0, 3b
-		nop
-		
-		j 8b
-		subu $a2, $a2, $t0
-
-memcpy:
 memcpy_from_uspace:
 memcpy_to_uspace:
Index: kernel/generic/include/lib/memfnc.h
===================================================================
--- kernel/generic/include/lib/memfnc.h	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
+++ kernel/generic/include/lib/memfnc.h	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup generic
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_LIB_MEMFNC_H_
+#define KERN_LIB_MEMFNC_H_
+
+#include <typedefs.h>
+
+extern void *memset(void *, int, size_t);
+extern void *memcpy(void *, const void *, size_t);
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/src/lib/memfnc.c
===================================================================
--- kernel/generic/src/lib/memfnc.c	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
+++ kernel/generic/src/lib/memfnc.c	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -0,0 +1,90 @@
+	/*
+ * Copyright (c) 2011 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup generic
+ * @{
+ */
+
+/**
+ * @file
+ * @brief Memory string functions.
+ *
+ * This file provides architecture independent functions to manipulate blocks
+ * of memory. These functions are optimized as much as generic functions of
+ * this type can be.
+ */
+
+#include <lib/memfnc.h>
+#include <typedefs.h>
+
+/** Fill block of memory.
+ *
+ * Fill cnt bytes at dst address with the value val.
+ *
+ * @param dst Destination address to fill.
+ * @param val Value to fill.
+ * @param cnt Number of bytes to fill.
+ *
+ * @return Destination address.
+ *
+ */
+void *memset(void *dst, int val, size_t cnt)
+{
+	uint8_t *dp = (uint8_t *) dst;
+	
+	while (cnt-- != 0)
+		*dp++ = val;
+	
+	return dst;
+}
+
+/** Move memory block without overlapping.
+ *
+ * Copy cnt bytes from src address to dst address. The source
+ * and destination memory areas cannot overlap.
+ *
+ * @param dst Destination address to copy to.
+ * @param src Source address to copy from.
+ * @param cnt Number of bytes to copy.
+ *
+ * @return Destination address.
+ *
+ */
+void *memcpy(void *dst, const void *src, size_t cnt)
+{
+	uint8_t *dp = (uint8_t *) dst;
+	const uint8_t *sp = (uint8_t *) src;
+	
+	while (cnt-- != 0)
+		*dp++ = *sp++;
+	
+	return dst;
+}
+
+/** @}
+ */
Index: uspace/lib/c/arch/amd64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/amd64/Makefile.inc	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ uspace/lib/c/arch/amd64/Makefile.inc	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -28,5 +28,4 @@
 
 ARCH_SOURCES = \
-	arch/$(UARCH)/src/asm.S \
 	arch/$(UARCH)/src/entry.s \
 	arch/$(UARCH)/src/entryjmp.s \
Index: pace/lib/c/arch/amd64/src/asm.S
===================================================================
--- uspace/lib/c/arch/amd64/src/asm.S	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ 	(revision )
@@ -1,101 +1,0 @@
-/*
- * Copyright (c) 2013 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-.text
-.global memset
-.global memcpy
-
-#define MEMSET_DST   %rdi
-#define MEMSET_VAL   %rsi
-#define MEMSET_SIZE  %rdx
-
-#define MEMCPY_DST   %rdi
-#define MEMCPY_SRC   %rsi
-#define MEMCPY_SIZE  %rdx
-
-/* Fill memory with byte pattern
- *
- * This is a conventional memset().
- *
- * @param MEMSET_DST  Destination address.
- * @param MEMSET_VAL  Value to fill.
- * @param MEMSET_SIZE Size.
- *
- * @return MEMSET_DST.
- *
- */
-memset:
-	movq MEMSET_DST, %r8    /* save %rdi */
-	
-	/* Create byte pattern */
-	movzbl %sil, %esi       /* MEMSET_VAL */
-	movabs $0x0101010101010101, %rax
-	imulq %rsi, %rax
-	
-	movq MEMSET_SIZE, %rcx
-	shrq $3, %rcx           /* size / 8 */
-	
-	rep stosq               /* store as much as possible word by word */
-	
-	movq MEMSET_SIZE, %rcx
-	andq $7, %rcx           /* size % 8 */
-	jz 0f
-	
-	rep stosb               /* store the rest byte by byte */
-	
-	0:
-		movq %r8, %rax
-		ret                 /* return MEMCPY_SRC, success */
-
-/** Copy memory from/to userspace.
- *
- * This is a conventional memcpy().
- *
- * @param MEMCPY_DST  Destination address.
- * @param MEMCPY_SRC  Source address.
- * @param MEMCPY_SIZE Number of bytes to copy.
- *
- * @retrun MEMCPY_DST on success, 0 on failure.
- *
- */
-memcpy:
-	movq MEMCPY_DST, %rax
-	
-	movq MEMCPY_SIZE, %rcx
-	shrq $3, %rcx           /* size / 8 */
-	
-	rep movsq               /* copy as much as possible word by word */
-	
-	movq MEMCPY_SIZE, %rcx
-	andq $7, %rcx           /* size % 8 */
-	jz 0f
-	
-	rep movsb               /* copy the rest byte by byte */
-	
-	0:
-		ret                 /* return MEMCPY_SRC, success */
Index: uspace/lib/c/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.inc	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ uspace/lib/c/arch/ia32/Makefile.inc	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -28,5 +28,4 @@
 
 ARCH_SOURCES = \
-	arch/$(UARCH)/src/asm.S \
 	arch/$(UARCH)/src/entry.S \
 	arch/$(UARCH)/src/entryjmp.s \
Index: pace/lib/c/arch/ia32/src/asm.S
===================================================================
--- uspace/lib/c/arch/ia32/src/asm.S	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ 	(revision )
@@ -1,123 +1,0 @@
-/*
- * Copyright (c) 2013 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-.text
-.global memset
-.global memcpy
-
-#define MEMSET_DST   4
-#define MEMSET_VAL   8
-#define MEMSET_SIZE  12
-
-#define MEMCPY_DST   4
-#define MEMCPY_SRC   8
-#define MEMCPY_SIZE  12
-
-/* Fill memory with byte pattern
- *
- * This is a conventional memset().
- *
- * @param MEMSET_DST(%esp)  Destination address.
- * @param MEMSET_VAL(%esp)  Value to fill.
- * @param MEMSET_SIZE(%esp) Size.
- *
- * @return MEMSET_DST(%esp).
- *
- */
-memset:
-	movl %edi, %edx  /* save %edi */
-	
-	movl MEMSET_DST(%esp), %edi
-	movl MEMSET_VAL(%esp), %ecx
-	
-	/* Create byte pattern */
-	movb %cl, %ch
-	movw %cx, %ax
-	shll $16, %eax
-	orw %cx, %ax
-	
-	movl MEMSET_SIZE(%esp), %ecx
-	shrl $2, %ecx  /* size / 4 */
-	
-	/* Write whole words */
-	rep stosl
-	
-	movl MEMSET_SIZE(%esp), %ecx
-	andl $3, %ecx  /* size % 4 */
-	jz 0f
-	
-	/* Copy the rest byte by byte */
-	rep stosb
-	
-	0:
-	
-		movl %edx, %edi
-		
-		/* MEMSET_DST(%esp), success */
-		movl MEMSET_DST(%esp), %eax
-		ret
-
-/** Copy memory to/from userspace.
- *
- * This is a conventional memcpy().
- *
- * @param MEMCPY_DST(%esp)  Destination address.
- * @param MEMCPY_SRC(%esp)  Source address.
- * @param MEMCPY_SIZE(%esp) Size.
- *
- * @return MEMCPY_DST(%esp).
- *
- */
-memcpy:
-	movl %edi, %edx  /* save %edi */
-	movl %esi, %eax  /* save %esi */
-	
-	movl MEMCPY_SIZE(%esp), %ecx
-	shrl $2, %ecx  /* size / 4 */
-	
-	movl MEMCPY_DST(%esp), %edi
-	movl MEMCPY_SRC(%esp), %esi
-	
-	/* Copy whole words */
-	rep movsl
-	
-	movl MEMCPY_SIZE(%esp), %ecx
-	andl $3, %ecx  /* size % 4 */
-	jz 0f
-	
-	/* Copy the rest byte by byte */
-	rep movsb
-	
-	0:
-	
-		movl %edx, %edi
-		movl %eax, %esi
-		
-		/* MEMCPY_DST(%esp), success */
-		movl MEMCPY_DST(%esp), %eax
-		ret
Index: uspace/lib/c/arch/mips32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/mips32/Makefile.inc	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ uspace/lib/c/arch/mips32/Makefile.inc	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -28,5 +28,4 @@
 
 ARCH_SOURCES = \
-	arch/$(UARCH)/src/asm.S \
 	arch/$(UARCH)/src/entry.S \
 	arch/$(UARCH)/src/entryjmp.S \
Index: pace/lib/c/arch/mips32/src/asm.S
===================================================================
--- uspace/lib/c/arch/mips32/src/asm.S	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ 	(revision )
@@ -1,182 +1,0 @@
-/*
- * Copyright (c) 2013 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-.text
-
-.set noat
-.set noreorder
-.set nomacro
-
-.global memset
-.global memcpy
-
-memset:
-	move $v0, $a0
-	beqz $a2, 0f
-	addiu $t1, $a2, -1
-	
-	negu $t0, $a0
-	andi $t0, $t0, 0x3
-	sltu $v1, $a2, $t0
-	bnez $v1, 1f
-	andi $a1, $a1, 0xff
-	
-	7:
-		sltiu $v1, $a2, 4
-		beqz $v1, 2f
-		move $v1, $v0
-		
-		 move $t0, $a2
-	
-	3:
-		sb $a1, 0($v1)
-		addiu $v1, $v1, 1
-		subu $a3, $v1, $v0
-		sltu $a3, $a3, $t0
-		bnez $a3, 3b
-		addiu $t1, $t1, -1
-		
-		beq $a2, $t0, 0f
-		subu $a2, $a2, $t0
-	
-	8:
-		srl $a0, $a2, 0x2
-		sll $t4, $a0, 0x2
-		beqz $t4, 4f
-		sll $t2, $a1, 0x10
-		
-		sll $t3, $a1, 0x8
-		or $t3, $a1, $t3
-		sll $a3, $a1, 0x18
-		or $t3, $t3, $t2
-		or $t3, $t3, $a3
-		addu $t0, $v0, $t0
-		move $a3, $zero
-	
-	5:
-		addiu $a3, $a3, 1
-		sltu $t2, $a3, $a0
-		sw $t3, 0($t0)
-		bnez $t2, 5b
-		addiu $t0, $t0, 4
-		
-		addu $v1, $v1, $t4
-		beq $a2, $t4, 0f
-		subu $t1, $t1, $t4
-	
-	4:
-		addiu $t1, $t1, 1
-		addu $t1, $v1, $t1
-		sb $a1, 0($v1)
-	
-	6:
-		addiu $v1, $v1, 1
-		bnel $v1, $t1, 6b
-		sb $a1, 0($v1)
-	
-	0:
-		jr $ra
-		nop
-	
-	1:
-		j 7b
-		move $t0, $a2
-	
-	2:
-		bnez $t0, 3b
-		nop
-		
-		j 8b
-		subu $a2, $a2, $t0
-
-memcpy:
-	move $t2, $a0  /* save dst */
-	
-	addiu $v0, $a1, 3
-	li $v1, -4  /* 0xfffffffffffffffc */
-	and $v0, $v0, $v1
-	beq $a1, $v0, 3f
-	move $t0, $a0
-	
-	0:
-		beq $a2, $zero, 2f
-		move $a3, $zero
-	
-	1:
-		addu $v0, $a1, $a3
-		lbu $a0, 0($v0)
-		addu $v1, $t0, $a3
-		addiu $a3, $a3, 1
-		bne $a3, $a2, 1b
-		sb $a0, 0($v1)
-	
-	2:
-		jr $ra
-		move $v0, $t2
-	
-	3:
-		addiu $v0, $a0, 3
-		and $v0, $v0, $v1
-		bne $a0, $v0, 0b
-		srl $t1, $a2, 2
-		
-		beq $t1, $zero, 5f
-		move $a3, $zero
-		
-		move $a3, $zero
-		move $a0, $zero
-	
-	4:
-		addu $v0, $a1, $a0
-		lw $v1, 0($v0)
-		addiu $a3, $a3, 1
-		addu $v0, $t0, $a0
-		sw $v1, 0($v0)
-		bne $a3, $t1, 4b
-		addiu $a0, $a0, 4
-	
-	5:
-		andi $a2, $a2, 0x3
-		beq $a2, $zero, 2b
-		nop
-		
-		sll $v0, $a3, 2
-		addu $t1, $v0, $t0
-		move $a3, $zero
-		addu $t0, $v0, $a1
-	
-	6:
-		addu $v0, $t0, $a3
-		lbu $a0, 0($v0)
-		addu $v1, $t1, $a3
-		addiu $a3, $a3, 1
-		bne $a3, $a2, 6b
-		sb $a0, 0($v1)
-		
-		jr $ra
-		move $v0, $t2
Index: uspace/lib/c/arch/mips32eb/Makefile.inc
===================================================================
--- uspace/lib/c/arch/mips32eb/Makefile.inc	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ uspace/lib/c/arch/mips32eb/Makefile.inc	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -28,5 +28,4 @@
 
 ARCH_SOURCES = \
-	arch/$(UARCH)/src/asm.S \
 	arch/$(UARCH)/src/entry.S \
 	arch/$(UARCH)/src/entryjmp.S \
Index: uspace/lib/c/generic/mem.c
===================================================================
--- uspace/lib/c/generic/mem.c	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ uspace/lib/c/generic/mem.c	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -38,4 +38,151 @@
 #include <sys/types.h>
 
+/** Fill memory block with a constant value. */
+void *memset(void *dest, int b, size_t n)
+{
+	char *pb;
+	unsigned long *pw;
+	size_t word_size;
+	size_t n_words;
+
+	unsigned long pattern;
+	size_t i;
+	size_t fill;
+
+	/* Fill initial segment. */
+	word_size = sizeof(unsigned long);
+	fill = word_size - ((uintptr_t) dest & (word_size - 1));
+	if (fill > n) fill = n;
+
+	pb = dest;
+
+	i = fill;
+	while (i-- != 0)
+		*pb++ = b;
+
+	/* Compute remaining size. */
+	n -= fill;
+	if (n == 0) return dest;
+
+	n_words = n / word_size;
+	n = n % word_size;
+	pw = (unsigned long *) pb;
+
+	/* Create word-sized pattern for aligned segment. */
+	pattern = 0;
+	i = word_size;
+	while (i-- != 0)
+		pattern = (pattern << 8) | (uint8_t) b;
+
+	/* Fill aligned segment. */
+	i = n_words;
+	while (i-- != 0)
+		*pw++ = pattern;
+
+	pb = (char *) pw;
+
+	/* Fill final segment. */
+	i = n;
+	while (i-- != 0)
+		*pb++ = b;
+
+	return dest;
+}
+
+struct along {
+	unsigned long n;
+} __attribute__ ((packed));
+
+static void *unaligned_memcpy(void *dst, const void *src, size_t n)
+{
+	size_t i, j;
+	struct along *adst = dst;
+	const struct along *asrc = src;
+
+	for (i = 0; i < n / sizeof(unsigned long); i++)
+		adst[i].n = asrc[i].n;
+		
+	for (j = 0; j < n % sizeof(unsigned long); j++)
+		((unsigned char *) (((unsigned long *) dst) + i))[j] =
+		    ((unsigned char *) (((unsigned long *) src) + i))[j];
+		
+	return (char *) dst;
+}
+
+/** Copy memory block. */
+void *memcpy(void *dst, const void *src, size_t n)
+{
+	size_t i;
+	size_t mod, fill;
+	size_t word_size;
+	size_t n_words;
+
+	const unsigned long *srcw;
+	unsigned long *dstw;
+	const uint8_t *srcb;
+	uint8_t *dstb;
+
+	word_size = sizeof(unsigned long);
+
+	/*
+	 * Are source and destination addresses congruent modulo word_size?
+	 * If not, use unaligned_memcpy().
+	 */
+
+	if (((uintptr_t) dst & (word_size - 1)) !=
+	    ((uintptr_t) src & (word_size - 1)))
+ 		return unaligned_memcpy(dst, src, n);
+
+	/*
+	 * mod is the address modulo word size. fill is the length of the
+	 * initial buffer segment before the first word boundary.
+	 * If the buffer is very short, use unaligned_memcpy(), too.
+	 */
+
+	mod = (uintptr_t) dst & (word_size - 1);
+	fill = word_size - mod;
+	if (fill > n) fill = n;
+
+	/* Copy the initial segment. */
+
+	srcb = src;
+	dstb = dst;
+
+	i = fill;
+	while (i-- != 0)
+		*dstb++ = *srcb++;
+
+	/* Compute remaining length. */
+
+	n -= fill;
+	if (n == 0) return dst;
+
+	/* Pointers to aligned segment. */
+
+	dstw = (unsigned long *) dstb;
+	srcw = (const unsigned long *) srcb;
+
+	n_words = n / word_size;	/* Number of whole words to copy. */
+	n -= n_words * word_size;	/* Remaining bytes at the end. */
+
+	/* "Fast" copy. */
+	i = n_words;
+	while (i-- != 0)
+		*dstw++ = *srcw++;
+
+	/*
+	 * Copy the rest.
+	 */
+
+	srcb = (const uint8_t *) srcw;
+	dstb = (uint8_t *) dstw;
+
+	i = n;
+	while (i-- != 0)
+		*dstb++ = *srcb++;
+
+	return dst;
+}
+
 /** Move memory block with possible overlapping. */
 void *memmove(void *dst, const void *src, size_t n)
Index: uspace/lib/c/include/mem.h
===================================================================
--- uspace/lib/c/include/mem.h	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ uspace/lib/c/include/mem.h	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -38,10 +38,10 @@
 #include <sys/types.h>
 
-#define memset(dst, val, cnt)  __builtin_memset((dst), (val), (cnt))
-#define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
-
 #define bzero(ptr, len)  memset((ptr), 0, (len))
 
+extern void *memset(void *, int, size_t);
+extern void *memcpy(void *, const void *, size_t);
 extern void *memmove(void *, const void *, size_t);
+
 extern int bcmp(const void *, const void *, size_t);
 
Index: uspace/lib/posix/include/posix/string.h
===================================================================
--- uspace/lib/posix/include/posix/string.h	(revision 582f4d284c7d2a59f56b13c67c7688f2a9aff086)
+++ uspace/lib/posix/include/posix/string.h	(revision 45f7449e0a82becbb9eb64d8afe4237b1bb85912)
@@ -60,19 +60,14 @@
  * forward declarations ought to be enough.
  */
-
 /* From str.h. */
-
-extern char *strtok_r(char *, const char *, char **);
-extern char *strtok(char *, const char *);
+extern char * strtok_r(char *, const char *, char **);
+extern char * strtok(char *, const char *);
 
 /* From mem.h */
+#define bzero(ptr, len)  memset((ptr), 0, (len))
+extern void *memset(void *, int, size_t);
+extern void *memcpy(void *, const void *, size_t);
+extern void *memmove(void *, const void *, size_t);
 
-#define memset(dst, val, cnt)  __builtin_memset((dst), (val), (cnt))
-#define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
-
-#define bzero(ptr, len)  memset((ptr), 0, (len))
-
-extern void *memmove(void *, const void *, size_t);
-extern int bcmp(const void *, const void *, size_t);
 
 /* Copying and Concatenation */
