[Info-vax] Rust as a HS language, was: Re: Quiet?

Simon Clubley clubley at remove_me.eisner.decus.org-Earth.UFP
Sat Apr 9 15:59:04 EDT 2022


On 2022-04-09, Dan Cross <cross at spitfire.i.gajendra.net> wrote:
> In article <t2pn8f$r5q$1 at news.misty.com>,
> Johnny Billquist  <bqt at softjar.se> wrote:
>>
>>volatile is simple enough. Every reference have to stay, and be kept in 
>>the same order, and order also kept in relation to other volatile 
>>variables, and the value cannot be "cached" or placed in a register, or 
>>whatever. Memory barriers all around.
>
> The last time this came up where I was involved, the murky stuff
> revolved around precise semantics of generated loads and stores.
> What you wrote above is true, but suppose I'm doing multiple
> stores into aligned buffers; can the compiler lower into stores
> into a larger datum, or must they be kept distinct?  That is,
> suppose I'm writing a bunch of uint16_t's from an aligned source
> into an aligned destination; can the compiler turn that into
> corresponding loads/stores of uint32_t?  Can it write to the
> same byte twice?  And how do I work with volatile byte buffers
> without memcpy?
>

Volatile is very simple as far as I am concerned when answering
the above questions.

One read in the source code is exactly one read in the generated code.

One write in the source code is exactly one write in the generated code.

A set of reads or a set of writes cannot be combined.

If the source code asks for two 16-bit reads or writes, then that's
exactly what it gets. This cannot be converted to a single 32-bit
read or write.

If the compiler does anything else, it's broken.

Reasoning: the most common use of volatile I have in my code is
for reading and writing to device registers. If the compiler did
any of the above in your questions, it would break my code.

I would never use memcpy() with volatile BTW, I would always read
and write the volatile area directly in my source code if I was
working with something larger than a set of registers.

Also, when it comes to talking to hardware, the compiler has no
idea what the hardware alignment is or what the size of the
register the code is talking to is. It has to use the information
in the source code and nothing else.

Simon.

-- 
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Walking destinations on a map are further away than they appear.



More information about the Info-vax mailing list