Skip to content

Commit 95fee37

Browse files
author
Michal Simek
committed
microblaze: Do loop unrolling for optimized memset implementation
Align implementation with memcpy and memmove where also remaining bytes are copied via final switch case instead of using simple implementations which loop. But this alignment has much stronger reason and definitely aligning implementation is not the key point here. It is just good to have in mind that the same technique is used already there. In GCC 10, now -ftree-loop-distribute-patterns optimization is on at O2. This optimization causes GCC to convert the while loop in memset.c into a call to memset. So this optimization is transforming a loop in a memset/memcpy into a call to the function itself. This makes the memset implementation as recursive. "-freestanding" option will disable the built-in library function but it has been added in generic library implementation. In default microblaze kernel defconfig we have CONFIG_OPT_LIB_FUNCTION enabled so it will always pick optimized version of memset which is target specific so we are replacing the while() loop with switch case to avoid recursive memset call. Issue with freestanding was already discussed in connection to commit 33d0f96 ("lib/string.c: Use freestanding environment") and also this is topic in glibc and gcc. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888 http://patchwork.ozlabs.org/project/glibc/patch/[email protected]/ Signed-off-by: Michal Simek <[email protected]> Signed-off-by: Mahesh Bodapati <[email protected]> Link: https://lore.kernel.org/r/10a432e269a6d3349cf458e4f5792522779cba0d.1645797329.git.michal.simek@xilinx.com
1 parent 8f0f265 commit 95fee37

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

arch/microblaze/lib/memset.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,19 @@ void *memset(void *v_src, int c, __kernel_size_t n)
7474
}
7575

7676
/* Simple, byte oriented memset or the rest of count. */
77-
while (n--)
77+
switch (n) {
78+
case 3:
7879
*src++ = c;
80+
fallthrough;
81+
case 2:
82+
*src++ = c;
83+
fallthrough;
84+
case 1:
85+
*src++ = c;
86+
break;
87+
default:
88+
break;
89+
}
7990

8091
return v_src;
8192
}

0 commit comments

Comments
 (0)