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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c5f68ab74d5099ee X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.73.229 with SMTP id o5mr6401995pbv.7.1323995038670; Thu, 15 Dec 2011 16:23:58 -0800 (PST) MIME-Version: 1.0 Path: lh20ni27104pbb.0!nntp.google.com!news2.google.com!goblin1!goblin.stu.neva.ru!news.tornevall.net!news.jacob-sparre.dk!pnx.dk!jacob-sparre.dk!ada-dk.org!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Interfaces.Shift_Left Date: Thu, 15 Dec 2011 18:23:54 -0600 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <18214312-82f5-45c4-b20d-cb530b500929@h3g2000yqa.googlegroups.com> <5f989095-5c1c-4b23-a538-d70f4718b4b1@l19g2000yqc.googlegroups.com> <9ktu5mFn31U1@mid.individual.net> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1323995037 12153 69.95.181.76 (16 Dec 2011 00:23:57 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Fri, 16 Dec 2011 00:23:57 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Date: 2011-12-15T18:23:54-06:00 List-Id: "Niklas Holsti" wrote in message news:9ktu5mFn31U1@mid.individual.net... > On 11-12-15 00:49 , Randy Brukardt wrote: >> "awdorrin" wrote in message >> news:a76daa61-49f7-4235-af65-11973a012f35@v29g2000yqv.googlegroups.com... >>> I understand what you are saying and I do agree in theory. >>> >>> The situation is that bit shifting is being used to retrieve data of >>> various bit lengths and positions from compound records. >>> >>> For instance, retrieving a 6-bit signed value from a 32-bit field. >> >> Right. This definitely should be done using record representation clauses >> if >> there is a choice. > > I'm sorry to say that I disagree, and now always use the shift-and-mask > method. Might as well write in C then, this sort of code is complete, unmaintainable junk. > I used to be charmed by record representation clauses, until I wanted to > write Ada 95 code that was portable between machines with different bit > numbering orders. It's true, that's a problem. Luckily, it's not a real problem in practice for the vast majority of users, since pretty much all popular machines these days use the same bit numbering. > I know that it is claimed that record representation clauses can be > written to be portable between different bit numberings. But in my > opinion, the schemes that do not use the Bit_Order attribute make the > representation clauses ugly and hard to write and read, while the RM > language that describes the Bit_Order attribute and its effects has > surpassed my understanding whenever I've tried to read it -- I simply > could not be sure that it would have the effect that I wanted. It will have the right effect or be illegal. (At least that was my understanding.) The problem is that the non-default bit ordering makes it trivial to declare discontiguous (from the persepective of the default bit-ordering) components, and we didn't want to force compilers to support that sort of stuff. There is little customer demand for that sort of thing (most of the ones that exist are like you and gave up completely wanting more control than the language could possibly provide), so it didn't make sense to require the effort. > I still would like to define the bit-level structure of data in a > declarative way, rather than with field-extraction and field-insertion > operations, but I have reluctantly concluded that the operational method > is better for portable Ada programs, at least in my applications. > > Another factor in this decision is that in my applications, the raw data > (machine instructions for various processors) can actually have several > different structures (instruction formats), so an approach using record > representation clauses needs as many different record types and unchecked > conversions from the raw data (bit-strings or words) to the appropriate > record type. The operational approach entirely avoids these conversions. Of course, the vast majority of Unchecked_Conversions generate no code at all, so these conversions have no run-time impact and IMHO they're still more readable than a bunch of shifts or multiplies. Anyway, I understand that everyone's mileage may vary. I doubt that many applications have the problem of decoding data that are both in the wrong bit-order and are unknown at run-time. (Truth-in-advertising provision: most of the Janus/Ada compiler uses multiplies and divides to create machine instructions, because early versions of Janus/Ada had no support for record representation clauses or any other bit operations at all. We used assembler code whenever those operations were unavoidable -- hardly an ideal approach for portability reasons. Later versions (like the never-finished 68K and SPARC codegens) used record rep. clauses; I recall we had some issues with non-default bit-ordering but don't remember anymore how we solved them.) Randy.