tirsdag den 29. oktober 2019

Vector instructions (3)

This will be the last article regarding vectors.
This article deals with string (text) search which is finding the first occurrence of an element. An element can be a byte, halfword, or fullword. The string to search is in the second operand Vector Register and the element(s) to search for is(are) in the third Vector Register. The result is an offset to the element in the searched Vector Register (second operand). If you search for multiple elements the result is the first occurrence of any of the searched elements. My example will show it. 
In my example I will use byte search which you will most likely use. 
The instruction VFAEB will search for the first occurrence of either “D” or “C” in the text string “ABCDEFGHIJKLMNOP”.
Because “C” comes before “D” in the text string the result will be 2, - the offset to “C” in the text string.
        VL 1,V1_FLD,DOUBLEWORD_ALIGNED         
         VL    2,V2_FLD,DOUBLEWORD_ALIGNED         
         VFAEB 3,1,2,1                             
         VST   3,VECTOR_RESULT,DOUBLEWORD_ALIGNED  
         B     RETURN                              
VECTOR   DS 0D                                  
V1_FLD   DC CL16'ABCDEFGHIJKLMNOP'              
V2_FLD   DC CL2'DC' 
         DC    XL14'00'

The vectors will contain the results shown below.
VECTOR REGISTER VALUES                          
VR0...... 00000000  00000000 00000000 00000000
VR1...... C1C2C3C4  C5C6C7C8 C9D1D2D3 D4D5D6D7
VR2...... C4C30000  00000000 00000000 00000000
VR3...... 00000000  00000002 00000000 00000000

Ingen kommentarer:

Send en kommentar