Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

C Code. C Code Run. Run, Code, RUN! PLEASE!!!!


devel / comp.arch / Re: Secrets of the ancients, What the World Needs Now

SubjectAuthor
* What the World Needs NowQuadibloc
+* Re: What the World Needs NowMitchAlsup
|+* Re: What the World Needs NowQuadibloc
||+- Re: What the World Needs NowScott Lurndal
||+* Re: What the World Needs NowMitchAlsup
|||`* Re: What the World Needs NowQuadibloc
||| `- Re: What the World Needs NowQuadibloc
||`- Re: What the World Needs NowQuadibloc
|`* Re: What the World Needs NowEricP
| +- Re: What the World Needs NowBGB
| `* Re: What the World Needs NowQuadibloc
|  +* Re: What the World Needs NowEricP
|  |`* Re: What the World Needs NowQuadibloc
|  | +* Re: What the World Needs NowMitchAlsup
|  | |`- Re: What the World Needs NowQuadibloc
|  | `* Re: What the World Needs NowEricP
|  |  +* Re: What the World Needs NowThomas Koenig
|  |  |+- Re: What the World Needs NowMitchAlsup
|  |  |`- Re: What the World Needs NowScott Lurndal
|  |  +- Re: What the World Needs NowQuadibloc
|  |  `* Re: What the World Needs NowBGB
|  |   `* Re: What the World Needs NowEricP
|  |    +- Re: What the World Needs NowBGB
|  |    `* Re: What the World Needs NowMitchAlsup
|  |     `* Re: What the World Needs NowEricP
|  |      +* Re: What the World Needs NowMitchAlsup
|  |      |`* Re: What the World Needs NowEricP
|  |      | `* Re: What the World Needs NowMitchAlsup
|  |      |  `- Re: What the World Needs NowScott Lurndal
|  |      `* Re: What the World Needs NowScott Lurndal
|  |       `- Re: What the World Needs NowMitchAlsup
|  `* Re: What the World Needs NowAnton Ertl
|   `* Re: What the World Needs NowQuadibloc
|    +* Re: What the World Needs NowQuadibloc
|    |+- Re: What the World Needs NowQuadibloc
|    |`- Re: What the World Needs NowAnton Ertl
|    +* Re: What the World Needs NowAnton Ertl
|    |+* Re: What the World Needs NowQuadibloc
|    ||`- Re: What the World Needs NowAnton Ertl
|    |`* Re: What the World Needs NowScott Lurndal
|    | `- Re: What the World Needs NowQuadibloc
|    `* Re: What the World Needs NowAnton Ertl
|     `* Re: What the World Needs NowThomas Koenig
|      +- Re: What the World Needs NowAnton Ertl
|      `* Re: Secrets of the ancients, What the World Needs NowJohn Levine
|       `* Re: Secrets of the ancients, What the World Needs NowThomas Koenig
|        `* Re: Secrets of the ancients, What the World Needs NowJohn Levine
|         `* Re: Secrets of the ancients, What the World Needs NowThomas Koenig
|          +* Re: Secrets of the ancients, What the World Needs NowJohn Levine
|          |`* Re: Secrets of the ancients, What the World Needs NowScott Lurndal
|          | `* Re: Secrets of the ancients, What the World Needs NowJohn Levine
|          |  `- Re: Secrets of the ancients, What the World Needs NowMitchAlsup
|          `* Re: Secrets of the ancients, What the World Needs NowNiklas Holsti
|           `* Re: Secrets of the ancients, What the World Needs NowAnton Ertl
|            `* Re: Secrets of the ancients, What the World Needs NowNiklas Holsti
|             +* Re: Secrets of the ancients, What the World Needs NowThomas Koenig
|             |+* Re: Secrets of the ancients, What the World Needs NowMitchAlsup
|             ||`* Re: Secrets of the ancients, What the World Needs NowNiklas Holsti
|             || +- Re: Secrets of the ancients, What the World Needs NowMitchAlsup
|             || `* Re: Secrets of the ancients, What the World Needs NowTerje Mathisen
|             ||  `- Re: Secrets of the ancients, What the World Needs NowNiklas Holsti
|             |`- Re: Secrets of the ancients, What the World Needs NowNiklas Holsti
|             +* Re: Secrets of the ancients, What the World Needs NowDavid Brown
|             |`* Re: Secrets of the ancients, What the World Needs NowStephen Fuld
|             | `* Re: Secrets of the ancients, What the World Needs NowAnton Ertl
|             |  +* Re: Secrets of the ancients, What the World Needs NowMitchAlsup
|             |  |+* Re: Secrets of the ancients, What the World Needs NowAnton Ertl
|             |  ||`* Nested functions and representation of closures (was: Secrets of the ancients, WStefan Monnier
|             |  || +* Re: Nested functions and representation of closuresDavid Brown
|             |  || |+* Re: Nested functions and representation of closuresThomas Koenig
|             |  || ||`* Re: Nested functions and representation of closuresEricP
|             |  || || `* Re: Nested functions and representation of closuresMitchAlsup
|             |  || ||  `- Re: Nested functions and representation of closuresEricP
|             |  || |`* Re: Nested functions and representation of closuresMichael S
|             |  || | `- Re: Nested functions and representation of closuresDavid Brown
|             |  || `* Re: Nested functions and representation of closures (was: Secrets of the ancientAnton Ertl
|             |  ||  `- Re: Nested functions and representation of closuresBGB
|             |  |+- Re: Secrets of the ancients, What the World Needs NowGeorge Neuner
|             |  |`- Re: Secrets of the ancients, What the World Needs NowJean-Marc Bourguet
|             |  `* Re: Secrets of the ancients, What the World Needs NowTim Rentsch
|             |   `* Re: Secrets of the ancients, What the World Needs NowMitchAlsup
|             |    +* Re: Secrets of the ancients, What the World Needs NowJohn Levine
|             |    |+- Re: Secrets of the ancients, What the World Needs NowMitchAlsup
|             |    |`* Re: Secrets of the ancients, What the World Needs NowAnton Ertl
|             |    | `- Re: Secrets of the ancients, What the World Needs NowGeorge Neuner
|             |    `- Re: Secrets of the ancients, What the World Needs NowTim Rentsch
|             `- Re: Secrets of the ancients, What the World Needs NowThomas Koenig
`* Re: What the World Needs NowQuadibloc
 `* Re: What the World Needs NowQuadibloc
  `- Re: What the World Needs NowQuadibloc

Pages:1234
Re: Secrets of the ancients, What the World Needs Now

<ult6sm$2hq7$1@gal.iecc.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35898&group=comp.arch#35898

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!not-for-mail
From: johnl@taugh.com (John Levine)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Tue, 19 Dec 2023 22:53:10 -0000 (UTC)
Organization: Taughannock Networks
Message-ID: <ult6sm$2hq7$1@gal.iecc.com>
References: <uletbu$19ohv$1@dont-email.me> <uls9ri$144lp$1@newsreader4.netcologne.de> <ulsc6i$2lqq$1@gal.iecc.com> <i9kgN.11546$5Hnd.8431@fx03.iad>
Injection-Date: Tue, 19 Dec 2023 22:53:10 -0000 (UTC)
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="83783"; mail-complaints-to="abuse@iecc.com"
In-Reply-To: <uletbu$19ohv$1@dont-email.me> <uls9ri$144lp$1@newsreader4.netcologne.de> <ulsc6i$2lqq$1@gal.iecc.com> <i9kgN.11546$5Hnd.8431@fx03.iad>
Cleverness: some
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: johnl@iecc.com (John Levine)
 by: John Levine - Tue, 19 Dec 2023 22:53 UTC

According to Scott Lurndal <slp53@pacbell.net>:
>>If you want to support nested functions, it's not hard, you make
>>function pointers two words, the code pointer and the static chain.
>
>Why? Nested functions need access to containing function local _data_,
>not code. The actual generated code is independent of the containing
>function.

Sorry, I meant pointers to nested functions. You are quite right that
if you can't take the address of an internal function, the code is
straightforward.

--
Regards,
John Levine, johnl@taugh.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. https://jl.ly

Re: Secrets of the ancients, What the World Needs Now

<6e0aca25ebd272bb9bd76ad4aa81b260@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35905&group=comp.arch#35905

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!.POSTED!not-for-mail
From: mitchalsup@aol.com (MitchAlsup)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Wed, 20 Dec 2023 01:48:46 +0000
Organization: novaBBS
Message-ID: <6e0aca25ebd272bb9bd76ad4aa81b260@news.novabbs.com>
References: <uletbu$19ohv$1@dont-email.me> <uls9ri$144lp$1@newsreader4.netcologne.de> <ulsc6i$2lqq$1@gal.iecc.com> <i9kgN.11546$5Hnd.8431@fx03.iad> <ult6sm$2hq7$1@gal.iecc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="486893"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
X-Rslight-Posting-User: 7e9c45bcd6d4757c5904fbe9a694742e6f8aa949
X-Rslight-Site: $2y$10$WeH.LToK1hS8FIFNMA18W.f58/VVCtXC/lCTHRHJ/l1y09xy5CyQa
 by: MitchAlsup - Wed, 20 Dec 2023 01:48 UTC

John Levine wrote:

> According to Scott Lurndal <slp53@pacbell.net>:
>>>If you want to support nested functions, it's not hard, you make
>>>function pointers two words, the code pointer and the static chain.

Quibble:

The conventional understanding is that a word is 32-bits* whereas by now
all address spaces are 64-bit capable. (*) except in x86 land where
word remains 16-bits (crikey) which makes "word" even less useful
when describing pointers.

>>
>>Why? Nested functions need access to containing function local _data_,
>>not code. The actual generated code is independent of the containing
>>function.

> Sorry, I meant pointers to nested functions. You are quite right that
> if you can't take the address of an internal function, the code is
> straightforward.

Say you have an array of pointers to nested recursive functions;
Each of these pointers was initialized at some depth of recursion,
and run into an indexed dereference of one of those pointers::

result = fun_p[k](arguments);

How do figure out where on the call-stack the scope of this particular
function being called resides ??

Then: is it possible to pass this nested function pointer through a
void * pointer and back to a nested function pointer and retain the
to access the function in the scope it was initialized ??

void *p = fun_p[k];
result = p(arguments);

Re: Secrets of the ancients, What the World Needs Now

<kufnq3Fmig1U1@mid.individual.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35911&group=comp.arch#35911

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Wed, 20 Dec 2023 10:43:47 +0200
Organization: Tidorum Ltd
Lines: 46
Message-ID: <kufnq3Fmig1U1@mid.individual.net>
References: <uletbu$19ohv$1@dont-email.me>
<ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com>
<uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com>
<uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net>
<2023Dec19.191250@mips.complang.tuwien.ac.at>
<kuegl7FbsrjU2@mid.individual.net> <ult3ms$14n37$1@newsreader4.netcologne.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net OoVC8T6gaDMt3SoD7+VRWg+BNcWvfQCN/5Ktqd/XpOzxOVff28
Cancel-Lock: sha1:kWB210gvJmyhPCfXkg8hKoVXC+k= sha256:r9g3Ik0kZj81DleHtevlEdWLi/K7T2d9R0Tduju9Rl8=
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <ult3ms$14n37$1@newsreader4.netcologne.de>
 by: Niklas Holsti - Wed, 20 Dec 2023 08:43 UTC

On 2023-12-19 23:58, Thomas Koenig wrote:
> Niklas Holsti <niklas.holsti@tidorum.invalid> schrieb:
>
>>> E.g., consider a numerical integration function integrate(f,lo,hi),
>>> which expects a function with one parameter f(x), and you want to
>>> integrate x^y (pow(x,y) in C), where y is, say, passed as parameter.
>>
>>
>> That is the canonical example, yes. But it happens I have never needed
>> to do numerical integration in my Ada programs. I do have some cases
>> where I have used locally instantiated generics with generic function
>> parameters in the way I described above. In Ada the integration example
>> would be declared thusly:
>>
>> generic
>> with function F (X : Float) return Float;
>> function Integrate (Lo, Hi : Float) return Float;
>>
>> although one would usually not limit it to a specific number type such
>> as Float, but would make this type also a generic (type) parameter.
>> IIRC, the ability to define numerical integration as a generic
>> subprogram, with the function to be integrated as a generic parameter,
>> was one of the reasons presented for omitting function pointers entirely
>> from original Ada (Ada 83).
>
> Interesting, thanks!
>
> Just one remark: Making numerical routines generic can be a bit
> problematic if constants depend on the accuracy of a type; things
> like tolerances for checks for convergence, number of coefficients
> in a polynomial (or Chebyshev) evaluation, quantities to divide by
> for numeric differentiation etc.

I certainly agree that the numerical analysis involved in implementing
something type-generic to a known accuracy is hard, and probably beyond
my skills. However, Ada provides a number of "attributes" that can be
used to query the properties of a floating-point type, including a
generic formal type, for example S'Model_Epsilon which shows the
accuracy of the floating-point type S. In principle, a generic algorithm
could adjust itself according to these properties.

For the full list of these attributes and their definitions, see
http://www.ada-auth.org/standards/22rm/html/RM-A-5-3.html and
http://www.ada-auth.org/standards/22rm/html/RM-G-2-2.html.

Re: Secrets of the ancients, What the World Needs Now

<kufo8dFmig3U1@mid.individual.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35912&group=comp.arch#35912

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Wed, 20 Dec 2023 10:51:25 +0200
Organization: Tidorum Ltd
Lines: 50
Message-ID: <kufo8dFmig3U1@mid.individual.net>
References: <uletbu$19ohv$1@dont-email.me>
<ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com>
<uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com>
<uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net>
<2023Dec19.191250@mips.complang.tuwien.ac.at>
<kuegl7FbsrjU2@mid.individual.net> <ult3ms$14n37$1@newsreader4.netcologne.de>
<dc73b645013a758c6bd9d18b0fcbfb22@news.novabbs.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net xLvBd5f7ZR8HWMzJo/VrhwvtpYz8pb1xNKSb1OSuEAehblp/4H
Cancel-Lock: sha1:ZKxacgGf8BLAUDtY5BzkR0B2QBw= sha256:0iz4k7AtJ0ZeaS3HgyGyTlMtB88+3Nq+v314dVjqe7w=
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <dc73b645013a758c6bd9d18b0fcbfb22@news.novabbs.com>
 by: Niklas Holsti - Wed, 20 Dec 2023 08:51 UTC

On 2023-12-20 0:37, MitchAlsup wrote:
> Thomas Koenig wrote:
>
>> Niklas Holsti <niklas.holsti@tidorum.invalid> schrieb:
>
>>>> E.g., consider a numerical integration function integrate(f,lo,hi),
>>>> which expects a function with one parameter f(x), and you want to
>>>> integrate x^y (pow(x,y) in C), where y is, say, passed as parameter.
>>>
>>>
>>> That is the canonical example, yes. But it happens I have never
>>> needed to do numerical integration in my Ada programs. I do have some
>>> cases where I have used locally instantiated generics with generic
>>> function parameters in the way I described above. In Ada the
>>> integration example would be declared thusly:
>>>
>>>     generic
>>>        with function F (X : Float) return Float;
>>>     function Integrate (Lo, Hi : Float) return Float;
>>>
>>> although one would usually not limit it to a specific number type
>>> such as Float, but would make this type also a generic (type)
>>> parameter. IIRC, the ability to define numerical integration as a
>>> generic subprogram, with the function to be integrated as a generic
>>> parameter, was one of the reasons presented for omitting function
>>> pointers entirely from original Ada (Ada 83).
>
>> Interesting, thanks!
>
>> Just one remark: Making numerical routines generic can be a bit
>> problematic if constants depend on the accuracy of a type; things
>> like tolerances for checks for convergence,
>
> whether compiler constant arithmetic has the same numeric properties as
> compiled code instruction sequences,

Ada compilers are required to evaluate typeless constant arithmetic to
unbounded precision (as "bignums"). For example, the constant pi is
defined thusly in the standard package Ada.Numerics:

Pi : constant :=
3.14159_26535_89793_23846_26433_83279_50288_41971_69399_37511;

and all the digits are significant in any computation involving Pi and
other typeless constants.

Computation with typed constants is required to use the operations of
that type, so should match what the target code does.

Re: Secrets of the ancients, What the World Needs Now

<ulusjs$j0q5$3@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35915&group=comp.arch#35915

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Wed, 20 Dec 2023 15:10:04 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <ulusjs$j0q5$3@dont-email.me>
References: <uletbu$19ohv$1@dont-email.me>
<ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com>
<uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com>
<uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net>
<2023Dec19.191250@mips.complang.tuwien.ac.at>
<kuegl7FbsrjU2@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 20 Dec 2023 14:10:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="53c55e9701c1f197290cc0d22587086b";
logging-data="623429"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dWYvADitV67LFe6juh6FBfZ25Ir+k/bk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:O4pgjY+EsSI6d9h0IoWtZLblSvY=
Content-Language: en-GB
In-Reply-To: <kuegl7FbsrjU2@mid.individual.net>
 by: David Brown - Wed, 20 Dec 2023 14:10 UTC

On 19/12/2023 22:35, Niklas Holsti wrote:
> On 2023-12-19 20:12, Anton Ertl wrote:
>> Niklas Holsti <niklas.holsti@tidorum.invalid> writes:
>>> In my own (non-critical) Ada programs, small nested subprograms are not
>>> unusual, but pointers to them are very rare (I don't recall a single
>>> case of it).
>>
>> That's interesting, because a major reason for using nested functions
>> (or, more generally, closures), is if you need to pass a function with
>> a given interface, but have to pass additional data to that function.
>
>
> In Ada, instead of passing a (nested) function pointer to some service
> that needs such a parameter, one can implement the service as a generic
> program unit, where the function to be passed is given as a generic
> parameter, and instantiate that generic locally in the nested context,
> thus binding the instance with the nested function.
>
> Depending on the way the compiler implements such generics (as macros,
> or with shared code) this may or may not be implemented by passing a
> function pointer, but even if it is, the compiler can use a "fat
> pointer" for this generic case, without being forced to use a fat
> pointer for all function pointers.
>

That sounds very like lambdas in C++. It is much better than the way
nested functions in (extended) C sometimes have to be implemented, where
run-time generated trampoline functions on the stack are used to hide
the "fat" when a fat pointer would be safer and more efficient.

Re: What the World Needs Now

<qBEgN.26431$LONb.2938@fx08.iad>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35917&group=comp.arch#35917

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!3.eu.feeder.erje.net!2.eu.feeder.erje.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx08.iad.POSTED!not-for-mail
From: ThatWouldBeTelling@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: What the World Needs Now
References: <uletbu$19ohv$1@dont-email.me> <5c7dd089ac74ea85a07413b08347a333@news.novabbs.com> <ALZeN.1985$U1cc.561@fx04.iad> <ulkine$2fi18$1@dont-email.me> <sDkfN.51804$Wp_8.32752@fx17.iad> <ulld29$2jkgh$1@dont-email.me> <PuFfN.53323$p%Mb.32922@fx15.iad> <uloo9t$3cr2r$1@dont-email.me> <J_%fN.65941$Wp_8.29224@fx17.iad> <0e17e28cd97d3872f2260887512ec040@news.novabbs.com>
In-Reply-To: <0e17e28cd97d3872f2260887512ec040@news.novabbs.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 24
Message-ID: <qBEgN.26431$LONb.2938@fx08.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Wed, 20 Dec 2023 16:27:02 UTC
Date: Wed, 20 Dec 2023 11:26:54 -0500
X-Received-Bytes: 1971
 by: EricP - Wed, 20 Dec 2023 16:26 UTC

MitchAlsup wrote:
> EricP wrote:
>
>>
>> If one has super and User mode, and R,W,E enables, that's 6 PTE bits.
>> The PTE is very cramped so there is a big incentive to save any bits.
>> We can get that down to 3 PTE bits by throwing out the silly
>> combinations,
>> Write-only, Execute-only, Super:NoAccess+User:RWE,...
>
> If one uses a different page table for user and supervisor, you only
> need those 3-bits. In my case Guest OS has its own table and its own
> ASID completely separate from application. ASID plays the part of G
> (global).

Ok but all major OS's view the current process address space (P-space)
as directly addressable from system space (S-space), so the OS can reach
directly into the current process to read or write memory to pass args
to/from syscalls or deliver signals, etc.

To support this view of virtual memory on that platform all OS's would
need to maintain two parallel page tables to map each P-space twice,
one for user mode and one for super mode.

Re: Secrets of the ancients, What the World Needs Now

<29794d0b0c5d90fc63131829d3aa24d9@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35919&group=comp.arch#35919

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!.POSTED!not-for-mail
From: mitchalsup@aol.com (MitchAlsup)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Wed, 20 Dec 2023 16:40:32 +0000
Organization: novaBBS
Message-ID: <29794d0b0c5d90fc63131829d3aa24d9@news.novabbs.com>
References: <uletbu$19ohv$1@dont-email.me> <ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com> <uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com> <uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net> <2023Dec19.191250@mips.complang.tuwien.ac.at> <kuegl7FbsrjU2@mid.individual.net> <ult3ms$14n37$1@newsreader4.netcologne.de> <dc73b645013a758c6bd9d18b0fcbfb22@news.novabbs.com> <kufo8dFmig3U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="555376"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$S.agxvGwVXsOlRDbT4KbLuZmCzk6xHNCRFsCw.r6LEAt9.WHtQq1.
X-Rslight-Posting-User: 7e9c45bcd6d4757c5904fbe9a694742e6f8aa949
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
 by: MitchAlsup - Wed, 20 Dec 2023 16:40 UTC

Niklas Holsti wrote:

> On 2023-12-20 0:37, MitchAlsup wrote:
>> Thomas Koenig wrote:
>>
>>> Niklas Holsti <niklas.holsti@tidorum.invalid> schrieb:
>>
>>>>> E.g., consider a numerical integration function integrate(f,lo,hi),
>>>>> which expects a function with one parameter f(x), and you want to
>>>>> integrate x^y (pow(x,y) in C), where y is, say, passed as parameter.
>>>>
>>>>
>>>> That is the canonical example, yes. But it happens I have never
>>>> needed to do numerical integration in my Ada programs. I do have some
>>>> cases where I have used locally instantiated generics with generic
>>>> function parameters in the way I described above. In Ada the
>>>> integration example would be declared thusly:
>>>>
>>>>     generic
>>>>        with function F (X : Float) return Float;
>>>>     function Integrate (Lo, Hi : Float) return Float;
>>>>
>>>> although one would usually not limit it to a specific number type
>>>> such as Float, but would make this type also a generic (type)
>>>> parameter. IIRC, the ability to define numerical integration as a
>>>> generic subprogram, with the function to be integrated as a generic
>>>> parameter, was one of the reasons presented for omitting function
>>>> pointers entirely from original Ada (Ada 83).
>>
>>> Interesting, thanks!
>>
>>> Just one remark: Making numerical routines generic can be a bit
>>> problematic if constants depend on the accuracy of a type; things
>>> like tolerances for checks for convergence,
>>
>> whether compiler constant arithmetic has the same numeric properties as
>> compiled code instruction sequences,

> Ada compilers are required to evaluate typeless constant arithmetic to
> unbounded precision (as "bignums"). For example, the constant pi is
> defined thusly in the standard package Ada.Numerics:

> Pi : constant :=
> 3.14159_26535_89793_23846_26433_83279_50288_41971_69399_37511;

> and all the digits are significant in any computation involving Pi and
> other typeless constants.

> Computation with typed constants is required to use the operations of
> that type, so should match what the target code does.

What happens when the hosting machine makes a rounding error that the
target machine would not ?? {{Say, for example, the ADA routine changes
the rounding mode as it goes about its business, but the host compiler
does not see the rounding mode being changed ??}}

Re: What the World Needs Now

<9f2d0ab603721cddbf722e7cf3857ae9@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35920&group=comp.arch#35920

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!.POSTED!not-for-mail
From: mitchalsup@aol.com (MitchAlsup)
Newsgroups: comp.arch
Subject: Re: What the World Needs Now
Date: Wed, 20 Dec 2023 16:37:40 +0000
Organization: novaBBS
Message-ID: <9f2d0ab603721cddbf722e7cf3857ae9@news.novabbs.com>
References: <uletbu$19ohv$1@dont-email.me> <5c7dd089ac74ea85a07413b08347a333@news.novabbs.com> <ALZeN.1985$U1cc.561@fx04.iad> <ulkine$2fi18$1@dont-email.me> <sDkfN.51804$Wp_8.32752@fx17.iad> <ulld29$2jkgh$1@dont-email.me> <PuFfN.53323$p%Mb.32922@fx15.iad> <uloo9t$3cr2r$1@dont-email.me> <J_%fN.65941$Wp_8.29224@fx17.iad> <0e17e28cd97d3872f2260887512ec040@news.novabbs.com> <qBEgN.26431$LONb.2938@fx08.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="555376"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
X-Rslight-Posting-User: 7e9c45bcd6d4757c5904fbe9a694742e6f8aa949
X-Rslight-Site: $2y$10$7Z4rGTDMgQClwQIgPYajh.kKJfdlo2YJ8.OMK6/CaxF/t9LhKd9Ny
 by: MitchAlsup - Wed, 20 Dec 2023 16:37 UTC

EricP wrote:

> MitchAlsup wrote:
>> EricP wrote:
>>
>>>
>>> If one has super and User mode, and R,W,E enables, that's 6 PTE bits.
>>> The PTE is very cramped so there is a big incentive to save any bits.
>>> We can get that down to 3 PTE bits by throwing out the silly
>>> combinations,
>>> Write-only, Execute-only, Super:NoAccess+User:RWE,...
>>
>> If one uses a different page table for user and supervisor, you only
>> need those 3-bits. In my case Guest OS has its own table and its own
>> ASID completely separate from application. ASID plays the part of G
>> (global).

> Ok but all major OS's view the current process address space (P-space)
> as directly addressable from system space (S-space), so the OS can reach
> directly into the current process to read or write memory to pass args
> to/from syscalls or deliver signals, etc.

My 66000 provides this. Guest OS can reach down into application VaS,
application cannot reach up into Guest OS VaS. When Guest OS accesses
its own VaS it uses its own ASID, when accessing application it uses
application ASID. The same analogue occurs in Guest HV reaching down
into Guest OS VaS. When Guest HV accesses its own VaS it uses 1-level
translation and its own ASID; when accessing Guest OS it uses 2-level
translation and Guest OS ASID.

Switching between levels is fast because all the required information
is loaded at all times. Switching contexts is fast because only 1
register needs to be written, the data is obtained as if the control
registers were a cache of the data at the written address.

> To support this view of virtual memory on that platform all OS's would
> need to maintain two parallel page tables to map each P-space twice,
> one for user mode and one for super mode.

Re: Secrets of the ancients, What the World Needs Now

<ulvac2$l7hl$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35921&group=comp.arch#35921

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: sfuld@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Wed, 20 Dec 2023 10:04:50 -0800
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <ulvac2$l7hl$1@dont-email.me>
References: <uletbu$19ohv$1@dont-email.me>
<ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com>
<uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com>
<uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net>
<2023Dec19.191250@mips.complang.tuwien.ac.at>
<kuegl7FbsrjU2@mid.individual.net> <ulusjs$j0q5$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 20 Dec 2023 18:04:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0b4df9f8b7e1c56a57110571215f0840";
logging-data="695861"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194Ujyf2FjJ08GDiq80SVJ7UT7A4ameyxE="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:huojModTMI/kY4sGib/SRexfDX8=
In-Reply-To: <ulusjs$j0q5$3@dont-email.me>
Content-Language: en-US
 by: Stephen Fuld - Wed, 20 Dec 2023 18:04 UTC

On 12/20/2023 6:10 AM, David Brown wrote:
> On 19/12/2023 22:35, Niklas Holsti wrote:
>> On 2023-12-19 20:12, Anton Ertl wrote:
>>> Niklas Holsti <niklas.holsti@tidorum.invalid> writes:
>>>> In my own (non-critical) Ada programs, small nested subprograms are not
>>>> unusual, but pointers to them are very rare (I don't recall a single
>>>> case of it).
>>>
>>> That's interesting, because a major reason for using nested functions
>>> (or, more generally, closures), is if you need to pass a function with
>>> a given interface, but have to pass additional data to that function.
>>
>>
>> In Ada, instead of passing a (nested) function pointer to some service
>> that needs such a parameter, one can implement the service as a
>> generic program unit, where the function to be passed is given as a
>> generic parameter, and instantiate that generic locally in the nested
>> context, thus binding the instance with the nested function.
>>
>> Depending on the way the compiler implements such generics (as macros,
>> or with shared code) this may or may not be implemented by passing a
>> function pointer, but even if it is, the compiler can use a "fat
>> pointer" for this generic case, without being forced to use a fat
>> pointer for all function pointers.
>>
>
> That sounds very like lambdas in C++.  It is much better than the way
> nested functions in (extended) C sometimes have to be implemented, where
> run-time generated trampoline functions on the stack are used to hide
> the "fat" when a fat pointer would be safer and more efficient.

I believe Pascal, back in the 1970s implemented nested functions, though
I don't know how any specific implementation accomplished it. ISTM,
this is a nice mechanism for program development, allowing "iterative"
development.

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: What the World Needs Now

<z9GgN.75075$c3Ea.2907@fx10.iad>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35923&group=comp.arch#35923

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!nntp.comgw.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx10.iad.POSTED!not-for-mail
From: ThatWouldBeTelling@thevillage.com (EricP)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
MIME-Version: 1.0
Newsgroups: comp.arch
Subject: Re: What the World Needs Now
References: <uletbu$19ohv$1@dont-email.me> <5c7dd089ac74ea85a07413b08347a333@news.novabbs.com> <ALZeN.1985$U1cc.561@fx04.iad> <ulkine$2fi18$1@dont-email.me> <sDkfN.51804$Wp_8.32752@fx17.iad> <ulld29$2jkgh$1@dont-email.me> <PuFfN.53323$p%Mb.32922@fx15.iad> <uloo9t$3cr2r$1@dont-email.me> <J_%fN.65941$Wp_8.29224@fx17.iad> <0e17e28cd97d3872f2260887512ec040@news.novabbs.com> <qBEgN.26431$LONb.2938@fx08.iad> <9f2d0ab603721cddbf722e7cf3857ae9@news.novabbs.com>
In-Reply-To: <9f2d0ab603721cddbf722e7cf3857ae9@news.novabbs.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 43
Message-ID: <z9GgN.75075$c3Ea.2907@fx10.iad>
X-Complaints-To: abuse@UsenetServer.com
NNTP-Posting-Date: Wed, 20 Dec 2023 18:13:51 UTC
Date: Wed, 20 Dec 2023 13:13:29 -0500
X-Received-Bytes: 3034
 by: EricP - Wed, 20 Dec 2023 18:13 UTC

MitchAlsup wrote:
> EricP wrote:
>
>> MitchAlsup wrote:
>>> EricP wrote:
>>>
>>>>
>>>> If one has super and User mode, and R,W,E enables, that's 6 PTE bits.
>>>> The PTE is very cramped so there is a big incentive to save any bits.
>>>> We can get that down to 3 PTE bits by throwing out the silly
>>>> combinations,
>>>> Write-only, Execute-only, Super:NoAccess+User:RWE,...
>>>
>>> If one uses a different page table for user and supervisor, you only
>>> need those 3-bits. In my case Guest OS has its own table and its own
>>> ASID completely separate from application. ASID plays the part of G
>>> (global).
>
>> Ok but all major OS's view the current process address space (P-space)
>> as directly addressable from system space (S-space), so the OS can reach
>> directly into the current process to read or write memory to pass args
>> to/from syscalls or deliver signals, etc.
>
> My 66000 provides this. Guest OS can reach down into application VaS,
> application cannot reach up into Guest OS VaS. When Guest OS accesses
> its own VaS it uses its own ASID, when accessing application it uses
> application ASID. The same analogue occurs in Guest HV reaching down
> into Guest OS VaS. When Guest HV accesses its own VaS it uses 1-level
> translation and its own ASID; when accessing Guest OS it uses 2-level
> translation and Guest OS ASID.
>
> Switching between levels is fast because all the required information
> is loaded at all times. Switching contexts is fast because only 1
> register needs to be written, the data is obtained as if the control
> registers were a cache of the data at the written address.

How does these two ASIDs allow 3 bits in a PTE to grant different
access for the same page to user and OS? For example S:RW,U:RE

>> To support this view of virtual memory on that platform all OS's would
>> need to maintain two parallel page tables to map each P-space twice,
>> one for user mode and one for super mode.

Re: What the World Needs Now

<nkGgN.14619$5Hnd.7577@fx03.iad>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35924&group=comp.arch#35924

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx03.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: What the World Needs Now
Newsgroups: comp.arch
References: <uletbu$19ohv$1@dont-email.me> <5c7dd089ac74ea85a07413b08347a333@news.novabbs.com> <ALZeN.1985$U1cc.561@fx04.iad> <ulkine$2fi18$1@dont-email.me> <sDkfN.51804$Wp_8.32752@fx17.iad> <ulld29$2jkgh$1@dont-email.me> <PuFfN.53323$p%Mb.32922@fx15.iad> <uloo9t$3cr2r$1@dont-email.me> <J_%fN.65941$Wp_8.29224@fx17.iad> <0e17e28cd97d3872f2260887512ec040@news.novabbs.com> <qBEgN.26431$LONb.2938@fx08.iad>
Lines: 36
Message-ID: <nkGgN.14619$5Hnd.7577@fx03.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 20 Dec 2023 18:25:23 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 20 Dec 2023 18:25:23 GMT
X-Received-Bytes: 2513
 by: Scott Lurndal - Wed, 20 Dec 2023 18:25 UTC

EricP <ThatWouldBeTelling@thevillage.com> writes:
>MitchAlsup wrote:
>> EricP wrote:
>>
>>>
>>> If one has super and User mode, and R,W,E enables, that's 6 PTE bits.
>>> The PTE is very cramped so there is a big incentive to save any bits.
>>> We can get that down to 3 PTE bits by throwing out the silly
>>> combinations,
>>> Write-only, Execute-only, Super:NoAccess+User:RWE,...
>>
>> If one uses a different page table for user and supervisor, you only
>> need those 3-bits. In my case Guest OS has its own table and its own
>> ASID completely separate from application. ASID plays the part of G
>> (global).
>
>Ok but all major OS's view the current process address space (P-space)
>as directly addressable from system space (S-space), so the OS can reach
>directly into the current process to read or write memory to pass args
>to/from syscalls or deliver signals, etc.
>
>To support this view of virtual memory on that platform all OS's would
>need to maintain two parallel page tables to map each P-space twice,
>one for user mode and one for super mode.

ARMv8 maps each half separately. There is a separate translation table
for each half of the virtual address space, with the high-half holding
the kernel code and data, and the low half holding the user portion.

Each half has it's own translation table base register and each half
can use a different asid.

Context switch between processes simply requires reloading the
table base register for the lower half (TTBR0_EL1). No other
TLB maintainance is required unless the 16-bit ASID wraps.

Re: Secrets of the ancients, What the World Needs Now

<2023Dec20.194712@mips.complang.tuwien.ac.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35925&group=comp.arch#35925

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Wed, 20 Dec 2023 18:47:12 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 27
Message-ID: <2023Dec20.194712@mips.complang.tuwien.ac.at>
References: <uletbu$19ohv$1@dont-email.me> <ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com> <uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com> <uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net> <2023Dec19.191250@mips.complang.tuwien.ac.at> <kuegl7FbsrjU2@mid.individual.net> <ulusjs$j0q5$3@dont-email.me> <ulvac2$l7hl$1@dont-email.me>
Injection-Info: dont-email.me; posting-host="1f6480fbdc6f52ff5822f0e6f5f28b62";
logging-data="722389"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+V+Mdd7aIacYP4z16zNRkh"
Cancel-Lock: sha1:hRajXUOyPn0jl+tgKo2vs8KmRp0=
X-newsreader: xrn 10.11
 by: Anton Ertl - Wed, 20 Dec 2023 18:47 UTC

Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
>I believe Pascal, back in the 1970s implemented nested functions, though
>I don't know how any specific implementation accomplished it.

AFAIK Pascal implementations all just use static links chains to the
enclosing scopes. So you access an outer local by following the link
chain as many levels as you cross scopes. Pascal allows passing
nested functions/procedures as parameters, but does not support
variables containing them, or any other first-class handling of them.
This avoids the upward funarg problem (as the Lispers call it). These
parameters consist of the code pointer and the static link pointer.

Modula-2 has nested procedures, and allows putting procedures in
variables, fields, etc., but eliminates the upward funarg problem by
only allowing to store global-level procedures in variables, not
nested procedures. So it went closer to C.

Oberon originally had nested procedures, and AFAIK similar rules to
Modula-2. When I asked Wirth in 2020 if he has a good example for the
use of nested procedures (I thought he would have, given that he kept
this feature for so many years), he told me that he had removed nested
functions in 2013 or so.

- anton
--
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>

Re: Secrets of the ancients, What the World Needs Now

<4bab9ad8e39f0b0c1610a7549478c9ac@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35927&group=comp.arch#35927

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!.POSTED!not-for-mail
From: mitchalsup@aol.com (MitchAlsup)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Wed, 20 Dec 2023 21:09:44 +0000
Organization: novaBBS
Message-ID: <4bab9ad8e39f0b0c1610a7549478c9ac@news.novabbs.com>
References: <uletbu$19ohv$1@dont-email.me> <ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com> <uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com> <uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net> <2023Dec19.191250@mips.complang.tuwien.ac.at> <kuegl7FbsrjU2@mid.individual.net> <ulusjs$j0q5$3@dont-email.me> <ulvac2$l7hl$1@dont-email.me> <2023Dec20.194712@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="577650"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 7e9c45bcd6d4757c5904fbe9a694742e6f8aa949
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
X-Rslight-Site: $2y$10$w2u00RPYTBjr2uJraBZsLOPZb7jZn7B8.WxUv1krLJ.wl0ItmMDK.
 by: MitchAlsup - Wed, 20 Dec 2023 21:09 UTC

Anton Ertl wrote:

> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
>>I believe Pascal, back in the 1970s implemented nested functions, though
>>I don't know how any specific implementation accomplished it.

> AFAIK Pascal implementations all just use static links chains to the
> enclosing scopes. So you access an outer local by following the link
> chain as many levels as you cross scopes.

How does Pascal do this counting when there are recursive frames on
the stack ??

> Pascal allows passing
> nested functions/procedures as parameters, but does not support
> variables containing them, or any other first-class handling of them.
> This avoids the upward funarg problem (as the Lispers call it). These
> parameters consist of the code pointer and the static link pointer.

> Modula-2 has nested procedures, and allows putting procedures in
> variables, fields, etc., but eliminates the upward funarg problem by
> only allowing to store global-level procedures in variables, not
> nested procedures. So it went closer to C.

> Oberon originally had nested procedures, and AFAIK similar rules to
> Modula-2. When I asked Wirth in 2020 if he has a good example for the
> use of nested procedures (I thought he would have, given that he kept
> this feature for so many years), he told me that he had removed nested
> functions in 2013 or so.

> - anton

Re: What the World Needs Now

<708cb7d2d0ff6d6c2a05d657332e6f0d@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35929&group=comp.arch#35929

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!.POSTED!not-for-mail
From: mitchalsup@aol.com (MitchAlsup)
Newsgroups: comp.arch
Subject: Re: What the World Needs Now
Date: Wed, 20 Dec 2023 21:11:37 +0000
Organization: novaBBS
Message-ID: <708cb7d2d0ff6d6c2a05d657332e6f0d@news.novabbs.com>
References: <uletbu$19ohv$1@dont-email.me> <5c7dd089ac74ea85a07413b08347a333@news.novabbs.com> <ALZeN.1985$U1cc.561@fx04.iad> <ulkine$2fi18$1@dont-email.me> <sDkfN.51804$Wp_8.32752@fx17.iad> <ulld29$2jkgh$1@dont-email.me> <PuFfN.53323$p%Mb.32922@fx15.iad> <uloo9t$3cr2r$1@dont-email.me> <J_%fN.65941$Wp_8.29224@fx17.iad> <0e17e28cd97d3872f2260887512ec040@news.novabbs.com> <qBEgN.26431$LONb.2938@fx08.iad> <nkGgN.14619$5Hnd.7577@fx03.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="578234"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
X-Rslight-Posting-User: 7e9c45bcd6d4757c5904fbe9a694742e6f8aa949
X-Rslight-Site: $2y$10$lfqguKR0bDN2JxUmyFeOWeXYbgFhpoRDP0/PExyYPNzjgZzgpiZh6
 by: MitchAlsup - Wed, 20 Dec 2023 21:11 UTC

Scott Lurndal wrote:

> EricP <ThatWouldBeTelling@thevillage.com> writes:
>>MitchAlsup wrote:
>>>
>>
>>To support this view of virtual memory on that platform all OS's would
>>need to maintain two parallel page tables to map each P-space twice,
>>one for user mode and one for super mode.

> ARMv8 maps each half separately. There is a separate translation table
> for each half of the virtual address space, with the high-half holding
> the kernel code and data, and the low half holding the user portion.

> Each half has it's own translation table base register and each half
> can use a different asid.

> Context switch between processes simply requires reloading the
> table base register for the lower half (TTBR0_EL1). No other
> TLB maintainance is required unless the 16-bit ASID wraps.

Oddly enough; I did not know this until reading this paragraph--and
yet, I converged on apparently the same scheme.

Re: Secrets of the ancients, What the World Needs Now

<2023Dec20.223744@mips.complang.tuwien.ac.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35930&group=comp.arch#35930

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Wed, 20 Dec 2023 21:37:44 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 47
Message-ID: <2023Dec20.223744@mips.complang.tuwien.ac.at>
References: <uletbu$19ohv$1@dont-email.me> <ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com> <uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com> <uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net> <2023Dec19.191250@mips.complang.tuwien.ac.at> <kuegl7FbsrjU2@mid.individual.net> <ulusjs$j0q5$3@dont-email.me> <ulvac2$l7hl$1@dont-email.me> <2023Dec20.194712@mips.complang.tuwien.ac.at> <4bab9ad8e39f0b0c1610a7549478c9ac@news.novabbs.com>
Injection-Info: dont-email.me; posting-host="1f6480fbdc6f52ff5822f0e6f5f28b62";
logging-data="775133"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18V/t/2qJ07OSc0dzApPvAs"
Cancel-Lock: sha1:rvDA6q8kZQmGfP97sL4gM+YZ/7U=
X-newsreader: xrn 10.11
 by: Anton Ertl - Wed, 20 Dec 2023 21:37 UTC

mitchalsup@aol.com (MitchAlsup) writes:
>Anton Ertl wrote:
>
>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
>>>I believe Pascal, back in the 1970s implemented nested functions, though
>>>I don't know how any specific implementation accomplished it.
>
>> AFAIK Pascal implementations all just use static links chains to the
>> enclosing scopes. So you access an outer local by following the link
>> chain as many levels as you cross scopes.
>
>How does Pascal do this counting when there are recursive frames on
>the stack ??

The static scope level is independent of recursion. Note that this
kind of implementation has a static link in addition to the dynamic
link.

E.g., consider

procedure a(...)
procedure b(...)
procedure c(...)
begin
b(...)
end;
begin
c(...);
end;
begin
b(...);
end;

After a few levels of recursion you have dynamic and static chains like this:

dynamic: c->b->c->b->c->b->a
static: --^--------------^

And upon the next call to b:

dynamic: b->c->b->c->b->c->b->a
static: --------------------^

- anton
--
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>

Re: What the World Needs Now

<f006b74173a88d0c059fe169b7299323@news.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35931&group=comp.arch#35931

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!.POSTED!not-for-mail
From: mitchalsup@aol.com (MitchAlsup)
Newsgroups: comp.arch
Subject: Re: What the World Needs Now
Date: Wed, 20 Dec 2023 22:00:06 +0000
Organization: novaBBS
Message-ID: <f006b74173a88d0c059fe169b7299323@news.novabbs.com>
References: <uletbu$19ohv$1@dont-email.me> <5c7dd089ac74ea85a07413b08347a333@news.novabbs.com> <ALZeN.1985$U1cc.561@fx04.iad> <ulkine$2fi18$1@dont-email.me> <sDkfN.51804$Wp_8.32752@fx17.iad> <ulld29$2jkgh$1@dont-email.me> <PuFfN.53323$p%Mb.32922@fx15.iad> <uloo9t$3cr2r$1@dont-email.me> <J_%fN.65941$Wp_8.29224@fx17.iad> <0e17e28cd97d3872f2260887512ec040@news.novabbs.com> <qBEgN.26431$LONb.2938@fx08.iad> <9f2d0ab603721cddbf722e7cf3857ae9@news.novabbs.com> <z9GgN.75075$c3Ea.2907@fx10.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="582256"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: 7e9c45bcd6d4757c5904fbe9a694742e6f8aa949
X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on novalink.us
X-Rslight-Site: $2y$10$3de.ELAbZBrAI6/8EdPNDu9geieHNw.4EdDnh5AlPsj02HAwpZ7uS
 by: MitchAlsup - Wed, 20 Dec 2023 22:00 UTC

EricP wrote:

> MitchAlsup wrote:
>> EricP wrote:
>>
>>> MitchAlsup wrote:
>>>> EricP wrote:
>>>>
>>>>>
>>>>> If one has super and User mode, and R,W,E enables, that's 6 PTE bits.
>>>>> The PTE is very cramped so there is a big incentive to save any bits.
>>>>> We can get that down to 3 PTE bits by throwing out the silly
>>>>> combinations,
>>>>> Write-only, Execute-only, Super:NoAccess+User:RWE,...
>>>>
>>>> If one uses a different page table for user and supervisor, you only
>>>> need those 3-bits. In my case Guest OS has its own table and its own
>>>> ASID completely separate from application. ASID plays the part of G
>>>> (global).
>>
>>> Ok but all major OS's view the current process address space (P-space)
>>> as directly addressable from system space (S-space), so the OS can reach
>>> directly into the current process to read or write memory to pass args
>>> to/from syscalls or deliver signals, etc.
>>
>> My 66000 provides this. Guest OS can reach down into application VaS,
>> application cannot reach up into Guest OS VaS. When Guest OS accesses
>> its own VaS it uses its own ASID, when accessing application it uses
>> application ASID. The same analogue occurs in Guest HV reaching down
>> into Guest OS VaS. When Guest HV accesses its own VaS it uses 1-level
>> translation and its own ASID; when accessing Guest OS it uses 2-level
>> translation and Guest OS ASID.
>>
>> Switching between levels is fast because all the required information
>> is loaded at all times. Switching contexts is fast because only 1
>> register needs to be written, the data is obtained as if the control
>> registers were a cache of the data at the written address.

> How does these two ASIDs allow 3 bits in a PTE to grant different
> access for the same page to user and OS? For example S:RW,U:RE

I was planning on ignoring access rights when a more privileged thread
accesses less privileged data.

>>> To support this view of virtual memory on that platform all OS's would
>>> need to maintain two parallel page tables to map each P-space twice,
>>> one for user mode and one for super mode.

Nested functions and representation of closures (was: Secrets of the ancients, What the World Needs Now)

<jwva5q4bjqs.fsf-monnier+comp.arch@gnu.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35932&group=comp.arch#35932

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: monnier@iro.umontreal.ca (Stefan Monnier)
Newsgroups: comp.arch
Subject: Nested functions and representation of closures (was: Secrets of the ancients, What the World Needs Now)
Date: Wed, 20 Dec 2023 17:26:53 -0500
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <jwva5q4bjqs.fsf-monnier+comp.arch@gnu.org>
References: <uletbu$19ohv$1@dont-email.me>
<ulml73$10fu3$1@newsreader4.netcologne.de>
<uln60k$2m9s$1@gal.iecc.com>
<uln86f$10rpl$1@newsreader4.netcologne.de>
<ulnj9g$2719$1@gal.iecc.com>
<uls9ri$144lp$1@newsreader4.netcologne.de>
<kue2p4FbsrjU1@mid.individual.net>
<2023Dec19.191250@mips.complang.tuwien.ac.at>
<kuegl7FbsrjU2@mid.individual.net> <ulusjs$j0q5$3@dont-email.me>
<ulvac2$l7hl$1@dont-email.me>
<2023Dec20.194712@mips.complang.tuwien.ac.at>
<4bab9ad8e39f0b0c1610a7549478c9ac@news.novabbs.com>
<2023Dec20.223744@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="0ba0f9638ffe42b84af8b1b2d7645611";
logging-data="787082"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wLLcUlU6E/69gdaVFQTr/RzgCvclZBFI="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:Ye7JM8OdDB7CMXOxSdlFx+ahjAw=
sha1:I5+KZOL1+p7wrHXOgI61tuwVYTQ=
 by: Stefan Monnier - Wed, 20 Dec 2023 22:26 UTC

Anton Ertl [2023-12-20 21:37:44] wrote:
> mitchalsup@aol.com (MitchAlsup) writes:
>>Anton Ertl wrote:
>>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
>>>>I believe Pascal, back in the 1970s implemented nested functions, though
>>>>I don't know how any specific implementation accomplished it.
>>> AFAIK Pascal implementations all just use static links chains to the
>>> enclosing scopes. So you access an outer local by following the link
>>> chain as many levels as you cross scopes.
>>How does Pascal do this counting when there are recursive frames on
>>the stack ??
> The static scope level is independent of recursion. Note that this
> kind of implementation has a static link in addition to the dynamic
> link.

Maybe I'm missing something but I think Pascal's display is "orthogonal"
to the issue discussed before of how to stuff together a code pointer
together with a pointer to its associated data.

Pascal's display is one possible representation of closures, but it
doesn't save you from the need to use a kind of "fat pointer" for the
first-class functions.

What saves Pascal is that first-class functions aren't first class at
all, so Pascal can safely and easily represent them any way it likes,
including as a pair of two values (a pointer to the code, and a pointer
to a stack frame, typically).

It's harder in C because some code wants to be able to convert
a function pointer to a `void*` and back, so you usually want to make it
fit into the size of a normal pointer.

Stefan

Re: Nested functions and representation of closures

<ulvr5s$o52i$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35933&group=comp.arch#35933

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: Nested functions and representation of closures
Date: Wed, 20 Dec 2023 23:51:40 +0100
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <ulvr5s$o52i$1@dont-email.me>
References: <uletbu$19ohv$1@dont-email.me>
<ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com>
<uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com>
<uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net>
<2023Dec19.191250@mips.complang.tuwien.ac.at>
<kuegl7FbsrjU2@mid.individual.net> <ulusjs$j0q5$3@dont-email.me>
<ulvac2$l7hl$1@dont-email.me> <2023Dec20.194712@mips.complang.tuwien.ac.at>
<4bab9ad8e39f0b0c1610a7549478c9ac@news.novabbs.com>
<2023Dec20.223744@mips.complang.tuwien.ac.at>
<jwva5q4bjqs.fsf-monnier+comp.arch@gnu.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 20 Dec 2023 22:51:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cd5865c07a5f4d70812c727aa637634b";
logging-data="791634"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yqg+jVq5HSWbHbv1Z41rVfFrCH+uiDVk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ARdx74wqmCmrjtJIcK70XB4XTP4=
Content-Language: en-GB
In-Reply-To: <jwva5q4bjqs.fsf-monnier+comp.arch@gnu.org>
 by: David Brown - Wed, 20 Dec 2023 22:51 UTC

On 20/12/2023 23:26, Stefan Monnier wrote:
> Anton Ertl [2023-12-20 21:37:44] wrote:
>> mitchalsup@aol.com (MitchAlsup) writes:
>>> Anton Ertl wrote:
>>>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
>>>>> I believe Pascal, back in the 1970s implemented nested functions, though
>>>>> I don't know how any specific implementation accomplished it.
>>>> AFAIK Pascal implementations all just use static links chains to the
>>>> enclosing scopes. So you access an outer local by following the link
>>>> chain as many levels as you cross scopes.
>>> How does Pascal do this counting when there are recursive frames on
>>> the stack ??
>> The static scope level is independent of recursion. Note that this
>> kind of implementation has a static link in addition to the dynamic
>> link.
>
> Maybe I'm missing something but I think Pascal's display is "orthogonal"
> to the issue discussed before of how to stuff together a code pointer
> together with a pointer to its associated data.
>
> Pascal's display is one possible representation of closures, but it
> doesn't save you from the need to use a kind of "fat pointer" for the
> first-class functions.
>
> What saves Pascal is that first-class functions aren't first class at
> all, so Pascal can safely and easily represent them any way it likes,
> including as a pair of two values (a pointer to the code, and a pointer
> to a stack frame, typically).
>
> It's harder in C because some code wants to be able to convert
> a function pointer to a `void*` and back, so you usually want to make it
> fit into the size of a normal pointer.
>

Converting between function pointers and data pointers (like void*) is
undefined behaviour in C. Of course, some people want to do that
regardless, and on many platforms you can probably get away with it if
you are lucky. On some platforms, however, data pointers and function
pointers are different sizes. (There are even some platforms where
pointers to different types of data are different sizes.)

But you /are/ allowed to convert back and forth between different
function pointer types in C, which means function pointers are always
the same size. And for efficiency, that would generally be the smallest
size that works for normal functions - i.e., typically just the address
in memory of the function's code.

So what saves C is that nested functions are not part of the language!
And when you have extensions that support nested functions, such as
supported by gcc, if the function really needs a fat pointer you have a
trampoline on the stack to hide that and make it look like a normal
"thin" pointer.

Re: What the World Needs Now

<V4MgN.75090$c3Ea.6734@fx10.iad>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35935&group=comp.arch#35935

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.neodome.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx10.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: What the World Needs Now
Newsgroups: comp.arch
References: <uletbu$19ohv$1@dont-email.me> <ALZeN.1985$U1cc.561@fx04.iad> <ulkine$2fi18$1@dont-email.me> <sDkfN.51804$Wp_8.32752@fx17.iad> <ulld29$2jkgh$1@dont-email.me> <PuFfN.53323$p%Mb.32922@fx15.iad> <uloo9t$3cr2r$1@dont-email.me> <J_%fN.65941$Wp_8.29224@fx17.iad> <0e17e28cd97d3872f2260887512ec040@news.novabbs.com> <qBEgN.26431$LONb.2938@fx08.iad> <9f2d0ab603721cddbf722e7cf3857ae9@news.novabbs.com> <z9GgN.75075$c3Ea.2907@fx10.iad> <f006b74173a88d0c059fe169b7299323@news.novabbs.com>
Lines: 54
Message-ID: <V4MgN.75090$c3Ea.6734@fx10.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 21 Dec 2023 00:58:29 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 21 Dec 2023 00:58:29 GMT
X-Received-Bytes: 3567
 by: Scott Lurndal - Thu, 21 Dec 2023 00:58 UTC

mitchalsup@aol.com (MitchAlsup) writes:
>EricP wrote:
>
>> MitchAlsup wrote:
>>> EricP wrote:
>>>
>>>> MitchAlsup wrote:
>>>>> EricP wrote:
>>>>>
>>>>>>
>>>>>> If one has super and User mode, and R,W,E enables, that's 6 PTE bits.
>>>>>> The PTE is very cramped so there is a big incentive to save any bits.
>>>>>> We can get that down to 3 PTE bits by throwing out the silly
>>>>>> combinations,
>>>>>> Write-only, Execute-only, Super:NoAccess+User:RWE,...
>>>>>
>>>>> If one uses a different page table for user and supervisor, you only
>>>>> need those 3-bits. In my case Guest OS has its own table and its own
>>>>> ASID completely separate from application. ASID plays the part of G
>>>>> (global).
>>>
>>>> Ok but all major OS's view the current process address space (P-space)
>>>> as directly addressable from system space (S-space), so the OS can reach
>>>> directly into the current process to read or write memory to pass args
>>>> to/from syscalls or deliver signals, etc.
>>>
>>> My 66000 provides this. Guest OS can reach down into application VaS,
>>> application cannot reach up into Guest OS VaS. When Guest OS accesses
>>> its own VaS it uses its own ASID, when accessing application it uses
>>> application ASID. The same analogue occurs in Guest HV reaching down
>>> into Guest OS VaS. When Guest HV accesses its own VaS it uses 1-level
>>> translation and its own ASID; when accessing Guest OS it uses 2-level
>>> translation and Guest OS ASID.
>>>
>>> Switching between levels is fast because all the required information
>>> is loaded at all times. Switching contexts is fast because only 1
>>> register needs to be written, the data is obtained as if the control
>>> registers were a cache of the data at the written address.
>
>> How does these two ASIDs allow 3 bits in a PTE to grant different
>> access for the same page to user and OS? For example S:RW,U:RE
>
>I was planning on ignoring access rights when a more privileged thread
>accesses less privileged data.

ARMv8 has PAN (privileged access never) which can be used to prevent
access by privileged code to unprivileged code and data. The bit
(in the PSR) can be set and reset by the kernel, so the kernel will
explicitly reset it when accessing user data, and set it otherwise.

If the kernel accesses nonprivileged data while PAN is set, it will fault.

https://developer.arm.com/documentation/102376/0100/Permissions-attributes

Re: Secrets of the ancients, What the World Needs Now

<io57oit8mfer3aac2cco9ib3ofjiq4rucn@4ax.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35940&group=comp.arch#35940

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!.POSTED!not-for-mail
From: gneuner2@comcast.net (George Neuner)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Thu, 21 Dec 2023 00:08:33 -0500
Organization: i2pn2 (i2pn.org)
Message-ID: <io57oit8mfer3aac2cco9ib3ofjiq4rucn@4ax.com>
References: <ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com> <uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com> <uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net> <2023Dec19.191250@mips.complang.tuwien.ac.at> <kuegl7FbsrjU2@mid.individual.net> <ulusjs$j0q5$3@dont-email.me> <ulvac2$l7hl$1@dont-email.me> <2023Dec20.194712@mips.complang.tuwien.ac.at> <4bab9ad8e39f0b0c1610a7549478c9ac@news.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: i2pn2.org;
logging-data="612374"; mail-complaints-to="usenet@i2pn2.org";
posting-account="h5eMH71iFfocGZucc+SnA0y5I+72/ecoTCcIjMd3Uww";
User-Agent: ForteAgent/8.00.32.1272
 by: George Neuner - Thu, 21 Dec 2023 05:08 UTC

On Wed, 20 Dec 2023 21:09:44 +0000, mitchalsup@aol.com (MitchAlsup)
wrote:

>Anton Ertl wrote:
>
>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
>>>I believe Pascal, back in the 1970s implemented nested functions, though
>>>I don't know how any specific implementation accomplished it.
>
>> AFAIK Pascal implementations all just use static links chains to the
>> enclosing scopes.

@Anton: implementation dependent - some use displays instead.

>So you access an outer local by following the link
>> chain as many levels as you cross scopes.
>
>How does Pascal do this counting when there are recursive frames on
>the stack ??

To access non-local, non-global things (variables, functions, etc.)
nested functions require that the definition scopes be tracked through
the chain of function calls.

To this end there are 2 different kinds of links: by convention
referred to as 'static' and 'dynamic'.

dynamic = who called who
static = who defined who

The stack frame in a language - such as Pascal - having nested
functions contains both kinds of links. The dynamic link is the same
as in C: it just points to the immediate caller. The static link,
however, points to the last created frame of the function that
/defined/ the currently executing function.

[view with a fixed width font]

Expanding a bit on Anton's example, consider:

A defines B and C
B defines D
C defines E

A runs
A calls B
B calls D
D calls C
C calls E
E calls E
E calls A
A calls B
B calls D
D calls B

dynamic: A <- B <- D <- C <- E <- E <- A <- B <- D <- B
static : ^
: ^-----
: ^-----
: ^---------------
: ^-----
: ^----------
: ^
: ^-----
: ^-----
: ^---------------

You can see the dynamic links simply reflect the call chain. The
static links however, jump around and appear to form multiple chains.

The top level function A has no enclosing scope, so its static link is
to self. However, B, C, D and E all can access things defined in
enclosing scopes by following the chain of static links: e.g., a D
instance has a link to the last B instance, and that B instance has a
link to the last A instance.

Obviously there has to be a way to FIND the last instance of a scope
as it may be deep in the stack. The /simplest/ way is to mark each
frame with a small integer identifying their static nest level: e.g.,
A = 1, B = 2, C = 2, D = 3, E = 3

A 'display' is another way to implement non-local, non-global access
which uses an array of frame pointers rather than a 'chain' of static
links woven through the stack frames. Accessing an enclosing scope is
simply an indirection through display[target scope].

When entering a function at nest level N, the value of display[N] is
saved in the frame and display[N] set to point to the last instance of
the enclosing level N-1 frame. Exiting the function, display[N] is
restored from the saved value.

This makes /maintaining/ a display a bit most costly than using static
links - ie. a static link can simply be abandoned. However, if there
is significant use of things from multiple deep scopes [where 'deep'
is 2 or more scopes away], the display will be faster to use.

Only display elements at or (numerically) lower than the nest level of
the current function can (legally) be used - e.g., a function at level
3 can use display[1] .. display[3], whereas using display[4] or higher
would constiture an error.

So, assuming the same example as above:

A defines B and C
B defines D
C defines E

display[ 1 2 3 4 5 6 ]
A runs [ A . . . . . ] L = 1
A calls B [ A A . . . . ] L = 2
B calls D [ A A B . . . ] L = 3
D calls C [ A A b . . . ] L = 2
C calls E [ A A C . . . ] L = 3
E calls E [ A A C . . . ] L = 3
E calls A [ A a c . . . ] L = 1
A calls B [ A A c . . . ] L = 2
B calls D [ A A B . . . ] L = 3
D calls B [ A A b . . . ] L = 2

'L' indicates the current run level (after the call). Display values
at nest levels greater than the current run level are shown as
lowercase: they ARE still in the array, but (theoretically) are not
accessible from the currently running function.

Although it sort of /looks/ like the display is a stack, the elements
at indices greater than the current nest level still are in the array
and MAY still have meaning.

Unfortunately, there is a limit to how complex an example can be shown
here ... a far more complicated example would be required to show
saving and restoring values.

Using displays also interacts with threading: the display is part of
the thread state. However, thread local storage works fine for this -
in use displays tend to be cached quite effectively and so there is
little or no need for special hardware to handle them.

You might ask "who makes multiple deep accesses to different frames?"
That's a fair question to which I don't have a good answer. Displays
fell out of favor ... not because they were troublesome, but rather
because better compilation methods were developed to turn nested
functions into flat closures (which could be in heap or on stack) and
these mostly removed the need for either displays or static links.

YMMV.

>> Pascal allows passing
>> nested functions/procedures as parameters, but does not support
>> variables containing them

@Anton: again, implementation dependent. Standard Pascal (ISO and
ANSI) does not recognize 'function pointer' variables, but some
extended Pascals did.

>> , or any other first-class handling of them.
>> This avoids the upward funarg problem (as the Lispers call it). These
>> parameters consist of the code pointer and the static link pointer.

Yes, in Standard Pascal you could only call functions defined at the
same nesting level or in an enclosing levels WITHIN THE SAME SCOPE
CHAIN. In the example above E couldn't call D because their
definition scopes are disjoint.

However, again, some extended Pascals did allow cross scope calls
using pointers provided the caller and callee both were within a
common enclosing scope. IOW there were implementations in which you
could create a pointer to E in A and then call E from D.

>> Modula-2 has nested procedures, and allows putting procedures in
>> variables, fields, etc., but eliminates the upward funarg problem by
>> only allowing to store global-level procedures in variables, not
>> nested procedures. So it went closer to C.
>
>> Oberon originally had nested procedures, and AFAIK similar rules to
>> Modula-2. When I asked Wirth in 2020 if he has a good example for the
>> use of nested procedures (I thought he would have, given that he kept
>> this feature for so many years), he told me that he had removed nested
>> functions in 2013 or so.

Yes, for complex code, simple nested functions often are inadequate
and you need (not necessarily 'first-class' but) persistent closures.

[Consider that closures in Lisp really are 2nd class because they must
be bound to a symbol in order to be stored/persisted. In Scheme where
they ARE 1st class, they can be stored and passed around - including
upward - just like any other value.]

>> - anton

Re: Nested functions and representation of closures (was: Secrets of the ancients, What the World Needs Now)

<2023Dec21.074154@mips.complang.tuwien.ac.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35941&group=comp.arch#35941

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.furie.org.uk!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Nested functions and representation of closures (was: Secrets of the ancients, What the World Needs Now)
Date: Thu, 21 Dec 2023 06:41:54 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 88
Message-ID: <2023Dec21.074154@mips.complang.tuwien.ac.at>
References: <uletbu$19ohv$1@dont-email.me> <ulnj9g$2719$1@gal.iecc.com> <uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net> <2023Dec19.191250@mips.complang.tuwien.ac.at> <kuegl7FbsrjU2@mid.individual.net> <ulusjs$j0q5$3@dont-email.me> <ulvac2$l7hl$1@dont-email.me> <2023Dec20.194712@mips.complang.tuwien.ac.at> <4bab9ad8e39f0b0c1610a7549478c9ac@news.novabbs.com> <2023Dec20.223744@mips.complang.tuwien.ac.at> <jwva5q4bjqs.fsf-monnier+comp.arch@gnu.org>
Injection-Info: dont-email.me; posting-host="22d67c57d4c94525ca046727884919fe";
logging-data="1043392"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9LfL3jFO9UBPsXgw6DSYf"
Cancel-Lock: sha1:f4kqdn/DBKxZ9xxK5RCn6XLa5+E=
X-newsreader: xrn 10.11
 by: Anton Ertl - Thu, 21 Dec 2023 06:41 UTC

Stefan Monnier <monnier@iro.umontreal.ca> writes:
>Anton Ertl [2023-12-20 21:37:44] wrote:
>> mitchalsup@aol.com (MitchAlsup) writes:
>>>Anton Ertl wrote:
>>>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
>>>>>I believe Pascal, back in the 1970s implemented nested functions, though
>>>>>I don't know how any specific implementation accomplished it.
>>>> AFAIK Pascal implementations all just use static links chains to the
>>>> enclosing scopes. So you access an outer local by following the link
>>>> chain as many levels as you cross scopes.
>>>How does Pascal do this counting when there are recursive frames on
>>>the stack ??
>> The static scope level is independent of recursion. Note that this
>> kind of implementation has a static link in addition to the dynamic
>> link.
>
>Maybe I'm missing something but I think Pascal's display is "orthogonal"
>to the issue discussed before of how to stuff together a code pointer
>together with a pointer to its associated data.

Certainly. For example, AFAIK Pascal implementations do not use a
display, but just follows static links (but maybe somebody with more
knowledge can correct me). Cohen [cohen91] described how to use a
display for type inclusion tests. IIRC Wirth wrote a letter in reply
where he stated that he had tried to use a display for accessing outer
locals around 1970, but found that it hurt performance, and that he
was happy that this technique was useful for something after all.

@Article{cohen91,
author = "Norman H. Cohen",
title = "Type-Extension Type Tests Can Be Performed In Constant
Time",
journal = "ACM Transactions on Programming Languages and
Systems",
volume = "13",
number = "4",
pages = "626--629",
month = oct,
year = "1991",
refs = "2",
checked = "19940624",
source = "Dept. Library",
keywords = "class, descriptor, display, extensible data type,
inheritance, membership test, object-oriented
programming, type extension, type test",
note = "Technical Correspondence",
abstract = "Wirth's proposal for type extensions includes an
algorithm for determining whether a give value belongs
to an extension of a given type. In the worst case,
this algorithm takes time proportional to the depth of
the type-extension hierarchy. Wirth describes the loop
in this algorithm as ``unavoidable,'' but in fact, the
test can be performed in constant time by associating a
``display'' of base types with each type descriptor.",
xref = "Wirth:acm:toplas:1988",
reffrom = "Corney:Gough:plasa:1994",
}

>Pascal's display is one possible representation of closures, but it
>doesn't save you from the need to use a kind of "fat pointer" for the
>first-class functions.

Correct.

>What saves Pascal is that first-class functions aren't first class at
>all, so Pascal can safely and easily represent them any way it likes,
>including as a pair of two values (a pointer to the code, and a pointer
>to a stack frame, typically).

Even first-class closures are not a problem. The easiest way is to
let them be a type of two machine words, a code pointer and an
environment pointer.

>It's harder in C because some code wants to be able to convert
>a function pointer to a `void*` and back, so you usually want to make it
>fit into the size of a normal pointer.

Even first class closures that are represented in one machine word are
not a problem. Just box the two words and pass a pointer to that box.

The problem is an ABI that passes function pointers as code pointers
and where calling a function pointer performs an indirect call to the
passed pointer. I.e., a typical C ABI.

- anton
--
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>

Re: Secrets of the ancients, What the World Needs Now

<um1b33$12lv4$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35946&group=comp.arch#35946

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: terje.mathisen@tmsw.no (Terje Mathisen)
Newsgroups: comp.arch
Subject: Re: Secrets of the ancients, What the World Needs Now
Date: Thu, 21 Dec 2023 13:29:23 +0100
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <um1b33$12lv4$2@dont-email.me>
References: <uletbu$19ohv$1@dont-email.me>
<ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com>
<uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com>
<uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net>
<2023Dec19.191250@mips.complang.tuwien.ac.at>
<kuegl7FbsrjU2@mid.individual.net> <ult3ms$14n37$1@newsreader4.netcologne.de>
<dc73b645013a758c6bd9d18b0fcbfb22@news.novabbs.com>
<kufo8dFmig3U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Date: Thu, 21 Dec 2023 12:29:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7438c4f507dea2cfeae135832a9734ea";
logging-data="1136612"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196aTQxB7PAkn0Gp+fdIXytoNHhybiMEJF1tfpIGjOrQQ=="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.18
Cancel-Lock: sha1:QCkEQ4dbdBSiS3VC6pDBBUZ58sg=
In-Reply-To: <kufo8dFmig3U1@mid.individual.net>
 by: Terje Mathisen - Thu, 21 Dec 2023 12:29 UTC

Niklas Holsti wrote:
> On 2023-12-20 0:37, MitchAlsup wrote:
>> Thomas Koenig wrote:
>>
>>> Niklas Holsti <niklas.holsti@tidorum.invalid> schrieb:
>>
>>>>> E.g., consider a numerical integration function integrate(f,lo,hi),
>>>>> which expects a function with one parameter f(x), and you want to
>>>>> integrate x^y (pow(x,y) in C), where y is, say, passed as parameter.
>>>>
>>>>
>>>> That is the canonical example, yes. But it happens I have never
>>>> needed to do numerical integration in my Ada programs. I do have
>>>> some cases where I have used locally instantiated generics with
>>>> generic function parameters in the way I described above. In Ada the
>>>> integration example would be declared thusly:
>>>>
>>>>     generic
>>>>        with function F (X : Float) return Float;
>>>>     function Integrate (Lo, Hi : Float) return Float;
>>>>
>>>> although one would usually not limit it to a specific number type
>>>> such as Float, but would make this type also a generic (type)
>>>> parameter. IIRC, the ability to define numerical integration as a
>>>> generic subprogram, with the function to be integrated as a generic
>>>> parameter, was one of the reasons presented for omitting function
>>>> pointers entirely from original Ada (Ada 83).
>>
>>> Interesting, thanks!
>>
>>> Just one remark: Making numerical routines generic can be a bit
>>> problematic if constants depend on the accuracy of a type; things
>>> like tolerances for checks for convergence,
>>
>> whether compiler constant arithmetic has the same numeric properties
>> as compiled code instruction sequences,
>
>
> Ada compilers are required to evaluate typeless constant arithmetic to
> unbounded precision (as "bignums"). For example, the constant pi is
> defined thusly in the standard package Ada.Numerics:
>
>     Pi : constant :>        3.14159_26535_89793_23846_26433_83279_50288_41971_69399_37511;
>
> and all the digits are significant in any computation involving Pi and
> other typeless constants.
>
> Computation with typed constants is required to use the operations of
> that type, so should match what the target code does.
>
And still, 50 digits is only ~170 bits, so not enough to do arbitrary
parameter reductions (which requires ~1100 bits).

Terje

--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

Re: Nested functions and representation of closures

<um1d1k$17d9u$1@newsreader4.netcologne.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35947&group=comp.arch#35947

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-f912-0-a604-b934-e5d3-16ed.ipv6dyn.netcologne.de!not-for-mail
From: tkoenig@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Nested functions and representation of closures
Date: Thu, 21 Dec 2023 13:02:44 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <um1d1k$17d9u$1@newsreader4.netcologne.de>
References: <uletbu$19ohv$1@dont-email.me>
<ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com>
<uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com>
<uls9ri$144lp$1@newsreader4.netcologne.de>
<kue2p4FbsrjU1@mid.individual.net>
<2023Dec19.191250@mips.complang.tuwien.ac.at>
<kuegl7FbsrjU2@mid.individual.net> <ulusjs$j0q5$3@dont-email.me>
<ulvac2$l7hl$1@dont-email.me> <2023Dec20.194712@mips.complang.tuwien.ac.at>
<4bab9ad8e39f0b0c1610a7549478c9ac@news.novabbs.com>
<2023Dec20.223744@mips.complang.tuwien.ac.at>
<jwva5q4bjqs.fsf-monnier+comp.arch@gnu.org> <ulvr5s$o52i$1@dont-email.me>
Injection-Date: Thu, 21 Dec 2023 13:02:44 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-f912-0-a604-b934-e5d3-16ed.ipv6dyn.netcologne.de:2001:4dd7:f912:0:a604:b934:e5d3:16ed";
logging-data="1291582"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Thu, 21 Dec 2023 13:02 UTC

David Brown <david.brown@hesbynett.no> schrieb:

> So what saves C is that nested functions are not part of the language!
> And when you have extensions that support nested functions, such as
> supported by gcc, if the function really needs a fat pointer you have a
> trampoline on the stack to hide that and make it look like a normal
> "thin" pointer.

I looked at what the Fortran compilers I could lay my hands on did
with the following code, which uses a contained subroutine inside
a subroutine:

module test
contains
subroutine t(f)
interface
subroutine f()
end subroutine
end interface
call f()
end subroutine
end module

subroutine foo(i)
use test
integer, intent(inout):: i
call t(bar)
contains
subroutine bar()
call xxx(i)
end
end

Interestingly, every compiler I could lay my hands on on short
notice (gfortran for several architectures, ifort, xlf, the new
flang for llvm) used trampolines.

See https://godbolt.org/z/nv5nr934q , which is for POWER and
contains a call to a subroutine suggestively called
__trampoline_setup.

Re: Nested functions and representation of closures

<20231221152238.000034d9@yahoo.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35949&group=comp.arch#35949

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: already5chosen@yahoo.com (Michael S)
Newsgroups: comp.arch
Subject: Re: Nested functions and representation of closures
Date: Thu, 21 Dec 2023 15:22:38 +0200
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <20231221152238.000034d9@yahoo.com>
References: <uletbu$19ohv$1@dont-email.me>
<ulml73$10fu3$1@newsreader4.netcologne.de>
<uln60k$2m9s$1@gal.iecc.com>
<uln86f$10rpl$1@newsreader4.netcologne.de>
<ulnj9g$2719$1@gal.iecc.com>
<uls9ri$144lp$1@newsreader4.netcologne.de>
<kue2p4FbsrjU1@mid.individual.net>
<2023Dec19.191250@mips.complang.tuwien.ac.at>
<kuegl7FbsrjU2@mid.individual.net>
<ulusjs$j0q5$3@dont-email.me>
<ulvac2$l7hl$1@dont-email.me>
<2023Dec20.194712@mips.complang.tuwien.ac.at>
<4bab9ad8e39f0b0c1610a7549478c9ac@news.novabbs.com>
<2023Dec20.223744@mips.complang.tuwien.ac.at>
<jwva5q4bjqs.fsf-monnier+comp.arch@gnu.org>
<ulvr5s$o52i$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="ad61e48ed7f6a2e90dee9db879d36192";
logging-data="1140154"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zAtir4kylqAYuF6vUqqMK/HsseREBm8A="
Cancel-Lock: sha1:u6gB3gnEtmH5b61RgNOgLOeLLiQ=
X-Newsreader: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-w64-mingw32)
 by: Michael S - Thu, 21 Dec 2023 13:22 UTC

On Wed, 20 Dec 2023 23:51:40 +0100
David Brown <david.brown@hesbynett.no> wrote:

> On 20/12/2023 23:26, Stefan Monnier wrote:
> > Anton Ertl [2023-12-20 21:37:44] wrote:
> >> mitchalsup@aol.com (MitchAlsup) writes:
> >>> Anton Ertl wrote:
> >>>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
> >>>>> I believe Pascal, back in the 1970s implemented nested
> >>>>> functions, though I don't know how any specific implementation
> >>>>> accomplished it.
> >>>> AFAIK Pascal implementations all just use static links chains to
> >>>> the enclosing scopes. So you access an outer local by following
> >>>> the link chain as many levels as you cross scopes.
> >>> How does Pascal do this counting when there are recursive frames
> >>> on the stack ??
> >> The static scope level is independent of recursion. Note that this
> >> kind of implementation has a static link in addition to the dynamic
> >> link.
> >
> > Maybe I'm missing something but I think Pascal's display is
> > "orthogonal" to the issue discussed before of how to stuff together
> > a code pointer together with a pointer to its associated data.
> >
> > Pascal's display is one possible representation of closures, but it
> > doesn't save you from the need to use a kind of "fat pointer" for
> > the first-class functions.
> >
> > What saves Pascal is that first-class functions aren't first class
> > at all, so Pascal can safely and easily represent them any way it
> > likes, including as a pair of two values (a pointer to the code,
> > and a pointer to a stack frame, typically).
> >
> > It's harder in C because some code wants to be able to convert
> > a function pointer to a `void*` and back, so you usually want to
> > make it fit into the size of a normal pointer.
> >
>
> Converting between function pointers and data pointers (like void*)
> is undefined behaviour in C. Of course, some people want to do that
> regardless, and on many platforms you can probably get away with it
> if you are lucky.

On both leading general-purpose computing platforms, i.e. on Windows and
on Posix-compatibles, you don't have to be lucky: this type of
conversion is guaranteed to work. Period. In both cases it is an
integral part of dynamic linking APIs.

> On some platforms, however, data pointers and
> function pointers are different sizes. (There are even some
> platforms where pointers to different types of data are different
> sizes.)
>
> But you /are/ allowed to convert back and forth between different
> function pointer types in C, which means function pointers are always
> the same size. And for efficiency, that would generally be the
> smallest size that works for normal functions - i.e., typically just
> the address in memory of the function's code.
>
> So what saves C is that nested functions are not part of the
> language! And when you have extensions that support nested functions,
> such as supported by gcc, if the function really needs a fat pointer
> you have a trampoline on the stack to hide that and make it look like
> a normal "thin" pointer.
>
>

Re: Nested functions and representation of closures

<um1i28$13q53$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=35951&group=comp.arch#35951

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!nntp.comgw.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: Nested functions and representation of closures
Date: Thu, 21 Dec 2023 15:28:23 +0100
Organization: A noiseless patient Spider
Lines: 107
Message-ID: <um1i28$13q53$1@dont-email.me>
References: <uletbu$19ohv$1@dont-email.me>
<ulml73$10fu3$1@newsreader4.netcologne.de> <uln60k$2m9s$1@gal.iecc.com>
<uln86f$10rpl$1@newsreader4.netcologne.de> <ulnj9g$2719$1@gal.iecc.com>
<uls9ri$144lp$1@newsreader4.netcologne.de> <kue2p4FbsrjU1@mid.individual.net>
<2023Dec19.191250@mips.complang.tuwien.ac.at>
<kuegl7FbsrjU2@mid.individual.net> <ulusjs$j0q5$3@dont-email.me>
<ulvac2$l7hl$1@dont-email.me> <2023Dec20.194712@mips.complang.tuwien.ac.at>
<4bab9ad8e39f0b0c1610a7549478c9ac@news.novabbs.com>
<2023Dec20.223744@mips.complang.tuwien.ac.at>
<jwva5q4bjqs.fsf-monnier+comp.arch@gnu.org> <ulvr5s$o52i$1@dont-email.me>
<20231221152238.000034d9@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 21 Dec 2023 14:28:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="886bdbbdb47f52bca9bcfd243becfcfa";
logging-data="1173667"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UiwwpOlyfpqk2Uwg1TX2b8bnRyDzJmug="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:vRb8OBz4vkHzXqqTBiKg8/7e/9w=
Content-Language: en-GB
In-Reply-To: <20231221152238.000034d9@yahoo.com>
 by: David Brown - Thu, 21 Dec 2023 14:28 UTC

On 21/12/2023 14:22, Michael S wrote:
> On Wed, 20 Dec 2023 23:51:40 +0100
> David Brown <david.brown@hesbynett.no> wrote:
>
>> On 20/12/2023 23:26, Stefan Monnier wrote:
>>> Anton Ertl [2023-12-20 21:37:44] wrote:
>>>> mitchalsup@aol.com (MitchAlsup) writes:
>>>>> Anton Ertl wrote:
>>>>>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> writes:
>>>>>>> I believe Pascal, back in the 1970s implemented nested
>>>>>>> functions, though I don't know how any specific implementation
>>>>>>> accomplished it.
>>>>>> AFAIK Pascal implementations all just use static links chains to
>>>>>> the enclosing scopes. So you access an outer local by following
>>>>>> the link chain as many levels as you cross scopes.
>>>>> How does Pascal do this counting when there are recursive frames
>>>>> on the stack ??
>>>> The static scope level is independent of recursion. Note that this
>>>> kind of implementation has a static link in addition to the dynamic
>>>> link.
>>>
>>> Maybe I'm missing something but I think Pascal's display is
>>> "orthogonal" to the issue discussed before of how to stuff together
>>> a code pointer together with a pointer to its associated data.
>>>
>>> Pascal's display is one possible representation of closures, but it
>>> doesn't save you from the need to use a kind of "fat pointer" for
>>> the first-class functions.
>>>
>>> What saves Pascal is that first-class functions aren't first class
>>> at all, so Pascal can safely and easily represent them any way it
>>> likes, including as a pair of two values (a pointer to the code,
>>> and a pointer to a stack frame, typically).
>>>
>>> It's harder in C because some code wants to be able to convert
>>> a function pointer to a `void*` and back, so you usually want to
>>> make it fit into the size of a normal pointer.
>>>
>>
>> Converting between function pointers and data pointers (like void*)
>> is undefined behaviour in C. Of course, some people want to do that
>> regardless, and on many platforms you can probably get away with it
>> if you are lucky.
>
> On both leading general-purpose computing platforms, i.e. on Windows and
> on Posix-compatibles, you don't have to be lucky: this type of
> conversion is guaranteed to work. Period. In both cases it is an
> integral part of dynamic linking APIs.

Nope.

POSIX requires that an object of type "void *" can hold a pointer to a
function. But it does not require that a conversion between a function
and a data pointer is defined. Not only is this code not guaranteed to
have defined behaviour or work as you might expect, but a conforming C
compiler is obliged to issue a diagnostic about it:

void (*foo)(void);

foo = (void (*)(void) dlsym(handle, "foo");

What /does/ work, for any POSIX system, is:

*(void ** )(&foo) = dlsym(handle, "foo");

<https://pubs.opengroup.org/onlinepubs/009696899/functions/dlsym.html>

Note that having the same size - and even the same representation - is
not all that is needed for things to work as naïvely as you might assume
in C.

And of course, the C world is vastly greater than just the "leading
general-purpose computing platforms", and it includes targets where
function pointers and data pointers are significantly different. Some
platforms (including quite popular ones in their day, like DOS) support
different memory models where data and code pointers can be big and
flexible or small and efficient. Things that work on one platform might
not work on others. The C language - defined by the standards - gives a
common subset. If you are writing in C, and you have not specified a
particular target but you rely on target-specific features, your code
relies on luck.

>
>> On some platforms, however, data pointers and
>> function pointers are different sizes. (There are even some
>> platforms where pointers to different types of data are different
>> sizes.)
>>
>> But you /are/ allowed to convert back and forth between different
>> function pointer types in C, which means function pointers are always
>> the same size. And for efficiency, that would generally be the
>> smallest size that works for normal functions - i.e., typically just
>> the address in memory of the function's code.
>>
>> So what saves C is that nested functions are not part of the
>> language! And when you have extensions that support nested functions,
>> such as supported by gcc, if the function really needs a fat pointer
>> you have a trampoline on the stack to hide that and make it look like
>> a normal "thin" pointer.
>>
>>
>
>


devel / comp.arch / Re: Secrets of the ancients, What the World Needs Now

Pages:1234
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor