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,9dec3ff1604723d9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 MSIE X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Bitmanipulation in Ada References: <87k6vwrwym.fsf@insalien.org> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 19 Aug 2004 19:17:00 GMT NNTP-Posting-Host: 63.184.8.168 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.pas.earthlink.net 1092943020 63.184.8.168 (Thu, 19 Aug 2004 12:17:00 PDT) NNTP-Posting-Date: Thu, 19 Aug 2004 12:17:00 PDT Xref: g2news1.google.com comp.lang.ada:2869 Date: 2004-08-19T19:17:00+00:00 List-Id: Bernd Specht wrote: > Jeffrey Carter wrote in news:wSSUc.27249$9Y6.977 > @newsread1.news.pas.earthlink.net: >>In many cases, Unchecked_Conversion will generate no code, and need not >>involve an assignment. In well designed software, the part(s) of the >>software that deals with values as an integer and those that deal with >>them as bit arrays will be kept separate. So you do something like: > > Always? What do you think about bitscrambling software which has to treat > data alternating as bitvector and as integer value in a loop like this (not > exeactly this for securitity reasons): I don't see any claims for "always" in my statements. > ... > loop > declare > x : boolean; > begin > x := b(k); > b(k) := b(32 - k); > b (32 - k) := x; > I := I * prime1 mod prime2; > end; > end loop; > > Can you find an equivalent algorithm where you can separate the bit-ops and > the integer-ops? Assuming that I and B are Integer and Bit_Array versions of the same value, sure. Replace the assignment to I with Update_Integer (Value => To_Integer (B) ); where procedure Update_Integer (Value : in out Integer) is -- null; begin -- Update_Integer Value := Value * Prime1 mod Prime2; end Update_Integer; and To_Integer is an appropriate instantiation of Unchecked_Conversion. If measurement shows that the overhead of calling a procedure causes you to violate timing requirements, you can inline the procedure. -- Jeff Carter "Sons of a silly person." Monty Python & the Holy Grail 02