From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 64D183959C31 for ; Tue, 1 Jun 2021 16:28:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 64D183959C31 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622564936; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eQ8memft3u3OEhNtPLqqOgGrKcc43Ds0aVWmMI95oIA=; b=H4d5KbDzdXIxFKk6KGq+Q1xu6/G3UPEhbUEiXt+tZPIhZQg8u7UI23bZnWhRSn+WtdGP3L aYyW2rbkFhpzHIDGczvKwpdJil6LrdMjoeb9LbbCPSj5RxeIwOR/AiXIzp0e4SGjDVJpmv wtyq1jRgD7DVok4uUqkwVXvB9vCKYxQ= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-384-4QMYVb25OMqU6NEirOOsoQ-1; Tue, 01 Jun 2021 12:28:54 -0400 X-MC-Unique: 4QMYVb25OMqU6NEirOOsoQ-1 Received: by mail-pl1-f198.google.com with SMTP id b15-20020a1709027e0fb02900fef41cdedfso4846102plm.3 for ; Tue, 01 Jun 2021 09:28:53 -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:from:date :message-id:subject:to:cc; bh=eQ8memft3u3OEhNtPLqqOgGrKcc43Ds0aVWmMI95oIA=; b=hqUTd55kuAJpYqtM0sH4ny6YUnFvZfOy1ajS1XKiWltAh1a7krReru5SSZuAyNx/eo K32v6sca2jNbZanSf7funANtLK8D6h6yrny2gkr8z3xX9grJyxGgdtwtNVryvuEFoFdr vTIHe1REBhNt/PltKL2Ai57pHDk/aHIcNIt54VWM0IB9OrVhKOwWApfDhw5rcqGMkSAg oHAKtGdDDnIPVVB33KhcPpirSIRH6VLRtJDEAsbmEqZRtLjlgKfzlhV9Z02DD3WLmZYE cqbuuN/P1QthlXjDXEsLjqTqx7tG7qP8fF/99KJRIOvrh4ZdedjU7zC/GaTwMX+s36wj GpMg== X-Gm-Message-State: AOAM531Wv1QoEqiiH61jVNgF25fM1PvA/AIK90HCN8T2R9+APJ/ce3Ms dosC5xhuyA+4O2LwJmVKNZLR/RE8QfE5x6ieRTl7QbLW2LppHG4+GmTgZ/WjNevP/xdfI5MVUUP shl9EA5q90B2Vvxza2eeJkCA01t+WnCs= X-Received: by 2002:aa7:8d4a:0:b029:2e8:df53:cbd6 with SMTP id s10-20020aa78d4a0000b02902e8df53cbd6mr22402100pfe.13.1622564933048; Tue, 01 Jun 2021 09:28:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyL27owYLz8slVBTTuUfPBDX6bh63WQgWzGD5YB/cWmHTh0u7FRDFYBmBl7+MBFT1m7PEV54ATUWNI9J+7vWk8= X-Received: by 2002:aa7:8d4a:0:b029:2e8:df53:cbd6 with SMTP id s10-20020aa78d4a0000b02902e8df53cbd6mr22402082pfe.13.1622564932822; Tue, 01 Jun 2021 09:28:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jeff Johnston Date: Tue, 1 Jun 2021 12:28:41 -0400 Message-ID: Subject: Re: incorrectly rounded square root To: Paul Zimmermann Cc: Newlib , joel@rtems.org Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jjohnstn@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, HTML_MESSAGE, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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 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: Tue, 01 Jun 2021 16:28:57 -0000 Ok, not sure what is happening. You should be using the newlib/libm/machine/shared_x86/fenv.c which includes fesetround which you can confirm. Comparing to glibc's version of fesetround, it is very similar. The only difference appears to be that glibc does the x87 fpu first, then the MSCSR register for sse, where newlib's version intermixes the code, but the same insn's are used. Looking at the sqrtf implementation of newlib's libm/math/ef_sqrt.c vs glibc's sysdeps/ieee754/flt-32/e_sqrtf.c the rounding logic is identical. /* use floating add to find out rounding direction */ if(ix!=0) { z = one-tiny; /* trigger inexact flag */ if (z>=one) { z = one+tiny; if (z>one) q += 2; else q += (q&1); } } ix = (q>>1)+0x3f000000; ix += (m <<23); SET_FLOAT_WORD(z,ix); return z; In fact, other than the normalization code, the code is identical (not sure that difference is applicable here). Corinna is on vacation so I'm cc'ing Joel in case he can offer some input. -- Jeff J. On Tue, Jun 1, 2021 at 3:12 AM Paul Zimmermann wrote: > Hi Jeff, > > > Not all platforms supply a machine implementation of fesetround. Which > > platform are you using? > > this is on a Intel(R) Core(TM) i5-4590, with gcc 10.2.1, under > Debian GNU/Linux 11 (bullseye). > > Best regards, > Paul > >