From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Clubley Newsgroups: comp.lang.ada Subject: Re: Oberon and Wirthian languages Date: Thu, 24 Apr 2014 00:20:06 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <1ljwj8f.1wqbhvuabsdw1N%csampson@inetworld.net> <51c7d6d4-e3be-44d5-a4ce-f7e875345588@googlegroups.com> <%J32v.70539$kp1.45343@fx14.iad> <8761m535e4.fsf_-_@ludovic-brenta.org> Injection-Date: Thu, 24 Apr 2014 00:20:06 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="e458ff8b81bc0c159989eb0e36c6e372"; logging-data="12880"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bT+YgkgyLURrlHBMSjp2RTZLYSUrn4H8=" User-Agent: slrn/0.9.8.1 (VMS/Multinet) Cancel-Lock: sha1:qZXp1YqsV59Tmn3UpWVoGPWoXA4= Xref: news.eternal-september.org comp.lang.ada:19555 Date: 2014-04-24T00:20:06+00:00 List-Id: On 2014-04-23, Simon Wright wrote: > Simon Clubley writes: > >> I wonder if we need something like that for Ada proper so we don't >> have to read the register into a temporary variable first in order to >> guarantee a single register read and a single register write while >> updating a subset of bitfields in the register. >> >> Having to use a temporary variable to guarantee a update of, say, a >> couple of bitfields (out of a possible large number of bitfields) at >> the same time just feels as if it isn't elegant. > > But hardware isn't (usually) elegant! If what the hardware designer > wants is for you to read the register, change the values you need to in > the local copy, then write the modified value back, that's what the code > should do, surely, without relying on compiler magic with obscure > pragmas to make it happen? (Ada's pragma Atomic is quite obscure enough > already!) The problem is the compiler does this automatically when you use C style masks, but you have to do the work manually when you try to write clean code by using record bitfields (in Ada) or bitfield structs (in C) and need to do the read/write exactly once and want to update more than one of the bitfields at the same time. This whole discussion started when someone suggested that in a C replacement language we should drop the use of masks when possible in favour of a bitfield approach. I _strongly_ agree with this, but neither C or Ada, as they stand, make it easy to do this. I proposed the following syntax for a C replacement language: atomic using uart0.config1 .flag1 := 0; .enable := 1; .txdis := 0; end atomic; (I'm not too sure about the leading dots however.) which would be a direct replacement for the use of C style masks when modifying registers and would update the bitfields listed while preserving the other unlisted bitfields and would guarantee only one read and one write to the register. The code above is a _lot_ safer and cleaner than using masks but to do that in C or Ada at the moment requires the use of temporary variables which is not clean as the above approach (or an approach like it). Simon. -- Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP Microsoft: Bringing you 1980s technology to a 21st century world