From patchwork Mon Mar 30 19:28:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 38682 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by sourceware.org (Postfix) with ESMTPS id E9B8B385B834 for ; Mon, 30 Mar 2020 19:28:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E9B8B385B834 Received: by mail-qk1-x734.google.com with SMTP id j4so20349431qkc.11 for ; Mon, 30 Mar 2020 12:28:13 -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=LIU6VQNkPk0nSBqvHrb1XRrR79L8+adTTOHKlgvwMVU=; b=rZkyisJmDkHhsIr9eAnAARPMhUNrvxyoirxwy/hx9wh6ZfeMDHOHzbgYivj7qru1Hd FVj68vruTRpqMON/942K+QXFUJqPk6saGdTGF8pYeG4uASet988aKEgxxPzpp+WTt+Go B+Q2YiUTah/hDQ5rplqzROkP+Zi2wgN8NOKizdtFrOAdRn+maQfscbhrDmqimcX7mUkB qTaOkZXdpaOXxYFM9w8pwHnoIAWeqwToZt/znGcMizCUbxZmyKatBf8ezmbN8t5+83Y1 yewVvSr+0eWXRa5spg4prp6f8YBy12owrv5RhV21n2D0nmU1yXXodw3j5IQ86T1TFo+K vWDQ== X-Gm-Message-State: ANhLgQ2+ZeCRRiUahij/jkYYuamzu7jSk1bZJDNXnFTcCXK2+ExvJEhJ Clvf4LI10Ux6uf9c6bahx3XMEcIK6/g= X-Google-Smtp-Source: ADFU+vspif7qjEWGZApyiq7AeyHBEnL0DPRbscaYnpwJeaf8/VWfU/sJRcJEGSGjtebviNEojYc0Cg== X-Received: by 2002:a37:b17:: with SMTP id 23mr1721063qkl.326.1585596493289; Mon, 30 Mar 2020 12:28:13 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id u51sm11906514qth.46.2020.03.30.12.28.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2020 12:28:12 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [RFC] x86_64: Add SSE sfp-exceptions Date: Mon, 30 Mar 2020 16:28:08 -0300 Message-Id: <20200330192808.2855376-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-26.4 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_SHORT, 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, 30 Mar 2020 19:28:15 -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 libgcc __sfp_handle_exceptions (used on float128 implementation), however, will set either SEE or i387 exception depending of the exception to raise. This broke the internal assumption of float128 where only SSE operations will be used. This patch reimplements the libgcc __sfp_handle_exceptions to use only SSE operations and sets libgcc to use it instead of its own implementation. And I think we should fix libgcc in a similar manner, since checking on config/i386/64/sfp-machine.h it already only supports SSE rounding mode and x86_64 ABI also expectes float128 to use SSE registers [1] (although it is not clear on how future implementation might implement it). Checked on x86_64-linux-gnu. [1] https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI --- sysdeps/x86/fpu/sfp-exceptions.c | 58 ++++++++++++++++++++++++++++++++ sysdeps/x86_64/fpu/Makefile | 3 ++ 2 files changed, 61 insertions(+) create mode 100644 sysdeps/x86/fpu/sfp-exceptions.c diff --git a/sysdeps/x86/fpu/sfp-exceptions.c b/sysdeps/x86/fpu/sfp-exceptions.c new file mode 100644 index 0000000000..2ddbfe11ba --- /dev/null +++ b/sysdeps/x86/fpu/sfp-exceptions.c @@ -0,0 +1,58 @@ +/* x86_64 soft-fp exception handling for _Float128. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +void +__sfp_handle_exceptions (int _fex) +{ + if (_fex & FP_EX_INVALID) + { + float f = 0.0f; + math_force_eval (f / f); + } + if (_fex & FP_EX_DENORM) + { + float f = FLT_MIN, g = 2.0f; + math_force_eval (f / g); + } + if (_fex & FP_EX_DIVZERO) + { + float f = 1.0f, g = 0.0f; + math_force_eval (f / g); + } + if (_fex & FP_EX_OVERFLOW) + { + float force_underflow = FLT_MAX * FLT_MAX; + math_force_eval (force_underflow); + } + if (_fex & FP_EX_UNDERFLOW) + { + float force_overflow = FLT_MIN * FLT_MIN; + math_force_eval (force_overflow); + } + if (_fex & FP_EX_INEXACT) + { + float f = 1.0f, g = 3.0f; + math_force_eval (f / g); + } +} +strong_alias (__sfp_handle_exceptions, __wrap___sfp_handle_exceptions) diff --git a/sysdeps/x86_64/fpu/Makefile b/sysdeps/x86_64/fpu/Makefile index a4ff2723a8..5becb96fa3 100644 --- a/sysdeps/x86_64/fpu/Makefile +++ b/sysdeps/x86_64/fpu/Makefile @@ -25,6 +25,9 @@ endif # Variables for libmvec tests. ifeq ($(subdir),math) +libm-routines += sfp-exceptions +LDFLAGS-m.so += -Wl,--wrap=__sfp_handle_exceptions + ifeq ($(build-mathvec),yes) libmvec-tests += double-vlen2 double-vlen4 double-vlen4-avx2 \ float-vlen4 float-vlen8 float-vlen8-avx2