microblaze: Do loop unrolling for optimized memset implementation
authorMichal Simek <michal.simek@xilinx.com>
Fri, 25 Feb 2022 13:55:35 +0000 (14:55 +0100)
committerMichal Simek <michal.simek@xilinx.com>
Thu, 21 Apr 2022 08:54:20 +0000 (10:54 +0200)
commit95fee37be45f443a8a322ee7f6f78167b73f2abc
treee1ceab05f04971000d00154c57a53dd61667f62d
parent8f0f265e6cf5b6d99a5a5d01b36985bc1131183e
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
33d0f96ffd73 ("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/20191121021040.14554-1-sandra@codesourcery.com/

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Mahesh Bodapati <mbodapat@xilinx.com>
Link: https://lore.kernel.org/r/10a432e269a6d3349cf458e4f5792522779cba0d.1645797329.git.michal.simek@xilinx.com
arch/microblaze/lib/memset.c