From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gJ+jMqf13WETWQAAWB0awg (envelope-from ) for ; Tue, 11 Jan 2022 16:24:55 -0500 Received: by simark.ca (Postfix, from userid 112) id C9E1D1F34E; Tue, 11 Jan 2022 16:24:55 -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 DFA651F0E7 for ; Tue, 11 Jan 2022 16:24:54 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8E954393A411 for ; Tue, 11 Jan 2022 21:24:54 +0000 (GMT) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70092.outbound.protection.outlook.com [40.107.7.92]) by sourceware.org (Postfix) with ESMTPS id 42B1B3858029 for ; Tue, 11 Jan 2022 21:24:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 42B1B3858029 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=eaIjP/rS5k4cGytA7V2XwgpXD816+OVLpfPajDAO6w/1SfAq4q0sOb0v6RhcKOYALOTl7EqXs1CK4llHSK3CoYFZAbViC+X59ayEp8+9385ikGfaS6QNWK4wA/MBYHH8EUv9P5kKS36wqgVj1O94Gi+4ldABMgJ0TZdmJ5j78WAwGQADaVvspgqKUoNx4iebRsJEh8pLDIUBAf3ilf7F6neq2oEpt2TZd56AKnntU4X1EQox8+TMpihvdjAL8HbZnONkzalyHE+DqbvtcH8iEaZWn9eDbuFzMNYVp4aIsQB6AYFyC7JoxERQdcnGVjChsMIkIUyv1YoVxuCEeakUJQ== 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=3vYynNg0iybE0U4hsxFv+XnxmJ9ZG75KH1yOV2234x8=; b=Xys7kKnx72Wp9krW1pRMeXB1Syv4a+pXAnjbTaAbhWqKMOCRaIhNPUlFxT+N5MhaVKLbUq25fo2bqrk0hi5kvT2NNw/7wIxZFDPTk0KgUUHfkni5oTwmPEWYRU9BfHN6Nk2nghmeYSKhpDo7WTe7mhf4nmmTfaKtpBsNCsZ9nDi00wksiM1opc3lOjm6sUNl1+qQnQyX7i4D5aTxGlvmju8L3QbbeXOkla1oujwm9Qb5krPBu4MuEVdxDKYShyLAoo1aRySlJUpPDRMe2+MPJhhhnnVf15kMArpDG3j/nUal5v1Qr4r0Sor7CHTU6aYlEfuPw8Rxb1i6MVZVf3oQ4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; 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=3vYynNg0iybE0U4hsxFv+XnxmJ9ZG75KH1yOV2234x8=; b=EeDJk7S2OXs4I7vp3+4U5FxXYgxxnQbaC19HIPR8dgqVQCmn/dYa2S/tcKkYgMY94lQQVuDWlUR2t2l6arvyvtFxuw88S9hMncvz79Lo0waL/bY8rPXOeuid1+A42P9PknFan/F3H8ogjHv1iDoYLV5a227LQKhiQf16YiawbDA= 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 PA4PR03MB7278.eurprd03.prod.outlook.com (2603:10a6:102:10e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.9; Tue, 11 Jan 2022 21:24:25 +0000 Received: from VI1PR03MB4208.eurprd03.prod.outlook.com ([fe80::cc1b:e71f:5d70:48a3]) by VI1PR03MB4208.eurprd03.prod.outlook.com ([fe80::cc1b:e71f:5d70:48a3%3]) with mapi id 15.20.4888.010; Tue, 11 Jan 2022 21:24:25 +0000 From: Dragan Mladjenovic To: gdb-patches@sourceware.org Subject: [PATCH v3 1/4] sim: Allow toggling of quiet NaN-bit semantics Date: Tue, 11 Jan 2022 22:24:03 +0100 Message-Id: <20220111212406.32312-2-Dragan.Mladjenovic@syrmia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220111212406.32312-1-Dragan.Mladjenovic@syrmia.com> References: <20220111212406.32312-1-Dragan.Mladjenovic@syrmia.com> Content-Type: text/plain X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) 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: 77ca2f01-7909-46e4-f6f9-08d9d548be05 X-MS-TrafficTypeDiagnostic: PA4PR03MB7278:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o4vvkDls/GhcjFlL01UouIaE3czA4BabLLr51jjp0aTI6vm/b2EKPW39B6XX1AhIwdPxD3PqI8eeWUwZwMZvVfwnY2Vl+sSSggWn0gFuXmDtAkTeiXqmU8aCBv6h00/cTyad2PViIfq+bFeH6y/NWydCCPWw3eDNF5jXTDdqZRI/fvdNw1JTJhO4gxk6VQyldWYOVP2rBJHtuOk6j1bKxtgQkdmVOTh4v6yvYqwAvfoLNRg/wuD7+csrrfDLnlSIIWloBDRbB1PAttz6IaWNWTxHcxlvcuzH95x8kJkr/+hWI/8TeeWt3wxKxf45YhBnycGb/XCB9JYC4vSg4MJJ0ExvBwvIIBquNZf0oE/thVhJi3MLS6THpucuIRO3RTIgiLvspcEDlLc3oNZAwqkifnXXBmMzaLE9lnxuKdC9eG4lg4zW2qwBdZx5SxeoWESuNur62I+7JCAp2DNlGXmyOvcL7B0GxH1Z6p3SQXgO74nOEXMhNRWz4E9rISpPQ4Rs7qh2186f8l3x89IEKSQ7MBsEpAwFShWRWIEe1iAb/lfZ1bLbwLcgiPcSenUt3IpHJ2H2oDrd075CBVFIsdWpmyu/g7TwSa+omfudwo5l0LoGDBrsj0S5ure0IJ//Y3Yt29/D1fCAuKAv411jkScFNcYFcp4nnMER0sLmOXa2KL0+aXCnmrhpoh0oMIkl/MOAzRkZMP9yi2dhbhb7vpMmLw++tZaoHaXaQ55iJmn2jeN8KTWgNx7uxcyD7lnsLUoqBuYeljGjNgyWsEPwkCv4qzXXqBAi8YD7lISkQ/B/5Bs= 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:(39830400003)(396003)(346002)(366004)(136003)(376002)(83380400001)(5660300002)(36756003)(4326008)(8936002)(66556008)(186003)(54906003)(1076003)(26005)(6666004)(316002)(6506007)(66946007)(86362001)(6486002)(6512007)(8676002)(2616005)(66476007)(6916009)(38100700002)(52116002)(38350700002)(508600001)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/INi+gwnMJU4u8qQjubwIFp7T6XvfhYd6zIL7agnuWsPGTAiCFfzf6xdYVty?= =?us-ascii?Q?5wytbPNacyQUeoQ7MtHLfIVL+15TXR7YWrk7/32v4Rz2WajBvKba3a166AO5?= =?us-ascii?Q?FWOoJUQP5J8Dm78a8bEtU+DYgX+2qDZ6qNe0ztZdPKIthR35Ig6HiC6aVSuE?= =?us-ascii?Q?UAzLdUO8/9dUAg2l5bU8kuMK40cDhGqjiNYV7f/CEbPXp0uRCzaEpH20zg+X?= =?us-ascii?Q?pYF4ktlOfCYeCS3xpGoZO+ORToaAHSnY7QrP/hYo37SB1gHQOJXsBg/DUg0S?= =?us-ascii?Q?dX9nMBT86yQMmcwW9UAh74a/ZgdFkGcJZSaljuvrbvpcpKWPD4/J3Hjpy8YQ?= =?us-ascii?Q?c5jVpFkVJyrerUBSWR62B057cxwD3oTwnwCUjVajX4HGV9FyJ3R9D2ENNkDJ?= =?us-ascii?Q?2485anYSzpfPm3uS3eFL6BlUQo/WClA7o1GtnmR7qi06l6TJz46KbldL0Lb7?= =?us-ascii?Q?+IObgZ4mVIONuT3MnhNkPsdaKcFnFmokVowOm2y6hzf3ZQyHV2EnNfBCHqJF?= =?us-ascii?Q?XbSdTp4wJPcbSGI+bExfkYpecdvNHJ9CtvbkNzn8C36/xyCkdWA3RrdQiMoR?= =?us-ascii?Q?PYdMnmCXdi47v5UDnSFcfMz8rYpiePBvQTJbuGyRYJONLt8DBYL/XUxBrnkL?= =?us-ascii?Q?vKDB/amPLuj90V7fQGm4AO//bIpfQ+54tfAzLFpLqZHRCPSsal2H3lKDtNhB?= =?us-ascii?Q?buV0QCTaiCeAdSDjRpTZhRmR0/EhFB0LdcEQuXlXdmaV7Slmlw9hw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0Ti0LgCedjH8SVS/p1xJiP74zrpHwypciptkfuJm7?= =?us-ascii?Q?9OQhvA=3D=3D?= X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77ca2f01-7909-46e4-f6f9-08d9d548be05 X-MS-Exchange-CrossTenant-AuthSource: VI1PR03MB4208.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2022 21:24:25.5184 (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: 8vLwoCwC8eqKv89UDMiqHkPLIWdDytqGs4PTIiyXFBgBxBjzgcO+jW4UqcLBXotXMAQW7wKHa+gbcoXwpB1ENJez7VGdwIXeeTmUzSI/YAg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR03MB7278 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-01-11 Faraz Shahbazker sim/common/ChangeLog: * sim-fpu.c (sim_fpu_quiet_nan_inverted): New. (pack_fpu, unpack_fpu): Allow reversal of quiet NaN semantics. * sim-fpu.h (sim_fpu_quiet_nan_inverted): New extern. 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 | 35 ++++++++++++++++++++--------------- sim/common/sim-fpu.h | 2 ++ sim/mips/cp1.h | 4 ++++ sim/mips/mips.igen | 3 +++ sim/mips/sim-main.h | 3 --- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/sim/common/sim-fpu.c b/sim/common/sim-fpu.c index a05c57897ff..13af3eb7477 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 @@ -2530,6 +2527,14 @@ const sim_fpu sim_fpu_max32 = { const sim_fpu sim_fpu_max64 = { sim_fpu_class_number, 0, LSMASK64 (NR_FRAC_GUARD, NR_GUARDS64), NORMAL_EXPMAX64 }; + +/* 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. */ +bool sim_fpu_quiet_nan_inverted = false; #endif diff --git a/sim/common/sim-fpu.h b/sim/common/sim-fpu.h index 447621b5d73..bcbe6ea16f2 100644 --- a/sim/common/sim-fpu.h +++ b/sim/common/sim-fpu.h @@ -375,7 +375,9 @@ 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); +/* Toggle quiet NaN semantics. */ +extern bool 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