🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #848

Re: Large constants in RISC

#848
From: Terje Mathisen
Date: Sat, 21 Nov 2026 07:53
96 lines
4790 bytes
EricP wrote:
> On 2026-Nov-20 16:01, MitchAlsup wrote:
>> EricP <ThatWouldBeTelling@thevillage.com> posted:
>>
>>> On 2026-Nov-19 08:59, Stefan Monnier wrote:
>>>> aph@littlepinkcloud.invalid [2026-11-19 09:42:51] wrote:
>>>>> In a way, it does. Most large constants I see are addresses.
>>>>> AArch64 (almost) always has a 48-bit user space, so except for
>>>>> floating-point doubles and the very occasional large integer, constant
>>>>> loads look like
>>>>>
>>>>>    mov x0, 42857; movk x0, 0x60b8, lsl 16; movk x0, 0xaaaa, lsl 32
>>>>
>>>> Interesting.  I would have expected that most AArch64 code is position
>>>> independent (e.g. for address space randomization purposes), so I 
>>>> wonder
>>>> in which circumstances we end up with such instruction sequences to
>>>> build hardcoded addresses.
>>>>
>>>>
>>>> === Stefan
>>>
>>> An application or OS can require that certain data structures
>>> are mapped at predefined virtual addresses.
>>> For example, an OS could define that the page tables are mapped at 
>>> 0xC00...00.
>>> The user mode OS interface could define that an int64 system clock is 
>>> mapped
>>> read-only at a particular virtual address so it can be read without a 
>>> system call.
>>
>> This just gave me an idea::
>>
>> a) when walking the page tables (TLB miss)
>> b) and you are at the (smallest) page level and you get another PTP
>> ...instead of a PTE,
>> then
>> c) this PTP accesses a PTE which provides for accessing a single
>> c.1) Double Word
>> or
>> c.2) Single line
>>
>> Making such access/PTE not blead address space to where it is not 
>> desired.
>> So, you can access the timer/time but not the surrounding control 
>> registers.
>>
>> You saw it here first!
> 
> I meant the software clock in memory. There are two clocks,
> a hardware and a software clock that the OS controls the adjustments
> HW clock can drift so OS adjusts its memory copy according to its own 
> algorithm.

That's just one way to do it:

FreeBSD had the first optimal (as in minimum resources for maximum 
precisiion) implementation, written by phk of NTP and FreeBSD fame, more 
recently the Varnish cache.

The design is to keep the sw clock in shareable memory, along with a 
user-space function to retrieve the current time:

(seconds, nanoseconds) = readclock()

implemented minimally as

   for (;;) {
     n = system.nanoseconds;  // All of these are marked volatile
     s = system.seconds;
     t = system.lasttick;
  // Avoids reading during update
     if (n == system.nanoseconds && s == system.seconds) break;
   }
   ticks = rdtsc();
   // Calculate the offset from last tick:
   delta = ticks - t;
   nsdelta = (delta * system.scaling_factor) >> system.scaling_shift;
   n += nsdelta;
   while n >= 1000000000 {
     s++;
     n -= 1000000000;
   }
   return (s, n);


-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
Technical Details
Message-ID: <11driml$3t06d$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11d76uq$11cdc$1@paganini.bofh.team> <11d7ct8$17akn$1@dont-email.me> <11d7ih2$11orr$1@paganini.bofh.team> <11d9d0d$1rsce$1@dont-email.me> <11d9tq8$1b9c1$2@paganini.bofh.team> <2026Nov14.201017@mips.complang.tuwien.ac.at> <6af911ea.18530156@news.eternal-september.org> <SYScnWsR3rgGWWP3nZ2dnZfqn_WdnZ2d@supernews.com> <jwv1p8hhqmy.fsf-monnier+comp.arch@gnu.org> <4m2MS.132607$Lt64.106487@fx41.iad> <1795208471-5857@newsgrouper.org> <uy4MS.79596$EAo4.22156@fx22.iad>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Terje Mathisen <terje.mathisen@tmsw.no>
Newsgroups: comp.arch
Subject: Re: Large constants in RISC
Date: Sat, 21 Nov 2026 08:53:56 +0100
Organization: A noiseless patient Spider
Lines: 96
Message-ID: <11driml$3t06d$1@dont-email.me>
References: <11d76uq$11cdc$1@paganini.bofh.team>
 <11d7ct8$17akn$1@dont-email.me> <11d7ih2$11orr$1@paganini.bofh.team>
 <11d9d0d$1rsce$1@dont-email.me> <11d9tq8$1b9c1$2@paganini.bofh.team>
 <2026Nov14.201017@mips.complang.tuwien.ac.at>
 <6af911ea.18530156@news.eternal-september.org>
 <SYScnWsR3rgGWWP3nZ2dnZfqn_WdnZ2d@supernews.com>
 <jwv1p8hhqmy.fsf-monnier+comp.arch@gnu.org>
 <4m2MS.132607$Lt64.106487@fx41.iad> <1795208471-5857@newsgrouper.org>
 <uy4MS.79596$EAo4.22156@fx22.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sat, 21 Nov 2026 07:53:58 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="4096205"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/31FaQ890LBWDqAU+tsyCtzO7YV0F6MeqWW04xoAYT3g=="; posting-host="38d130bc46ad0e3248d9904e2038941a"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101
 Firefox/140.0 SeaMonkey/2.53.24
Cancel-Lock: sha1:qoaAWKqP/cIoerPBcsHX3DiUS/s= sha256:aEZtu9AaEk2aqZBHDCZZZNKB/7NIRZkZfAK4SXOTAlo=
	sha1:dobef6alq9PbY6gzpSK+XxuwtCE= sha256:M7d9sq16vOTQ9iabAa5X7YJd50Bf+3AIkISHLzsA+fc=
In-Reply-To: <uy4MS.79596$EAo4.22156@fx22.iad>