From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +GNkDYBa+mHsSgAAWB0awg (envelope-from ) for ; Wed, 02 Feb 2022 05:18:40 -0500 Received: by simark.ca (Postfix, from userid 112) id 34C251F3BA; Wed, 2 Feb 2022 05:18:40 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.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 33C641ECEB for ; Wed, 2 Feb 2022 05:18:39 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D5E863858D1E for ; Wed, 2 Feb 2022 10:18:37 +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 F0B023858D1E for ; Wed, 2 Feb 2022 10:17:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F0B023858D1E 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=c36I+hp9sPxWO2dRc6gzXttNJbp7BouX0OVbi4pZb5CX5ynBmlVawq/W7qkRJRsyvqT3pbNcspWzsjCz0pN2rPif/49f7gHRFyMG5Ol5Ke45+gi8BPsTp1Armo3IRpj1AB3j6y0pX/muenckLHLNs7BeSM7BYKO/TljyJAqixdbOnA6DyIoF5Mli2S5NWOCvIL/zSdBm+PZAB73EJDRuYOjG3Ac7yii16dVC9nk/ro9SyIUkidsoE401Q7/yYlX0wl93hELn9ONxUQQdvRhddu0KcCsmB0UqQQVpKR8ducOdB9wXZ8S8cmvf/FxCuZ26gopOfnSJjl2L2SPSR/sayg== 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=vAqA3TpLbWGkmCSTo7jyRf+BPMOrX7mt8ruHH4AlCNE=; b=jHidxSFlMnYBDJVmOn9CflzvX09r7o1ldoKCLNPQ0AjRGGMLvgqPNKlXGFnaLughtOKJNNzk7j8B6CbqxWIuGxsn6VwRH+xQ9q1I/fMUPNuxOjY4sUMGZ6Sc91JZq7mU3yBltNiAPDTqkfids+ygPnGxc6q29D7Wk4mfD8Zgg3FTkGUhHkpMasjoJF/RQn3z2JRPpBUS6v6pVjJVwnsyuiLU6IRCQddzcUwKlUCOh2LlZNLnJ3h1LHng1Pm8FyZTIivOmZs9Ac01ahtwlDCaoXB10QagRli+pLdwCBSdB24njQbrQ9iC4Jtfd9VUPW3jDUHzvWl/b53Xwy+xg5TYjQ== 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=vAqA3TpLbWGkmCSTo7jyRf+BPMOrX7mt8ruHH4AlCNE=; b=AtXLYhmEhZIRaZlK+YUfNl+5IRTcpgdbWkkvHLUl6p0HhTuI0Hp+CKCZY9ftQpO8vt+I+9adU118d8BPphswSCVmZdeLsXQlS9IFaT+PxBneWxESR49wie2Pt2wHLhr+5nGuxmkMS5BH8gh9qQelOVevGqH1qpolbj0KHnPayXA= 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 1/4] sim: Allow toggling of quiet NaN-bit semantics Date: Wed, 2 Feb 2022 11:17:22 +0100 Message-Id: <20220202101725.23671-2-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: 65b3d470-5068-4fc6-6a9c-08d9e6354032 X-MS-TrafficTypeDiagnostic: AM0PR03MB3924:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1wZzgbY9DAtM7hCiRMYOvww5DY67+SgMqZz5lK3GTSMyFD1M2EV+DpLilbIRdeqwI8bYicm00qxvoLVXMw7Xpd6x11qvSFZss7KvIomWl9gNLRvWwlij9zalKY6chikVvmM7Fg305fDb05oagtFbXC4ojgAbLTRQamkwHsXva/Oo147leE0tzOjkQyKDtIToA4L50XiZY4pkrjEo61J6QI8xJBfTCZqy7wj/Am68BXSOf8dPeCBUwO4WhQ7++Ata1EF8UTYjT6hzVYoh5o+g/PHs4drHODPAPU/0W60asa0UVI5Wjf2zWyYUrmZrrIAt0M7KARPbMYyal3A/h7BhnJo2iZEgepYGr35K0ROUaYv7/y9jiTKVpLemEmg8M/XpwVPvCnOku0rl3FygMhMYTReNnCL/c9gfE9NtVI7svn+S5rtL6y7+sB2CfKKuzJAuuPcFl1ihJQRz6//+J7uZM/wjUI9mxhEYtzKhD70mgRjUNRbINsCZJDL92xQom2P7/DP0oJPbp9gFqc0GrhgdfgjQqm990nlO6j3EQabSwS8LQO5UnkA+tRTfkjzWKFBsmmycNPN51eCJJ6PP7VdsnVjqYdzMp4fKiObxUT3p8Afsy+/inqJcfYC4JJc0AWXnsFo2tg1lCstebDL2RMkI/r49G9HIc0b/83x/AoO50v1NoA1zPURCRTAnspw8xIu89R6Vb946hNnBGa5OGz7nyjf4gKBzUivbM4qWsi+97fwDR6h7/S4VuRbY8Ine89uDSq6Zzj7SaNZclwD+lgdA/R2//3yohCKFQiLEEnrAedg= 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?Q4ul2A9eK/eeQWH7YWAoLw3kq1F+xZyS4q4rc7M++ybgW/beQIykg5zcKN1W?= =?us-ascii?Q?InkHEtQdoVGtsr1jS/eJ4ZZBe+QXS/MYKbxKKM6GcRiuufDU29rQur7coyvL?= =?us-ascii?Q?oGb6qohqc9OD87Hcnck9Qf6xgTgFQUf7SYQf07ExE1881PZg+3Y46To1ORvF?= =?us-ascii?Q?AAhy+Sl+GAmiCUK/AnRsH7uVHIG7ky57/1u7TM1vwRnCQecy+wFERnIf9YZi?= =?us-ascii?Q?U+9+V1KGkYihk8OJqmjEUMAeizlGuTCYUcNdZVOLQGm2fdrfOWuh58qS7tDb?= =?us-ascii?Q?PxSuckrxiPw1++41y1OX0FqmyOhDAta3LiwJoTTRMyjBDalYNT9/jxWtTHYo?= =?us-ascii?Q?FXf8f64wQAu22BosulldUUQv8R8vOQg873Wfm1SRphVjqoSZaawRMQssBTOz?= =?us-ascii?Q?WYtWhPMPXQ91eAQ2d5P9JuyTw1VFDtJ8I1HgsBLB7FFjY6qFOGpz05P6FmUH?= =?us-ascii?Q?/u+oxwqTbhFbox4jFYnOaIjuVi/u1RPrky50UzHvrwcjoKUKgm+SQUUAacV3?= =?us-ascii?Q?VFD6XuzcpkFI7gJYhnzK7boEEK1a1gyAWD14YWmT2eSAQfHfhIyd4F/DnmCQ?= =?us-ascii?Q?MUo67ULUtcsVEmbDf0aODuofB+3t7iZJbyBn8Qf5er9UWzalfP344ERkunvd?= =?us-ascii?Q?Gdx25zXe5gC/KPCyD5nZsmB2mp3mhL7P0gdEKdKDWwd/cuE4C3/+I5zlasZ6?= =?us-ascii?Q?MVCg7pSend2jtyoCqEqibm/qcBnXoDCXy5Op1h8hcUMeEAMuqrKRbkfzlba6?= =?us-ascii?Q?9Y8iLMXOJUNJTqdoayBg+8HvXxFoXmgJ38dTPbQ/58f7HZf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OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 65b3d470-5068-4fc6-6a9c-08d9e6354032 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.5274 (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: zTya8+jwmN14/incy8k7rHSfvqUtx2VsMuOx3BbK1OMEFxa/sO/A6PoPww3R37Wfe8CpRjPHuy2o8ff/DVYt9JhEXE9bfub2zAEU5M2PauA= 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 IEEE754-1985 specifies the top bit of the mantissa as an indicator of signalling vs. quiet NaN, but does not define the precise semantics. Most architectures treat this bit as indicating quiet NaN, but legacy (pre-R6) MIPS goes the other way and treats it as signalling NaN. This used to be controlled by a macro that was only defined for MIPS. This patch replaces the macro with a variable to track the current semantics of the NaN bit and allows differentiation between older (pre-R6) and and newer MIPS cores. 2022-02-01 Faraz Shahbazker sim/common/ChangeLog: * sim-fpu.c (_sim_fpu): New. (pack_fpu, unpack_fpu): Allow reversal of quiet NaN semantics. * sim-fpu.h (sim_fpu_state): New struct. (_sim_fpu): New extern. (sim_fpu_quiet_nan_inverted): New define. sim/mips/ChangeLog: * cp1.h (fcsr_NAN2008_mask, fcsr_NAN2008_shift): New. * mips.igen (check_fpu): Select default quiet NaN mode for legacy MIPS. * sim-main.h (SIM_QUIET_NAN_NEGATED): Remove. --- sim/common/sim-fpu.c | 31 ++++++++++++++++--------------- sim/common/sim-fpu.h | 25 +++++++++++++++++++++++++ sim/mips/cp1.h | 4 ++++ sim/mips/mips.igen | 3 +++ sim/mips/sim-main.h | 3 --- 5 files changed, 48 insertions(+), 18 deletions(-) Changes from v4: Tidy up the comments. Designated initializers. diff --git a/sim/common/sim-fpu.c b/sim/common/sim-fpu.c index a05c57897ff..276ad234174 100644 --- a/sim/common/sim-fpu.c +++ b/sim/common/sim-fpu.c @@ -198,11 +198,10 @@ pack_fpu (const sim_fpu *src, /* Force fraction to correct class. */ fraction = src->fraction; fraction >>= NR_GUARDS; -#ifdef SIM_QUIET_NAN_NEGATED - fraction |= QUIET_NAN - 1; -#else - fraction |= QUIET_NAN; -#endif + if (sim_fpu_quiet_nan_inverted) + fraction |= QUIET_NAN - 1; + else + fraction |= QUIET_NAN; break; case sim_fpu_class_snan: sign = src->sign; @@ -210,11 +209,10 @@ pack_fpu (const sim_fpu *src, /* Force fraction to correct class. */ fraction = src->fraction; fraction >>= NR_GUARDS; -#ifdef SIM_QUIET_NAN_NEGATED - fraction |= QUIET_NAN; -#else - fraction &= ~QUIET_NAN; -#endif + if (sim_fpu_quiet_nan_inverted) + fraction |= QUIET_NAN; + else + fraction &= ~QUIET_NAN; break; case sim_fpu_class_infinity: sign = src->sign; @@ -372,11 +370,10 @@ unpack_fpu (sim_fpu *dst, uint64_t packed, int is_double) /* Non zero fraction, means NaN. */ dst->sign = sign; dst->fraction = (fraction << NR_GUARDS); -#ifdef SIM_QUIET_NAN_NEGATED - qnan = (fraction & QUIET_NAN) == 0; -#else - qnan = fraction >= QUIET_NAN; -#endif + if (sim_fpu_quiet_nan_inverted) + qnan = (fraction & QUIET_NAN) == 0; + else + qnan = fraction >= QUIET_NAN; if (qnan) dst->class = sim_fpu_class_qnan; else @@ -2512,6 +2509,10 @@ sim_fpu_gt (int *is, /* A number of useful constants */ #if EXTERN_SIM_FPU_P +sim_fpu_state _sim_fpu = { + .quiet_nan_inverted = false, +}; + const sim_fpu sim_fpu_zero = { sim_fpu_class_zero, 0, 0, 0 }; diff --git a/sim/common/sim-fpu.h b/sim/common/sim-fpu.h index 447621b5d73..b0b318cb283 100644 --- a/sim/common/sim-fpu.h +++ b/sim/common/sim-fpu.h @@ -25,6 +25,8 @@ along with this program. If not, see . */ #define SIM_FPU_H +#include + /* The FPU intermediate type - this object, passed by reference, should be treated as opaque. @@ -157,6 +159,17 @@ typedef enum +/* State used by the FPU. + + FIXME: This state is global, but should be moved to SIM_CPU. */ + +typedef struct _sim_fpu_state { + bool quiet_nan_inverted; /* Toggle quiet NaN semantics. */ +} sim_fpu_state; + + + + /* Directly map between a 32/64 bit register and the sim_fpu internal type. @@ -375,7 +388,19 @@ enum { INLINE_SIM_FPU (int) sim_fpu_is (const sim_fpu *l); INLINE_SIM_FPU (int) sim_fpu_cmp (const sim_fpu *l, const sim_fpu *r); +/* Global FPU state. */ + +extern sim_fpu_state _sim_fpu; + + +/* IEEE 754-1985 specifies the top bit of the mantissa as an indicator + of signalling vs. quiet NaN, but does not specify the semantics. + Most architectures treat this bit as quiet NaN, but legacy (pre-R6) + MIPS goes the other way and treats it as signalling. This variable + tracks the current semantics of the NaN bit and allows differentiation + between pre-R6 and R6 MIPS cores. */ +#define sim_fpu_quiet_nan_inverted _sim_fpu.quiet_nan_inverted /* A number of useful constants. */ diff --git a/sim/mips/cp1.h b/sim/mips/cp1.h index 96c51a7b736..d6d8a8874fd 100644 --- a/sim/mips/cp1.h +++ b/sim/mips/cp1.h @@ -40,6 +40,10 @@ along with this program. If not, see . */ #define fcsr_RM_mask (0x00000003) #define fcsr_RM_shift (0) +/* FCSR bits for IEEE754-2008 compliance. */ +#define fcsr_NAN2008_mask (0x00040000) +#define fcsr_NAN2008_shift (18) + #define fenr_FS (0x00000004) /* Macros to update and retrieve the FCSR condition-code bits. This diff --git a/sim/mips/mips.igen b/sim/mips/mips.igen index c5db5c2304f..b0c5e5995af 100644 --- a/sim/mips/mips.igen +++ b/sim/mips/mips.igen @@ -5050,6 +5050,9 @@ { if (! COP_Usable (1)) SignalExceptionCoProcessorUnusable (1); + + FCSR &= ~fcsr_NAN2008_mask; + sim_fpu_quiet_nan_inverted = true; } diff --git a/sim/mips/sim-main.h b/sim/mips/sim-main.h index d724688a434..8e3e85f2585 100644 --- a/sim/mips/sim-main.h +++ b/sim/mips/sim-main.h @@ -20,9 +20,6 @@ along with this program. If not, see . */ #ifndef SIM_MAIN_H #define SIM_MAIN_H -/* MIPS uses an unusual format for floating point quiet NaNs. */ -#define SIM_QUIET_NAN_NEGATED - #define SIM_CORE_SIGNAL(SD,CPU,CIA,MAP,NR_BYTES,ADDR,TRANSFER,ERROR) \ mips_core_signal ((SD), (CPU), (CIA), (MAP), (NR_BYTES), (ADDR), (TRANSFER), (ERROR)) -- 2.17.1