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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,53a810f13e8ba40 X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: Byte/Bit Twiddling in Ada Date: 1997/02/26 Message-ID: #1/1 X-Deja-AN: 221664727 References: <5dvfnn$olj@neocad.xilinx.com> <33048844.7AEB@elca-matrix.ch> <01bc1b6e$f5d65c30$3e208b82@wd> Organization: New York University Newsgroups: comp.lang.ada Date: 1997-02-26T00:00:00+00:00 List-Id: Wiljan said <<> GNAT *does* generate good code for messing with individual bits of a bit > packed array, which seems the most common usage. > I do not agree on that Robert, Plese check out the following program: with Ada.Text_Io; use Ada.Text_Io; procedure testsetcomp is type set is array(0..31) of boolean; pragma pack (set); A, B : Set; begin A := (5..10=>True, others=>False); B := (others=>False); B (5..10) := (others=>True); if A <= B then Put_Line ("A<=B"); else Put_Line ("not A<=B"); end if; end testsetcomp; When I check the code generated using gnat -S -O2 -gnatp on above source I find the compiler generating loops for all kind of things. >> Robert replies, well you may or may not agree with me, but the above example is entirely irrelevant to the statement I made, which is that the code for messing with INDIVIDUAL bits of a bit packed array is good. In the above examples, EVERY reference to the packed array is to a collection of bits -- PRECISELY what I noted was not handled very well!!! Wiljan said <> Well this is a nice example of why this sort of stuff is not as easy as you think. The issue of whether A<=B can be done in a single compare or requires bit by bit code depends on the ordering of the bits in the array which is not specified by the language. Typically at least in the little-endian case, where A(0) and B(0), the most significant bits in the semantics of the comparison, are at the LEAST significant bit position in the word. Sure there is lots of special casing possible, and *some* of it will get done in time. But this is certainly not at the top of the list of important optimizations!