From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc2e.google.com (mail-oo1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) by sourceware.org (Postfix) with ESMTPS id 4AA5D3858D1E for ; Fri, 12 Jan 2024 16:46:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4AA5D3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4AA5D3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705077967; cv=none; b=AnyNQvo1gJ2OeV+bR3vtEtEne0eMyTmhnuKk6M+7wRCUv0Ngc6QHE+QI2pA4ospTHkRJafQvf25h6UH0HwnuAlmCoYf1IM6JBrSKA+wqGaA9yXv6EqigGVT6ACMvFi/RXqo7IPQDdvd8tDya4G313fD5aJbQHH1JNiQvhdqcHLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705077967; c=relaxed/simple; bh=M/Z3pHBo3wW6ZAYD00s0q2T/p3H5qutxyuvIxplh1Ig=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Tv++VJHqUJDk3pyUAOSX+Tn8n6uC23Se9ie/fJEwaQXucjHDBveF4Mqat1cvaSf0DBHboPblF7IccxxIrMFDl1jk+0pH/hm1+xVAtm/xR1/FSUIM+S3DWWEz357UXS4sjo4JrnXcpa6L9vL0NbZzXsQh8pbfB2XGMzIQPRO9SPo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-58e256505f7so3296134eaf.3 for ; Fri, 12 Jan 2024 08:46:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705077963; x=1705682763; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=WQa+bmFrKpNVKi7NQngKm2danKAACvIXS6L5zSCwSAE=; b=uIkAoeBymV09YK0xDNm5GDHhPC2NvIpEKy3oQqCqZEjbSrrnSwgTNE2P2NBq4S7PaZ OQbFy32R5eHwloaYb09QXn7Hg2dgBpbqZ2ZpyXyjF2aT/LK+IqCT/0S0jizU28Oo6QsL k7xm623JhpVux99N17W/BeVy0qKlx2MMzvyrkzPRM8h5kFhSikrzBEaKAiRW6oLXyoXx DnkQzOM2IEvkDEkDBeTPPDd/Lx0tbRm+KwVw8Y5i/iUMDE3L3niqrNYnKq51MSlAoBKj PZf4rnZy8M7B3XkMxD2EBPJ+UIeZtD6aebx0U8lqYSmBZ1mRWgFI/VEcCroSOYXBLx8+ 0MpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705077963; x=1705682763; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WQa+bmFrKpNVKi7NQngKm2danKAACvIXS6L5zSCwSAE=; b=gZbkH5z/eYQYBhf7ThrNBXnYdh/a4kHZOayzSf7sMvPVdVILu9Cw0znIFJ9/ZyE32S GZM2iAtCa4TENW+EqVrDTRzlI4Q+6+YfHXRyhFPVW8UEaM6Etd0EiLBnOXXBwrzcqR0d GLc3Bfmko3bN9b6hTEETMBPYbCwgdKwOgZM2B99/6O16ufzKIpgSJFWHFhY4eVoqt5SJ 3BnET4q36UBK+cOTt9ifL98+4d5FgW/L5HIlsqVcb6ZRK79mJhVzuFhepara0RW+Rv/V CWAQEQGqFu3N/pxVsUekx7S8TV+LfLjEB+lwT6E6Rcx1PSR7RYqXLxjkT+D1NEmhc/1U UVYQ== X-Gm-Message-State: AOJu0YzXvvVBoPdSceVkY/cc/kG0UvYfyXNnTpuKB+1RjoA1BEn47aPR 7B76QVdncc9oaRlcZZzhGD7Vaf9XhEkp8w== X-Google-Smtp-Source: AGHT+IHm7mb1OELWKtyyuK2D+DbwbxhDksoBm21biYUoTU2MJ5Mwe4wWI6xCmPSpgncHtxQn5lBA5g== X-Received: by 2002:a05:6358:415:b0:174:b1f1:85bd with SMTP id 21-20020a056358041500b00174b1f185bdmr1519608rwd.39.1705077963408; Fri, 12 Jan 2024 08:46:03 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c1:9dd2:7131:ee55:aeab:3a03? ([2804:1b3:a7c1:9dd2:7131:ee55:aeab:3a03]) by smtp.gmail.com with ESMTPSA id n8-20020aa78a48000000b006da5e1638b6sm3485723pfa.19.2024.01.12.08.46.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jan 2024 08:46:02 -0800 (PST) Message-ID: <8dee0ad6-196b-40c1-b3fb-6be7147d8dc7@linaro.org> Date: Fri, 12 Jan 2024 13:45:59 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] sparc: Force calculation that raises exception Content-Language: en-US To: Daniel Cederman , libc-alpha@sourceware.org Cc: daniel@gaisler.com, andreas@gaisler.com References: <20240112092628.2464455-1-cederman@gaisler.com> <20240112092628.2464455-3-cederman@gaisler.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20240112092628.2464455-3-cederman@gaisler.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 12/01/24 06:26, Daniel Cederman wrote: > Read out the FPU control word to force the calculation to complete and > raise the exception. > > With this change the math/test-fenv test pass for LEON. Is this to try mitigate 'GRFPU Floating-point controller: Missing FDIV/FSQRT Result' [1]? If so, wouldn't be better to use '-mfix-ut699' when building against leon3? There are potentially multiple usages of FDIV/FSQRT within libc/libm that might be subject to this issue. At least recent gcc versions seems to add the required nops after fsqrt: $ cat t.c #include #include #define math_force_eval(x) \ ({ __typeof (x) __x = (x); __asm __volatile__ ("" : : "m" (__x)); }) int foo (void) { static const struct { double zero, one, max, min, pi; } c = { 0.0, 1.0, DBL_MAX, DBL_MIN, M_PI }; double d; asm ("" : "=e" (d) : "0" (c.zero)); d /= c.zero; __asm __volatile ("" : : "e" (d)); } $ sparc64-linux-gnu -m32 -mcpu=leon3 -O2 -mhard-float -mfix-ut699 t.c -S -o - [...] foo: sethi %hi(.LC0), %g1 ldd [%g1+%lo(.LC0)], %f10 fmovs %f10, %f8 fmovs %f11, %f9 fdivd %f8, %f10, %f8 std %f8, [%sp-8] nop nop jmp %o7+8 [...] In any case this penalize non-leon3 chips with the extra 'stx fsr,...', so it should be used only for leon (and with a proper explanation of why it is required). [1] https://www.gaisler.com/doc/antn/GRLIB-TN-0013.pdf > > Signed-off-by: Daniel Cederman > --- > sysdeps/sparc/fpu/fraiseexcpt.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/sysdeps/sparc/fpu/fraiseexcpt.c b/sysdeps/sparc/fpu/fraiseexcpt.c > index 26a7720ec9..43176cf6a3 100644 > --- a/sysdeps/sparc/fpu/fraiseexcpt.c > +++ b/sysdeps/sparc/fpu/fraiseexcpt.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > > int > __feraiseexcept (int excepts) > @@ -30,6 +31,7 @@ __feraiseexcept (int excepts) > 0.0, 1.0, DBL_MAX, DBL_MIN, M_PI > }; > double d; > + fpu_control_t cw; > > /* Raise exceptions represented by EXPECTS. But we must raise only > one signal at a time. It is important the if the overflow/underflow > @@ -43,6 +45,7 @@ __feraiseexcept (int excepts) > __asm ("" : "=e" (d) : "0" (c.zero)); > d /= c.zero; > __asm __volatile ("" : : "e" (d)); > + _FPU_GETCW(cw); > } > > /* Next: division by zero. */ > @@ -51,6 +54,7 @@ __feraiseexcept (int excepts) > __asm ("" : "=e" (d) : "0" (c.one)); > d /= c.zero; > __asm __volatile ("" : : "e" (d)); > + _FPU_GETCW(cw); > } > > /* Next: overflow. */ > @@ -59,6 +63,7 @@ __feraiseexcept (int excepts) > __asm ("" : "=e" (d) : "0" (c.max)); > d *= d; > __asm __volatile ("" : : "e" (d)); > + _FPU_GETCW(cw); > } > > /* Next: underflow. */ > @@ -67,6 +72,7 @@ __feraiseexcept (int excepts) > __asm ("" : "=e" (d) : "0" (c.min)); > d *= d; > __asm __volatile ("" : : "e" (d)); > + _FPU_GETCW(cw); > } > > /* Last: inexact. */ > @@ -75,6 +81,7 @@ __feraiseexcept (int excepts) > __asm ("" : "=e" (d) : "0" (c.one)); > d /= c.pi; > __asm __volatile ("" : : "e" (d)); > + _FPU_GETCW(cw); > } > > /* Success. */