Text file src/internal/bytealg/indexbyte_s390x.s

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "go_asm.h"
     6  #include "textflag.h"
     7  
     8  
     9  TEXT ·IndexByte<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-40
    10  	MOVD    R5, R4
    11  	AND	$0xff, R4
    12  	BR      indexbytebody<>(SB)
    13  
    14  TEXT ·IndexByteString<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-32
    15  	AND	$0xff, R4
    16  	BR      indexbytebody<>(SB)
    17  
    18  // input:
    19  // R2: s
    20  // R3: s_len
    21  // R4: c -- byte sought
    22  // For regabiargs output value(index) stored in R2
    23  // For !regabiargs address of output value(index) stored in R5
    24  TEXT indexbytebody<>(SB),NOSPLIT|NOFRAME,$0
    25          CMPBEQ  R3, $0, notfound
    26          MOVD    R2, R6          // store base for later
    27          ADD     R2, R3, R8      // the address after the end of the string
    28          //if the length is small, use loop; otherwise, use vector or srst search
    29          CMPBGE  R3, $16, large
    30  
    31  residual:
    32          CMPBEQ  R2, R8, notfound
    33          MOVBZ   0(R2), R7
    34          LA      1(R2), R2
    35          CMPBNE  R7, R4, residual
    36  
    37  found:
    38          SUB     R6, R2
    39          SUB     $1, R2
    40          RET
    41  
    42  notfound:
    43          MOVD    $-1, R2
    44          RET
    45  
    46  large:
    47          MOVBZ   internal∕cpu·S390X+const_offsetS390xHasVX(SB), R1
    48          CMPBNE  R1, $0, vectorimpl
    49  
    50  srstimpl:                       // no vector facility
    51          MOVBZ   R4, R0          // c needs to be in R0, leave until last minute as currently R0 is expected to be 0
    52  srstloop:
    53          WORD    $0xB25E0082     // srst %r8, %r2 (search the range [R2, R8))
    54          BVS     srstloop        // interrupted - continue
    55          BGT     notfoundr0
    56  foundr0:
    57          XOR     R0, R0          // reset R0
    58          SUB     R6, R8          // remove base
    59          MOVD    R8, R2
    60          RET
    61  notfoundr0:
    62          XOR     R0, R0          // reset R0
    63          MOVD    $-1, R2
    64          RET
    65  
    66  vectorimpl:
    67          //if the address is not 16byte aligned, use loop for the header
    68          MOVD    R2, R8
    69          AND     $15, R8
    70          CMPBGT  R8, $0, notaligned
    71  
    72  aligned:
    73          ADD     R6, R3, R8
    74          MOVD    R8, R7
    75          AND     $-16, R7
    76          // replicate c across V17
    77          VLVGB   $0, R4, V19
    78          VREPB   $0, V19, V17
    79  
    80  vectorloop:
    81          CMPBGE  R2, R7, residual
    82          VL      0(R2), V16    // load string to be searched into V16
    83          ADD     $16, R2
    84          VFEEBS  V16, V17, V18 // search V17 in V16 and set conditional code accordingly
    85          BVS     vectorloop
    86  
    87          // when vector search found c in the string
    88          VLGVB   $7, V18, R7   // load 7th element of V18 containing index into R7
    89          SUB     $16, R2
    90          SUB     R6, R2
    91          ADD     R2, R7
    92          MOVD    R7, R2
    93          RET
    94  
    95  notaligned:
    96          MOVD    R2, R8
    97          AND     $-16, R8
    98          ADD     $16, R8
    99  notalignedloop:
   100          CMPBEQ  R2, R8, aligned
   101          MOVBZ   0(R2), R7
   102          LA      1(R2), R2
   103          CMPBNE  R7, R4, notalignedloop
   104          BR      found
   105  
   106  

View as plain text