[Bug c/94833] New: vec_first_match_index does not function as described in its description

2020-04-28 Thread cjashfor at linux dot ibm.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94833

Bug ID: 94833
   Summary: vec_first_match_index does not function as described
in its description
   Product: gcc
   Version: 9.3.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: cjashfor at linux dot ibm.com
CC: carll at gcc dot gnu.org
  Target Milestone: ---

The description in the 64-bit ELF V2 ABI Specification 1.4 says this:

Purpose:
Performs a comparison of equality on each of the corresponding elements of ARG1
and
ARG2, and returns the first position of equality.
Result value:
Returns the element index of the position of the first character match. If no
match, returns
the number of characters as an element count in the vector argument.


Note that it doesn't make any mention of null or EOS characters.  By the
description, it ought to compare null characters for equality as well, but it
doesn't.  It seems to terminate the comparison when it sees that there's a null
(0x00) in one of the two vector elements.  Here's my test case:

#include 
#include 

int main() {
vector unsigned char v1 = { 0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 };

vector unsigned char vec_0s = vec_splats((unsigned char)0x0);

int first_match_index = vec_first_match_index(v1, vec_0s);
if (first_match_index != 0) {
printf("Failed: first_match_index should be 0 but it is %d\n",
first_match_index);
} else {
printf("Passed\n");
}
return 0;
}


I compiled it with -mcpu=power9 -maltivec.  When the test case is run, it says
this:

Failed: first_match_index should be 0 but it is 16

I don't know whether the description is incomplete or the function isn't
implemented correctly.

[Bug c/94833] vec_first_match_index does not function as described in its description

2020-04-28 Thread cjashfor at linux dot ibm.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94833

--- Comment #1 from Corey Ashford  ---
When I look at the disassembly, I see it uses vcmpnezb, but maybe it should use
vcmpneb instead:

int first_match_index = vec_first_match_index(v1, vec_0s);
1504:   07 09 00 10 vcmpnezb v0,v0,v1