Message ID | 20240629204434.2289174-1-mickael9@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <newlib-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CBB6D389EC9C for <patchwork@sourceware.org>; Sat, 29 Jun 2024 20:44:56 +0000 (GMT) X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id AD67C389EC52 for <newlib@sourceware.org>; Sat, 29 Jun 2024 20:44:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD67C389EC52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AD67C389EC52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::231 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719693881; cv=none; b=V8vKndBeyy3QKAwGfKbhCPfUY+QKLweHsOwArsstZ+mpDWM9MBQnQMpUkGpfkFS6IyaQmGn+QApGW6KyH/NgWufj8ydPpdcyphLDVxEZUt73mabgdYBT1QNbObDMiEX24qedRXc9e4gc5Iom6Dr+LXv8h0jVQ6zS85Z5ZJcy1Ts= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719693881; c=relaxed/simple; bh=oc3xoWuo0iIRDzKgp9lADuUN1btSsAQY7DVpcES/XCg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HoRNgaqa8i3+vqScd3y86TGKyc2/3PuREUiJlXLSdGdpzYiXhA9KJHuny20KH6B1YfwfkmKGL+v3DRAngPGHlx4+NWj+K8AYUCmC+9nMCkGRpGLMELubsagaQqB3/MTNJ2vM1xW9iQ7rhXJRaTkCm+WaG3hqRREGbTwQR66tyBQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3c9cc681ee4so1078152b6e.0 for <newlib@sourceware.org>; Sat, 29 Jun 2024 13:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719693878; x=1720298678; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=coeliS8k4WbbCQvPeGk6LJxcHn83IkpbYeuy2MvW0Xc=; b=UKBPspcKvJJycnwhzCxM1o/NYzrX6v9jEJSprOzcuwpZFvfqVDYHaCM4QI0C8kJYoe L6X/NM3Us5whH+fKfJs4RNi9w48Nyo0SoqjiXrUylQcjf+Tm2mwFo7jA9ow/6LQX/WYw 1W8yv+on/zU4m3eD5MZewDAnjBNx3WmTmQlWfF4jHhtRGNK0byJ5Di0Cb6J+6hmhmpZv iUuORMiwt2lGV0rByZ5fBuno0IFdHZ0buQneESteus7vLIQ088oENg+LJlL1IbE06THv LwziQ8WUpqmlm29yYPymRUt3a5szcot1/A4wIXawouVyW4tjaAGMw9od7ecaIYwmt4yg /U5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719693878; x=1720298678; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=coeliS8k4WbbCQvPeGk6LJxcHn83IkpbYeuy2MvW0Xc=; b=vRpeE7Tz9Jnn28dUBgPJA/ardQzqyjWIG3x/fswfvMTY0LPSfrNVk30gmNSzEaG0lc GqVtE2e22G5yNwG8nvoW5vBrw81GqMiZw8eeZosmT42Yy02apspM9i7/kjuiol8getVC arwr4vBd3RT2r0MuaM1bc7dWPE4eUie/KxrmEEENyustWHIOI75F5qVFN8bcCNBvAj88 qKVE6R8rNKFe6zpBT9LTiUNDqJCPnRsR2CNVkeQfizVk+KcQCcWi4GXIK8A74ROEC9hm BahiqK4ggIL2NyLS5EM/Clj9bzk/ThlyYXP+M7JrC5MytUtgK9ipBZcJz9DMJzyuZY/C Wchw== X-Gm-Message-State: AOJu0YzgsIFagv1KlbzbQJV9LTM/NU/lhfUGDMu2IgG7Hz4vs4lKkgPS yjgf04g6IqdbbMDCnFmfPp0c58l2TpnlK6fJslx5twJupcB5o2amK7Zd5EC8Bkg= X-Google-Smtp-Source: AGHT+IEfVYI/4a4CwwnD4fvS4MY72S+AneL4gbgP0lXkXy5ZuzaD2KPaH7O7fEtKuE/o2Fp3w3YoPg== X-Received: by 2002:a05:6808:1489:b0:3d5:5cd4:5a1e with SMTP id 5614622812f47-3d6b2c1ed79mr2461375b6e.1.1719693878154; Sat, 29 Jun 2024 13:44:38 -0700 (PDT) Received: from localhost ([2a01:e0a:1a9:65d0:ab9:c1a1:d7cd:b827]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac10c8ba8sm36294265ad.62.2024.06.29.13.44.36 for <newlib@sourceware.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Jun 2024 13:44:37 -0700 (PDT) From: =?utf-8?q?Micka=C3=ABl_Thomas?= <mickael9@gmail.com> To: newlib@sourceware.org Subject: [PATCH] Fix ARM optimized fma & fmaf implementations Date: Sat, 29 Jun 2024 22:44:34 +0200 Message-ID: <20240629204434.2289174-1-mickael9@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list <newlib.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/newlib>, <mailto:newlib-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/newlib/> List-Post: <mailto:newlib@sourceware.org> List-Help: <mailto:newlib-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/newlib>, <mailto:newlib-request@sourceware.org?subject=subscribe> Errors-To: newlib-bounces+patchwork=sourceware.org@sourceware.org |
Series |
Fix ARM optimized fma & fmaf implementations
|
|
Commit Message
Mickaël Thomas
June 29, 2024, 8:44 p.m. UTC
The vfma.f32|64 z, x, y instruction performs the operation z += x * y without intermediate rounding. The register used for z is both read and written by the instruction. The inline assembly must therefore use the "+" constraint modifier. Using "=" the generated assembly gives an incorrect result. Current (incorrect) implementation: In archive arm-none-eabi/thumb/v8-m.main+dp/hard/newlib/libm.a: <fma>: eea0 0b01 vfma.f64 d0, d0, d1 4770 bx lr <fmaf>: eea0 0a20 vfma.f32 s0, s0, s1 4770 bx lr Correct implementation: <fma>: eea0 2b01 vfma.f64 d2, d0, d1 eeb0 0b42 vmov.f64 d0, d2 4770 bx lr <fmaf>: eea0 1a20 vfma.f32 s2, s0, s1 eeb0 0a41 vmov.f32 s0, s2 4770 bx lr --- newlib/libm/machine/arm/s_fma_arm.c | 2 +- newlib/libm/machine/arm/sf_fma_arm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Comments
On 29/06/2024 21:44, Mickaël Thomas wrote: > The vfma.f32|64 z, x, y instruction performs the operation > z += x * y without intermediate rounding. > > The register used for z is both read and written by the instruction. > The inline assembly must therefore use the "+" constraint modifier. > Using "=" the generated assembly gives an incorrect result. > > Current (incorrect) implementation: > > In archive arm-none-eabi/thumb/v8-m.main+dp/hard/newlib/libm.a: > > <fma>: > eea0 0b01 vfma.f64 d0, d0, d1 > 4770 bx lr > <fmaf>: > eea0 0a20 vfma.f32 s0, s0, s1 > 4770 bx lr > > Correct implementation: > > <fma>: > eea0 2b01 vfma.f64 d2, d0, d1 > eeb0 0b42 vmov.f64 d0, d2 > 4770 bx lr > > <fmaf>: > eea0 1a20 vfma.f32 s2, s0, s1 > eeb0 0a41 vmov.f32 s0, s2 > 4770 bx lr > --- > newlib/libm/machine/arm/s_fma_arm.c | 2 +- > newlib/libm/machine/arm/sf_fma_arm.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/newlib/libm/machine/arm/s_fma_arm.c b/newlib/libm/machine/arm/s_fma_arm.c > index f945419b5..6a2b403e1 100644 > --- a/newlib/libm/machine/arm/s_fma_arm.c > +++ b/newlib/libm/machine/arm/s_fma_arm.c > @@ -41,7 +41,7 @@ > double > fma (double x, double y, double z) > { > - asm ("vfma.f64 %P0, %P1, %P2" : "=w" (z) : "w" (x), "w" (y)); > + asm ("vfma.f64 %P0, %P1, %P2" : "+w" (z) : "w" (x), "w" (y)); > return z; > } > > diff --git a/newlib/libm/machine/arm/sf_fma_arm.c b/newlib/libm/machine/arm/sf_fma_arm.c > index 4befd9017..8d1b63d99 100644 > --- a/newlib/libm/machine/arm/sf_fma_arm.c > +++ b/newlib/libm/machine/arm/sf_fma_arm.c > @@ -41,7 +41,7 @@ > float > fmaf (float x, float y, float z) > { > - asm ("vfma.f32 %0, %1, %2" : "=t" (z) : "t" (x), "t" (y)); > + asm ("vfma.f32 %0, %1, %2" : "+t" (z) : "t" (x), "t" (y)); > return z; > } > Nice catch. Patch applied. Thank you. R.
diff --git a/newlib/libm/machine/arm/s_fma_arm.c b/newlib/libm/machine/arm/s_fma_arm.c index f945419b5..6a2b403e1 100644 --- a/newlib/libm/machine/arm/s_fma_arm.c +++ b/newlib/libm/machine/arm/s_fma_arm.c @@ -41,7 +41,7 @@ double fma (double x, double y, double z) { - asm ("vfma.f64 %P0, %P1, %P2" : "=w" (z) : "w" (x), "w" (y)); + asm ("vfma.f64 %P0, %P1, %P2" : "+w" (z) : "w" (x), "w" (y)); return z; } diff --git a/newlib/libm/machine/arm/sf_fma_arm.c b/newlib/libm/machine/arm/sf_fma_arm.c index 4befd9017..8d1b63d99 100644 --- a/newlib/libm/machine/arm/sf_fma_arm.c +++ b/newlib/libm/machine/arm/sf_fma_arm.c @@ -41,7 +41,7 @@ float fmaf (float x, float y, float z) { - asm ("vfma.f32 %0, %1, %2" : "=t" (z) : "t" (x), "t" (y)); + asm ("vfma.f32 %0, %1, %2" : "+t" (z) : "t" (x), "t" (y)); return z; }