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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,553a6b79b2471571 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed01.chello.at!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: How do you bitwise operations in Ada '83 and '95 Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <9315684D-C216-4EDA-8852-0A6BD4C275B0@amado-alves.info> <1e7szqc5niq0u$.1oqd2mhiiccyx.dlg@40tude.net> Date: Fri, 21 Jul 2006 14:09:04 +0200 Message-ID: <71nkuwdmd7v5.xs4ho9ifpcfx$.dlg@40tude.net> NNTP-Posting-Date: 21 Jul 2006 14:09:04 MEST NNTP-Posting-Host: 95f8d77c.newsread4.arcor-online.net X-Trace: DXC=7anA\T;m_K<3JZ5;?1=4k>[6LHn;2LCV>7enW;^6ZC`4IXm65S@:3>? X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:5859 Date: 2006-07-21T14:09:04+02:00 List-Id: On Fri, 21 Jul 2006 05:58:18 -0400, Stephen Leake wrote: > "Dmitry A. Kazakov" writes: > >> On Thu, 20 Jul 2006 05:03:23 -0400, Stephen Leake wrote: >> >>> Marius Amado-Alves writes: >>> >>>> Note that I don't do bit shifting. Instead I multiply or divide by a >>>> magnitude. I don't think bit shifting is portable. >>> >>> See LRM B.2, Interfaces.Shift_Left, Shift_Right, Rotate_Left, Rotate_Right. >> >> Hmm, it reads (Ada 95): >> >> "{shift} {rotate} For each such modular type in Interfaces, shifting and >> rotating subprograms as specified in the declaration of Interfaces above. >> These subprograms are Intrinsic. They operate on a bit-by-bit basis, using >> the binary representation of the value of the operands to yield a binary >> representation for the result." >> >> That looks non-portable to me. >> >> Here is my definition of "portable": >> >> Let T is a modular type Unsigned_n compiled on two different machines. For >> any valid X of T the result of Shift_Left (X, m) yields same numerical >> value on both machines. >> >> I don't know if that was overlooked or that was an intent of language >> designers to get at the underlying machine representation. Probably the >> latter. I'm not a language lawyer, though. > > I'm missing something here. Assuming machines A and B both have > Unsigned_16, please show me an Ada statement that produces > different results on the two machines. > > I can see shift/rotate is non-portable if machine B doesn't have > Unsigned_16, but otherwise I don't see the problem. > > Hmm. I suppose if machine A is one's complement, and machine B is > two's compliment? No, the Unsigned bit representation is still the > same; that's why these operations are not defined on signed types. It depends on endianness. Provided that storage elements are octets on both machines, which assumption could be wrong, 128 shifted left might yield 0, 256 or even 64 (what is "left"?). When considering *any* thinkable architecture, it might be even impossible to implement Shift_* at all. Let some crazy hardware store numbers in only odd bits, reserving even ones for something else (like a check-sum). On such imaginary hardware Shift_Left (*, 1) wouldn't even yield a valid number! Actually "they operate on a bit-by-bit basis" is quite hazy. What is bit? Which bits are adjacent? How are they ordered? What does "left" mean? Which bits are of the number? etc. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de