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, the *original* way people used to do this for 2-D arrays (in
assembly and HLLs like C) was to create a table of pointers that point
at the beginning of each row in the array. Fetch the pointer with the
leftmost index (assuming row-major ordering) and then add the second
index to this base address.

However, as memory speeds are now much slower than CPU speeds, it's
questionable whether this technique really buys you much. imul is
relatively fast on modern x86 processors (though it did take a hit on
the PIV). Unless the table is sitting in the level one cache, I
suspect that the imul approach may be faster.

Of course, if the row size is a power of two, then you can use shifts
(which, unfortunately, also took a speed hit on the PIV). You can also
use the LEA instruction in place of multiply for certain values. But
once you're executing 3 or 4 instructions, imul is probably going to be
around as fast.

As always, try a bunch of different ways out and see what works best
for your typical input data values.
Cheers,
Randy Hyde

.



Relevant Pages

  • Re: 2-dimensional DW array access without MULs?
    ... I'm trying to optimize something for 8088 that is fairly MUL ... if my word array is 128 columns or less I could use ... shl ax,1;*2 ... You can help this process by adjusting the size of the dimensions to ...
    (comp.lang.asm.x86)
  • 2-dimensional DW array access without MULs?
    ... I'm trying to optimize something for 8088 that is fairly MUL ... aligned by a power of 2 so that I can use shifts to get to the right ... if my word array is 128 columns or less I could use ... I'm just curious how people usually work with 2-dimensional arrays that ...
    (comp.lang.asm.x86)
  • Re: Cobol Myth Busters
    ... Correct interpretation of findings: ... one wonders why you constructed for your testing an array ... How could INDEXED BY speed up a subscript? ... drawn *only* by comparing executions speeds against arrays defined identically ...
    (comp.lang.cobol)
  • Re: Disk IO Slowly Grinds to a (near) Halt
    ... I ran some dd raw throughput tests and while write speeds seemed to be ... kept the disks busy enough to keep the raid-check and smart self-tests ... to interrupt both the smart self test and the raid recheck. ... the other array had finished both checks in less than 12 hours. ...
    (Linux-Kernel)
  • Re: RC4 on AMD64
    ... >>You sustain 2.4Gbps often to your disk array? ... Suppose AES gets broken. ... If a customer needs Gbps speeds I'd tell them with a straightface to use ...
    (sci.crypt)