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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no 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.204.129.212 with SMTP id p20mr148743bks.6.1324241092507; Sun, 18 Dec 2011 12:44:52 -0800 (PST) Path: jh9ni27087bkb.0!nntp.google.com!news1.google.com!news4.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Interfaces.Shift_Left Date: Sun, 18 Dec 2011 22:47:15 +0200 Organization: Tidorum Ltd Message-ID: <9l71m2FlhuU1@mid.individual.net> References: <18214312-82f5-45c4-b20d-cb530b500929@h3g2000yqa.googlegroups.com> <5f989095-5c1c-4b23-a538-d70f4718b4b1@l19g2000yqc.googlegroups.com> <9ktu5mFn31U1@mid.individual.net> Mime-Version: 1.0 X-Trace: individual.net Q3Nx2wflBNvjOEd4h671vgBF2yrVUhC4eGCoUStX11FPlXGffm Cancel-Lock: sha1:1/pb9U7kfVQ4mLFyn/pqQfr9KHw= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2011-12-18T22:47:15+02:00 List-Id: On 11-12-16 02:23 , Randy Brukardt wrote: > "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. Ooh, harsh words. I'm trying not to take offence. Of course I hide the implementation in an "extract field" function with the bit numbers as parameters. My code typically decodes machine instructions from the instruction set of some processor; the user manual of that processor is the specification for my SW; the user manual normally shows the format of a given instruction by a figure of the instruction with the fields indicated by bit numbers; there is an immediate correspondence between this figure and the calls of the "extract field" functions. Very easy to write, check, and maintain, in my experience. >> 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. "All the world is a VAX -- no, an Intel -- no, an Xxx", eh? I do not want to write programs that have such an implementation dependency. I wouldn't go so far as to call such code "junk", but it would be as bad as assuming that Integer is 32 bits. >> 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.) I'm sure that is the intention. But as I haven't been able to understand the conditions under which Bit_Order works, I haven't dared to rely on it. Maybe I could understand Bit_Order if I tried harder, but then there's the other factor: >> 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 Sure, run-time is no problem; the problem is having to write a lot of type declarations, plus their representation clauses. There's just much more text, more type names, more component names, which to me have little benefit. Each of these types and components would be used only once, in the Ada code that translates an instruction of that format into my internal representation. > and IMHO they're still > more readable than a bunch of shifts or multiplies. I agree, if the shifts and masks would be written in-line, which I don't do. I write calls to my "extract field" function instead, which I find very readable and easy to compare to the specification. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .