From patchwork Fri Sep 25 15:20:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 304399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1224C4727D for ; Fri, 25 Sep 2020 15:24:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 29B8F2311D for ; Fri, 25 Sep 2020 15:24:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yEY7d/Jh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29B8F2311D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLpaI-000478-4P for qemu-devel@archiver.kernel.org; Fri, 25 Sep 2020 11:24:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLpWo-0000sj-K7 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:20:54 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:35402) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLpWm-0005QV-Kz for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:20:54 -0400 Received: by mail-pf1-x444.google.com with SMTP id k8so3530132pfk.2 for ; Fri, 25 Sep 2020 08:20:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=23xCfoE1xB51TMKAcRj/+leExlJ4p0flEWY8kvOZXBg=; b=yEY7d/Jh675fzi/SDdmzpnwMkTkfycAww8HTpKGPyjkvl2Ryh9TZlCw15NXKfQW3vS 0JGNCLNKrxmUGSJhj791ibHdc/fMaXucxeMiTDH5qAH9C95tOUQy2MkIt/+ZAsZXZCdW DWrpVKRuWK1DyDTpX1ZcHo/ALL0K97tsfEHE/gui2SzICFynEMN0IgGMmS8HhF9BTkUF mQY3QLoan3bHAME5DAg2COPZhgQUZ7TkkRJnoCSKJO/kHj9uB7IVlohjjkzb30MBr06c w6m0+VGdwRFCuiLprG0+BFoumQ4NmFHglH/JgsDAcBLXXNSDsw2I9xeU8SXH+1/vd8qp DjHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=23xCfoE1xB51TMKAcRj/+leExlJ4p0flEWY8kvOZXBg=; b=tORAuRwj21RQjnRWIHvesEQvo87wvqZMxy2ThNgCwo3loA034nHHmHyrhE9Qu8C4oK QtSfSdAEW2o3FTGmKPt4Xjx8e+tIQll681h0aBB7Ad08POGqPfwYjpEi4eJf9Uu4PWjp PEueCbdrpcpJNV1YzlnTYfounW5fSyoqycXFk71FhGmAHS0n2RR880BH214n0XY+zMIu Bi6V0f80qlYBgtdcCFH/r2sMS+2hPWlqBYedtfU4qLSRUS9/rEyqj3MsLBFPeItLGjzS UvWBeoiYbM1x7x6ISXY8o5LgCPq5wABefdWmdhYQOcTpNR6IrrtwnOrfk3bjNw/aFB7x 8yiw== X-Gm-Message-State: AOAM530tf9MtYJR/VSHjg3/c8sqkgpHyn8VafPJIu2uM7alYZQBW8+ke f9NNvE2DfbqmyF5DcxJ+pYU2s7r7MmbkIg== X-Google-Smtp-Source: ABdhPJy5YuCDp9N5S0BQH1PUq7UITmnPPXKjm5yjQHt9ltc21EOSwOScpkMQEUe6nb4/lVIBRCSHYQ== X-Received: by 2002:a63:d512:: with SMTP id c18mr422925pgg.387.1601047250524; Fri, 25 Sep 2020 08:20:50 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id a5sm2717859pgk.13.2020.09.25.08.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 08:20:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 01/10] softfloat: Use mulu64 for mul64To128 Date: Fri, 25 Sep 2020 08:20:38 -0700 Message-Id: <20200925152047.709901-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925152047.709901-1-richard.henderson@linaro.org> References: <20200925152047.709901-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bharata@linux.ibm.com, alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Via host-utils.h, we use a host widening multiply for 64-bit hosts, and a common subroutine for 32-bit hosts. Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- include/fpu/softfloat-macros.h | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h index a35ec2893a..57845f8af0 100644 --- a/include/fpu/softfloat-macros.h +++ b/include/fpu/softfloat-macros.h @@ -83,6 +83,7 @@ this code that are retained. #define FPU_SOFTFLOAT_MACROS_H #include "fpu/softfloat-types.h" +#include "qemu/host-utils.h" /*---------------------------------------------------------------------------- | Shifts `a' right by the number of bits given in `count'. If any nonzero @@ -515,27 +516,10 @@ static inline void | `z0Ptr' and `z1Ptr'. *----------------------------------------------------------------------------*/ -static inline void mul64To128( uint64_t a, uint64_t b, uint64_t *z0Ptr, uint64_t *z1Ptr ) +static inline void +mul64To128(uint64_t a, uint64_t b, uint64_t *z0Ptr, uint64_t *z1Ptr) { - uint32_t aHigh, aLow, bHigh, bLow; - uint64_t z0, zMiddleA, zMiddleB, z1; - - aLow = a; - aHigh = a>>32; - bLow = b; - bHigh = b>>32; - z1 = ( (uint64_t) aLow ) * bLow; - zMiddleA = ( (uint64_t) aLow ) * bHigh; - zMiddleB = ( (uint64_t) aHigh ) * bLow; - z0 = ( (uint64_t) aHigh ) * bHigh; - zMiddleA += zMiddleB; - z0 += ( ( (uint64_t) ( zMiddleA < zMiddleB ) )<<32 ) + ( zMiddleA>>32 ); - zMiddleA <<= 32; - z1 += zMiddleA; - z0 += ( z1 < zMiddleA ); - *z1Ptr = z1; - *z0Ptr = z0; - + mulu64(z1Ptr, z0Ptr, a, b); } /*---------------------------------------------------------------------------- From patchwork Fri Sep 25 15:20:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 272715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32429C4727C for ; Fri, 25 Sep 2020 15:25:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 88A9E2311D for ; Fri, 25 Sep 2020 15:25:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="S3ekjQ6a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88A9E2311D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLpb2-00059p-JT for qemu-devel@archiver.kernel.org; Fri, 25 Sep 2020 11:25:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLpWp-0000vX-VW for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:20:55 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:44608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLpWo-0005Qj-0K for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:20:55 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 7so2840604pgm.11 for ; Fri, 25 Sep 2020 08:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5Xncpr5K+BGk/N6uEu+J3gIdvJF6CZ9YQEmHEPvJu74=; b=S3ekjQ6aLH8wOrUE4kLcFniubnlsZLqpez/Uqxc2Z8e7wFAnrGsI0SYBoX2C8auwxQ iKSlL7szeEh5EpPZAg2vdbGohpr0DpzAAqiDdxcxgOlFiFRBBOxtSbWXaYFji7vBMGfB LAfsM+ncrbJP3Gzzh6Nu3hhZ54KkYs+crNaYOKVbAjATIo0lNVId/ekmRvruFjWQ9gJ1 D2+HN6eYS5Mh04naQf6bG668FX+K9FwUChAdxLMdiBrPAanhiiAzN6n/U0RA4GcUCSOr cz7hs9pXIXWKfDCuVAhIH0LzsP6SjwL41W2h+jgNyBi6aWeE9FKRDiSSYHYGWLeOgh/O LA1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5Xncpr5K+BGk/N6uEu+J3gIdvJF6CZ9YQEmHEPvJu74=; b=M6/yYlR6RHnRzmffzwWggpDbOOSjVgnaTjvO2IGAdpehAt/ePkVKetbDDsWSv0hqe0 Wx1O19oYF/uTLP5pfzYLuX1IsXZVzEckD00C2yCpAnrQ1dKeqBklQZzkZ4N8dugFUBxN vEOGduVGWpU3msXKIZQfDe5Pm9uI6F2tw5p/vb1bFVq9bGguueQDuVvjSBNM6Zd1B75B uOfZqcmwoHs5zCkniTtn0qMk1pgTeH0yswjEpPmAedQiTBKQl4lvZqwmF55IxvIjW4Wy SMiYuIoD8LguWiGq7dVf7BZ5ziLY60PVKHiJcvkiTN271oKT3Fx+GSsUq/4sdAYmyNgg KWGg== X-Gm-Message-State: AOAM531tQuqhORGOx8WuWOH4l1z+wVlxfTPgVPJgIeawa2dkOua4W10F eV3m3jY3FDyUpjw2XvmsGi0UT6eoXA0f5w== X-Google-Smtp-Source: ABdhPJxo1WOePL/GCL3Du4qDIOLKkYQVdJH1oQk6RGAc15uFYZ53FKy8mlVZJRcQA4izz6Fh8fW8EQ== X-Received: by 2002:a62:178d:0:b029:13e:d13d:a0f8 with SMTP id 135-20020a62178d0000b029013ed13da0f8mr4495253pfx.20.1601047251820; Fri, 25 Sep 2020 08:20:51 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id a5sm2717859pgk.13.2020.09.25.08.20.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 08:20:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 02/10] softfloat: Use int128.h for some operations Date: Fri, 25 Sep 2020 08:20:39 -0700 Message-Id: <20200925152047.709901-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925152047.709901-1-richard.henderson@linaro.org> References: <20200925152047.709901-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bharata@linux.ibm.com, alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use our Int128, which wraps the compiler's __int128_t, instead of open-coding left shifts and arithmetic. We'd need to extend Int128 to have unsigned operations to replace more than these three. Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- include/fpu/softfloat-macros.h | 39 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h index 57845f8af0..95d88d05b8 100644 --- a/include/fpu/softfloat-macros.h +++ b/include/fpu/softfloat-macros.h @@ -84,6 +84,7 @@ this code that are retained. #include "fpu/softfloat-types.h" #include "qemu/host-utils.h" +#include "qemu/int128.h" /*---------------------------------------------------------------------------- | Shifts `a' right by the number of bits given in `count'. If any nonzero @@ -352,13 +353,11 @@ static inline void shortShift128Left(uint64_t a0, uint64_t a1, int count, static inline void shift128Left(uint64_t a0, uint64_t a1, int count, uint64_t *z0Ptr, uint64_t *z1Ptr) { - if (count < 64) { - *z1Ptr = a1 << count; - *z0Ptr = count == 0 ? a0 : (a0 << count) | (a1 >> (-count & 63)); - } else { - *z1Ptr = 0; - *z0Ptr = a1 << (count - 64); - } + Int128 a = int128_make128(a1, a0); + Int128 z = int128_lshift(a, count); + + *z0Ptr = int128_gethi(z); + *z1Ptr = int128_getlo(z); } /*---------------------------------------------------------------------------- @@ -405,15 +404,15 @@ static inline void *----------------------------------------------------------------------------*/ static inline void - add128( - uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, uint64_t *z0Ptr, uint64_t *z1Ptr ) +add128(uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, + uint64_t *z0Ptr, uint64_t *z1Ptr) { - uint64_t z1; - - z1 = a1 + b1; - *z1Ptr = z1; - *z0Ptr = a0 + b0 + ( z1 < a1 ); + Int128 a = int128_make128(a1, a0); + Int128 b = int128_make128(b1, b0); + Int128 z = int128_add(a, b); + *z0Ptr = int128_gethi(z); + *z1Ptr = int128_getlo(z); } /*---------------------------------------------------------------------------- @@ -463,13 +462,15 @@ static inline void *----------------------------------------------------------------------------*/ static inline void - sub128( - uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, uint64_t *z0Ptr, uint64_t *z1Ptr ) +sub128(uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1, + uint64_t *z0Ptr, uint64_t *z1Ptr) { + Int128 a = int128_make128(a1, a0); + Int128 b = int128_make128(b1, b0); + Int128 z = int128_sub(a, b); - *z1Ptr = a1 - b1; - *z0Ptr = a0 - b0 - ( a1 < b1 ); - + *z0Ptr = int128_gethi(z); + *z1Ptr = int128_getlo(z); } /*---------------------------------------------------------------------------- From patchwork Fri Sep 25 15:20:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 272714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1205DC4363D for ; Fri, 25 Sep 2020 15:26:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 974B7235F9 for ; Fri, 25 Sep 2020 15:26:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nXEM8fOL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 974B7235F9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLpcb-00071V-Kl for qemu-devel@archiver.kernel.org; Fri, 25 Sep 2020 11:26:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLpWr-0000yB-4q for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:20:57 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:43416) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLpWp-0005R0-E4 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:20:56 -0400 Received: by mail-pf1-x42c.google.com with SMTP id f18so3499295pfa.10 for ; Fri, 25 Sep 2020 08:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TRndLkCMxWNns7qPLAeoWU7hdSJPyNTmzGBqCDb04fk=; b=nXEM8fOLG1Tb0+hXhrGrxw11JS7PRU7sqoRTjUOLanQONpskeLnwGEvg4Z+3p/OojD xTEaDaebTLPE6jJ7JZpQUPv69muEsQ76haj1fkGnnCcUK3RxLgf8tHyfEr67/8GYXXu9 PeUN9YT3Z82K+ltRLbrEqP2uQhF18KaFlykK2/YRqmOF7Wxk5J26i6qd+F3bgpprALV5 oKEvQsmubScFWU1l5QnytiBzgJitqTXqkju1U6HqgzzYpbQPREn8k4MJxWiKHvcLvM7A t5Ik3AlZGCEy3oYiWKEDp3Sxun0I1T22Fg4gU4BQeqPYn3bFuUsdGsGm/97nRLvVObiW p68Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TRndLkCMxWNns7qPLAeoWU7hdSJPyNTmzGBqCDb04fk=; b=Gg6OR7nKJXf0q7KdIZFMqv3wfaSpPVdfvKAYgNtP3fWWuJ8uHkTrHatPv17qq4gw7D k50/9p8yHiBWu/hjSViI0DM58+/qvE40wKjdsEPdFN/9EusDI1Lv7PsUryTvH9n3i3fi 9bkoxYHUlGK9XSSK2UXo8FySM7bxEwd1XLPgMJWaLA5j6OgDbzVuWzOgY3h7oH3sd7Dx 0LlYRKnwWDfsC7xhsGbAAn/I9NuJji0psgleV19HKvE0yalBa3PS7OPMs9mTkupdTY4s 9B1pXBsdhUvSzYOEAePwRf1G2osK5q0gmznl3brhODjhInWHqRoVyLtG1CcH0LmP+IKm am6g== X-Gm-Message-State: AOAM532CdhH0UJqqSujYeUEF4T6Grgw2b72J63j+rMIEnGjVJ/4u49z2 qEeI9CGpgRIF0Bpo/wxsPL6Z7JTEcbxJgA== X-Google-Smtp-Source: ABdhPJxrc/9QZK8apML+2H7vI0n/LwuC05152Xoh5IO8jR7SMZ7x7C9Szs/t/+wEtXyqIxR4D+1jng== X-Received: by 2002:a62:6444:0:b029:13e:d13d:a12d with SMTP id y65-20020a6264440000b029013ed13da12dmr4527850pfb.21.1601047253573; Fri, 25 Sep 2020 08:20:53 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id a5sm2717859pgk.13.2020.09.25.08.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 08:20:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 03/10] softfloat: Tidy a * b + inf return Date: Fri, 25 Sep 2020 08:20:40 -0700 Message-Id: <20200925152047.709901-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925152047.709901-1-richard.henderson@linaro.org> References: <20200925152047.709901-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bharata@linux.ibm.com, alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" No reason to set values in 'a', when we already have float_class_inf in 'c', and can flip that sign. Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- fpu/softfloat.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 67cfa0fd82..9db55d2b11 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1380,9 +1380,8 @@ static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c, s->float_exception_flags |= float_flag_invalid; return parts_default_nan(s); } else { - a.cls = float_class_inf; - a.sign = c.sign ^ sign_flip; - return a; + c.sign ^= sign_flip; + return c; } } From patchwork Fri Sep 25 15:20:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 304397 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AE28C4363D for ; Fri, 25 Sep 2020 15:28:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 89A96235F9 for ; Fri, 25 Sep 2020 15:28:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Ch/5el9y" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89A96235F9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLpeI-0007vm-FN for qemu-devel@archiver.kernel.org; Fri, 25 Sep 2020 11:28:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLpWs-00011R-L2 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:20:58 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:32785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLpWq-0005R7-Pk for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:20:58 -0400 Received: by mail-pg1-x541.google.com with SMTP id o25so2880114pgm.0 for ; Fri, 25 Sep 2020 08:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uxihFy3jRjyF4IIfuuRuE9+EnA2kbJYXXHsvttdZmDI=; b=Ch/5el9yv57dB5RkIXJjq+SgU8pUJwUdhl7EkN2DUfxGupPfdCP/LqaWMAK4O80udP 2Nl+WaBKDhaHFIHHMKa+MajN1kO5wZG4J/MhGvBfQfsEOq7JVzbGgYEAT1MCsL6a/2Gl jAC57TR/dWO0GYyjXxmrvDUrVwfZ6n/RYR+tZh9sAL9edpSbVtHy7mqvDu4vT3Aif4vu 9F9jJDjPmDjGAJjrHkUKq8qdi9GrgmQwPb6uuhMEVGsNxfuDakCorXMt4rFon5GNxJjN Bz6Ec7Lk7tnNpU/2KVdnDO8rlDFfCJBm4aSK/qzOxDCkBU7o05DYmSlywd7CKs4Tjdv4 ukCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uxihFy3jRjyF4IIfuuRuE9+EnA2kbJYXXHsvttdZmDI=; b=FCcfD61t+J1HaDqmSMgX1fX0XC3bbxzbeWhPnZAtztnu9rw2mog8AkgEnE5wwIPzvp Zo0P0T21rJxCwlLyW4Xh74IBNrk1u4gTkWq8rxn0ZrnONWzRYvk9/0Wp6kKNsKcxnHyE cpTFGCQdwWgYmkuuF48fb7g/pXQk6oJ8EOUMePuaVjc/8x2asEWlLXJHViIxS0ZjJhRW DQivmVi9y+fnYPOFC4bmJ23walBvHT+Jr3VyUoUJC+yOCNCBMl8XDylBG07pPucb/c22 vE5cf2lpskQFWX9S0u6wfvMucM9coOVuRnBFg9mJzY08ncDww9/fVKVKSmFmUACAoeoQ aiPA== X-Gm-Message-State: AOAM5304xuPiSmgL2xmocaPbKlklRsuufEy/sTznmIZvbql7b/NBATrU 56AUGbqL0IaKmZb+iqRPfeftgyuwKD3tdQ== X-Google-Smtp-Source: ABdhPJwUzxYfPZyOcF8OSS7FkmHUQ5bhF+NiD/Mw73lSSS83ynUBj+eSQZmQjumy49kXv4V6WdihZA== X-Received: by 2002:a63:78b:: with SMTP id 133mr428682pgh.381.1601047254974; Fri, 25 Sep 2020 08:20:54 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id a5sm2717859pgk.13.2020.09.25.08.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 08:20:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 04/10] softfloat: Add float_cmask and constants Date: Fri, 25 Sep 2020 08:20:41 -0700 Message-Id: <20200925152047.709901-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925152047.709901-1-richard.henderson@linaro.org> References: <20200925152047.709901-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bharata@linux.ibm.com, alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Testing more than one class at a time is better done with masks. This reduces the static branch count. Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- fpu/softfloat.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 9db55d2b11..3e625c47cd 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -469,6 +469,20 @@ typedef enum __attribute__ ((__packed__)) { float_class_snan, } FloatClass; +#define float_cmask(bit) (1u << (bit)) + +enum { + float_cmask_zero = float_cmask(float_class_zero), + float_cmask_normal = float_cmask(float_class_normal), + float_cmask_inf = float_cmask(float_class_inf), + float_cmask_qnan = float_cmask(float_class_qnan), + float_cmask_snan = float_cmask(float_class_snan), + + float_cmask_infzero = float_cmask_zero | float_cmask_inf, + float_cmask_anynan = float_cmask_qnan | float_cmask_snan, +}; + + /* Simple helpers for checking if, or what kind of, NaN we have */ static inline __attribute__((unused)) bool is_nan(FloatClass c) { @@ -1335,24 +1349,27 @@ bfloat16 QEMU_FLATTEN bfloat16_mul(bfloat16 a, bfloat16 b, float_status *status) static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c, int flags, float_status *s) { - bool inf_zero = ((1 << a.cls) | (1 << b.cls)) == - ((1 << float_class_inf) | (1 << float_class_zero)); - bool p_sign; + bool inf_zero, p_sign; bool sign_flip = flags & float_muladd_negate_result; FloatClass p_class; uint64_t hi, lo; int p_exp; + int ab_mask, abc_mask; + + ab_mask = float_cmask(a.cls) | float_cmask(b.cls); + abc_mask = float_cmask(c.cls) | ab_mask; + inf_zero = ab_mask == float_cmask_infzero; /* It is implementation-defined whether the cases of (0,inf,qnan) * and (inf,0,qnan) raise InvalidOperation or not (and what QNaN * they return if they do), so we have to hand this information * off to the target-specific pick-a-NaN routine. */ - if (is_nan(a.cls) || is_nan(b.cls) || is_nan(c.cls)) { + if (unlikely(abc_mask & float_cmask_anynan)) { return pick_nan_muladd(a, b, c, inf_zero, s); } - if (inf_zero) { + if (unlikely(inf_zero)) { s->float_exception_flags |= float_flag_invalid; return parts_default_nan(s); } @@ -1367,9 +1384,9 @@ static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c, p_sign ^= 1; } - if (a.cls == float_class_inf || b.cls == float_class_inf) { + if (ab_mask & float_cmask_inf) { p_class = float_class_inf; - } else if (a.cls == float_class_zero || b.cls == float_class_zero) { + } else if (ab_mask & float_cmask_zero) { p_class = float_class_zero; } else { p_class = float_class_normal; From patchwork Fri Sep 25 15:20:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 304396 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6F43C4727D for ; Fri, 25 Sep 2020 15:30:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 511F9235F9 for ; Fri, 25 Sep 2020 15:30:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OiKnVN91" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 511F9235F9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLpfs-0001Ie-Dp for qemu-devel@archiver.kernel.org; Fri, 25 Sep 2020 11:30:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLpWt-00013i-RT for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:20:59 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:35903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLpWs-0005RI-1A for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:20:59 -0400 Received: by mail-pf1-x441.google.com with SMTP id d9so3520005pfd.3 for ; Fri, 25 Sep 2020 08:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UqQqsLP6qYPuAh+FMkFGchn7mynGi7GNJsDQP3A30QE=; b=OiKnVN91aBweyamlSCjk0SaZouoMY1iYZUf3pZWoda1TxCUEC8IdUtYaH6L1nrFCYY KP32aPS1nYAv52mgEJimPKWzySn4WHNheeizJlD0oEz/Tg2bxbsA30+7hAPAeqn6nve9 Cfxb1qfVzXfrz9GGjv/Jt+v0ODO1nOP1N8OjRLDry29TnEHfz4GQ1nVrfYe8Fazot11I 17y+i7u6zd3/uNg/QaGQBJyikSVVVBXWdLroV7LGhSLNfHjaV7PU5SezhvwUjNnF05EP G8O2bNFj+EOv1TiuAsZqvkXz3Zeo47VUYS9VJsFUMinXbU1ZNRWLs+QaNwxkJ/oZIYTZ dPLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UqQqsLP6qYPuAh+FMkFGchn7mynGi7GNJsDQP3A30QE=; b=FnnTlZxGxKkCvUuvCoXzVH8LMeddDIlC2gFwAWQzUxSEhw2nho8khVgNorcZlLd4Yr MfRziTFWUliB0kkQBDDN56ltmLKWHvCMO8mnAfaEmlaMJX7+qSukgsJ6hQ9hiNV+yWkK kTdkaZSVQQErwUvB3bC0Qwcj+fO4XTxEIGF07pH8b5caGZ/0pyFKlNkAYKJpM6SldYzk RNjGFPSUeqRhXBO+Cpq5g/r/KPOvHgw6inYv+UnGv+GsitrTmf2P7Y+R9aF6BZVuLZHZ 5JmiHRgmymyCMCn6B9C3EUyKEsg33VsPjifeGZnSlKkXEgDmfxus1Pf4EYVX6LDccL4g CT6g== X-Gm-Message-State: AOAM531tBsIJnHcV8hpZYzdeomsaN89bs4rtoi5Ckgkzj1ThzdZPUI61 XERRQcCtyRYC5tRj388PciWGbzKH1lOK6A== X-Google-Smtp-Source: ABdhPJzOcwpx0gcIDdFnWkfdUPaWe5iqpKyxO3QIEuYD2zJ0NfzhA1wuSM0E+9G4Ony0d3WI4+3FSQ== X-Received: by 2002:a62:7b94:0:b029:142:2501:35e4 with SMTP id w142-20020a627b940000b0290142250135e4mr4582809pfc.68.1601047256226; Fri, 25 Sep 2020 08:20:56 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id a5sm2717859pgk.13.2020.09.25.08.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 08:20:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 05/10] softfloat: Inline pick_nan_muladd into its caller Date: Fri, 25 Sep 2020 08:20:42 -0700 Message-Id: <20200925152047.709901-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925152047.709901-1-richard.henderson@linaro.org> References: <20200925152047.709901-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bharata@linux.ibm.com, alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Because of FloatParts, there will only ever be one caller. Inlining allows us to re-use abc_mask for the snan test. Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson --- fpu/softfloat.c | 75 +++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 3e625c47cd..e038434a07 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -929,45 +929,6 @@ static FloatParts pick_nan(FloatParts a, FloatParts b, float_status *s) return a; } -static FloatParts pick_nan_muladd(FloatParts a, FloatParts b, FloatParts c, - bool inf_zero, float_status *s) -{ - int which; - - if (is_snan(a.cls) || is_snan(b.cls) || is_snan(c.cls)) { - s->float_exception_flags |= float_flag_invalid; - } - - which = pickNaNMulAdd(a.cls, b.cls, c.cls, inf_zero, s); - - if (s->default_nan_mode) { - /* Note that this check is after pickNaNMulAdd so that function - * has an opportunity to set the Invalid flag. - */ - which = 3; - } - - switch (which) { - case 0: - break; - case 1: - a = b; - break; - case 2: - a = c; - break; - case 3: - return parts_default_nan(s); - default: - g_assert_not_reached(); - } - - if (is_snan(a.cls)) { - return parts_silence_nan(a, s); - } - return a; -} - /* * Returns the result of adding or subtracting the values of the * floating-point values `a' and `b'. The operation is performed @@ -1366,7 +1327,41 @@ static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c, * off to the target-specific pick-a-NaN routine. */ if (unlikely(abc_mask & float_cmask_anynan)) { - return pick_nan_muladd(a, b, c, inf_zero, s); + int which; + + if (unlikely(abc_mask & float_cmask_snan)) { + float_raise(float_flag_invalid, s); + } + + which = pickNaNMulAdd(a.cls, b.cls, c.cls, inf_zero, s); + + if (s->default_nan_mode) { + /* + * Note that this check is after pickNaNMulAdd so that function + * has an opportunity to set the Invalid flag for inf_zero. + */ + which = 3; + } + + switch (which) { + case 0: + break; + case 1: + a = b; + break; + case 2: + a = c; + break; + case 3: + return parts_default_nan(s); + default: + g_assert_not_reached(); + } + + if (is_snan(a.cls)) { + return parts_silence_nan(a, s); + } + return a; } if (unlikely(inf_zero)) { From patchwork Fri Sep 25 15:20:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 304395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EBA0C4363D for ; Fri, 25 Sep 2020 15:33:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B3B520878 for ; Fri, 25 Sep 2020 15:33:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DfH0PnmO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B3B520878 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLpie-0003su-MV for qemu-devel@archiver.kernel.org; Fri, 25 Sep 2020 11:33:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLpX3-0001C4-S4 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:21:10 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:39335) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLpWv-0005Rg-EA for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:21:08 -0400 Received: by mail-pg1-x52e.google.com with SMTP id d13so2858870pgl.6 for ; Fri, 25 Sep 2020 08:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zvybnY1s2mhvbUfv1u1LxWyNi6dAzmSLhIeilyMRabs=; b=DfH0PnmOuG4uC9lp3V0SzThWm7AyCQRMHcLgHYgUDVl3HLYELOrlJehzK/i9mhjTWs IL7wTgAYA2Zo3Z6Cx8rAOFfvwujGT6eCPzDIdmescbNecjh8YoOpQK5sKLSKMTmROPIw 0Ew2YUXLfNx1ENJFfTK3DETQMeFNSBj4ucedVc2krG5lC1BzEUEyAyTIZQrRV20bQNSL F8rAoscHdyrQ+G/6qbUjjyv4IWn27OZ2ErPHoUJopR4Z6lWk2WCSt8drNHGMuL9af5ZJ dxYuULK1hLcaFxDqOs+55RcgZ43ui5ZwEaCZh/2z1p+LMEkl0+hkuzpMM/6wBrfjx1ZV Y7Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zvybnY1s2mhvbUfv1u1LxWyNi6dAzmSLhIeilyMRabs=; b=cWyJXelB7lbQBWnEuzGxg95Iy7mmZrf4DGJc1+JPOEiqUv9Gc7isiKXbQd92cGwpR/ znqhvK5TYXlXHKnwML6uW1vZ1lL+z6i/wWhfihwBLT820BG5nzkOxvDrE/WLItUE3Bol 8kkxkRmhkMG5hhNG5nMtJTRn2S1+II6TQSWUds6LAhGRmCV+gNbc168tH5sATf8h+U4p bLwgfiGSNFWAF38sMT1uy1ToJoEgSbJaWREawNYkuKgNA4zj7Qfy1OwuRiesfBqsFdtF ZiUfvh3wy3gwetwhgRrwqd2as/L30r8kR4VFyiiDK9gTh3c7U68GdMwNeGc1dwgYSpBs yDJQ== X-Gm-Message-State: AOAM533pXnNeISZ6VAvBk5tiKVILkKEwAc+tfvcOsJ2dtcVx/ZREO5ee 1x43zW/2OnZHbQEAGbKz3ljW/sfJUQZ7EQ== X-Google-Smtp-Source: ABdhPJwyLVlec+j1Py++fqic64/0TS91bv+9Bjkcq+hIJwZpDvsUdQ+m808tehO2w6+TAZ+t3amX7Q== X-Received: by 2002:a05:6a00:22d4:b029:150:bd5d:ce11 with SMTP id f20-20020a056a0022d4b0290150bd5dce11mr4537140pfj.38.1601047258117; Fri, 25 Sep 2020 08:20:58 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id a5sm2717859pgk.13.2020.09.25.08.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 08:20:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 06/10] softfloat: Implement float128_muladd Date: Fri, 25 Sep 2020 08:20:43 -0700 Message-Id: <20200925152047.709901-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925152047.709901-1-richard.henderson@linaro.org> References: <20200925152047.709901-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bharata@linux.ibm.com, alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- include/fpu/softfloat.h | 2 + fpu/softfloat.c | 416 +++++++++++++++++++++++++++++++++++++++- tests/fp/fp-test.c | 2 +- tests/fp/wrap.c.inc | 12 ++ 4 files changed, 430 insertions(+), 2 deletions(-) diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 78ad5ca738..a38433deb4 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -1196,6 +1196,8 @@ float128 float128_sub(float128, float128, float_status *status); float128 float128_mul(float128, float128, float_status *status); float128 float128_div(float128, float128, float_status *status); float128 float128_rem(float128, float128, float_status *status); +float128 float128_muladd(float128, float128, float128, int, + float_status *status); float128 float128_sqrt(float128, float_status *status); FloatRelation float128_compare(float128, float128, float_status *status); FloatRelation float128_compare_quiet(float128, float128, float_status *status); diff --git a/fpu/softfloat.c b/fpu/softfloat.c index e038434a07..49de31fec2 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -512,11 +512,19 @@ static inline __attribute__((unused)) bool is_qnan(FloatClass c) typedef struct { uint64_t frac; - int32_t exp; + int32_t exp; FloatClass cls; bool sign; } FloatParts; +/* Similar for float128. */ +typedef struct { + uint64_t frac0, frac1; + int32_t exp; + FloatClass cls; + bool sign; +} FloatParts128; + #define DECOMPOSED_BINARY_POINT (64 - 2) #define DECOMPOSED_IMPLICIT_BIT (1ull << DECOMPOSED_BINARY_POINT) #define DECOMPOSED_OVERFLOW_BIT (DECOMPOSED_IMPLICIT_BIT << 1) @@ -4574,6 +4582,46 @@ static void } +/*---------------------------------------------------------------------------- +| Returns the parts of floating-point value `a'. +*----------------------------------------------------------------------------*/ + +static void float128_unpack(FloatParts128 *p, float128 a, float_status *status) +{ + p->sign = extractFloat128Sign(a); + p->exp = extractFloat128Exp(a); + p->frac0 = extractFloat128Frac0(a); + p->frac1 = extractFloat128Frac1(a); + + if (p->exp == 0) { + if ((p->frac0 | p->frac1) == 0) { + p->cls = float_class_zero; + } else if (status->flush_inputs_to_zero) { + float_raise(float_flag_input_denormal, status); + p->cls = float_class_zero; + p->frac0 = p->frac1 = 0; + } else { + normalizeFloat128Subnormal(p->frac0, p->frac1, &p->exp, + &p->frac0, &p->frac1); + p->exp -= 0x3fff; + p->cls = float_class_normal; + } + } else if (p->exp == 0x7fff) { + if ((p->frac0 | p->frac1) == 0) { + p->cls = float_class_inf; + } else if (float128_is_signaling_nan(a, status)) { + p->cls = float_class_snan; + } else { + p->cls = float_class_qnan; + } + } else { + /* Add the implicit bit. */ + p->frac0 |= UINT64_C(0x0001000000000000); + p->exp -= 0x3fff; + p->cls = float_class_normal; + } +} + /*---------------------------------------------------------------------------- | Packs the sign `zSign', the exponent `zExp', and the significand formed | by the concatenation of `zSig0' and `zSig1' into a quadruple-precision @@ -7205,6 +7253,372 @@ float128 float128_mul(float128 a, float128 b, float_status *status) } +typedef struct UInt256 { + /* Indexed big-endian, to match the rest of softfloat numbering. */ + uint64_t w[4]; +} UInt256; + +static inline uint64_t shl_double(uint64_t h, uint64_t l, unsigned lsh) +{ + return lsh ? (h << lsh) | (l >> (64 - lsh)) : h; +} + +static inline uint64_t shr_double(uint64_t h, uint64_t l, unsigned rsh) +{ + return rsh ? (h << (64 - rsh)) | (l >> rsh) : l; +} + +static void shortShift256Left(UInt256 *p, unsigned lsh) +{ + if (lsh != 0) { + p->w[0] = shl_double(p->w[0], p->w[1], lsh); + p->w[1] = shl_double(p->w[1], p->w[2], lsh); + p->w[2] = shl_double(p->w[2], p->w[3], lsh); + p->w[3] <<= lsh; + } +} + +static inline void shift256RightJamming(UInt256 *p, unsigned count) +{ + uint64_t out, p0, p1, p2, p3; + + p0 = p->w[0]; + p1 = p->w[1]; + p2 = p->w[2]; + p3 = p->w[3]; + + if (unlikely(count == 0)) { + return; + } else if (likely(count < 64)) { + out = 0; + } else if (likely(count < 256)) { + if (count < 128) { + out = p3; + p3 = p2; + p2 = p1; + p1 = p0; + p0 = 0; + } else if (count < 192) { + out = p2 | p3; + p3 = p1; + p2 = p0; + p1 = 0; + p0 = 0; + } else { + out = p1 | p2 | p3; + p3 = p0; + p2 = 0; + p1 = 0; + p0 = 0; + } + count &= 63; + if (count == 0) { + goto done; + } + } else { + out = p0 | p1 | p2 | p3; + p3 = 0; + p2 = 0; + p1 = 0; + p0 = 0; + goto done; + } + + out |= shr_double(p3, 0, count); + p3 = shr_double(p2, p3, count); + p2 = shr_double(p1, p2, count); + p1 = shr_double(p0, p1, count); + p0 = p0 >> count; + + done: + p->w[3] = p3 | (out != 0); + p->w[2] = p2; + p->w[1] = p1; + p->w[0] = p0; +} + +/* R = A - B */ +static void sub256(UInt256 *r, UInt256 *a, UInt256 *b) +{ + bool borrow = false; + + for (int i = 3; i >= 0; --i) { + uint64_t at = a->w[i]; + uint64_t bt = b->w[i]; + uint64_t rt = at - bt; + + if (borrow) { + borrow = at <= bt; + rt -= 1; + } else { + borrow = at < bt; + } + r->w[i] = rt; + } +} + +/* A = -A */ +static void neg256(UInt256 *a) +{ + /* + * Recall that -X - 1 = ~X, and that since this is negation, + * once we find a non-zero number, all subsequent words will + * have borrow-in, and thus use NOT. + */ + uint64_t t = a->w[3]; + if (likely(t)) { + a->w[3] = -t; + goto not2; + } + t = a->w[2]; + if (likely(t)) { + a->w[2] = -t; + goto not1; + } + t = a->w[1]; + if (likely(t)) { + a->w[1] = -t; + goto not0; + } + a->w[0] = -a->w[0]; + return; + not2: + a->w[2] = ~a->w[2]; + not1: + a->w[1] = ~a->w[1]; + not0: + a->w[0] = ~a->w[0]; +} + +/* A += B */ +static void add256(UInt256 *a, UInt256 *b) +{ + bool carry = false; + + for (int i = 3; i >= 0; --i) { + uint64_t bt = b->w[i]; + uint64_t at = a->w[i] + bt; + + if (carry) { + at += 1; + carry = at <= bt; + } else { + carry = at < bt; + } + a->w[i] = at; + } +} + +float128 float128_muladd(float128 a_f, float128 b_f, float128 c_f, + int flags, float_status *status) +{ + bool inf_zero, p_sign, sign_flip; + int p_exp, exp_diff, shift, ab_mask, abc_mask; + FloatParts128 a, b, c; + FloatClass p_cls; + UInt256 p_frac, c_frac; + + float128_unpack(&a, a_f, status); + float128_unpack(&b, b_f, status); + float128_unpack(&c, c_f, status); + + ab_mask = float_cmask(a.cls) | float_cmask(b.cls); + abc_mask = float_cmask(c.cls) | ab_mask; + inf_zero = ab_mask == float_cmask_infzero; + + /* If any input is a NaN, select the required result. */ + if (unlikely(abc_mask & float_cmask_anynan)) { + if (unlikely(abc_mask & float_cmask_snan)) { + float_raise(float_flag_invalid, status); + } + + int which = pickNaNMulAdd(a.cls, b.cls, c.cls, inf_zero, status); + if (status->default_nan_mode) { + which = 3; + } + switch (which) { + case 0: + break; + case 1: + a_f = b_f; + a.cls = b.cls; + break; + case 2: + a_f = c_f; + a.cls = c.cls; + break; + case 3: + return float128_default_nan(status); + } + if (is_snan(a.cls)) { + return float128_silence_nan(a_f, status); + } + return a_f; + } + + /* After dealing with input NaNs, look for Inf * Zero. */ + if (unlikely(inf_zero)) { + float_raise(float_flag_invalid, status); + return float128_default_nan(status); + } + + p_sign = a.sign ^ b.sign; + + if (flags & float_muladd_negate_c) { + c.sign ^= 1; + } + if (flags & float_muladd_negate_product) { + p_sign ^= 1; + } + sign_flip = (flags & float_muladd_negate_result); + + if (ab_mask & float_cmask_inf) { + p_cls = float_class_inf; + } else if (ab_mask & float_cmask_zero) { + p_cls = float_class_zero; + } else { + p_cls = float_class_normal; + } + + if (c.cls == float_class_inf) { + if (p_cls == float_class_inf && p_sign != c.sign) { + /* +Inf + -Inf = NaN */ + float_raise(float_flag_invalid, status); + return float128_default_nan(status); + } + /* Inf + Inf = Inf of the proper sign; reuse the return below. */ + p_cls = float_class_inf; + p_sign = c.sign; + } + + if (p_cls == float_class_inf) { + return packFloat128(p_sign ^ sign_flip, 0x7fff, 0, 0); + } + + if (p_cls == float_class_zero) { + if (c.cls == float_class_zero) { + if (p_sign != c.sign) { + p_sign = status->float_rounding_mode == float_round_down; + } + return packFloat128(p_sign ^ sign_flip, 0, 0, 0); + } + + if (flags & float_muladd_halve_result) { + c.exp -= 1; + } + return roundAndPackFloat128(c.sign ^ sign_flip, + c.exp + 0x3fff - 1, + c.frac0, c.frac1, 0, status); + } + + /* a & b should be normals now... */ + assert(a.cls == float_class_normal && b.cls == float_class_normal); + + /* Multiply of 2 113-bit numbers produces a 226-bit result. */ + mul128To256(a.frac0, a.frac1, b.frac0, b.frac1, + &p_frac.w[0], &p_frac.w[1], &p_frac.w[2], &p_frac.w[3]); + + /* Realign the binary point at bit 48 of p_frac[0]. */ + shift = clz64(p_frac.w[0]) - 15; + shortShift256Left(&p_frac, shift); + p_exp = a.exp + b.exp - (shift - 16); + exp_diff = p_exp - c.exp; + + /* Extend the fraction part of the addend to 256 bits. */ + c_frac.w[0] = c.frac0; + c_frac.w[1] = c.frac1; + c_frac.w[2] = 0; + c_frac.w[3] = 0; + + /* Add or subtract C from the intermediate product. */ + if (c.cls == float_class_zero) { + /* Fall through to rounding after addition (with zero). */ + } else if (p_sign != c.sign) { + /* Subtraction */ + if (exp_diff < 0) { + shift256RightJamming(&p_frac, -exp_diff); + sub256(&p_frac, &c_frac, &p_frac); + p_exp = c.exp; + p_sign ^= 1; + } else if (exp_diff > 0) { + shift256RightJamming(&c_frac, exp_diff); + sub256(&p_frac, &p_frac, &c_frac); + } else { + /* Low 128 bits of C are known to be zero. */ + sub128(p_frac.w[0], p_frac.w[1], c_frac.w[0], c_frac.w[1], + &p_frac.w[0], &p_frac.w[1]); + /* + * Since we have normalized to bit 48 of p_frac[0], + * a negative result means C > P and we need to invert. + */ + if ((int64_t)p_frac.w[0] < 0) { + neg256(&p_frac); + p_sign ^= 1; + } + } + + /* + * Gross normalization of the 256-bit subtraction result. + * Fine tuning below shared with addition. + */ + if (p_frac.w[0] != 0) { + /* nothing to do */ + } else if (p_frac.w[1] != 0) { + p_exp -= 64; + p_frac.w[0] = p_frac.w[1]; + p_frac.w[1] = p_frac.w[2]; + p_frac.w[2] = p_frac.w[3]; + p_frac.w[3] = 0; + } else if (p_frac.w[2] != 0) { + p_exp -= 128; + p_frac.w[0] = p_frac.w[2]; + p_frac.w[1] = p_frac.w[3]; + p_frac.w[2] = 0; + p_frac.w[3] = 0; + } else if (p_frac.w[3] != 0) { + p_exp -= 192; + p_frac.w[0] = p_frac.w[3]; + p_frac.w[1] = 0; + p_frac.w[2] = 0; + p_frac.w[3] = 0; + } else { + /* Subtraction was exact: result is zero. */ + p_sign = status->float_rounding_mode == float_round_down; + return packFloat128(p_sign ^ sign_flip, 0, 0, 0); + } + } else { + /* Addition */ + if (exp_diff <= 0) { + shift256RightJamming(&p_frac, -exp_diff); + /* Low 128 bits of C are known to be zero. */ + add128(p_frac.w[0], p_frac.w[1], c_frac.w[0], c_frac.w[1], + &p_frac.w[0], &p_frac.w[1]); + p_exp = c.exp; + } else { + shift256RightJamming(&c_frac, exp_diff); + add256(&p_frac, &c_frac); + } + } + + /* Fine normalization of the 256-bit result: p_frac[0] != 0. */ + shift = clz64(p_frac.w[0]) - 15; + if (shift < 0) { + shift256RightJamming(&p_frac, -shift); + } else if (shift > 0) { + shortShift256Left(&p_frac, shift); + } + p_exp -= shift; + + if (flags & float_muladd_halve_result) { + p_exp -= 1; + } + return roundAndPackFloat128(p_sign ^ sign_flip, + p_exp + 0x3fff - 1, + p_frac.w[0], p_frac.w[1], + p_frac.w[2] | (p_frac.w[3] != 0), + status); +} + /*---------------------------------------------------------------------------- | Returns the result of dividing the quadruple-precision floating-point value | `a' by the corresponding value `b'. The operation is performed according to diff --git a/tests/fp/fp-test.c b/tests/fp/fp-test.c index 06ffebd6db..9bbb0dba67 100644 --- a/tests/fp/fp-test.c +++ b/tests/fp/fp-test.c @@ -717,7 +717,7 @@ static void do_testfloat(int op, int rmode, bool exact) test_abz_f128(true_abz_f128M, subj_abz_f128M); break; case F128_MULADD: - not_implemented(); + test_abcz_f128(slow_f128M_mulAdd, qemu_f128_mulAdd); break; case F128_SQRT: test_az_f128(slow_f128M_sqrt, qemu_f128M_sqrt); diff --git a/tests/fp/wrap.c.inc b/tests/fp/wrap.c.inc index 0cbd20013e..65a713deae 100644 --- a/tests/fp/wrap.c.inc +++ b/tests/fp/wrap.c.inc @@ -574,6 +574,18 @@ WRAP_MULADD(qemu_f32_mulAdd, float32_muladd, float32) WRAP_MULADD(qemu_f64_mulAdd, float64_muladd, float64) #undef WRAP_MULADD +static void qemu_f128_mulAdd(const float128_t *ap, const float128_t *bp, + const float128_t *cp, float128_t *res) +{ + float128 a, b, c, ret; + + a = soft_to_qemu128(*ap); + b = soft_to_qemu128(*bp); + c = soft_to_qemu128(*cp); + ret = float128_muladd(a, b, c, 0, &qsf); + *res = qemu_to_soft128(ret); +} + #define WRAP_CMP16(name, func, retcond) \ static bool name(float16_t a, float16_t b) \ { \ From patchwork Fri Sep 25 15:20:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 272716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB070C4363D for ; Fri, 25 Sep 2020 15:23:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 44DF520878 for ; Fri, 25 Sep 2020 15:23:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="s8V/9v2c" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44DF520878 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLpZH-00031g-EL for qemu-devel@archiver.kernel.org; Fri, 25 Sep 2020 11:23:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLpWx-000196-1n for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:21:03 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:39080) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLpWv-0005Rc-4V for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:21:02 -0400 Received: by mail-pf1-x435.google.com with SMTP id n14so3504978pff.6 for ; Fri, 25 Sep 2020 08:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3yQCWJz2XvIuWxIxwKUVSmwsGHFnvzDWcrT0q0novuc=; b=s8V/9v2c+fxdUT7wzmHcNArfgaI6fis0aoSnwOCIHhHE2VHpQEll+Kh725N7WdJek1 /w7qyKIWtpWFoHC1gCul7lUc9WML3zQ/8u2pm/fKyMObcXweGaf9in6dFcSR00GDpk1V dbmRwlE8rDiWvbnR36RFG5GRsd4fwjwxdCEXvGUAoxe/0cZVpoXIa81tp96lBiWZ5G5E FtfH9WO6+zw+XWjcQmsWklseuh1oBAEt6M5d+6M5p8nHNzVd4c1zIyIby09iJuLoGYYH zbFZcsbvd3xr7ShpKv3ZPB1DHegpR9Z7sy6LJEgpoa23uA7CTIGGA3JdoYBQ2Mz/JQ0l x15g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3yQCWJz2XvIuWxIxwKUVSmwsGHFnvzDWcrT0q0novuc=; b=lnFqaswhbRGeXj8d/KVMa3GogZ0ZKcdADMPBVr1NCiXVUCDwu3TWD1sJ5vmoTpNZKZ e6+ryGOhcDeq4p1U2NRVHUn7c6vdFNe3zc7F1XXnFvEhBqJOunA7etkRuMYlnVbQeiKc 87w9Ubt5i3s/jfhvR3qTZrhwWNjWnY16MIK/Imxxk44vpUYIhs5GODPOc6dCYluFjFE6 bmQLOpT6vJ7m2DoWfL4L8+pDcH5hU3Gj4DsWMWaQpq39GiegPB+zuL3x8fI+nmC2nQuI C+8lxGL0OEuFTwuxltiNf7PwcY/TBE9vXP3pd3HNxQNe3RzSgsV3j20gfwH8rz64kEqE 7wPw== X-Gm-Message-State: AOAM5317YdnFUNlEn4Advm9HDFW6hgXpV4w2sylXnhXsDEf1M1SILqdA m0YwZFnej+vihfamJMOhLacnZa8MqlOodg== X-Google-Smtp-Source: ABdhPJymvICOJtSEwIcHtiLNPY3X5CxysTpja1ByzlGLTOg3cA3KB/KkLLhaE6YLlIKj63Nd9N66Mw== X-Received: by 2002:a17:902:309:b029:d1:e5e7:ca3f with SMTP id 9-20020a1709020309b02900d1e5e7ca3fmr5065160pld.43.1601047259306; Fri, 25 Sep 2020 08:20:59 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id a5sm2717859pgk.13.2020.09.25.08.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 08:20:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 07/10] softfloat: Use x86_64 assembly for {add, sub}{192, 256} Date: Fri, 25 Sep 2020 08:20:44 -0700 Message-Id: <20200925152047.709901-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925152047.709901-1-richard.henderson@linaro.org> References: <20200925152047.709901-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bharata@linux.ibm.com, alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The compiler cannot chain more than two additions together. Use inline assembly for 3 or 4 additions. Signed-off-by: Richard Henderson --- include/fpu/softfloat-macros.h | 18 ++++++++++++++++-- fpu/softfloat.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h index 95d88d05b8..99fa124e56 100644 --- a/include/fpu/softfloat-macros.h +++ b/include/fpu/softfloat-macros.h @@ -436,6 +436,13 @@ static inline void uint64_t *z2Ptr ) { +#ifdef __x86_64__ + asm("add %5, %2\n\t" + "adc %4, %1\n\t" + "adc %3, %0" + : "=&r"(*z0Ptr), "=&r"(*z1Ptr), "=&r"(*z2Ptr) + : "rm"(b0), "rm"(b1), "rm"(b2), "0"(a0), "1"(a1), "2"(a2)); +#else uint64_t z0, z1, z2; int8_t carry0, carry1; @@ -450,7 +457,7 @@ static inline void *z2Ptr = z2; *z1Ptr = z1; *z0Ptr = z0; - +#endif } /*---------------------------------------------------------------------------- @@ -494,6 +501,13 @@ static inline void uint64_t *z2Ptr ) { +#ifdef __x86_64__ + asm("sub %5, %2\n\t" + "sbb %4, %1\n\t" + "sbb %3, %0" + : "=&r"(*z0Ptr), "=&r"(*z1Ptr), "=&r"(*z2Ptr) + : "rm"(b0), "rm"(b1), "rm"(b2), "0"(a0), "1"(a1), "2"(a2)); +#else uint64_t z0, z1, z2; int8_t borrow0, borrow1; @@ -508,7 +522,7 @@ static inline void *z2Ptr = z2; *z1Ptr = z1; *z0Ptr = z0; - +#endif } /*---------------------------------------------------------------------------- diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 49de31fec2..54d0b210ac 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -7340,6 +7340,15 @@ static inline void shift256RightJamming(UInt256 *p, unsigned count) /* R = A - B */ static void sub256(UInt256 *r, UInt256 *a, UInt256 *b) { +#if defined(__x86_64__) + asm("sub %7, %3\n\t" + "sbb %6, %2\n\t" + "sbb %5, %1\n\t" + "sbb %4, %0" + : "=&r"(r->w[0]), "=&r"(r->w[1]), "=&r"(r->w[2]), "=&r"(r->w[3]) + : "rme"(b->w[0]), "rme"(b->w[1]), "rme"(b->w[2]), "rme"(b->w[3]), + "0"(a->w[0]), "1"(a->w[1]), "2"(a->w[2]), "3"(a->w[3])); +#else bool borrow = false; for (int i = 3; i >= 0; --i) { @@ -7355,11 +7364,21 @@ static void sub256(UInt256 *r, UInt256 *a, UInt256 *b) } r->w[i] = rt; } +#endif } /* A = -A */ static void neg256(UInt256 *a) { +#if defined(__x86_64__) + asm("negq %3\n\t" + "sbb %6, %2\n\t" + "sbb %5, %1\n\t" + "sbb %4, %0" + : "=&r"(a->w[0]), "=&r"(a->w[1]), "=&r"(a->w[2]), "+rm"(a->w[3]) + : "rme"(a->w[0]), "rme"(a->w[1]), "rme"(a->w[2]), + "0"(0), "1"(0), "2"(0)); +#else /* * Recall that -X - 1 = ~X, and that since this is negation, * once we find a non-zero number, all subsequent words will @@ -7388,11 +7407,20 @@ static void neg256(UInt256 *a) a->w[1] = ~a->w[1]; not0: a->w[0] = ~a->w[0]; +#endif } /* A += B */ static void add256(UInt256 *a, UInt256 *b) { +#if defined(__x86_64__) + asm("add %7, %3\n\t" + "adc %6, %2\n\t" + "adc %5, %1\n\t" + "adc %4, %0" + : "+r"(a->w[0]), "+r"(a->w[1]), "+r"(a->w[2]), "+r"(a->w[3]) + : "rme"(b->w[0]), "rme"(b->w[1]), "rme"(b->w[2]), "rme"(b->w[3])); +#else bool carry = false; for (int i = 3; i >= 0; --i) { @@ -7407,6 +7435,7 @@ static void add256(UInt256 *a, UInt256 *b) } a->w[i] = at; } +#endif } float128 float128_muladd(float128 a_f, float128 b_f, float128 c_f, From patchwork Fri Sep 25 15:20:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 272713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E933BC4363D for ; Fri, 25 Sep 2020 15:31:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4518720878 for ; Fri, 25 Sep 2020 15:31:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="s2jX6yv6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4518720878 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLph1-0002Lq-8l for qemu-devel@archiver.kernel.org; Fri, 25 Sep 2020 11:31:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLpX3-0001C5-SC for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:21:10 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:37194) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLpWw-0005Ru-9B for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:21:09 -0400 Received: by mail-pf1-x441.google.com with SMTP id w7so3519781pfi.4 for ; Fri, 25 Sep 2020 08:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mpMuefpfKDSRa7HcV8+nIrrA4a3VHPfcVNzq0zqqZrA=; b=s2jX6yv6L6/OYkKhCLJhUKpvPgP6Qh3E4zUP/V/2J9EQboIuqhHH2Vniu9Lq8NJWKm b2ViiQWtzIxldMab9CixRJ7K5xqlrL804mf3CY+WXCC6mG7XU8mDsCBKQ3S/j0nlIAlW LOP62ur7H24YihB0umcT7SgHKQb9TKA7p20qAlk1dh6ItKOXGHXOphhwSv4Wn+NmFfG6 z16TpL1nWQP/d4U8pLWb3USIXctxjC6qzKN2cmjvZOELjKXMpJDuNgmFBr2nHKBTwoa8 wwa02ubeiEZPc/pQqtFl0kdZYwqPTzmydBSLlMWkSZYcCZTcQjKjcmf+IQ/9YVFfjqBg JDJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mpMuefpfKDSRa7HcV8+nIrrA4a3VHPfcVNzq0zqqZrA=; b=TYHr62WsTefMf7chK98eYSpaYeQ8gmJMQgHpnU9dsmdLcF1mMM2jUEmKMZcN7jW6ka vio3EzvRMLkAmzIS5EwsI0Itof9c2FKQdsVleO899b+7AKooT9QQorEJXrtJKU0b738v 9hTNLEQ5eyMD59aeyt9O/lHdsY7Aulrxk6kkQTkU7RVIKo8FUUzGXiiycF+Jjk3t6wSU Hgk+pE3yj3wWbL8I2mZqWORkXtUBgsyAUlui1+cyg70SX5dXgY7mrXNBwQlOrt0CyU9Q Ye1aUduFhoIlPTx3oq3TbN6tuUqHAaAW7wfApgsUklYh2rboditT0OriOZOozRSe176Z XGyQ== X-Gm-Message-State: AOAM531frLK4nsEsrzxab5gEw5meJGqRBPpsTHvuADNB09pdZ6oAH8cR ZYSXJk4hmzsfzzPEmkZpv+ZUxanWuL4Vug== X-Google-Smtp-Source: ABdhPJzehvrMKHj33fbqTtrMScVPTlqFQMlemzbuahlLQ8PdWsvK6TgXkKViP4O/DzNe5ORJ8I+YRw== X-Received: by 2002:aa7:9f4a:0:b029:142:2501:34f7 with SMTP id h10-20020aa79f4a0000b0290142250134f7mr4489385pfr.80.1601047260559; Fri, 25 Sep 2020 08:21:00 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id a5sm2717859pgk.13.2020.09.25.08.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 08:20:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 08/10] softfloat: Use x86_64 assembly for sh[rl]_double Date: Fri, 25 Sep 2020 08:20:45 -0700 Message-Id: <20200925152047.709901-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925152047.709901-1-richard.henderson@linaro.org> References: <20200925152047.709901-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bharata@linux.ibm.com, alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" GCC isn't recognizing this pattern for x86, and it probably couldn't recognize that the outer condition is not required either. Signed-off-by: Richard Henderson --- fpu/softfloat.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 54d0b210ac..fdf5bde69e 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -7260,12 +7260,22 @@ typedef struct UInt256 { static inline uint64_t shl_double(uint64_t h, uint64_t l, unsigned lsh) { +#ifdef __x86_64__ + asm("shld %b2, %1, %0" : "+r"(h) : "r"(l), "ci"(lsh)); + return h; +#else return lsh ? (h << lsh) | (l >> (64 - lsh)) : h; +#endif } static inline uint64_t shr_double(uint64_t h, uint64_t l, unsigned rsh) { +#ifdef __x86_64__ + asm("shrd %b2, %1, %0" : "+r"(l) : "r"(h), "ci"(rsh)); + return l; +#else return rsh ? (h << (64 - rsh)) | (l >> rsh) : l; +#endif } static void shortShift256Left(UInt256 *p, unsigned lsh) From patchwork Fri Sep 25 15:20:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 272712 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8401C4363D for ; Fri, 25 Sep 2020 15:33:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6D55420878 for ; Fri, 25 Sep 2020 15:33:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="P48Mm0V5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D55420878 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:32878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLpjH-0004RC-Jz for qemu-devel@archiver.kernel.org; Fri, 25 Sep 2020 11:33:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLpX6-0001Cu-U9 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:21:14 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:46808) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLpX2-0005Rz-Rw for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:21:12 -0400 Received: by mail-pg1-x543.google.com with SMTP id 34so2840786pgo.13 for ; Fri, 25 Sep 2020 08:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zr2QWZIaQ416tfvMuGmnFuEpgzcclZDiNIL1w+CaZnM=; b=P48Mm0V5ZXsyDICfr03qRnpHI2cflgPzbD+s83vBKG6aARRuGWJxDqHo3udWU4hl/j oyxYyxaVVGBlE1ySztLuJi4f1+eZNEddyYDTXv49z5W2UH/hKtyQRR9TSsA5dDpYFrVH U30MZXBo38S477lMCwnA1ePeVTHw4rzXgiwqBbFxFZZlwTeRscKJUGgxCffs8S2GQfMy /+82lRIbyJrrQdJMEHRX+ZlY0wtod5ez1/m74x+lQvP+PqSq4z39H5EwrvbqQynY0cmd sE3R+HiTFEz3ddjYYGJB1HT7gHWnGwDLVjnqrpMv6Klv9+jCzhVp0P+7slgFMG5uXcCG HYJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zr2QWZIaQ416tfvMuGmnFuEpgzcclZDiNIL1w+CaZnM=; b=enoK4yPwGl65bnujx6uGmy90kCxhrm9kkPx1lnFq3r1D7SsuWeU+ycTN8XNMvRph1Q hNt9zwq3AEo/a3Gic2R61AbEW0SvN7CAdSsfPDmObxVr4IrObKH6R0xoohmePv3M1M5g DD9VA0TBYwEC7CiIGhCYS/pxCJm8dcUMPJRc2AAIQfTBw177ypLmcthDTZHkCahxxK4y jDacdyjDZcIeKN1ULVhWgSG8TRPCIK7twEgLztuVTKp/RsJ2/wDaG9XpEACw5634N0mz plRi8pj04ogpsFxRJOz4UCJGHOS7hOLACsjABURL33cLkC1X4uTmXOOG7Pj2hww9Qs38 w9dA== X-Gm-Message-State: AOAM5302DMOgYFWoDHtb8VuPNhMPcbwy35LsmSSGkB+WW+e3DKtlDuw3 EbaUbJrNUVVD80FCpRKZWj2gFGhUTcoBjw== X-Google-Smtp-Source: ABdhPJwdAQXPL872sdEPiy5IQ3upfPMUvoXdE5S0t5BTBhFxgKyrLFnFliKgqkE0uFd40kvPqqj1dA== X-Received: by 2002:a17:902:b702:b029:d1:e598:4014 with SMTP id d2-20020a170902b702b02900d1e5984014mr5129473pls.78.1601047261839; Fri, 25 Sep 2020 08:21:01 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id a5sm2717859pgk.13.2020.09.25.08.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 08:21:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 09/10] softfloat: Use aarch64 assembly for {add, sub}{192, 256} Date: Fri, 25 Sep 2020 08:20:46 -0700 Message-Id: <20200925152047.709901-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925152047.709901-1-richard.henderson@linaro.org> References: <20200925152047.709901-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bharata@linux.ibm.com, alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The compiler cannot chain more than two additions together. Use inline assembly for 3 or 4 additions. Signed-off-by: Richard Henderson --- include/fpu/softfloat-macros.h | 14 ++++++++++++++ fpu/softfloat.c | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h index 99fa124e56..969a486fd2 100644 --- a/include/fpu/softfloat-macros.h +++ b/include/fpu/softfloat-macros.h @@ -442,6 +442,13 @@ static inline void "adc %3, %0" : "=&r"(*z0Ptr), "=&r"(*z1Ptr), "=&r"(*z2Ptr) : "rm"(b0), "rm"(b1), "rm"(b2), "0"(a0), "1"(a1), "2"(a2)); +#elif defined(__aarch64__) + asm("adds %2, %x5, %x8\n\t" + "adcs %1, %x4, %x7\n\t" + "adc %0, %x3, %x6" + : "=&r"(*z0Ptr), "=&r"(*z1Ptr), "=&r"(*z2Ptr) + : "rZ"(a0), "rZ"(a1), "rZ"(a2), "rZ"(b0), "rZ"(b1), "rZ"(b2) + : "cc"); #else uint64_t z0, z1, z2; int8_t carry0, carry1; @@ -507,6 +514,13 @@ static inline void "sbb %3, %0" : "=&r"(*z0Ptr), "=&r"(*z1Ptr), "=&r"(*z2Ptr) : "rm"(b0), "rm"(b1), "rm"(b2), "0"(a0), "1"(a1), "2"(a2)); +#elif defined(__aarch64__) + asm("subs %2, %x5, %x8\n\t" + "sbcs %1, %x4, %x7\n\t" + "sbc %0, %x3, %x6" + : "=&r"(*z0Ptr), "=&r"(*z1Ptr), "=&r"(*z2Ptr) + : "rZ"(a0), "rZ"(a1), "rZ"(a2), "rZ"(b0), "rZ"(b1), "rZ"(b2) + : "cc"); #else uint64_t z0, z1, z2; int8_t borrow0, borrow1; diff --git a/fpu/softfloat.c b/fpu/softfloat.c index fdf5bde69e..07dc17caad 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -7358,6 +7358,18 @@ static void sub256(UInt256 *r, UInt256 *a, UInt256 *b) : "=&r"(r->w[0]), "=&r"(r->w[1]), "=&r"(r->w[2]), "=&r"(r->w[3]) : "rme"(b->w[0]), "rme"(b->w[1]), "rme"(b->w[2]), "rme"(b->w[3]), "0"(a->w[0]), "1"(a->w[1]), "2"(a->w[2]), "3"(a->w[3])); +#elif defined(__aarch64__) + asm("subs %[r3], %x[a3], %x[b3]\n\t" + "sbcs %[r2], %x[a2], %x[b2]\n\t" + "sbcs %[r1], %x[a1], %x[b1]\n\t" + "sbc %[r0], %x[a0], %x[b0]" + : [r0] "=&r"(r->w[0]), [r1] "=&r"(r->w[1]), + [r2] "=&r"(r->w[2]), [r3] "=&r"(r->w[3]) + : [a0] "rZ"(a->w[0]), [a1] "rZ"(a->w[1]), + [a2] "rZ"(a->w[2]), [a3] "rZ"(a->w[3]), + [b0] "rZ"(b->w[0]), [b1] "rZ"(b->w[1]), + [b2] "rZ"(b->w[2]), [b3] "rZ"(b->w[3]) + : "cc"); #else bool borrow = false; @@ -7388,6 +7400,13 @@ static void neg256(UInt256 *a) : "=&r"(a->w[0]), "=&r"(a->w[1]), "=&r"(a->w[2]), "+rm"(a->w[3]) : "rme"(a->w[0]), "rme"(a->w[1]), "rme"(a->w[2]), "0"(0), "1"(0), "2"(0)); +#elif defined(__aarch64__) + asm("negs %3, %3\n\t" + "ngcs %2, %2\n\t" + "ngcs %1, %1\n\t" + "ngc %0, %0" + : "+r"(a->w[0]), "+r"(a->w[1]), "+r"(a->w[2]), "+r"(a->w[3]) + : : "cc"); #else /* * Recall that -X - 1 = ~X, and that since this is negation, @@ -7430,6 +7449,14 @@ static void add256(UInt256 *a, UInt256 *b) "adc %4, %0" : "+r"(a->w[0]), "+r"(a->w[1]), "+r"(a->w[2]), "+r"(a->w[3]) : "rme"(b->w[0]), "rme"(b->w[1]), "rme"(b->w[2]), "rme"(b->w[3])); +#elif defined(__aarch64__) + asm("adds %3, %3, %x7\n\t" + "adcs %2, %2, %x6\n\t" + "adcs %1, %1, %x5\n\t" + "adc %0, %0, %x4" + : "+r"(a->w[0]), "+r"(a->w[1]), "+r"(a->w[2]), "+r"(a->w[3]) + : "rZ"(b->w[0]), "rZ"(b->w[1]), "rZ"(b->w[2]), "rZ"(b->w[3]) + : "cc"); #else bool carry = false; From patchwork Fri Sep 25 15:20:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 304398 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 434E5C4363D for ; Fri, 25 Sep 2020 15:25:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A7CFC206A4 for ; Fri, 25 Sep 2020 15:25:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ko3LEYbf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7CFC206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLpbW-0005vE-Mj for qemu-devel@archiver.kernel.org; Fri, 25 Sep 2020 11:25:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLpX5-0001Cg-4Q for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:21:12 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:34081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLpX2-0005TI-SV for qemu-devel@nongnu.org; Fri, 25 Sep 2020 11:21:10 -0400 Received: by mail-pg1-x535.google.com with SMTP id u24so2879597pgi.1 for ; Fri, 25 Sep 2020 08:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xmBcp07NP8phRH9qOFxSa7PTiYpPJFfrWoI6zCboVds=; b=ko3LEYbfIrE/DeacDsw+Wid2M96lbzNGTN80dOSZQJrsPw4lzYW6jFQx9n5QxrRlLJ QCRElx8aYddKN2gtEUajC51/uylClb++mJuZVYzTnO3tU4Jg2vJTp1EtYd1LYVG1PcuP USsqc7xCWG8takqxo2jTyH0qcV/wGuZYNC+o/c4JptMiMuhmi/7302n+515PN/U7Iehb zNOJzNr9llMTmvYW8myrdwqd8jFD3C6QTnTjwk9xYJkcuvNkqHyw2NRmZI2X7mODOo2s 0R4vjl0CyWvdO97prv9FUnhnY37JrpiTZMU5qy2KQRI2kukM+zZhsJDh3cYiQVzFp26l yK6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xmBcp07NP8phRH9qOFxSa7PTiYpPJFfrWoI6zCboVds=; b=NE+aLgneg+q+f8hWuLcsiMkQys6UPVRpJnTjf3anlzY3TnTCJvHbzZu6RKRqyiGl8A h+jW4GSgl+UgR3Ct+caqAGz11lQJDmF6Y6lsgH/TSreXpqd+I8PPEYAubx9TlRUYs3sx txNBttZlX1xOg6Tq9tHZWU6siK9Zh4sazaZjaJdJsMgSSjgOig7cq9IuDhTYex+6qHWu kR/Rr4oZ7PDXwkGp8zfKa/y0odfMIWRApcGau4cXjERBPGa1YjX9bX1MFZ0HNRi3xjmA yMpt5ULuTxpEt4jPkGhmplAdlfXqT01k71PqQJgKWSIooAGJqg5j7RBaePzFxv5GbcnN wNFg== X-Gm-Message-State: AOAM533Keq6Smtb8mWF/dOjnaRf9kFNy0OHAk2WX7Vh//MaNdyAMLa/+ npR6Il3kTiqEhNimdhrRM9zcchF4xmGRzA== X-Google-Smtp-Source: ABdhPJz4AwxGcDbWaX/mrrOvsZtcZK54EF53hd4dWti6BHsNytk2mG8Cvja39VqRwcygiVKhcpRElA== X-Received: by 2002:a17:902:82c2:b029:d1:f36a:ab97 with SMTP id u2-20020a17090282c2b02900d1f36aab97mr5042903plz.64.1601047264057; Fri, 25 Sep 2020 08:21:04 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id a5sm2717859pgk.13.2020.09.25.08.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 08:21:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 10/10] softfloat: Use ppc64 assembly for {add, sub}{192, 256} Date: Fri, 25 Sep 2020 08:20:47 -0700 Message-Id: <20200925152047.709901-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925152047.709901-1-richard.henderson@linaro.org> References: <20200925152047.709901-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bharata@linux.ibm.com, alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- include/fpu/softfloat-macros.h | 14 ++++++++++++++ fpu/softfloat.c | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h index 969a486fd2..d26cfaf267 100644 --- a/include/fpu/softfloat-macros.h +++ b/include/fpu/softfloat-macros.h @@ -449,6 +449,13 @@ static inline void : "=&r"(*z0Ptr), "=&r"(*z1Ptr), "=&r"(*z2Ptr) : "rZ"(a0), "rZ"(a1), "rZ"(a2), "rZ"(b0), "rZ"(b1), "rZ"(b2) : "cc"); +#elif defined(__powerpc64__) + asm("addc %2, %5, %8\n\t" + "adde %1, %4, %7\n\t" + "adde %0, %3, %6" + : "=r"(*z0Ptr), "=&r"(*z1Ptr), "=&r"(*z2Ptr) + : "r"(a0), "r"(a1), "r"(a2), "r"(b0), "r"(b1), "r"(b2) + : "ca"); #else uint64_t z0, z1, z2; int8_t carry0, carry1; @@ -521,6 +528,13 @@ static inline void : "=&r"(*z0Ptr), "=&r"(*z1Ptr), "=&r"(*z2Ptr) : "rZ"(a0), "rZ"(a1), "rZ"(a2), "rZ"(b0), "rZ"(b1), "rZ"(b2) : "cc"); +#elif defined(__powerpc64__) + asm("subfc %2, %8, %5\n\t" + "subfe %1, %7, %4\n\t" + "subfe %0, %6, %3" + : "=&r"(*z0Ptr), "=&r"(*z1Ptr), "=&r"(*z2Ptr) + : "r"(a0), "r"(a1), "r"(a2), "r"(b0), "r"(b1), "r"(b2) + : "ca"); #else uint64_t z0, z1, z2; int8_t borrow0, borrow1; diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 07dc17caad..9af75b9146 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -7370,6 +7370,18 @@ static void sub256(UInt256 *r, UInt256 *a, UInt256 *b) [b0] "rZ"(b->w[0]), [b1] "rZ"(b->w[1]), [b2] "rZ"(b->w[2]), [b3] "rZ"(b->w[3]) : "cc"); +#elif defined(__powerpc64__) + asm("subfc %[r3], %[b3], %[a3]\n\t" + "subfe %[r2], %[b2], %[a2]\n\t" + "subfe %[r1], %[b1], %[a1]\n\t" + "subfe %[r0], %[b0], %[a0]" + : [r0] "=&r"(r->w[0]), [r1] "=&r"(r->w[1]), + [r2] "=&r"(r->w[2]), [r3] "=&r"(r->w[3]) + : [a0] "r"(a->w[0]), [a1] "r"(a->w[1]), + [a2] "r"(a->w[2]), [a3] "r"(a->w[3]), + [b0] "r"(b->w[0]), [b1] "r"(b->w[1]), + [b2] "r"(b->w[2]), [b3] "r"(b->w[3]) + : "ca"); #else bool borrow = false; @@ -7407,6 +7419,13 @@ static void neg256(UInt256 *a) "ngc %0, %0" : "+r"(a->w[0]), "+r"(a->w[1]), "+r"(a->w[2]), "+r"(a->w[3]) : : "cc"); +#elif defined(__powerpc64__) + asm("subfic %3, %3, 0\n\t" + "subfze %2, %2\n\t" + "subfze %1, %1\n\t" + "subfze %0, %0" + : "+r"(a->w[0]), "+r"(a->w[1]), "+r"(a->w[2]), "+r"(a->w[3]) + : : "ca"); #else /* * Recall that -X - 1 = ~X, and that since this is negation, @@ -7457,6 +7476,14 @@ static void add256(UInt256 *a, UInt256 *b) : "+r"(a->w[0]), "+r"(a->w[1]), "+r"(a->w[2]), "+r"(a->w[3]) : "rZ"(b->w[0]), "rZ"(b->w[1]), "rZ"(b->w[2]), "rZ"(b->w[3]) : "cc"); +#elif defined(__powerpc64__) + asm("addc %3, %3, %7\n\t" + "adde %2, %2, %6\n\t" + "adde %1, %1, %5\n\t" + "adde %0, %0, %4" + : "+r"(a->w[0]), "+r"(a->w[1]), "+r"(a->w[2]), "+r"(a->w[3]) + : "r"(b->w[0]), "r"(b->w[1]), "r"(b->w[2]), "r"(b->w[3]) + : "ca"); #else bool carry = false;