On 17.05.19 19:56, Richard Henderson wrote:
> On 5/15/19 1:31 PM, David Hildenbrand wrote:
>> Similar to VECTOR FIND ELEMENT EQUAL, however the search also stops on
>> any inequality. A match for inequality seems to have precedence over
>> a match for zero, because both elements have to be zero.
>>
>> Signed-off-by: David Hildenbrand <da...@redhat.com>
>> ---
>>  target/s390x/helper.h            |  6 ++++
>>  target/s390x/insn-data.def       |  2 ++
>>  target/s390x/translate_vx.inc.c  | 31 +++++++++++++++++++
>>  target/s390x/vec_string_helper.c | 53 ++++++++++++++++++++++++++++++++
>>  4 files changed, 92 insertions(+)
> 
> Like the previous, only with
> 
> static inline uint64_t nonzero_search(uint64_t a, uint64_t m)
> {
>     return (((a & m) + m) | a) & ~m;
> }
> 
> for the inequality.
> 
> 
> r~
> 

It's a little bit more tricky. because we have to identify the smaller
element. Right now I have this

+static int vfene(void *v1, const void *v2, const void *v3, bool zs,
uint8_t es)
+{
+    const uint64_t mask = dup_const(es, -1ull >> (65 - (1 << es) * 8));
+    uint64_t a0, a1, b0, b1, e0, e1, z0, z1;
+    uint64_t first_zero = 16;
+    uint64_t first_inequal;
+    bool smaller = false;
+
+    a0 = s390_vec_read_element64(v2, 0);
+    a1 = s390_vec_read_element64(v2, 1);
+    b0 = s390_vec_read_element64(v3, 0);
+    b1 = s390_vec_read_element64(v3, 1);
+    e0 = nonzero_search(a0 ^ b0, mask);
+    e1 = nonzero_search(a1 ^ b1, mask);
+    first_inequal = match_index(e0, e1);
+
+    /* identify the smaller element */
+    if (first_inequal < 16) {
+        uint8_t enr = first_inequal / (1 << es);
+        uint32_t a = s390_vec_read_element(v2, enr, es);
+        uint32_t b = s390_vec_read_element(v3, enr, es);
+        smaller = a < b;
+    }
+
+    if (zs) {
+        z0 = zero_search(a0, mask);
+        z1 = zero_search(a1, mask);
+        first_zero = match_index(z0, z1);
+    }
+
+    /* zero out the destination vector */
+    s390_vec_write_element64(v1, 0, 0);
+    s390_vec_write_element64(v1, 1, 0);
+
+    if (first_zero == 16 && first_inequal == 16) {
+        s390_vec_write_element8(v1, 7, 16);
+        return 3;
+    } else if (first_zero < first_inequal) {
+        s390_vec_write_element8(v1, 7, first_zero);
+        return 0;
+    }
+    s390_vec_write_element8(v1, 7, first_inequal);
+    return smaller ? 1 : 2;
+}


-- 

Thanks,

David / dhildenb

Reply via email to