]> Cypherpunks repositories - gostls13.git/commitdiff
internal/bytealg: fix bug in index function for ppc64le/power9
authorArchana R <aravind5@in.ibm.com>
Fri, 28 Oct 2022 07:42:39 +0000 (02:42 -0500)
committerLynn Boger <laboger@linux.vnet.ibm.com>
Mon, 31 Oct 2022 12:52:07 +0000 (12:52 +0000)
The index function was not handling certain corner cases where there
were two more bytes to be examined in the tail end of the string to
complete the comparison. Fix code to ensure that when the string has
to be shifted two more times the correct bytes are examined.
Also hoisted vsplat to V10 so that all paths use the correct value.
Some comments had incorrect register names and corrected the same.
Added the strings that were failing to strings test for verification.

Fixes #56457

Change-Id: Idba7cbc802e3d73c8f4fe89309871cc8447792f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/446135
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Archana Ravindar <ravindararchana@gmail.com>

src/internal/bytealg/index_ppc64x.s
src/strings/strings_test.go

index 38442ce27cec992fa2b75c89cd67be090ab411ef..735159cd8e24dfa4648315decc32254a2dc1d9e1 100644 (file)
@@ -614,7 +614,7 @@ index4loop:
 next4:
        VSPLTISB $0, V10            // Clear
        MOVD     $3, R9             // Number of bytes beyond 16
-       LXVB16X  (R7)(R9), V3       // Load 16 bytes @R7 into V2
+       LXVB16X  (R7)(R9), V3       // Load 16 bytes @R7 into V3
        VSLDOI   $13, V3, V10, V3   // Shift left last 3 bytes
        VSLDOI   $1, V2, V3, V4     // V4=(V2:V3)<<1
        VSLDOI   $2, V2, V3, V9     // V9=(V2:V3)<<2
@@ -654,11 +654,11 @@ index2to16:
 
        ADD $19, R7, R9    // To check 4 indices per iteration, need at least 16+3 bytes
        CMP R9, LASTBYTE
-       BGT index2to16tail
-
        // At least 16 bytes of string left
        // Mask the number of bytes in sep
        VSPLTISB $0, V10            // Clear
+       BGT index2to16tail
+
        MOVD     $3, R17            // Number of bytes beyond 16
 
 index2to16loop:
@@ -720,14 +720,15 @@ extra2:
        ADD        $1, R7          // Not found, try next partial string
        CMP        R7, LASTSTR     // Check for end of string
        BGT        notfound        // If at end, then not found
-       VSLDOI     $1, V1, V25, V1 // Shift string left by 1 byte
+       VOR        V1, V1, V4      // save remaining string
+       VSLDOI     $1, V1, V25, V1 // Shift string left by 1 byte for 17th byte
        VAND       V1, SEPMASK, V2 // Just compare size of sep
        VCMPEQUBCC V0, V2, V3      // Compare sep and partial string
        BLT        CR6, found      // Found
        ADD        $1, R7          // Not found, try next partial string
        CMP        R7, LASTSTR     // Check for end of string
        BGT        notfound        // If at end, then not found
-       VSLDOI     $1, V1, V25, V1 // Shift string left by 1 byte
+       VSLDOI     $2, V4, V25, V1 // Shift saved string left by 2 bytes for 18th byte
        BR         index2to16next  // Check the remaining partial string in index2to16next
 
 short:
index 27489c2d1651c7900ada1c0a6603d90484ac9285..3991d127511b15ae2b43faf0132de59dcf9f1d93 100644 (file)
@@ -54,6 +54,11 @@ var indexTests = []IndexTest{
        {"foo", "", 0},
        {"foo", "o", 1},
        {"abcABCabc", "A", 3},
+       {"jrzm6jjhorimglljrea4w3rlgosts0w2gia17hno2td4qd1jz", "jz", 47},
+       {"ekkuk5oft4eq0ocpacknhwouic1uua46unx12l37nioq9wbpnocqks6", "ks6", 52},
+       {"999f2xmimunbuyew5vrkla9cpwhmxan8o98ec", "98ec", 33},
+       {"9lpt9r98i04k8bz6c6dsrthb96bhi", "96bhi", 24},
+       {"55u558eqfaod2r2gu42xxsu631xf0zobs5840vl", "5840vl", 33},
        // cases with one byte strings - test special case in Index()
        {"", "a", -1},
        {"x", "a", -1},