Re: 2-dimensional DW array access without MULs?




Jim Leonard wrote:
I'm still trying to teach myself, so forgive me for getting something
wrong... I'm trying to optimize something for 8088 that is fairly MUL
heavy, and I thought a good way to do that was, for one particular
operation, precalculate a table and then just do (x,y) lookups into the
table. Only problem is, I can't figure out to do this without a MUL to
get to the right row/column in the array.

The only thing I can think of is to make my word array's column size
aligned by a power of 2 so that I can use shifts to get to the right
(x,y)... Or, if my word array is 128 columns or less I could use
something like "mov bh,y; shl bh,1; mov bl,x, mov result,[offset
myarray+bx]"... Is this the right line of thinking?

I'm just curious how people usually work with 2-dimensional arrays that
are not byte arrays, or have dimensions not aligned to a power of 2, or
over 64K, preferably with examples... Is LEA usually used for this? I
checked a few resouces but most of them list the different addressing
modes but not provide example usage (although I confess I haven't
checked Hyde's book yet).

Thanks in advance for any advice!


Well, if you're going to be doing random accesses into a two (or more)
dimensional array, you're going to have to do a multiplication
operation in the general case. As you've already noticed, that doesn't
mean a multiplication *instruction* in all cases. You mentioned using
shifts when the dimension was a power-of-2. Other simple products can
often be computed faster than a multiplication as well. For example,
on an 8086, you can multiply by 14 faster with:

mov bx,ax
shl ax,1 ;*2
shl ax,1 ;*4
shl ax,1 ;*8
sub ax,bx ;*7
shl ax,1 *14

Than with a multiplication instruction.

If you've got a 386, you can use scaled addressing to generate many
interesting small multiplications with an lea or two.

You can help this process by adjusting the size of the dimensions to
many the required products easier to compute - and leaving the padding
space unused.

If the accesses are not purely random, there are often opportunities to
reduce the index calculations to simple adds to get to the next
element. A classic example is a dot-product loop where you'd be doing
something like:

for (i=0; i<n; i++)
s+=a[r][i]*b[i][c]; //where r and c are invariant for the loop

The stepping through those two arrays should reduce to a simple add
each (one the size of an element, the other the size of a row).

.



Relevant Pages

  • Re: Gaussian cluster antenna array data
    ... A gaussian array is aimed towards resonant elements in cluster form. ... but these dimensions have not been ...
    (rec.radio.amateur.antenna)
  • RE: Mass Adding Comments
    ... insert code to fill your own array as desired at the beginning of the ... 'Determine number of dimensions in array using Chip Pearson's method ... ' Loop, increasing the dimension index Ndx, until an error occurs. ... 'Exit sub if dimensions do not match ...
    (microsoft.public.excel.programming)
  • Re: Gaussian cluster antenna array data
    ... A gaussian array is aimed towards resonant elements in cluster form. ... but these dimensions have not been ...
    (rec.radio.amateur.antenna)
  • RE: Mass Adding Comments
    ... insert code to fill your own array as desired at the beginning of the ... 'Determine number of dimensions in array using Chip Pearson's method ... ' Loop, increasing the dimension index Ndx, until an error occurs. ... 'Exit sub if dimensions do not match ...
    (microsoft.public.excel.programming)
  • Re: Handling ubound on an uninitialised array
    ... Function ArrDim(vArr As Variant) As Integer ... Dim i As Long, x As Long ... > I believe that Tushar's comment re an UPPERBOUND of -1 may relate> to some functions like split/filter or a scripting dictionary's items> array which return an array if no results were found. ... > I've just written following function which gives the DIMENSIONS of an> array. ...
    (microsoft.public.excel.programming)