Path: utzoo!mnetor!uunet!epiwrl!epimass!jbuck From: jbuck@epimass.EPI.COM (Joe Buck) Newsgroups: comp.arch Subject: Re: RISC is a nasty no-no! Message-ID: <1970@epimass.EPI.COM> Date: 4 Mar 88 17:34:48 GMT References: <179@wsccs.UUCP: <696@nuchat.UUCP> <284@scdpyr.UUCP> <11199@duke.cs.duke.edu> <998@PT.CS.CMU.EDU> Reply-To: jbuck@epimass.EPI.COM (Joe Buck) Organization: Entropic Processing, Inc., Cupertino, CA Lines: 23 In article <998@PT.CS.CMU.EDU> edw@IUS1.CS.CMU.EDU (Eddie Wyatt) writes: >> Multiplication is not necessary to access 2-D arrays if the array is >> set up like most arrays in C, where each row is a typical vector and >> the 2-D array is just a vector of pointers to each row vector. >EXCUSE ME, but when I declare an array to be an n by m matrix in >C (float foo[n][m]) I get a contiguous block of memory. The >representation IS NOT row-vector or column-vector. So when I access >index number i,j someone has to perform the calculation >base + sizeof(type)*(i*m+j). No, the compiler doesn't have to do things that way. It can create an extra row of pointers to the beginning of each row: p_foo[n], where p_foo[i] contains &foo[i][0]. Then foo[i][j] is at *p_foo[i] + j. No multiply required, but there might be a shift or two to accomodate two-byte or four-byte array elements. The old Fortran compiler for PDP-11's running RT-11 had an option to do this: you're trading off speed for space. They called it "array vectoring". The array itself is still allocated the way you think it is, but there are extra pointers. -- - Joe Buck {uunet,ucbvax,sun,}!epimass.epi.com!jbuck Old Internet mailers: jbuck%epimass.epi.com@uunet.uu.net