diff --git a/lib/libc/memset.c b/lib/libc/memset.c
index f9dd4c5db..5ad6ede51 100644
--- a/lib/libc/memset.c
+++ b/lib/libc/memset.c
@@ -11,16 +11,16 @@
 void *memset(void *dst, int val, size_t count)
 {
 	char *ptr = dst;
-	uint64_t *ptr64;
-	uint64_t fill = (unsigned char)val;
+	uint32_t *ptr32;
+	uint32_t fill = (unsigned char)val;
 
 	/* Simplify code below by making sure we write at least one byte. */
 	if (count == 0) {
 		return dst;
 	}
 
-	/* Handle the first part, until the pointer becomes 64-bit aligned. */
-	while (((uintptr_t)ptr & 7)) {
+	/* Handle the first part, until the pointer becomes 32-bit aligned. */
+	while (((uintptr_t)ptr & 3)) {
 		*ptr++ = val;
 		if (--count == 0) {
 			return dst;
@@ -30,16 +30,15 @@ void *memset(void *dst, int val, size_t count)
 	/* Duplicate the fill byte to the rest of the 64-bit word. */
 	fill |= fill << 8;
 	fill |= fill << 16;
-	fill |= fill << 32;
 
-	/* Use 64-bit writes for as long as possible. */
-	ptr64 = (void *)ptr;
-	for (; count >= 8; count -= 8) {
-		*ptr64++ = fill;
+	/* Use 32-bit writes for as long as possible. */
+	ptr32 = (void *)ptr;
+	for (; count >= 4; count -= 4) {
+		*ptr32++ = fill;
 	}
 
 	/* Handle the remaining part byte-per-byte. */
-	ptr = (void *)ptr64;
+	ptr = (void *)ptr32;
 	while (count--) {
 		*ptr++ = val;
 	}
