public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Two questions about the optimization of string functions in glibc for the powerpc architecture.
@ 2023-10-08  7:14 yuucyf
  2023-10-08  7:36 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: yuucyf @ 2023-10-08  7:14 UTC (permalink / raw)
  To: libc-alpha

[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]

Hi all,

I have some questions to ask.
In the glibc source code, there are various string optimization functions for different PowerPC architectures in the sysdeps/powerpc/powerpc64/multiarch directory, such as xxx_power7, xxx_power8, xxx_power9, and so on. When building glibc, I've noticed that these source files generate .o files, and all of them are eventually merged into libc.a. My question is, if I use the strcpy function in my user code, which version of strcpy is actually linked? GCC supports specifying the CPU type using -mcpu, but how does the linker choose which version of strcpy to link? Can you please explain in detail the process of determining which function is linked?
I'm currently writing a test case on a Power8 platform that uses the strcpy string function. However, when I disassemble it after linking, I found that it's not using strcpy-power8.S. Since it's not using the optimized string function for the Power8 platform, I'm curious why there are assembly implementations of optimized string functions for multiple platforms like PowerPC, ARM, MIPS, and others. How does it determine which platform-specific optimized string function to use on a particular platform? Could someone kindly provide a detailed explanation? 


Thank you!

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Two questions about the optimization of string functions in glibc for the powerpc architecture.
  2023-10-08  7:14 Two questions about the optimization of string functions in glibc for the powerpc architecture yuucyf
@ 2023-10-08  7:36 ` Florian Weimer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2023-10-08  7:36 UTC (permalink / raw)
  To: yuucyf; +Cc: libc-alpha

> My question is, if I use the strcpy function in my user code, which
> version of strcpy is actually linked?

The implementation is selected at run time using the IFUNC mechanism,
see sysdeps/powerpc/powerpc64/multiarch/strcpy.c.

> I'm currently writing a test case on a Power8 platform that uses the
> strcpy string function. However, when I disassemble it after
> linking, I found that it's not using strcpy-power8.S.

The glibc test suite iterates over all implementations that the
current CPU supports, see for example string/test-strcpy.c and its use
of the FOR_EACH_IMPL macro.  So if you run on POWER9, you'll test
POWER8 (and earlier implementations), POWER9, but not POWER10
variants.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-08  7:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-08  7:14 Two questions about the optimization of string functions in glibc for the powerpc architecture yuucyf
2023-10-08  7:36 ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).