From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id MK81O45a+mHsSgAAWB0awg (envelope-from ) for ; Wed, 02 Feb 2022 05:18:54 -0500 Received: by simark.ca (Postfix, from userid 112) id F06BE1F3BA; Wed, 2 Feb 2022 05:18:54 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 F108D1ECEB for ; Wed, 2 Feb 2022 05:18:52 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5CDE8385C415 for ; Wed, 2 Feb 2022 10:18:52 +0000 (GMT) Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50116.outbound.protection.outlook.com [40.107.5.116]) by sourceware.org (Postfix) with ESMTPS id EECB63858D1E for ; Wed, 2 Feb 2022 10:17:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EECB63858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=syrmia.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=syrmia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gty6QW7QnkpKoSX0etADlO1ncnL9TgUEm/MB0VzQACW9R+u9uJUwvYSTC6R0MS3hWxJW1aH5jOaFtswEl1ZrhDe2QpmpDjFox4zsg54yCL4sweYjlIEOwiwpFpdNPx5zdc/WACf1sJ8UnuE6kxpCTCFP/8h+k1c7jq3cclZQGQX4LusSXTr1UizBXgLWhOHuZUwsbk9BtR/+unRSEc6FAdTt1dbhySbrvMHDk3+KLwOcR9vwtWcw52rg0ljQLl+xlag3x1TkwcBwrlWeOnhLtaLrMP52kcecHKkVjL1S2aq0wA2NUTbdIlhHqSp4GjYX7VrjMgOo66t/gYab3MbC+Q== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EtTQTj1QokqBqTi1ScBgiIY1+cO2ffuWljW2SwhAYuU=; b=WU/NI5fOzSkAW+wpRNm3DiAf1L7WHTm+vtxDgBC5kGCi/IJIgVVmc7AHf0Kuky22byW8XZ3Xrde/i2s9PuODb5XVDD/1qYL9Mlom+f7TuVW4Z1S+5tjN4M8umdGhAkoZFGaHN7NhOg5kfj5Hn+e7yPxKO0AseFYMwTifQU1v+XNwpVz/9ymYSWroTF/Na4LeUVUCwokKV5jtaaTEyVpVnMQfQ+2/pBH/0NQDInsMBAzNv5HQp33sLPEp4XZlvvhQ7IYpCYj7H3f5GUvN3NDMyNhng68YywZDDUkY0V7A157qQwIDOKHFKNA9kq2oSGBqRdeXHJmKZOpoAPr1Eag1rA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EtTQTj1QokqBqTi1ScBgiIY1+cO2ffuWljW2SwhAYuU=; b=LtlgEQMlVILddpZ+/9ERYDm/YolGDCxRv7iSycpJr5qTy8mZMqkyrX3RM0ZCScRkDTAHOd/kH+WEZy3K9ysSZQWuOIl1yQC6iYMQSD5Vx5ICKgWDABK3fWMmjwBag20+9kQPAx6BCBPScKZgXciD5hJ+6IiBJ5fMj/FWuXmT4wQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=syrmia.com; Received: from VI1PR03MB4208.eurprd03.prod.outlook.com (2603:10a6:803:51::25) by AM0PR03MB3924.eurprd03.prod.outlook.com (2603:10a6:208:6e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 2 Feb 2022 10:17:44 +0000 Received: from VI1PR03MB4208.eurprd03.prod.outlook.com ([fe80::2403:1065:f4bd:86c5]) by VI1PR03MB4208.eurprd03.prod.outlook.com ([fe80::2403:1065:f4bd:86c5%6]) with mapi id 15.20.4951.012; Wed, 2 Feb 2022 10:17:44 +0000 From: Dragan Mladjenovic To: gdb-patches@sourceware.org Subject: [PATCH v5 2/4] sim: Factor out NaN handling in floating point operations Date: Wed, 2 Feb 2022 11:17:23 +0100 Message-Id: <20220202101725.23671-3-Dragan.Mladjenovic@syrmia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220202101725.23671-1-Dragan.Mladjenovic@syrmia.com> References: <20220202101725.23671-1-Dragan.Mladjenovic@syrmia.com> Content-Type: text/plain X-ClientProxiedBy: VI1PR0601CA0041.eurprd06.prod.outlook.com (2603:10a6:800:1e::51) To VI1PR03MB4208.eurprd03.prod.outlook.com (2603:10a6:803:51::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: caa5cbd7-1c2c-407b-a226-08d9e635406b X-MS-TrafficTypeDiagnostic: AM0PR03MB3924:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5kQya8OW65SpO5xPJcRxupn0dPyw2XZt67teM3aFx30MEHpyH82B1ALz9u/4/iRddTylZDhYw78GWRNZlLiSjQdjtaR9V6cVH6+TOuBDlD/FJVuy95ApPzx9gFYs3qiMXeE5FG1lMWBaqlRAWIl/OVGRPA5sZr5DteM75KRSPK9+omihZGy6kVxbmplOUq/HyiFnyMnYaCewojsaQOj1KIYM8UBSa9ZEpBlXzOPXYla/uHDNbMfchZ1rDbWhMZ3E0Tnsv4fgYM7Y1oEDQvsddQvRbwA8IZJOT2zEIZPbO82jEiZk99spzQfC9jo+eRuejHlrLpwft9Agrr1G3FSEXXTOBAKW4I8msQAiKpvT/I8ZawFwi/qdXmkv6TA5F+zFp3ReeHIWNUVuhlsEwqK+3Q3WjeCqnDAT9rKyPB8ZX5TmF67lR29ZRb72pEDZGYbLp1mf4hotMBo4cA/4ejje8d/PyaVksHxNAwS9HTxI/1NNmjSyK+LrbS2TD1SCeELt+8fFIqNWOcjlRuNFzVGpKPHcBwSZ6lKiY0EXE7x2d9MaROjyHUlpRLKIUo4I+eOSZWu0kCn2iyjhULXXHUTqeunK2hIVeAFbd6zjRofpogOy8MxQS1MB4tHzHFjJDz8DnAiFokLgJcg+nyIf1rNnwxi0eCcK11oyMM3Px2I90jhZmxBchiRRWHDsp5WA1cDJ3s3T7Zx7pqh/RvSvxD8frg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR03MB4208.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(39840400004)(396003)(366004)(346002)(376002)(136003)(2616005)(186003)(26005)(1076003)(508600001)(4326008)(66476007)(8936002)(66556008)(8676002)(83380400001)(38100700002)(38350700002)(66946007)(5660300002)(6486002)(86362001)(6916009)(54906003)(6506007)(6512007)(6666004)(316002)(36756003)(2906002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?GC9AicR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2S?= =?us-ascii?Q?xVYe/hbY6PPH3XUsuDdaV+AESu527uBH88mKqCACBi/kp+b1MYE2vEKjh9jj?= =?us-ascii?Q?4AUwhplIUQuZ1/iTyTlnLlaHwfZplGsr/Y1uQJirXmx/0f/+iothFzpDA1RE?= =?us-ascii?Q?AeNWs8KzqVAHEvkF+Gg1u8LhwbHNCxGqZcS/pblRplsa7V7dN86+Lzd5xI5i?= =?us-ascii?Q?0eK3xer1HQMiSgVbAh/cLeVUD8xbvZELLal7rdtiWjIt+dPvZpgktq7CueaY?= =?us-ascii?Q?qm9v4sPcd+g/r3bZor7APC394Dlk8rF22ZFRpJNzliNTJdgk29yAc2KIICP9?= =?us-ascii?Q?Al0RW6W2IKVNvGRZhk/dyE8RfMoDtaR1JEHWffPBMnQD6kA0DIC4QIbH0U/j?= =?us-ascii?Q?l5Ulk4NvWojKSEzSg+OZp0nTEt6e0bsxQK/bqwLOrb1d5uiFKt7Q7CNzJ6F5?= =?us-ascii?Q?FzGl5FETcoMDh6u5u8s/0IgqwmxRSa92ivdb4OFbFkXw+BvdR/yv9P48c8un?= =?us-ascii?Q?SvJTXDuH9ohsOIxlANZ9FStc7e/VNukj/JUIuIHkPIsJdSIEr3j8X/qKQgCA?= =?us-ascii?Q?i2QcRwlvgNppHuisLRTdDcvEd1Bly/zp6fOhsxAcZrVhLau9D2Z88AUDbYOv?= =?us-ascii?Q?6z50XDn7F7kH0dzHW9g8cBtIMKmSinUwWo6diDQhlEdaHBPIdMA2eHOxCz2W?= =?us-ascii?Q?QpnLoUWaTVqyiLrvJ2GE1KkaqBxqaqH9F/uDShEKiRTxMR/IwUaEyZhHqE8Q?= =?us-ascii?Q?NDx2a3ofVxmNxRBB40UeKLOn8oj8IGO6nDiq2vV7dB8xwenZJnQVwQEHI+kq?= =?us-ascii?Q?2f7Ggw=3D=3D?= X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: caa5cbd7-1c2c-407b-a226-08d9e635406b X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB4208.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2022 10:17:43.8867 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tLageRM4i0BoJoyUeEN3UTKQhhp8ZdTv8fDV3k8K3AwCToZmSybUULqfN74PC3zDKTEHD2r3PIZuGJazbgcnm7HSyA8oP9WC+9f4Ls8Rnak= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR03MB3924 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: Chao-ying Fu , Faraz Shahbazker , "Maciej W . Rozycki" Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" From: Faraz Shahbazker 2022-02-01 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. * sim-fpu.h (sim_fpu_op_nan): New declaration. --- sim/common/sim-fpu.c | 189 +++++++------------------------------------ sim/common/sim-fpu.h | 10 +++ 2 files changed, 41 insertions(+), 158 deletions(-) diff --git a/sim/common/sim-fpu.c b/sim/common/sim-fpu.c index 276ad234174..9174eaf17b4 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); } +/* NaN handling for binary operations. */ +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 = sim_fpu_is_snan (l) ? *l : *r; + f->class = 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 = *l; + else /* if (sim_fpu_is_qnan (r)) */ + *f = *r; + return 0; +} /* Arithmetic ops */ @@ -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 = *l; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f = *r; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f = *l; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f = *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 = *l; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f = *r; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f = *l; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f = *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 = *l; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f = *r; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f = *l; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f = *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 = *l; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f = *r; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f = *l; - f->class = sim_fpu_class_qnan; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f = *r; - f->class = 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 = *l; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f = *r; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f = *l; - f->class = sim_fpu_class_qnan; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f = *r; - f->class = 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 = 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 = *l; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f = *r; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f = *l; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f = *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 = *l; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_snan (r)) - { - *f = *r; - f->class = sim_fpu_class_qnan; - return sim_fpu_status_invalid_snan; - } - if (sim_fpu_is_qnan (l)) - { - *f = *l; - return 0; - } - if (sim_fpu_is_qnan (r)) - { - *f = *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) diff --git a/sim/common/sim-fpu.h b/sim/common/sim-fpu.h index b0b318cb283..2a141981687 100644 --- a/sim/common/sim-fpu.h +++ b/sim/common/sim-fpu.h @@ -261,6 +261,16 @@ INLINE_SIM_FPU (int) sim_fpu_sqrt (sim_fpu *f, +/* NaN handling. + + Assuming that at least one of the inputs is NAN choose the correct + NAN result for the binary operation. */ + +INLINE_SIM_FPU (int) sim_fpu_op_nan (sim_fpu *f, + const sim_fpu *l, const sim_fpu *r); + + + /* Conversion of integer <-> floating point. */ INLINE_SIM_FPU (int) sim_fpu_i32to (sim_fpu *f, int32_t i, -- 2.17.1