General information on Hitachi SH math performance
Tue Aug 14 10:16:00 GMT 2001
> Dear Jeff Johnston,
> I'm a software developer from Italy. From many years I have developed
> embedded seftware, many of it for Hitachi microprocessor. After use
> commercial design environments now I'm looking on OpenSource projects.
> I have tryed to migrate from my commercial design environment (www.ghs.com
> MULTI 2000 for hitach SH series) to GNU gcc cross compiler. The benchmark
> indicate that the performance of compiler are good. Not is the same for the
> math functions. Integet and float math is slow.
> I have experience in assembly code. Could I increase performance of
> mathematical funcions for SH in newlib ? Unfurtunally I don't know the
> newlib structure and the internal new lib function structure. Is there any
> documentation ?
> Besr regards
You can get some documentation by doing a make info from the top of newlib.
Floating math is slow because the math routines use integer math algorithms.
This is because many embedded platforms do not have floating point math insns or
have floating point register support. Newlib has recently added the --enable-newlib-hw-fp
configuration option which uses floating point algorithms rather than the integer
versions. For platforms that have floating point insn support from the compiler,
this can improve performance and reduce the size of the library.
Regarding rewriting the math functions: there are two paths you can take in newlib.
If there are platform math insns that are not fully ANSI (e.g. may not handle
out of range data and set errno where needed), you can make fastmath versions
of the routines (see libc/include/machine/fastmath.h). The fastmath routines
currently reside in the libc/machine/xxxx directory (where xxxx is the platform).
If you want, you can look at the libc/machine/i386 directory which has a set
of fastmath routines for x86. The user gets access to them either by compiling
with the -ffast-math option or by defining __FAST_MATH__ or by including
fastmath.h directly (i.e. the user uses these optionally).
The second path is to completely override the math functions in assembler.
Currently, for libc, routines may be overridden by placing assembler versions
in the appropriate machine directory (e.g. libc/machine/i386). The name of the
object file must be the same as the generic C version (e.g. strcpy.o).
When the library gets built, the generic C version will be overridden with the
assembler. At the moment, there is no such machine directory set up
in libm, but this would be easy to provide if you had a set of math assembler
routines targetted specifically for the sh. The routines should be fully
ANSI compliant and tested. They should also accomodate various variants
of the platform in question (usually these are multilib options). For
example, see the libc/machine/sh directory for assembler examples that check
for big endian vs little endian, etc...).
-- Jeff J.
More information about the Newlib