comp.lang.ada
 help / color / mirror / Atom feed
From: Tucker Taft <stt@averstar.com>
Subject: Re: RISC
Date: Wed, 14 Mar 2001 16:57:59 -0500
Date: 2001-03-14T21:58:00+00:00	[thread overview]
Message-ID: <3AAFE967.44BAEDAD@averstar.com> (raw)
In-Reply-To: JqQr6.1962$y47.389981@news2-win.server.ntlworld.com

"chris.danx" wrote:
> 
> Hi,
>     I'm simulating a RISC machine in Ada.  Eventually the instructions will
> be mapped to native architecture (x86, m68xxx, SPARC, etc), but for now i
> want to simulate a machine, to limit the possibility of doing something
> nasty to anyone's machine.
> 
> I've decided to provide byte, word and long word  modes for most
> instructions.  The problem comes when clearing or setting byte or word
> portions of a register (the machine is loosely based on M68000).  The
> register is long word (32bit) and i want to set the lower 16bits or 8bits.
> I've managed to get this to work, problem is it's not very efficient.
> 
> The register is of type 'mod', so i divided by 2**8 or 2**16 then multiplied
> by it.  I know multiplication and division are costly and really i'm looking
> for something more efficient.  If this were Pascal i'd use 'shift
> left/right' which is quite fast.  What should i do to speed it up?  Does Ada
> have a shift L/R operation?  Is there another way to do it?

There are a few:
1)  Declare a record type (or types) and use a record rep clause (or clauses)
    to define the fields you are interested in.
2)  Use Interfaces.Unsigned_* and use the shifting operations there
3)  Use a packed bit array and use slicing (efficiency will probably
    vary significantly from compiler to compiler on this one)
4)  Use a modular type and use "and" with 255 or 65535 to extract the
    low-order 8/16 bits.

> 
> I have another problem with memory.  I thought about allocating one big
> block of memory (as an array) and accessing it by index.  The problem?  I do
> plan to dynamically allocate the memory, but i'll still be limited by the
> amount of memory allocable in a single array.  I've thought of a few ways of
> doing this but can't seem to avoid problems!  Anyone know of a solution?  I
> don't like using C, but i 'd run in to a similar problem binding with C
> anyway.

One good way to deal with large address spaces is to break the
address up into a page index and an offset within page, or
even a segment/page/offset.  E.g., the segment is the high 12 bits,
the page index is the next 8 bits, and the offset within page is
the low-order 12 bits.  You then have a top-level segment table
with 4096 segments, each of which is either null, if nothing
has ever been written into that segment, or a pointer to a 256-entry
page table.  Each entry in the page table is similarly either null,
or a pointer to a 4096-byte page, depending on whether anything has
ever been written to that page.  When reading memory, if the
corresponding segment or page entry is null, just return a 0.
When writing memory, if the corresponding segment or page entry is null,
and the value being written is other than 0, allocate the page,
and page table if necessary, and update the segment/page entries
to point to these new memory chunks, and then update the appropriate
byte(s) in the page.

This is essentially one kind of "sparse" array.  It also happens
to correspond to a way that virtual memory is implemented by a typical
MMU.
 
> Thanks,
> Chris Campbell
> 
> p.s. This isn't a homework assignment!!!

-- 
-Tucker Taft   stt@avercom.net   http://www.averstar.com/~stt/
Chief Technology Officer, AverCom Corporation (A Titan Company) 
Burlington, MA  USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/services/ebusiness_applications.html)



  reply	other threads:[~2001-03-14 21:57 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-14 20:23 RISC chris.danx
2001-03-14 21:57 ` Tucker Taft [this message]
2001-03-14 22:36   ` RISC chris.danx
2001-03-14 23:03     ` RISC Fraser Wilson
2001-03-15  1:30       ` RISC Corey Ashford
2001-03-15  9:19       ` RISC chris.danx
2001-03-15 12:37 ` RISC chris.danx
2001-03-15 13:03   ` RISC Tarjei T. Jensen
2001-03-15 18:29     ` RISC Robert A Duff
2001-03-15 14:40   ` RISC Ted Dennison
2001-03-15 14:49     ` RISC Robert A Duff
2001-03-15 17:37       ` RISC Marin David Condic
2001-03-15 18:28         ` RISC Robert A Duff
2001-03-15 19:16           ` RISC Marin David Condic
2001-03-16  8:44             ` RISC Martin Dowie
2001-03-16 14:40               ` RISC Marin David Condic
2001-03-20 10:17                 ` RISC Martin Dowie
2001-03-20 14:34                   ` RISC Marin David Condic
2001-03-20 15:45                     ` RISC Ted Dennison
2001-03-20 16:39                       ` RISC Robert A Duff
2001-03-20 18:10                       ` RISC Martin Dowie
2001-03-20 18:56                         ` RISC Ted Dennison
2001-03-22  9:16                       ` RISC - largish (code listed) Martin Dowie
2001-03-22  9:34                         ` Martin Dowie
2001-03-20 18:09                     ` RISC Martin Dowie
2001-03-20 20:00                       ` RISC Marin David Condic
2001-03-20 22:30                         ` RISC Robert A Duff
2001-03-20 22:48                           ` RISC Ted Dennison
2001-03-20 23:10                           ` RISC Marin David Condic
2001-03-21  0:18                             ` RISC Robert A Duff
2001-03-21 14:31                               ` RISC Marin David Condic
2001-03-21 16:47                                 ` RISC Ted Dennison
2001-03-21 17:36                                   ` RISC Marin David Condic
2001-03-16 15:09             ` RISC Tucker Taft
2001-03-16 17:10               ` RISC Robert A Duff
2001-03-16 19:02                 ` RISC Marin David Condic
2001-03-16 20:58                   ` RISC Robert A Duff
2001-03-19 16:17                     ` RISC Marin David Condic
2001-03-19 16:45                       ` RISC Florian Weimer
2001-03-19 17:14                         ` RISC Marin David Condic
2001-03-19 17:33                           ` RISC Florian Weimer
2001-03-21  5:57                           ` RISC Lao Xiao Hai
2001-03-16 22:19                   ` RISC Ted Dennison
2001-03-16 19:13                 ` RISC Laurent Guerby
2001-03-16 20:30                   ` RISC Robert A Duff
2001-03-16 20:51                 ` RISC Ole-Hjalmar Kristensen
2001-03-16 18:33               ` RISC Marin David Condic
2001-03-16 20:45                 ` RISC Robert A Duff
2001-03-17  1:13                   ` RISC Randy Brukardt
2001-03-19 16:34                   ` RISC Marin David Condic
2001-03-19 17:49                     ` RISC Robert A Duff
2001-03-16 20:08 ` RISC chris.danx
2001-03-16 20:31   ` RISC Marin David Condic
2001-03-17 21:51     ` RISC Robert A Duff
2001-03-18  6:37       ` RISC Charles Hixson
2001-03-19 15:42         ` RISC Robert A Duff
2001-03-19 17:02         ` RISC Marin David Condic
2001-03-19 17:45           ` RISC Robert A Duff
2001-03-19 18:48             ` RISC Marin David Condic
2001-03-19 16:45       ` RISC Marin David Condic
2001-03-16 22:27 ` RISC chris.danx
2001-03-17  2:49   ` RISC Jeffrey Carter
2001-03-19  9:43   ` RISC Martin Dowie
2001-03-19 11:06     ` RISC chris.danx
2001-03-28 22:24     ` RISC chris.danx
2001-03-29  0:52       ` RISC Corey Ashford
2001-03-29 12:42       ` RISC John English
2001-03-22 20:11 ` RISC chris.danx
2001-03-22 20:51   ` RISC Marin David Condic
2001-03-22 21:02   ` RISC tmoran
2001-03-22 21:18     ` RISC chris.danx
2001-03-22 21:45   ` RISC Britt Snodgrass
2001-03-22 22:43     ` RISC chris.danx
2001-03-28 11:37   ` RISC chris.danx
  -- strict thread matches above, loose matches on Subject: below --
2001-03-16 23:25 RISC Beard, Frank
2001-03-17 11:39 ` RISC chris.danx
2001-03-29  3:12 RISC Beard, Frank
2001-03-29  7:28 ` RISC Martin Dowie
2001-03-29 12:38 ` RISC chris.danx
2001-03-29 19:07 ` RISC Chad R. Meiners
2001-03-29 17:52 RISC Beard, Frank
2001-03-30 17:31 RISC Kent Paul Dolan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox