From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NOR01-SV0-obe.outbound.protection.outlook.com (mail-sv0nor01on2072.outbound.protection.outlook.com [40.107.225.72]) by sourceware.org (Postfix) with ESMTPS id 31AE23858D28 for ; Mon, 3 Jul 2023 14:52:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31AE23858D28 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=westcontrol.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=westcontrol.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U81LAMrqWkLAu9L7Oeum3sP7mdQXnHNlSMnV/PowYE+1K2l/ZRl1WGASmnmsL88HvADGnxKUr2tZbYnbZIOKAw1+XINJO+mVO0XQ0SDmcUEOQzCf7Bfh8MONYGazj/WrsrNisGOeX0tldmuXDtpOUWtN9LNHvVcnkn8sLLuznB0pOK/pRkHv3FUWUXHzbKOc529Jx5NaGFMfON5cDRLzG4uQwC4Syo0CLoPiw4pUNdsX1WdvFS+KAFmsnMmCY/jNILJSZ0rdAd5/jSQE4r9iXFzW5ND9qJA6XuFjfiXWFNKqQy3tJ8LNCPhV1Jp4gEt5poy3zlpscZuBf7/QD2bDZA== 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=axqHCyMXSbNoOG5dz620obvnCzQgbg/rcwCjOi3+8U0=; b=ktML12eDuwzkW7WVGnfvdhLEYJK9TLLLh5qr0FptV1J6Y5hDDMSHkKdqHXIe9Xdbogg70o9uCRisMdTa8HvoSTxUYwBkpPWEk1z0wovBdaJ/jcoKiLDQU9/y9PpBUvWy70v+KkGkgowrBsg3ftxLf503DSv/kAd63nlH2h0xCdNwMcfRErPWfuxsjkviUy1kGDoy5TvtdenXVgrwdjgHxFK9kXBk8J1ABw1JadMxbSoaRMEI5F1ntblAQ8foZEKo4/EAq3ClxgSDfpf8FFxsEDMaRoZR9tC3Ho5NT4SbgAyOMPBKlj6rFVY/UAkwVOQx9if07UeEeOL7FCyCLXtgyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=westcontrol.com; dmarc=pass action=none header.from=westcontrol.com; dkim=pass header.d=westcontrol.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=westcontrol.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=axqHCyMXSbNoOG5dz620obvnCzQgbg/rcwCjOi3+8U0=; b=BMo67Woz49F0odWD/YDZ+RcYe51sVD54oUQfB4UOgLRm7o8YkAYFdduVkRGo/n/MoVF2SdBpI5osa0T5iiWXjyXQEIrD0WV/r0ghZy5reCHG0+1wRd0U3x4fbc3B3dXWHCskSMgVaFaVulKeNelY4kxPQixsb3g91fw3FxFkME42Z5BNyZsZRAoaO4a2HvFdTj2vGXl9TqsnKFKJmk4ovYFGoSveuBB8MpDb+Hh74qP2+IzfKPWVT1kFJ4purPczhnhnJvUESdoTvC0L5KKqJvn98OfQKG2Ddf4vEmr4I3KWvhfYeZmJIiEfHgz1N42Z0Cz9/E/re+CAx8P3Uat+FQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=westcontrol.com; Received: from SV0P279MB0233.NORP279.PROD.OUTLOOK.COM (2603:10a6:f10:b::13) by OL1P279MB0227.NORP279.PROD.OUTLOOK.COM (2603:10a6:e10:d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Mon, 3 Jul 2023 14:52:34 +0000 Received: from SV0P279MB0233.NORP279.PROD.OUTLOOK.COM ([fe80::b999:1d1d:3eb1:b8f1]) by SV0P279MB0233.NORP279.PROD.OUTLOOK.COM ([fe80::b999:1d1d:3eb1:b8f1%7]) with mapi id 15.20.6544.024; Mon, 3 Jul 2023 14:52:34 +0000 Message-ID: Date: Mon, 3 Jul 2023 16:52:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: wishlist: support for shorter pointers Content-Language: en-GB To: =?UTF-8?Q?Rafa=c5=82_Pietrak?= , Jonathan Wakely Cc: waffl3x , "gcc@gcc.gnu.org" References: <439affd4-11fe-de80-94c8-6fc64cbf76ec@ztk-rp.eu> <21650b1b-1d2e-7929-3105-b8aaca629272@ztk-rp.eu> From: David Brown In-Reply-To: <21650b1b-1d2e-7929-3105-b8aaca629272@ztk-rp.eu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SV0P279CA0048.NORP279.PROD.OUTLOOK.COM (2603:10a6:f10:13::17) To SV0P279MB0233.NORP279.PROD.OUTLOOK.COM (2603:10a6:f10:b::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SV0P279MB0233:EE_|OL1P279MB0227:EE_ X-MS-Office365-Filtering-Correlation-Id: d8623f08-44d1-40f9-2524-08db7bd52254 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8u6P6Qh+uATCfsVWs2mrVruy0RpYqY26UAs7uV7nk6tBjVwezbAeUxMHTZXPSHZ0wL0NGQ2HoCYWZnqnifi1DS30fFPluYCTSAa9uhYWw1go6/F3rqxqUDgi5mAbtINrdeW6iaDDAKJWI1to7bS0hNz/TfgOSAqP0JcoixtaaAt2Cn7HzjyQB+QoJ0j3MpPHcofzjvCRNFXgVif3qGjh6f0oKL60FBHZdG9dP/Hm5LCDkOjwmJixkQ4+neiwhMR861dz01rMvSrV4euAMOvp8zFITxGapBalirbp/JaWAvahR6GEoWucq35lY91P4ptWK7+CO1ya0fE8XOxb5yad1eohs0Hg0GUldHNykOzT84cyXnYg5ObnB4jyEuVrTFj+vddtoQcyvzy9loB7jRGxhe37qFFR07G30gXwe7uQITHSLYzb4GIAf6EnOhVErc+3c8ZIo1DNEe2FI6Ztnh19rwCuN1MEc/b4xR/mGu+AYGAKeO5JksVm0WRj5fbltJcpzt2pLPHqpQaDe9KO/NU6AqbhIbU5gZlwijDqDF7PvhcrHzixPPU+c1h9/nV4GJ5KCV8pCxDbFLW0JWJgCciK1pKl4rEt8IwVp5cruvZa224UQa07Ibtq48kPL2mgZNZSq44PBKQEN3jJNPSuXunqag== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SV0P279MB0233.NORP279.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(136003)(376002)(396003)(39840400004)(366004)(451199021)(26005)(478600001)(31686004)(6506007)(6512007)(86362001)(31696002)(2616005)(186003)(54906003)(38100700002)(66476007)(66556008)(66946007)(4326008)(83380400001)(110136005)(53546011)(6486002)(316002)(5660300002)(8936002)(8676002)(66899021)(41300700001)(2906002)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MUxHTW1FSEFVZ2tQSHZuR3VLOTJBTEcrZ3o2eWgzYTV0eklqMnVVdDNKUEI1?= =?utf-8?B?QnZQbWVIY3V3ajBQcVNZam9sa1BUaVhobVAyQVNkQUo5Z2tzaFRHSTFKRk5T?= =?utf-8?B?dmd0elNuZ2RleFl1UE8zd2ZRZ2VSeVRwZ1VyQTRBbWwxeXJaR1RXUUdUT0xw?= =?utf-8?B?RWFDZ3lwckRVamJwUXp6ckFTa21jRlp3QnkvRENWNnh1b1MyVUxyVEFuN1Fj?= =?utf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dzazRGWEVUYW9zRGtIazcyRTNRSHIxWDFpVGl5?= =?utf-8?B?bktHVjI5ZkhHN3ZHd0Y2SG04dTAwaGp4NnUzS09WQUcwWCtJUytuWVUxcnRI?= =?utf-8?Q?Rt543cV+MtBywR1wJE1tkVsVn?= X-OriginatorOrg: westcontrol.com X-MS-Exchange-CrossTenant-Network-Message-Id: d8623f08-44d1-40f9-2524-08db7bd52254 X-MS-Exchange-CrossTenant-AuthSource: SV0P279MB0233.NORP279.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2023 14:52:34.0633 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: c75fbd3c-42ad-4db0-9cff-972faf83ae45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RCX+6AIu9CAWYcZZbO4I/oy0ORb7Y1qLdZGCz3JFeAZBC2HASfvdkxwZvZp2rjoFHjGzLycXMNqQPMVSf0gm2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OL1P279MB0227 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 28/06/2023 10:35, Rafał Pietrak via Gcc wrote: > Hi Jonathan, > > W dniu 28.06.2023 o 09:31, Jonathan Wakely pisze: >> >> >> >> If you use a C++ library type for your pointers the syntax above >> doesn't need to change, and the fancy pointer type can be implemented >> portable, with customisation for targets where you could use 16 bits >> for the pointers. > > As you can expect from the problem I've stated - I don't know C++, so > I'll need some more advice there. > > But, before I dive into learning C++ (forgive the naive question).... > isn't it so, that C++ comes with a heavy runtime? One that will bloat my > tiny project? Or the bloat comes only when one uses particular > elaborated class/inheritance scenarios, and this particular case ( for > (...; ...; x = x->next) {} ) will not draw any of that into this project? > Let me make a few points (in no particular order) : 1. For some RISC targets, such as PowerPC, it is common to have a section of memory called the "small data section". One of the registers is dedicated as an anchor to this section, and data within it is addressed as Rx + 16-bit offset. But this is primarily for data at fixed (statically allocated) addresses, since reads and writes using this address mode are smaller and faster than full 32-bit addresses. Normal pointers are still 32-bit. It also requires a dedicated register - not a big cost when you have 31 GPRs, but much more costly when you have only 13. 2. C++ is only costly if you use costly features. On small embedded systems, you want "-fno-exceptions -fno-rtti", and you will get as good (or bad!) results for C++ as for C. Many standard library features will, however, result in a great deal of code - it is usually fairly obvious which classes and functions are appropriate. 3. In C, you could make a type such as : typedef struct { uint16_t p; } small_pointer_t; and conversion functions : static const uintptr_t ram_base = 0x20000000; static inline void * sp_to_voidp(small_pointer_t sp) { return (void *)(ram_base + sp); } static inline small_pointer_t voidp_to_sp(void * p) { small_pointer_t sp; sp.p = (uintptr_t) p - ram_base; return sp; } Then you would use these access functions to turn your "small pointers" into normal pointers. The source code would become significantly harder to read and write, and less type-safe, but could be quite efficient. In C++, you'd use the same kinds of functions. But they would now be methods in a class template, and tied to overloaded operators and/or conversion functions. The result would be type-safe and let you continue to use a normal pointer-like syntax, and with equally efficient generated code. You could also equally conveniently have small pointers to ram and to peripheral groups. This mailing list is not really the place to work through an implementation of such class templates - but it certainly could be done. 4. It is worth taking a step back, and thinking about how you would like to use these pointers. It is likely that you would be better thinking in terms of an array, rather than pointers - after all, you don't want to be using dynamically allocated memory here if you can avoid it, and certainly not generic malloc(). If you can use an array, then your index type can be as small as you like - maybe uint8_t is enough. David