From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by sourceware.org (Postfix) with ESMTPS id E7CA3396E84D for ; Wed, 2 Jun 2021 13:07:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E7CA3396E84D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rtems.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f169.google.com with SMTP id e2so2518194ljk.4 for ; Wed, 02 Jun 2021 06:07:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=4qpxlGIe/SjaoPBfqNCVyvVez/WCs4vJJWU3HBfTmcA=; b=EM5yUMR9oDu3eGteGNpwkqsXXnbIaivksHLOrKPbafYVgNrdQP7qmXGZmNUQY7HSqq oPE7t2tmj2dAUDnK6FI4zWLaZ8hlSsdaeX5+qBQa9sizAAqSLBMiPa7zENzX8xWMdE7R a6X2dxFdi7XNd5umzPkmmKHdjmiwIsUw90Ja5aw8Pvrld8qPt7XbX2E3wwnTce/5Yffx OsKzmJoNSbJQp4ofh070kswEgXCH/asr41+b63AtPcCc2UV/6zmIAQHf6N6FT1eq2tDe OdMaRkJOIMd8TVd1xptloh2Nx9GY1mYaNoEu0oU4MYLz34fdTuroOhY0VV864yPb4BXB Sqjw== X-Gm-Message-State: AOAM530pUJuuhLnnq9xi9dkt1fzDglla+HdaImhEmqBsItEwIvsr+tJY r2pXPt1Ns9eEUpGDhOs7BNv8TB8G9DHBaQ== X-Google-Smtp-Source: ABdhPJynHy6senq5u84/q0nzXcx0JIN0i8MqCfo4RWiuVinCy/TXtprgDAUQy3BBrekOjx0cwoQvBg== X-Received: by 2002:a2e:7214:: with SMTP id n20mr13726285ljc.356.1622639278036; Wed, 02 Jun 2021 06:07:58 -0700 (PDT) Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com. [209.85.208.173]) by smtp.gmail.com with ESMTPSA id u3sm2343712ljg.78.2021.06.02.06.07.57 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Jun 2021 06:07:57 -0700 (PDT) Received: by mail-lj1-f173.google.com with SMTP id e11so2458969ljn.13 for ; Wed, 02 Jun 2021 06:07:57 -0700 (PDT) X-Received: by 2002:a2e:8653:: with SMTP id i19mr25199078ljj.11.1622639276957; Wed, 02 Jun 2021 06:07:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: joel@rtems.org From: Joel Sherrill Date: Wed, 2 Jun 2021 08:07:45 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: incorrectly rounded square root To: Paul Zimmermann Cc: Jeff Johnston , Newlib X-Spam-Status: No, score=-3031.7 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2021 13:08:10 -0000 On Wed, Jun 2, 2021 at 2:51 AM Paul Zimmermann wrote: > Hi Jeff, > > thank you for your answer. After investigating more it seems fesetround() > is ineffective with newlib. Indeed if I print the result of fegetround() > just after the fesetround() calls I get: > > fegetround: 0 > RNDN: 0x1.ff83fp+63 > fegetround: 0 > RNDZ: 0x1.ff83fp+63 > fegetround: 0 > RNDU: 0x1.ff83fp+63 > fegetround: 0 > RNDD: 0x1.ff83fp+63 > > whereas with GNU libc I get: > > fegetround: 0 > RNDN: 0x1.ff83fp+63 > fegetround: 3072 > RNDZ: 0x1.ff83eep+63 > fegetround: 2048 > RNDU: 0x1.ff83fp+63 > fegetround: 1024 > RNDD: 0x1.ff83eep+63 > > Thus it seems this has nothing to do with the square root. > > According to gdb the fesetround() code used is the following: > > (gdb) break fesetround > Breakpoint 1 at 0x1650: file > ../../../../../../newlib/libm/machine/x86_64/fenv.c, line 371. > That is close to what I see in the source. That matches a variable declaration in fesetround(). I was concerned that maybe the stub magic was resulting in empty methods getting in for one of these. But doing an objdump on i386-rtems, that doesn't appear to be the case. The implementation came from Cygwin and was lightly massaged to get here. A student and I migrated that code to newlib in Feb 2020. Corinna did some work in March 2021 to use this for Cygwin but I don't see any reason it is broken. The i386-rtems installed sys/fenv.h is the one for x86. fegetround() is quite simple and fesetround isn't much more than that. https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=newlib/libm/machine/shared_x86/fenv.c;h=ccc08e2d8103ab974baf8d9591f71e5565d73ace;hb=HEAD#l350 I really expected to see a build issue and you using a stub. Could you confirm that the code we expect to be in those methods really is there for you? The line number indicates you have the expected code but.... The rounding is set in the x87 control register and then if SSE is there (dynamic check), it is also set in the SSE control register. The rounding more is read from the x86 control register and the SSE control register is ignored. Could you step through get and set and see if it looks like the x87 control register is actually changed? I'm confused. This looks like it should work. --joel > Paul > > >