From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KLw7Jkbpq2CEYgAAWB0awg (envelope-from ) for ; Mon, 24 May 2021 13:58:30 -0400 Received: by simark.ca (Postfix, from userid 112) id 97D031F11E; Mon, 24 May 2021 13:58:30 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 1772B1F0FE for ; Mon, 24 May 2021 13:58:27 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CDBAD3891C11; Mon, 24 May 2021 17:58:26 +0000 (GMT) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2122.outbound.protection.outlook.com [40.107.223.122]) by sourceware.org (Postfix) with ESMTPS id BCF723858022 for ; Mon, 24 May 2021 17:58:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BCF723858022 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=wavecomp.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fshahbazker@wavecomp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BnykdFz9/2l1/pK3si9j8ernFJ25FUEiCd5BJwqIjaPSjWUPMh7Ni9McoNjotnf86B7bt58cr79Fp8RdKFXIkMwe35P4W/URxx2yu5+krgv+LKqkY4/M8B5oERBsV7wURpWnpQmDJXIn9ANC369P9v/DicxXXXqG6fvFnQ7PeEH04WWd/W+lodM8ZCJ2I0GhNZ6fQ5p8ZnHuie/PuoElT9+ijRh1R42WP88PsgsSkd0u8jg03L6LtVdG4V93y8OB5WwVasnHKyCjWYMOodoS5JToBrL32OOH0zx7OlUU1RUyclSk7O9fj+M+f6lXQzBDlFUYCe8lF2kJujlRQLDMMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bnq4oUDYcH//+U9UkJ0Jbh647epyWlkXZrpCotIQMKk=; b=kPLjIt8nVimfPrltkpTVGEaUGq6oYLPHgwqkjgK0rmDSWmfxxaNPeL6balScFx3LCAsL5absQ81N6wh6TETC263qUkJTJgjsLvlJ6Rx8VVPQKnWGpIyvnp824oYwIEp2RQOQdvNltRsKYpQPig3sEKt5odp18vLQU9mwQTyyWsFCSAyoaGZrv454spMBb2D/zZAP/9G63JV3cbRiiwZVWrJ1shR2cUZETt0aytUXVa3t+d5OAtZxu4MK4DYZMojv+Bts+12M/FSmpOBxhKIaR9JEzCL2hJ3dj0/ElkmWWOxFtZ46H59Tq49yxK0AaFy1NhvOxiVJ8E1hiJVSoOsZ4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=wavecomp.com; dkim=pass header.d=wavecomp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bnq4oUDYcH//+U9UkJ0Jbh647epyWlkXZrpCotIQMKk=; b=a2FvVrLSyXPyr7nlETF0sJ+3YKKVVcotWU0AhkNKpf1CiCyWzdn3uSz7w2zJGCeV1mawXEfHZSSIv32lsMgcyqE+/vdCa3GzDJxH7AwLVrrEunacMVGiRwLGNIQT6Aec+eIs2mwBxFcRAzwg6RIZh/YmHELqco9KLyZZWn3VF6k= Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=wavecomp.com; Received: from MW3PR22MB2299.namprd22.prod.outlook.com (2603:10b6:303:47::10) by MWHPR2201MB1343.namprd22.prod.outlook.com (2603:10b6:301:1c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.26; Mon, 24 May 2021 17:58:19 +0000 Received: from MW3PR22MB2299.namprd22.prod.outlook.com ([fe80::e098:7822:150b:bb5b]) by MW3PR22MB2299.namprd22.prod.outlook.com ([fe80::e098:7822:150b:bb5b%7]) with mapi id 15.20.4150.027; Mon, 24 May 2021 17:58:19 +0000 From: Faraz Shahbazker To: gdb-patches@sourceware.org, Mike Frysinger Subject: [PATCH v2 2/5] sim: Factor out NaN handling in floating point operations Date: Mon, 24 May 2021 23:27:59 +0530 Message-Id: <20210524175802.875687-3-fshahbazker@wavecomp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210524175802.875687-1-fshahbazker@wavecomp.com> References: <20210524175802.875687-1-fshahbazker@wavecomp.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-Originating-IP: [175.100.139.57] X-ClientProxiedBy: SJ0PR05CA0116.namprd05.prod.outlook.com (2603:10b6:a03:334::31) To MW3PR22MB2299.namprd22.prod.outlook.com (2603:10b6:303:47::10) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from frsxps.mipstec.com (175.100.139.57) by SJ0PR05CA0116.namprd05.prod.outlook.com (2603:10b6:a03:334::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.12 via Frontend Transport; Mon, 24 May 2021 17:58:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b67b1315-d6db-4df7-5a35-08d91edd8398 X-MS-TrafficTypeDiagnostic: MWHPR2201MB1343: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2150; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MyOKlA0mJzNPyj/JfF16dllPJMPhmZ11t4xeTDRSpgL21oIosjC9d8Zs+73LJcFf/wFQQGZGnOqY3e9k8EgLPUq4pbTezqI6YFjO484ibVjgEDd3kPxxx3D1gImhcDzkatTQHhNUkUJXBxQdgqELEQRbLtvg6AqCtxT0Lz9T2LcmA9ciifDJyO4Po6uSOxdnvPFsjv8L+MxEY6KGYLHH/QH29vhGOBoZiEaeoBnZ9fMk1/sv5lUM5GXjDeuMiCqqnmEYnR9bubVUucrY2hgF/wktz2cIAzZlF8MiFsnmseF1oFFTskm0RHjqsQGngPhhUHSN1/ERHF0jpZDihcGd63nScFeh1xSdHb21DCY3af4DZHIBA4nWnQCZzG1yfim5rx0YC95I/CffBOhbU4O+xcDp86u1gnUR1n3XIeSo5ddwcFou8zxl+q6nU7r6Ldfj4uF/leDt+ueo10nP4WZfgSEBCiONZKfAXjdpV+X2LP2lLIxOQgMZaDUIACdyYdYvKwm1NbkZGDwKLCsfd7aQn2Vz194FC81dYp1ho98gbXXFuHyq+r/qCcc56jhMRXLnnloHeo4V7+H4nq45QVzLB6GFHWkYeaZEffZbn8qcLOnjYbte2OrIwm/ZsYcNe/8FyMorkVdAwBgjw7ykJa1L2w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW3PR22MB2299.namprd22.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(396003)(39830400003)(136003)(346002)(376002)(478600001)(26005)(6666004)(107886003)(6512007)(4326008)(6506007)(16526019)(2906002)(6486002)(52116002)(38350700002)(6916009)(54906003)(316002)(956004)(8936002)(8676002)(86362001)(186003)(83380400001)(1076003)(66556008)(38100700002)(66946007)(66476007)(2616005)(5660300002)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?sbyVXlmsLweaHn1FXExkXYRsCy6GuXcefjw0Vv1NymRgsyeiZVg100nzjWo6?= =?us-ascii?Q?CjMTkDegAJb56Hi+bh6JzpygfsfM65ubgD+cOKmWC3vPgfiLy1IDlLeR92jU?= =?us-ascii?Q?tX+OEQJxw/gBe6oA+TlkfjaVbLy2ts29d9tk5amQInRL63R7b4EqJUL6iGoL?= =?us-ascii?Q?LNeagKbpQ84fUugAUMf+ZSGO9Ey3Dxwh70fUjOgAxu3ijv/ZFSClkatqx4mE?= =?us-ascii?Q?8lxtCVoL6sqn6fEO7OW+pQM7QJnNL4zH5+YM1oeP1tTmShkLSEc0gUA02sFO?= =?us-ascii?Q?GP4LcusOmd94kxNn3T8VfIAvCRg4/04mmS2IS7YH8tePmT5Co/vg0g4wjzXC?= =?us-ascii?Q?ZmQ9PrwpMsE5m3Q3TbGBo0ejeqJ0i4J79z8zU/FbzwSq2QoGkFZwI2kSZwv3?= =?us-ascii?Q?56UTArMRCG35GJaKYUmpdI4Xd+kYRHuaRtxtw0tyAqcRTMex/dQ5fHRGB9W/?= =?us-ascii?Q?YGD5ZX6ec9GjMawRIsxgWhMvLpa9LNLptHhbsmjKuiDnjYk9zWj0sougv07k?= =?us-ascii?Q?YD0kDERxBRe4nv0Q0NH+Pyg0B6XZgGZGZDo8Vul1H1jG0VW5FSqSViRokvHc?= =?us-ascii?Q?rXmIB0OKvGNmwyE2tF8xVUkkJz1cFOnuXqtRrC9KJPGo/omOC/9URtfXV1Ch?= =?us-ascii?Q?ZYjPIQiDZNCoHK8HsVo9y56CFqTm5pvCzrV/DemeSgEXmehhfLUpGMTBnSE9?= =?us-ascii?Q?Sobp8zE49VGixY0bxAx8e59QbHBQ7C3LCrGmFDePBOBYzT8BbIkqtz7z/A7p?= =?us-ascii?Q?zKRkCWljOkqLbbxe3GIB3rO7pVtBKTRMZeQGBI0oCpRV76yTtcZP/IUNl43N?= =?us-ascii?Q?Nz9lHOkMbS83iV1BHYZFZ0HB0qO/MCOjhe+eKyf7yW6FzG9q5fud486OD5Bj?= =?us-ascii?Q?wjU/FQn0lUMjBn+Gcm/whnKnEUnGfu0eyL7LxnvB/VwG+j+ls3U7tOg6WpD4?= =?us-ascii?Q?nZE4SPc4/M1WnthGEmMx1VYXIBL2zEh7W38ZMM+xL5kjUiK7O92QSHqQjvqu?= =?us-ascii?Q?f5cOnhRGAZGgxg2sENe9dxk7pi0AlGxnZ7Fd32gcpx8b+IWxFdo71Dqrd0IM?= =?us-ascii?Q?QSj9STzECptc67dtvwDwqMXjcmClpUyIPSXCwRPxwYXO1y7wwLIjWSNJXFh/?= =?us-ascii?Q?NLbxDifTMeC6JtB8wnR+Sk1N0j/+A80iBDaM0P1WrUaM5ZNXqJlb4qMC+dXa?= =?us-ascii?Q?eGny+gYgP/acQHuysuixwt0+aqYoXP88jXno7Ukrc8zi/0ngA/BjKa7B1XXv?= =?us-ascii?Q?zice9+XzUoG8PWcfnMx05kl5ygedK0/Q2ysh6ds1S6tJFnEFDVIJkrKu3iUe?= =?us-ascii?Q?96mH2VVJL3619fZ5aMcaxP6y?= X-OriginatorOrg: wavecomp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b67b1315-d6db-4df7-5a35-08d91edd8398 X-MS-Exchange-CrossTenant-AuthSource: MW3PR22MB2299.namprd22.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2021 17:58:19.7346 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XuTIZHzrI7xu/gysekxWYTAjjRTd8lIUFUh/lVM3s7a7PeQ9RIB65ENEEnFkjPPiQ1dYI2qYVWqkja6IvTzkkY5Tkad36qRdbjGVJqLgWh4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR2201MB1343 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Faraz Shahbazker , Chao-ying Fu Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 2021-05-24 Faraz Shahbazker sim/common/ChangeLog: * sim-fpu.c (sim_fpu_op_nan): New. (sim_fpu_add): Factor out NaN operand handling with a call to sim_fpu_op_nan. (sim_fpu_sub, sim_fpu_mul, sim_fpu_div): Likewise. (sim_fpu_rem, sim_fpu_max, sim_fpu_min): Likewise. --- Notes: Changes from v1: - indentation fixes - remove spurious character typo sim/common/sim-fpu.c | 189 +++++++------------------------------------ 1 file changed, 31 insertions(+), 158 deletions(-) diff --git a/sim/common/sim-fpu.c b/sim/common/sim-fpu.c index 4edd651fd52..96b1776e986 100644 --- a/sim/common/sim-fpu.c +++ b/sim/common/sim-fpu.c @@ -986,7 +986,24 @@ sim_fpu_round_64 (sim_fpu *f, return do_round (f, 1, round, denorm); } =20 +/* NaN handling for binary operations. */ =20 +INLINE_SIM_FPU (int) +sim_fpu_op_nan (sim_fpu *f, const sim_fpu *l, const sim_fpu *r) +{ + if (sim_fpu_is_snan (l) || sim_fpu_is_snan (r)) + { + *f =3D sim_fpu_is_snan (l) ? *l : *r; + f->class =3D sim_fpu_class_qnan; + return sim_fpu_status_invalid_snan; + } + ASSERT (sim_fpu_is_nan (l) || sim_fpu_is_nan (r)); + if (sim_fpu_is_qnan (l)) + *f =3D *l; + else /* if (sim_fpu_is_qnan (r)) */ + *f =3D *r; + return 0; +} =20 /* Arithmetic ops */ =20 @@ -995,28 +1012,8 @@ sim_fpu_add (sim_fpu *f, const sim_fpu *l, const sim_fpu *r) { - if (sim_fpu_is_snan (l)) - { - *f =3D *l; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f =3D *r; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f =3D *l; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f =3D *r; - return 0; - } + if (sim_fpu_is_nan (l) || sim_fpu_is_nan (r)) + return sim_fpu_op_nan (f, l, r); if (sim_fpu_is_infinity (l)) { if (sim_fpu_is_infinity (r) @@ -1144,28 +1141,8 @@ sim_fpu_sub (sim_fpu *f, const sim_fpu *l, const sim_fpu *r) { - if (sim_fpu_is_snan (l)) - { - *f =3D *l; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f =3D *r; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f =3D *l; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f =3D *r; - return 0; - } + if (sim_fpu_is_nan (l) || sim_fpu_is_nan (r)) + return sim_fpu_op_nan (f, l, r); if (sim_fpu_is_infinity (l)) { if (sim_fpu_is_infinity (r) @@ -1298,28 +1275,8 @@ sim_fpu_mul (sim_fpu *f, const sim_fpu *l, const sim_fpu *r) { - if (sim_fpu_is_snan (l)) - { - *f =3D *l; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f =3D *r; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f =3D *l; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f =3D *r; - return 0; - } + if (sim_fpu_is_nan (l) || sim_fpu_is_nan (r)) + return sim_fpu_op_nan (f, l, r); if (sim_fpu_is_infinity (l)) { if (sim_fpu_is_zero (r)) @@ -1423,30 +1380,8 @@ sim_fpu_div (sim_fpu *f, const sim_fpu *l, const sim_fpu *r) { - if (sim_fpu_is_snan (l)) - { - *f =3D *l; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f =3D *r; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f =3D *l; - f->class =3D sim_fpu_class_qnan; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f =3D *r; - f->class =3D sim_fpu_class_qnan; - return 0; - } + if (sim_fpu_is_nan (l) || sim_fpu_is_nan (r)) + return sim_fpu_op_nan (f, l, r); if (sim_fpu_is_infinity (l)) { if (sim_fpu_is_infinity (r)) @@ -1556,30 +1491,8 @@ sim_fpu_rem (sim_fpu *f, const sim_fpu *l, const sim_fpu *r) { - if (sim_fpu_is_snan (l)) - { - *f =3D *l; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f =3D *r; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f =3D *l; - f->class =3D sim_fpu_class_qnan; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f =3D *r; - f->class =3D sim_fpu_class_qnan; - return 0; - } + if (sim_fpu_is_nan (l) || sim_fpu_is_nan (r)) + return sim_fpu_op_nan (f, l, r); if (sim_fpu_is_infinity (l)) { *f =3D sim_fpu_qnan; @@ -1639,28 +1552,8 @@ sim_fpu_max (sim_fpu *f, const sim_fpu *l, const sim_fpu *r) { - if (sim_fpu_is_snan (l)) - { - *f =3D *l; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f =3D *r; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f =3D *l; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f =3D *r; - return 0; - } + if (sim_fpu_is_nan (l) || sim_fpu_is_nan (r)) + return sim_fpu_op_nan (f, l, r); if (sim_fpu_is_infinity (l)) { if (sim_fpu_is_infinity (r) @@ -1722,28 +1615,8 @@ sim_fpu_min (sim_fpu *f, const sim_fpu *l, const sim_fpu *r) { - if (sim_fpu_is_snan (l)) - { - *f =3D *l; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f =3D *r; - f->class =3D sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f =3D *l; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f =3D *r; - return 0; - } + if (sim_fpu_is_nan (l) || sim_fpu_is_nan (r)) + return sim_fpu_op_nan (f, l, r); if (sim_fpu_is_infinity (l)) { if (sim_fpu_is_infinity (r) --=20 2.25.1