ARRAY INDEXING

Abstract: A method and apparatus for sequentially generating a set of addresses, defined over a plurality of indices, for a multi-dimensional array stored in a memory for the condition where at least one of the address indices is fixed, is performed by simple addition, OR-ing and AND-ing. An accumulator or counter initially holds an arbitrary binary value composed of a set of binary indices corresponding to the address indices. This binary value is logically OR-ed with a first mask value having binary indices selected in value in relation to the fixed address indices. The resultant is logically AND-ed with a second mask value having binary indices selected in value in relation to the fixed address indices, and this operation produces a first address of the set. The same resultant is incremented and the incremented value is delivered to the accumulator for the cycle to be repeated.

Description: Array Indexing The present invention relates to array indexing in a computer and in particular to a method of and apparatus for sequentially generating a set of addresses, defined over a plurality of indices, for a multi-dimensional array stored in a memory, wherein at least one of the address indices is fixe . In accessing data stored in a digital memory, it is often desirable or necessary to step through the entries of a multi-dimensional array, holding one or more indices of the address constant whilst doing so. To illustrate this, reference is made to Figure 1 which shows a typical example of how a multi-dimensional array A[i, j ,k] where i = 0 to 1, j = 0 to 1, k = 0 to 3 may be stored in a computer's memory. The array is logically a sequence of elements each of which is identified with a unique combination of subscripts or indices (i,j,k) but is physically stored in a one dimensional array of locations in the memory. In order to enable hardware to access the one dimensional memory array it is necessary to translate logical addresses composed of the appropriate indices (i,j,k) to location addresses which can directly access the one dimensional array. It is therefore the case that associated with each set of indices in the multidimensional array there will be a number which, when used as an index to the underlying one dimensional array, will define the corresponding position in the one dimensional array. Thus, in the example shown in Figure 1, element A[l,0,3] will be in decimal location 11 (i.e. 1011 in binary) in the underlying one dimensional array. In the above example, location 11 is typically obtained from the array indices [1,0,3] as shown in Figure 2. The indices [1,0,3] i.e. i,j,k are held in respective distinct registers (i,j,k) and are then multiplied by appropriate constants (8, 4 and 1) . The results are then added together to form the location number (1011) in binary. Consider now that one wishes to step through the array A[i,j,k] , holding the value of j constant at 1 but going through all legitimate combinations of i and k. This involves accessing the set of array elements: A[0,1,0] , A[0,1,1] , A[0,l,2] , A[0,l,3] , A[1,1,0] , A[l,l,l] , A[l,l,2] , A[l,l,3] and the corresponding locations: 4,5,6,7,12,13,14,15 The normal process by which this would be done would be to: 1. reserve three computer registers for i, j, k; 2. initialise them to the values i = 0, j = 1, k = 0 3. set up a pair of nested loops in a computer program so that (a) the outer loop increments i through all its allowed values (b) the inner loop increments k through all its allowed values and (c) the kernel of the inner loop uses the process shown in Figure 2 to compute the location numbers from the indices of each array element . The disadvantage of this process is that it involves multiplication or shift operations and nested loops, all of which are relatively slow operations to perform using computer hardware. It is an object of the present invention to overcome or at least mitigate the above mentioned disadvantages of array address generating methods. According to a first aspect of the present invention there is provided a method of sequentially generating a set of addresses, defined over a plurality of indices, for a multi-dimensional array stored in a memory, wherein at least one of the address indices is fixed at an actual value, the method comprising the steps of: (a) providing a first binary address having address indices of arbitrary value; (b) replacing all of the bit values of the or each fixed index in the first binary address with l's; (c) incrementing the resulting binary value, wherein any carry value (s) generated propagate (s) across the or each fixed index; (d) replacing the bit values of the or each fixed index in the resulting binary value with the actual values to which each fixed index is set to provide a first address for the set; and (e) repeating steps (b) to (d) , using the preceding result of step (c) as a new first binary address value, until the required address set has been generated. In an embodiment of the above first aspect of the invention, the method comprises the steps of: (i) providing an accumulator and storing in the accumulator a binary value composed of a set of binary indices corresponding to the address indices; (ii) performing a logical OR operation between the binary value stored in the accumulator and a first mask binary value, where the first mask value is also composed of a set of binary indices with the or each index, corresponding to the or each fixed address index, being composed entirely of l's and the other indices being composed entirely of 0's; (iii) performing a logical AND operation between the result of the OR operation in step (ii) and a second mask binary value composed of a set of binary indices, where the or each index, corresponding to the or each fixed address index, contains the corresponding binary value of the fixed address index, and the other indices are composed entirely of l's, wherein the result of the AND operation provides a first address for the set; (iv) incrementing the result of the OR operation performed in step (ii) and storing the result in the accumulator; and (v) repeating steps (ii) to (iv) until the required address set has been generated. The present invention makes it possible, by suitable use of mask bits, to so arrange the inputs to a conventional computer adder that the operations required to step through a multi-dimensional array can be performed by simple addition, ORing and ANDing The binary value initially stored in the accumulator may be any arbitrary value although it would normally be initialised to zero. According to a second aspect of the present invention there is provided a digital computer memory comprising at least one digital data storage device and address generating means arranged to generate addresses according to the method of the above first aspect of the present invention for the purpose of accessing data stored in the or each data storage device. According to a third aspect of the present invention there is provided apparatus for carrying out the method of the above first aspect of the invention and comprising: a first register arranged to provide said accumulator; a second register arranged to store the first mask binary value; an OR logic unit coupled to said first and second registers for performing the OR operation of step (ii); a third register coupled to the OR unit and arranged to store the result of said OR operation; an incrementing unit coupled to said first and third registers and arranged to perform step (iv) ; a fourth register arranged to store said second mask value; and an AND logic unit coupled to said third and fourth registers and arranged to perform the AND operation of step (iii) . For a better understanding of the present invention and in order to show how the same may be carried into effect reference will now be made, by way of example, to the accompanying drawings, in which: Figure 1 illustrates the mapping of a logical 3- di ensional array onto a physical 1-dιmensional memory space; Figure 2 shows schematically a conventional process for generating the location in the 1-dιmensιonal memory space of Figure 1 corresponding to a 3-dimensional array address; Figure 3 shows a flow diagram illustrating the generation of multi-dimensional array addresses according to an embodiment of the invention,- Figure 4 shows schematically a system for carrying out the process of Figure 3. Considering the array A shown in Figure 1, instead of maintaining three registers (as per Figure 2) corresponding to the dimensions of the array to be traversed, an embodiment of the present invention requires (as per Figure 3) only a single counting register C and two mask words, p and q. The following steps are then followed: 1. a boolean OR operation is performed between the contents of register C and the mask word p; 2. the result of the first step is then incremented and returned to register C; 3. the mask q is 'ANDed' with the result of the first step and the result used as the location (m binary) of the current array element. For this technique to work, the mask words p, q must be prepared so that p holds l's in the positions corresponding to the dimensions of the array that are being held fixed and O's elsewhere, whilst the mask q contains: l's in the positions corresponding to the dimensions of the array that are being stepped through; a pattern of l's and O's in the positions corresponding to the dimensions of the array that are fixed, so that the patterns of l's and O's correspond to the appropriately multiplied constant indices of these dimensions; the value 0 in all other bit positions. The effect of the 'ORing' with p is to create a number with strings of l's between the fields that correspond to the dimensions being stepped through. These strings of l's have the effect of allowing carry bits to propagate through them to the fields in the words corresponding to the next varying dimension. As is illustrated in Figure 3 the register C is a four-bit register with the two least significant bits holding index k (where k = 0 to 3) and the two most significant bits holding indices i and j (where i, j = 0 to 1) and it is required to step through all possible addresses with j held constant at 1. The register C is initialised to 0000, or any other suitable value, before commencing address generation by applying steps 1, 2 and 3 above, whilst the mask words p and q are set to 0100 and llll respectively. One possible implementation of this technique, suitable for high speed computers, is shown in Figure 4. The apparatus contains three registers X,Y,Z that are loaded with new data every clock cycle. For reasons of simplicity all registers are shown having 4 bits (2 bits allocated to the first, least significant index k, and 1 bit allocated to each of the other two indices i, j) , but the technique applies equally well to longer or shorter registers. During each clock cycle, the apparatus will store in register X the address (in binary) of the next location in the 3-dimensional array to be accessed. Two auxiliary registers P, Q are loaded at the start of the process with the masks p, q described above. Each cycle, register Y is loaded with the result of 'ORing' the contents of registers Z and P, and register Z is subsequently loaded with [1 + Z] . Register X is loaded with the result of 'ANDing' the contents of registers Y and Q. Thus, without any circuitry more complex than an incrementer, a new array location (in binary) can be computed each cycle. An alternative software implementation involves executing a simple loop on a conventional computer processor such as is set out, for example, below. Assume in what follows that register SI holds the mask p, register DX holds the mask q and that register CX holds a count of the number of elements to visit . start: and AX, DX location now in AX call uselocation use the location to fetch and operate on the array element mov AX, BX recover previous value with propagate bits inc AX increment propagating the carries or AX, SI set the propagate bits again mov BX, AX save in BX loop start decrement CX and jump to start if nonzero Again the loop requires no slow multiply or shift instructions, and only a single loop is required. The embodiment described above is generally applicable to arrays having array indices each of which extends from 0 to 2 n_1 . This enables the generation of a carry bit, for propagation to the next variable index, when the maximum value in the preceding variable index is exceeded.

Claims: CLAIMS 1. A method of sequentially generating a set of addresses, defined over a plurality of indices, for a multi-dimensional array stored in a memory, wherein at least one of the address indices is fixed at an actual value, the method comprising the steps of: (a) providing a first binary address having address indices of arbitrary value; (b) replacing all of the bit values of the or each fixed index in the first binary address with l's; (c) incrementing the resulting binary value, wherein any carry value (s) generated propagate (s) across the or each fixed index; (d) replacing the bit values of the or each fixed index in the resulting binary value with the actual values to which each fixed index is set to provide a first address for the set; and (e) repeating steps (b) to (d) , using the preceding result of step (c) as a new first binary address value, until the required address set has been generated. 2. A method of sequentially generating a set of addresses, defined over a plurality of indices, for a multi-dimensional array stored in a memory, wherein at least one of the address indices is fixed at an actual value, the method comprising the steps of: (i) providing an accumulator and storing in the accumulator a binary value composed of a set of binary indices corresponding to the address indices; (ii) performing a logical OR operation between the binary value stored in the accumulator and a first mask binary value, where the first mask value is also composed of a set of binary indices with the or each index, corresponding to the or each fixed address index, being composed entirely of l's and the other indices being composed entirely of O's; (iii) performing a logical AND operation between the result of the OR operation in step (ii) and a second mask binary value composed of a set of binary indices, where the or each index, corresponding to the or each fixed address index, contains the corresponding binary value of the fixed address index, and the other indices are composed entirely of l's, wherein the result of the AND operation provides a first address for the set; (iv) incrementing the result of the OR operation performed in step (ii) and storing the result in the accumulator; and (v) repeating steps (ii) to (iv) until the required address set has been generated. 3. A method as claimed in claim 2, wherein the binary value initially stored in the accumulator is any arbitrary value . 4. A method as claimed in claim 3, wherein the arbitrary value is zero. 5. Apparatus for carrying out the method of any one of claims 2-4, said apparatus comprising: a first register arranged to provide said accumulator; a second register arranged to store the first mask binary value; an OR logic unit coupled to said first and second registers for performing the OR operation of step (ii) ,- a third register coupled to the OR unit and arranged to store the result of said OR operation; an incrementing unit coupled to said first and third registers and arranged to perform step (iv) ; a fourth register arranged to store said second mask value; and an AND logic unit coupled to said third and fourth registers and arranged to perform the AND operation of step (iii) . 6. A digital computer memory comprising at least one digital data storage device and address generating means arranged to generate addresses according to the method of claim 1 for the purpose of accessing data stored in the or each data storage device.

Inventors: COCKSHOTT WILLIAM PAUL, MCGREGOR DOUGLAS ROBERT, COCKSHOTT, WILLIAM, PAUL, MCGREGOR, DOUGLAS, ROBERT
Applicants: COCKSHOTT WILLIAM PAUL, MCGREGOR DOUGLAS ROBERT, UNIV STRATHCLYDE, COCKSHOTT, WILLIAM, PAUL, MCGREGOR, DOUGLAS, ROBERT, UNIVERSITY OF STRATHCLYDE
Application year: 1997
Main classification: G06F12
IPC codes: G06F12