.INDEX - do linear search with RPT instruction.

Alternate Entry Name: _INDEX

Usage:

B:
   idx = .index(vec, num, value
             [, delta, term, cmpinst, mask]);
C:
   int _index(void *vec, int num, int value,
              [ int delta, int term, int cmpinst,
                int mask] );

Where:

vec
is a pointer to the vector you want to search.
num
is the number of entries to search.
value
is the value you are looking for.
delta
is a number in the range 1 through 63. If "delta" is equal to N, .INDEX will examine every Nth word in "vec", i.e.
vec[0]
vec[delta]
     ...
vec[(num-1)*delta]

If "delta" is omitted, the default is 1.

term
is the repeat termination condition. This is specified in the lower 18 bits of "term" by ORing together values from B/MANIF/RPTBTS. The default is R.TZE so .INDEX searches for an exact match.
cmpinst
is the compare instruction to use for the search. This must be specified in bits 18-27 of "cmpinst". The default is 0115000 (CMPA).
mask
is the value of the Q register during the search. It will only be meaningful if the "cmpinst" is a CMPAQ, CMK, or CWL. It has no default.
idx
is the index in "vec" where a match was found. If a match is not found, -1 is returned.

Description:

.INDEX lets you perform fast linear searches using repeat instructions. By selecting different termination conditions and compare instructions, you can perform a wide variety of linear searches. The default is simply to search linearly through a vector for the first exact match of a value. .INDEX compensates for the overrun implicit in the RPT instruction, so if a match is found "vec[idx]" is the value that matched.

Although .INDEX is quite flexible, it is not a perfectly generalized linear search. There are a number of hardware-imposed restrictions. You can only search increasing memory addresses, "delta" cannot exceed 63, and the potential search address "vec[(num-1)*delta]" must exist within your program even when an actual match value exists. C programmers in particular should be aware that use of more than the first four arguments will be non-portable, and should be "hidden" with a less general "cover" function or macro.

See Also:

expl b bmac rptbts
for names and interpretation of the termination condition bits.
DPS 8 Assembly Instructions - DH03
for a more detailed decription of the RPT instruction, and the possible choices of comparison instructions.

Copyright © 1996, Thinkage Ltd.