From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sm.strop.com.pl (sm.strop.com.pl [83.17.179.219]) by sourceware.org (Postfix) with ESMTPS id 7CABB3858D35 for ; Tue, 4 Jul 2023 14:46:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CABB3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=ztk-rp.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ztk-rp.eu Received: from zorro.ztk-rp.eu ([::ffff:10.208.4.171]) (TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by sm.strop.com.pl with ESMTPS; Tue, 04 Jul 2023 16:46:26 +0200 id 000000000128160C.0000000064A430C2.000010C7 Received: from public-gprs569267.centertel.pl ([37.225.86.244]:8726 helo=[192.168.43.32]) by zorro.ztk-rp.eu with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qGhIP-00EOzo-29; Tue, 04 Jul 2023 16:46:25 +0200 Message-ID: Date: Tue, 4 Jul 2023 16:46:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Content-Language: en-US To: David Brown , Ian Lance Taylor Cc: "Richard Earnshaw (lists)" , Martin Uecker , "gcc@gcc.gnu.org" References: <439affd4-11fe-de80-94c8-6fc64cbf76ec@ztk-rp.eu> <112e711791835d56cca38654f83a009cb46707d4.camel@gwdg.de> <940e9ae5-8649-5a28-e29f-06f0b2982892@ztk-rp.eu> From: =?UTF-8?Q?Rafa=c5=82_Pietrak?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 37.225.86.244 X-SA-Exim-Mail-From: embedded@ztk-rp.eu X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,NICE_REPLY_A,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,T_SPF_HELO_PERMERROR autolearn=ham autolearn_force=no version=3.4.6 Subject: Re: wishlist: support for shorter pointers X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on zorro.ztk-rp.eu) Received-SPF: unknown (IP address lookup failed.) SPF=FROM; sender=embedded@ztk-rp.eu; remoteip=::ffff:10.208.4.171; remotehost=; helo=zorro.ztk-rp.eu; receiver=sm.strop.com.pl; List-Id: Hi, W dniu 4.07.2023 o 14:38, David Brown pisze: [---------] > A key difference is that using 32-bit pointers on an x86 is enough > address space for a large majority of use-cases, while even on the > smallest small ARM microcontroller, 16-bit is not enough.  (It's not > even enough to access all memory on larger AVR microcontrollers - the > only 8-bit device supported by mainline gcc.)  So while 16 bits would > cover the address space of the RAM on a small ARM microcontroller, it > would not cover access to code/flash space (including read-only data), > IO registers, or other areas of memory-mapped memory and peripherals. > Generic low-level pointers really have to be able to access everything. Naturaly 16-bit is "most of the time" not enough to cover the entire workspace on even the smallest MCU (AVR being the only close to an exception here), but in my little experience, that is not really necessary. Meaning "generic low-level pointers really have to...", I don't think so. I really don't. Programs often manipulate quite "localized" data, and compiler is capable enough to distinguish and keep separate pointers of different "domains". What makes it currently impossible is tools (semantic constructs like pragma or named sections) that would let it happen. > > So an equivalent of x32 mode would not work at all.  Really, what you > want is a 16-bit "small pointer" that is added to 0x20000000 (the base > address for RAM in small ARM devices, in case anyone following this > thread is unfamiliar with the details) to get a real data pointer.  And > you'd like these small pointers to have convenient syntax and efficient > use. more or less yes. But "with a twist". A "compiler construct" that would be (say) sufficient to get the RAM-savings/optimization I'm aiming at could be "reduced" to the ability to create "medium-size" array of "some objects" and have them reference each other all WITHIN that "array". That array was in my earlier emails referred to as segment or section. So whenever a programmer writes a construct like: struct test_s attribute((small-and-funny)) { struct test_s attribute((small-and-funny)) *next, *prev, *head; struct test_s attribute((small-and-funny)) *user, *group; } repository[1000]; struct test_s attribute((small-and-funny)) *master, *trash; compiler puts that data into that small array (dedicated section), so no "generic low-level pointers" referring that data would need to exist within the program. And if it happens, error is thrown (or autoconversion happen). > > I think a C++ class (or rather, class template) with inline functions is > the way to go here.  gcc's optimiser will give good code, and the C++ > class will let you get nice syntax to hide the messy details. OK. Thenx for the advice, but going into c++ is a major thing for me and (at least for the time being) I'll stay with ordinary "big" pointers in plain C instead. > There is no good way to do this in C.  Named address spaces would be a > possibility, but require quite a bit of effort and change to the > compiler to implement, and they don't give you anything that you would > not get from a C++ class. Yes. named address spaces would be great. And for code, too. > (That's not quite true - named address spaces can, I believe, also > influence the section name used for allocation of data defined in these > spaces, which cannot be done by a C++ class.) OK. -R