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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d2cba5965c7bfcd5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-03 09:30:55 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!chnws02.ne.ipsvc.net!cyclone.ne.ipsvc.net!24.128.8.70!typhoon.ne.ipsvc.net.POSTED!not-for-mail From: "Jeffrey Creem" Newsgroups: comp.lang.ada References: <3C823A1A.6030006@users.sf.net> <0CFB5EECF8614F8D.52C8F36A468D2F14.3AD3D533D2B72FDB@lp.airnews.net> Subject: Re: 64bit access to an array of 8bit values X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: Date: Sun, 03 Mar 2002 17:27:52 GMT NNTP-Posting-Host: 66.31.5.146 X-Complaints-To: abuse@mediaone.net X-Trace: typhoon.ne.ipsvc.net 1015176472 66.31.5.146 (Sun, 03 Mar 2002 12:27:52 EST) NNTP-Posting-Date: Sun, 03 Mar 2002 12:27:52 EST Organization: ATT Broadband Xref: archiver1.google.com comp.lang.ada:20729 Date: 2002-03-03T17:27:52+00:00 List-Id: "John R. Strohm" wrote in message news:0CFB5EECF8614F8D.52C8F36A468D2F14.3AD3D533D2B72FDB@lp.airnews.net... > The short answer is that you can't do what you want to do. The longer answer is that it is this abstract philosophical academic mindset that convinces people that nothing can be done in Ada. In fact you can do what you want to do. There are several "as portable as C or better" approches that could be taken to solve this problem (involving rep spec and either unchecked conversion of access types or array slices) that will solve this problem just fine. Some of these would probably break on some compiler with lack of full annex support or strange word sizes..But most of the time it would be fine. > > The Ada compiler is not required to allocate precisely one byte per array > element, and it probably didn't. Instead, it will probably allocate one > "word" per array element, because word access is probably faster than byte > access. > > Consider for a moment a processor like the TI 320C30 floating-point digital > signal processor. It provides a 32-bit word, but it does NOT provide any > direct mechanism for addressing individual bytes within the word. Location > N is 32 bits wide. Location N+1 is the next 32 bits. > > Consider for a moment the old Harris superminicomputers. They used a 24-bit > word. There is NOTHING the Ada compiler can do for you in that case, > because 32-bit and 64-bit access DOESN'T EXIST on that machine. > > I was told in school many years ago that there was also a German standard > architecture, that specified a 48-bit word, of which three bits were > reserved for type tagging. So you effectively had a 45-bit word that you > COULDN'T coerce to a different type without a lot of pain. > > The first easy answer is that you model your memory as an array of Bit64, > and do the necessary bitpicking to extract the Bit8, Bit16, and Bit32 values > yourself. If your machine doesn't support Bit64-like objects, then do it as > Bit32 and hack around the Bit64 access. > > The other easy answer is that you model your memory as an array of Bit8, and > then you build up your Bit16, Bit32, and Bit64 accesses by doing multiple > Bit8 fetches and stores. > > The UGLY answer is to create several procedures, MyPeek8, MyPoke8, MyPeek16, > MyPoke16, MyPeek32, ..., and then do assembly language interface to hide > your memory model under them. If you are a real glutton for punishment, > look at the Ada machine code insertion capability. Trust me: you DON'T want > to do this. (I had to do a VMEbus interface for a DSP board this way > several years ago. It worked, but it was NO FUN AT ALL.) > > "Dave Poirier" wrote in message > news:3C823A1A.6030006@users.sf.net... > > I'm trying to modelize a small virtual machine, and I'm stuck on the > > memory model. I'm defining the memory as an array of 8bit values, so > > that I am able to access every byte individually. The problem comes > > when I try to access them with other data size, like 16/32/64bit. GNAT > > simply refuses to do the pointer conversion (yeah, probably a bad habit). > > > > So, what would be a "clean" way to do it? here's what I tried > > > > ------ > > procedure test is > > type Bit8 is mod 2**8; > > type Bit64 is mod 2**64; > > type Bit8Acc is access Bit8; > > type Bit64Acc is access Bit64; > > > > type RamRange is range 0 .. 4000; > > > > Ram : array (RamRange) of aliased Bit8; > > Value : Bit64Acc; > > > > begin > > Value := Ram(0)'Access; > > end test; > > ------ > > > > test.adb:14:18: expected type "Bit64Acc" defined at line 6 > > test.adb:14:18: found type access to "bit8" defined at line 14 > > > > and also.. > > ------ > > procedure test is > > type Bit8 is mod 2**8; > > type Bit64 is mod 2**64; > > type Bit8Acc is access all Bit8; > > type Bit64Acc is access all Bit64; > > > > type RamRange is range 0 .. 4000; > > > > Ram : array (RamRange) of aliased Bit8; > > Value : Bit64Acc; > > > > begin > > Value := Bit64Acc(Ram(0)'Access); > > end test; > > ------ > > > > test.adb:14:12: argument of conversion cannot be access > > test.adb:14:12: use qualified expression instead > > > > I'm just a smooth skinned Ada95 newbie, so don't get too big weapons to > > send replies ;) > > > > Thanks for helping me learn :) > > EKS - Dave Poirier > > > >