From patchwork Mon Apr 20 18:56:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 38833 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by sourceware.org (Postfix) with ESMTPS id 1F8473858D31 for ; Mon, 20 Apr 2020 18:56:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1F8473858D31 Received: by mail-qk1-x743.google.com with SMTP id j4so11850122qkc.11 for ; Mon, 20 Apr 2020 11:56:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=KT4kYLpUVxUbSknfBwkQphfxEF8fw/F3iTJP4fmarls=; b=ujfDQNAVGrA+0wbgDlkdHAswhZaeiyK1Qrb7LoSxu4hX/Dre4wNzdhN2zJ4MoMFNNq +a6FSzQr97Ra87cJAIQ4PQe9xGQVQHmNm8pk/XfO55dF+T0BHpnuazJ+YCTtb8FMpjQK fZZWVX34b+DUEz6MaCbs5+8U+hwuCazmLzAB/nDtyZvDAMpF492ROZvDUwXF37hPayDm qe7kS3OOIKA1fRL3HPq6FTRPjV6CkqNLI2DwEE3ZBQsLVzUc0onMy6QR348+oemcaGFz s31NsK0lulJeSSzrsgx9kfAzIKI9LAppjRKmoP8y+5zd+5H6CdL+b7hdrpNxdq88MbBf gt1w== X-Gm-Message-State: AGi0PubmCFRWV5AYGZn3ppCePh9+8GkSt8jsxxocFtbLirhuSULF51RZ Dm2MQfKOz6uWQUTpq5OdcHZK48v6wFVvUQ== X-Google-Smtp-Source: APiQypLCxQBPCQxERNSP9jqpw5HQPer1xsRwsJtAJILFLgqGdf5fOtc6bpS2rs1BhPTyfRjO+CuN4g== X-Received: by 2002:a05:620a:1396:: with SMTP id k22mr17243885qki.424.1587409016204; Mon, 20 Apr 2020 11:56:56 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id n124sm249518qkn.136.2020.04.20.11.56.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 11:56:55 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] x86: Use default libc_fe* implementation for float128 Date: Mon, 20 Apr 2020 15:56:51 -0300 Message-Id: <20200420185651.944-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-25.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Apr 2020 18:56:58 -0000 The exported x86_64 fenv.h functions operate on both i387 and SSE (since they should work on both float, double, and long double) while the internal libc_fe* set either SSE (float, double, and float128) or i387 (long double). The rounding mode is used by soft-fp (libgcc and glibc), so that must be set for float128 computations. For x86_64 it uses SSE mode, while for i386 is uses x87. However for exception generation both 387 and SSE exception might be generated even for x86_64. The FP_EX_DIVZERO, FP_EX_DIVZERO, and FP_EX_INEXACT uses SSE while FP_EX_DENORM, FP_EX_OVERFLOW, and FP_EX_UNDERFLOW uses x87. For i686 it depends whether libgcc was built for SSE math (where it follows x86_64 behaviour) or x87 math (which uses only x87 mode). In any case use generic routines to handle float128 since it handles both modes. It allows to use libc_fe* macros on float128 implementation for x86_64. I checked on top of the libc_fe* optimization patchset for float128 [1] (which can be checked on my branch [2]) on both x86_64-linux-gnu and i686-linux-gnu. [1] https://sourceware.org/pipermail/libc-alpha/2020-March/112121.html [2] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/x86-libc_fe Checked on x86_64-linux-gnu. --- sysdeps/x86/fpu/fenv_private.h | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/sysdeps/x86/fpu/fenv_private.h b/sysdeps/x86/fpu/fenv_private.h index 8453aaa270..032bbd0dfa 100644 --- a/sysdeps/x86/fpu/fenv_private.h +++ b/sysdeps/x86/fpu/fenv_private.h @@ -293,28 +293,28 @@ libc_feresetround_387 (fenv_t *e) # define libc_feholdsetround_53bit libc_feholdsetround_387_53bit #endif -#ifdef __x86_64__ -/* The SSE rounding mode is used by soft-fp (libgcc and glibc) on - x86_64, so that must be set for float128 computations. */ -# define SET_RESTORE_ROUNDF128(RM) \ - SET_RESTORE_ROUND_GENERIC (RM, libc_feholdsetround_sse, libc_feresetround_sse) -# define libc_feholdexcept_setroundf128 libc_feholdexcept_setround_sse -# define libc_feupdateenv_testf128 libc_feupdateenv_test_sse -# define libc_feholdexceptf128 libc_feholdexcept_sse -# define libc_fesetenvf128 libc_fesetenv_sse -# define libc_feupdateenvf128 libc_feupdateenv_sse -# define libc_fesetroundf128 libc_fesetround_sse -#else -/* The 387 rounding mode is used by soft-fp for 32-bit, but whether - 387 or SSE exceptions are used depends on whether libgcc was built - for SSE math, which is not known when glibc is being built. */ -# define libc_feholdexcept_setroundf128 default_libc_feholdexcept_setround -# define libc_feupdateenv_testf128 default_libc_feupdateenv_test -# define libc_feholdexceptf128 default_libc_feholdexcept -# define libc_fesetenvf128 default_libc_fesetenv -# define libc_feupdateenvf128 default_libc_feupdateenv -# define libc_fesetroundf128 default_libc_fesetround -#endif +/* The rounding mode is used by soft-fp (libgcc and glibc), so that must be + set for float128 computations. For x86_64 it uses SSE mode, while for + i386 is uses x87. + + However for exception generation both 387 and SSE exception might be + generated even for x86_64: FP_EX_DIVZERO, FP_EX_DIVZERO, and FP_EX_INEXACT + uses SSE while FP_EX_DENORM, FP_EX_OVERFLOW, and FP_EX_UNDERFLOW uses x87. + + For i686 it depends whether libgcc was built for SSE math (where it + follows x86_64 behaviour) or x87 math (which uses only x87 mode). + + In any case use generic routines to handle float128 since it handles + both modes. */ +#define SET_RESTORE_ROUNDF128(RM) \ + SET_RESTORE_ROUND_GENERIC (RM, default_libc_feholdsetround, \ + default_libc_feresetround) +#define libc_feholdexcept_setroundf128 default_libc_feholdexcept_setround +#define libc_feupdateenv_testf128 default_libc_feupdateenv_test +#define libc_feholdexceptf128 default_libc_feholdexcept +#define libc_fesetenvf128 default_libc_fesetenv +#define libc_feupdateenvf128 default_libc_feupdateenv +#define libc_fesetroundf128 default_libc_fesetround /* We have support for rounding mode context. */ #define HAVE_RM_CTX 1