[PATCH v2] Add support for SoftFloat library on ARM (original) (raw)
Magnus Ihse Bursie magnus.ihse.bursie at oracle.com
Mon Dec 3 11:51:45 UTC 2018
- Previous message (by thread): RFR: JDK-8214311 dtrace gensrc has missing dependencies
- Next message (by thread): RFR: JDK-8214710 Fix hg log in update_copyright_year.sh
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Comment inline.
On 2018-11-30 14:38, Jakub Vaněk wrote:
Hi David,
I'm sending an alternative patch for handling the problem with _aeabi*glibc on arm softfloat builds. This patch adds integration code for SoftFloat-3e library. It adds appropriate configure options _and a switchable implementation of _aeabiglibc/_aeabiextlib_ functions. There are now two implementations of the glibc functions (now renamed _to extlib). The simpler one simply wraps aeabi* functions. The other one wraps SoftFloat-3 API. By using this mechanism, the building user can choose what happens. The external library is not required - if the path to its static library/include directory is not specified on configure commandline, standard system functions are used automatically. Thanks, Jakub # HG changeset patch # User Jakub Vaněk <linuxtardis at gmail.com> # Date 1543498682 -3600 # Thu Nov 29 14:38:02 2018 +0100 # Node ID bc14ee6f50c73703229f979e78b93bcef12ae106 # Parent a96844b3a929cc2eb92fe7963be8aec603f24a83 Add support for SoftFloat library on ARM diff --git a/doc/building.html b/doc/building.html --- a/doc/building.html +++ b/doc/building.html @@ -53,6 +53,7 @@
X11 ALSA libffi +SoftFloat Build Tools Requirements Autoconf @@ -415,6 +416,12 @@To install on an rpm-based Linux, try running sudo yum install libffi-devel
.Use
+--with-libffi=
ifconfigure
does not properly locate your libffi files.SoftFloat
+Berkeley SoftFloat-3 can be used on ARM processors without FPU to slightly enhance the arithmetic precision of some floating point operations. It is not required, system softfp routines can be used without any problems. The precision loss is extremely small, but the JCK detects it.
++
To install the library, you will have to download its source and build it for the target platform. To do so, take a look in the + +build/Linux-ARM-VFPv2-GCC
subdirectory.Use
--with-softfloat-lib=
and--with-softfloat-include=
to specify the path to thesoftfloat.a
archive and thesource/include
directory. If you omit them or use--without-softfloat-*
, standard system libraries will be used instead.Build Tools Requirements
Autoconf
The JDK requires Autoconf; on all platforms. At least version 2.69 is required.
@@ -486,6 +493,7 @@--with-x=
- Set the path to X11--with-alsa=
- Set the path to ALSA+ --with-libffi=
- Set the path to libffi--with-softfloat-lib=
,--with-softfloat-include=
- Set the path to SoftFloat library and include directory.--with-jtreg=
- Set the path to JTReg. See Running TestsCertain third-party libraries used by the JDK (libjpeg, giflib, libpng, lcms and zlib) are included in the JDK repository. The default behavior of the JDK build is to use this version of these libraries, but they might be replaced by an external version. To do so, specify
diff --git a/doc/building.md b/doc/building.md --- a/doc/building.md +++ b/doc/building.md @@ -527,6 +527,24 @@ Usesystem
as theoption in these arguments. (The default is
bundled
).--with-libffi=<path>
ifconfigure
does not properly locate your libffi files. +### SoftFloat + +Berkeley SoftFloat-3 +can be used on ARM processors without FPU to slightly enhance +the arithmetic precision of some floating point operations. It is not +required, system softfp routines can be used without any problems. +The precision loss is extremely small, but [the JCK detects it](_ _+http://mail.openjdk.java.net/pipermail/aarch32-port-dev/2016-November/000611.html). + + * To install the library, you will have to download its source and build it + for the target platform. To do so, take a look in the +build/Linux-ARM-VFPv2-GCC
subdirectory. + +Use--with-softfloat-lib=<path>
and--with-softfloat-include=<path>
+to specify the path to thesoftfloat.a
archive and thesource/include
+directory. If you omit them or use--without-softfloat-*
, standard +system libraries will be used instead. + ## Build Tools Requirements ### Autoconf @@ -694,6 +712,8 @@ *--with-x=<path>
- Set the path to X11 *--with-alsa=<path>
- Set the path to ALSA *--with-libffi=<path>
- Set the path to libffi + *--with-softfloat-lib=<path>
,--with-softfloat-include=<path>
- + Set the path to SoftFloat library and include directory. *--with-jtreg=<path>
- Set the path to JTReg. See [Running Tests](_ _#running-tests) diff --git a/make/autoconf/lib-softfloat.m4 b/make/autoconf/lib-softfloat.m4 new file mode 100644 --- /dev/null +++ b/make/autoconf/lib-softfloat.m4 @@ -0,0 +1,93 @@ +# +# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +################################################################################ +# Setup softfloat library +################################################################################ +ACDEFUNONCE([LIBSETUPSOFTFLOAT], +[ + ACARGWITH(softfloat-lib, [ASHELPSTRING([--with-softfloat-lib], + [specify the path to SoftFloat-3 static library])]) + ACARGWITH(softfloat-include, [ASHELPSTRING([--with-softfloat-include], + [specify the path to SoftFloat-3 include directory])]) + + ACMSGCHECKING([if softfloat helper library is to be used]) + + SOFTFLOATLIB=${withsoftfloatlib} + SOFTFLOATINC=${withsoftfloatinclude} + + if test "x$NEEDSLIBSOFTFLOAT" = xtrue; then + + if test "x${SOFTFLOATLIB}" = x || test "x${SOFTFLOATLIB}" = xno; then + SOFTFLOATFOUND=false + + if test "x${SOFTFLOATINC}" != x && test "x${SOFTFLOATINC}" != xno; then + ACMSGERROR([--with-softfloat-include was specified, but not --with-softfloat-lib]) + fi + + elif test "x${SOFTFLOATINC}" = x || test "x${SOFTFLOATINC}" = xno; then + SOFTFLOATFOUND=false + + if test "x${SOFTFLOATLIB}" != x && test "x${SOFTFLOATLIB}" != xno; then + ACMSGERROR([--with-softfloat-lib was specified, but not --with-softfloat-include]) + fi + + else + SOFTFLOATFOUND=true + fi + + if test "x$SOFTFLOATFOUND" = "xtrue"; then + ACMSGRESULT([yes, external library used]) + + SOFTFLOATLIBS="${SOFTFLOATLIB}" + SOFTFLOATCFLAGS="-I${SOFTFLOATINC} -DSOFTFLOATEXTERNAL" + + ACMSGCHECKING([for softfloat library]) + ACMSGRESULT([$SOFTFLOATLIBS]) + + ACMSGCHECKING([for softfloat compiler flags]) + ACMSGRESULT([$SOFTFLOATCFLAGS]) + + else + ACMSGRESULT([no, system softfp used]) + ACMSGNOTICE([Floating point operations may be less precise by a very small amount]) + SOFTFLOATLIBS= + SOFTFLOATCFLAGS= + fi + else + ACMSGRESULT([no, not needed]) + if test "x${SOFTFLOATLIB}" != x && test "x${SOFTFLOATLIB}" != xno; then + ACMSGWARN([[sflt build not used, so --with-softfloat-lib is ignored]]) + fi + if test "x${SOFTFLOATINC}" != x && test "x${SOFTFLOATINC}" != xno; then + ACMSGWARN([[sflt build not used, so --with-softfloat-include is ignored]]) + fi + SOFTFLOATLIBS= + SOFTFLOATCFLAGS= + fi + + ACSUBST(SOFTFLOATLIBS) + ACSUBST(SOFTFLOATCFLAGS) +]) diff --git a/make/autoconf/libraries.m4 b/make/autoconf/libraries.m4 --- a/make/autoconf/libraries.m4 +++ b/make/autoconf/libraries.m4 @@ -33,6 +33,7 @@ m4include([lib-x11.m4]) m4include([lib-fontconfig.m4]) m4include([lib-tests.m4]) +m4include([lib-softfloat.m4]) ################################################################################ # Determine which libraries are needed for this configuration @@ -79,6 +80,13 @@ NEEDSLIBALSA=false fi + if (test "x$OPENJDKTARGETCPU" == xarm && + (test "x$ARMFLOATTYPE" = "xsflt" || test "x$ARMFLOATTYPE" = "xvfp-sflt" )); then + NEEDSLIBSOFTFLOAT=true + else + NEEDSLIBSOFTFLOAT=false + fi + I don't think this name of the variable is particularly good. I realize you have tried to follow a pattern, but up until now we've had the situation that a library was either required, or not used. With softfloat, there's the third option of "use it if present, otherwise ignore". This meaning is not very well shown by the name NEEDS_LIB_SOFTFLOAT. I recommend changing this to "USES_LIB_SOFTFLOAT".
/Magnus
# Check if ffi is needed if HOTSPOTCHECKJVMVARIANT(zero); then NEEDSLIBFFI=true @@ -98,6 +106,7 @@ LIBSETUPFONTCONFIG LIBSETUPFREETYPE LIBSETUPALSA + LIBSETUPSOFTFLOAT LIBSETUPLIBFFI LIBSETUPBUNDLEDLIBS LIBSETUPMISCLIBS diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in --- a/make/autoconf/spec.gmk.in +++ b/make/autoconf/spec.gmk.in @@ -353,6 +353,8 @@ CUPSCFLAGS:=@CUPSCFLAGS@ ALSALIBS:=@ALSALIBS@ ALSACFLAGS:=@ALSACFLAGS@ +SOFTFLOATLIBS:=@SOFTFLOATLIBS@ +SOFTFLOATCFLAGS:=@SOFTFLOATCFLAGS@ LIBFFILIBS:=@LIBFFILIBS@ LIBFFICFLAGS:=@LIBFFICFLAGS@ ENABLELIBFFIBUNDLING:=@ENABLELIBFFIBUNDLING@ diff --git a/make/hotspot/lib/CompileJvm.gmk b/make/hotspot/lib/CompileJvm.gmk --- a/make/hotspot/lib/CompileJvm.gmk +++ b/make/hotspot/lib/CompileJvm.gmk @@ -49,6 +49,7 @@
_JVMLIBS += _ _$(JVMLIBSFEATURES) _ _+ $(SOFTFLOATLIBS) _ # # These files and directories are always excluded diff --git a/make/hotspot/lib/JvmFlags.gmk b/make/hotspot/lib/JvmFlags.gmk --- a/make/hotspot/lib/JvmFlags.gmk +++ b/make/hotspot/lib/JvmFlags.gmk @@ -88,6 +88,7 @@ _$(JVMCFLAGSTARGETDEFINES) _ _$(JVMCFLAGSFEATURES) _ _$(JVMCFLAGSINCLUDES) _ _+ $(SOFTFLOATCFLAGS) _ _$(EXTRACFLAGS) _ # diff --git a/src/hotspot/cpu/arm/assemblerarm32.hpp b/src/hotspot/cpu/arm/assemblerarm32.hpp --- a/src/hotspot/cpu/arm/assemblerarm32.hpp +++ b/src/hotspot/cpu/arm/assemblerarm32.hpp @@ -1242,10 +1242,10 @@ // Imported code from glibc soft-fp bundle for // calculation accuracy improvement. See CR 6757269. _-extern double aeabifaddglibc(float, float); _-extern double aeabifsubglibc(float, float); _-extern double aeabidaddglibc(double, double); _-extern double aeabidsubglibc(double, double); _+extern float aeabifaddextlib(float, float); _+extern float aeabifsubextlib(float, float); _+extern double aeabidaddextlib(double, double); _+extern double aeabidsubextlib(double, double); }; #endif // SOFTFP diff --git a/src/hotspot/cpu/arm/c1LIRGeneratorarm.cpp b/src/hotspot/cpu/arm/c1LIRGeneratorarm.cpp --- a/src/hotspot/cpu/arm/c1LIRGeneratorarm.cpp +++ b/src/hotspot/cpu/arm/c1LIRGeneratorarm.cpp @@ -490,27 +490,28 @@ // Call function compiled with -msoft-float. _// aeabiXXXXglibc: Imported code from glibc soft-fp bundle for calculation accuracy improvement. See CR 6757269. + // http://mail.openjdk.java.net/pipermail/aarch32-port-dev/2016-November/000611.html case Bytecodes::fadd: _- runtimefunc = CASTFROMFNPTR(address, aeabifaddglibc); _+ runtimefunc = CASTFROMFNPTR(address, aeabifaddextlib); break; case Bytecodes::fmul: _runtimefunc = CASTFROMFNPTR(address, aeabifmul); break; case Bytecodes::fsub: _- runtimefunc = CASTFROMFNPTR(address, aeabifsubglibc); _+ runtimefunc = CASTFROMFNPTR(address, aeabifsubextlib); break; case Bytecodes::fdiv: _runtimefunc = CASTFROMFNPTR(address, aeabifdiv); break; case Bytecodes::dadd: _- runtimefunc = CASTFROMFNPTR(address, aeabidaddglibc); _+ runtimefunc = CASTFROMFNPTR(address, aeabidaddextlib); break; case Bytecodes::dmul: _runtimefunc = CASTFROMFNPTR(address, aeabidmul); break; case Bytecodes::dsub: _- runtimefunc = CASTFROMFNPTR(address, aeabidsubglibc); _+ runtimefunc = CASTFROMFNPTR(address, aeabidsubextlib); break; case Bytecodes::ddiv: _runtimefunc = CASTFROMFNPTR(address, aeabiddiv); diff --git a/src/hotspot/cpu/arm/c1Runtime1arm.cpp b/src/hotspot/cpu/arm/c1Runtime1arm.cpp --- a/src/hotspot/cpu/arm/c1Runtime1arm.cpp +++ b/src/hotspot/cpu/arm/c1Runtime1arm.cpp @@ -804,15 +804,16 @@ _#define FUNCTIONCASE(a, f) _ if ((intptrt)a == CASTFROMFNPTR(intptrt, f)) return #f _- FUNCTIONCASE(entry, aeabifaddglibc); _+ // aeabiXXXXglibc: Imported code from glibc soft-fp bundle for calculation accuracy improvement. See CR 6757269. + // http://mail.openjdk.java.net/pipermail/aarch32-port-dev/2016-November/000611.html _+ FUNCTIONCASE(entry, aeabifaddextlib); _FUNCTIONCASE(entry, aeabifmul); _- FUNCTIONCASE(entry, aeabifsubglibc); _+ FUNCTIONCASE(entry, aeabifsubextlib); _FUNCTIONCASE(entry, aeabifdiv); _- // aeabiXXXXglibc: Imported code from glibc soft-fp bundle for calculation accuracy improvement. See CR 6757269. _- FUNCTIONCASE(entry, aeabidaddglibc); _+ FUNCTIONCASE(entry, aeabidaddextlib); _FUNCTIONCASE(entry, aeabidmul); _- FUNCTIONCASE(entry, aeabidsubglibc); _+ FUNCTIONCASE(entry, aeabidsubextlib); _FUNCTIONCASE(entry, aeabiddiv); _FUNCTIONCASE(entry, aeabif2d); diff --git a/src/hotspot/cpu/arm/softfloatarm.cpp b/src/hotspot/cpu/arm/softfloatarm.cpp new file mode 100644 --- /dev/null +++ b/src/hotspot/cpu/arm/softfloatarm.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifdef SOFTFP + +// Soft float function declarations +extern "C" { _+ extern float aeabifadd(float, float); _+ extern float aeabifsub(float, float); _+ extern double aeabidadd(double, double); _+ extern double aeabidsub(double, double); + _+ extern float aeabifaddextlib(float, float); _+ extern float aeabifsubextlib(float, float); _+ extern double aeabidaddextlib(double, double); _+ extern double aeabidsubextlib(double, double); +}; + +#ifdef SOFTFLOATEXTERNAL + +extern "C" { +#include "softfloat.h" +} + +#include + _+static float aeabifloathandling(float natA, float natB, bool add) { + float32t libA; + float32t libB; + float32t libC; + float natC; + + memcpy(&libA, &natA, sizeof(libA)); + memcpy(&libB, &natB, sizeof(libB)); + libC = add ? f32add(libA, libB) : f32sub(libA, libB); + memcpy(&natC, &libC, sizeof(libC)); + + return natC; +} + _+static double aeabidoublehandling(double natA, double natB, bool add) { + float64t libA; + float64t libB; + float64t libC; + double natC; + + memcpy(&libA, &natA, sizeof(libA)); + memcpy(&libB, &natB, sizeof(libB)); + libC = add ? f64add(libA, libB) : f64sub(libA, libB); + memcpy(&natC, &libC, sizeof(libC)); + + return natC; +} + _+float aeabifaddextlib(float a, float b) { _+ return aeabifloathandling(a, b, true); +} + _+float aeabifsubextlib(float a, float b) { _+ return aeabifloathandling(a, b, false); +} + _+double aeabidaddextlib(double a, double b) { _+ return aeabidoublehandling(a, b, true); +} + _+double aeabidsubextlib(double a, double b) { _+ return aeabidoublehandling(a, b, false); +} + +#else + _+float aeabifaddextlib(float a, float b) { _+ return aeabifadd(a, b); +} + _+float aeabifsubextlib(float a, float b) { _+ return aeabifsub(a, b); +} + _+double aeabidaddextlib(double a, double b) { _+ return aeabidadd(a, b); +} + +double aeabidsubextlib(double a, double b) { + return aeabidsub(a, b); +} + +#endif + +#endif // SOFTFP diff --git a/src/hotspot/cpu/arm/templateTablearm.cpp b/src/hotspot/cpu/arm/templateTablearm.cpp --- a/src/hotspot/cpu/arm/templateTablearm.cpp +++ b/src/hotspot/cpu/arm/templateTablearm.cpp @@ -1610,8 +1610,10 @@ __ mov(R1, R0tos); __ popi(R0); switch (op) { _- case add: _ callVMleaf(CASTFROMFNPTR(address, aeabifaddglibc), R0, R1); break; _- case sub: _ callVMleaf(CASTFROMFNPTR(address, aeabifsubglibc), R0, R1); break; _+ // aeabiXXXXglibc: Imported code from glibc soft-fp bundle for calculation accuracy improvement. See CR 6757269. + // http://mail.openjdk.java.net/pipermail/aarch32-port-dev/2016-November/000611.html _+ case add: _ callVMleaf(CASTFROMFNPTR(address, aeabifaddextlib), R0, R1); break; _+ case sub: _ callVMleaf(CASTFROMFNPTR(address, aeabifsubextlib), R0, R1); break; _case mul: _ callVMleaf(CASTFROMFNPTR(address, aeabifmul), R0, R1); break; case div: _ callVMleaf(CASTFROMFNPTR(address, aeabifdiv), R0, R1); break; case rem: _ callVMleaf(CASTFROMFNPTR(address, SharedRuntime::frem), R0, R1); break; @@ -1653,8 +1655,9 @@ __ popl(R0, R1); switch (op) { _// aeabiXXXXglibc: Imported code from glibc soft-fp bundle for calculation accuracy improvement. See CR 6757269. _- case add: _ callVMleaf(CASTFROMFNPTR(address, aeabidaddglibc), R0, R1, R2, R3); break; _- case sub: _ callVMleaf(CASTFROMFNPTR(address, aeabidsubglibc), R0, R1, R2, R3); break; + // http://mail.openjdk.java.net/pipermail/aarch32-port-dev/2016-November/000611.html _+ case add: _ callVMleaf(CASTFROMFNPTR(address, aeabidaddextlib), R0, R1, R2, R3); break; _+ case sub: _ callVMleaf(CASTFROMFNPTR(address, aeabidsubextlib), R0, R1, R2, R3); break; _case mul: _ callVMleaf(CASTFROMFNPTR(address, aeabidmul), R0, R1, R2, R3); break; _case div: _ callVMleaf(CASTFROMFNPTR(address, aeabiddiv), R0, R1, R2, R3); break; case rem: _ callVMleaf(CASTFROMFNPTR(address, SharedRuntime::drem), R0, R1, R2, R3); break;
- Previous message (by thread): RFR: JDK-8214311 dtrace gensrc has missing dependencies
- Next message (by thread): RFR: JDK-8214710 Fix hg log in update_copyright_year.sh
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]