1c1a81d4bSDavid Hildenbrand /* 2c1a81d4bSDavid Hildenbrand * QEMU TCG support -- s390x vector integer instruction support 3c1a81d4bSDavid Hildenbrand * 4c1a81d4bSDavid Hildenbrand * Copyright (C) 2019 Red Hat Inc 5c1a81d4bSDavid Hildenbrand * 6c1a81d4bSDavid Hildenbrand * Authors: 7c1a81d4bSDavid Hildenbrand * David Hildenbrand <david@redhat.com> 8c1a81d4bSDavid Hildenbrand * 9c1a81d4bSDavid Hildenbrand * This work is licensed under the terms of the GNU GPL, version 2 or later. 10c1a81d4bSDavid Hildenbrand * See the COPYING file in the top-level directory. 11c1a81d4bSDavid Hildenbrand */ 12c1a81d4bSDavid Hildenbrand #include "qemu/osdep.h" 13c1a81d4bSDavid Hildenbrand #include "qemu-common.h" 14c1a81d4bSDavid Hildenbrand #include "cpu.h" 15c1a81d4bSDavid Hildenbrand #include "vec.h" 16c1a81d4bSDavid Hildenbrand #include "exec/helper-proto.h" 17c1a81d4bSDavid Hildenbrand 18c1a81d4bSDavid Hildenbrand #define DEF_VAVG(BITS) \ 19c1a81d4bSDavid Hildenbrand void HELPER(gvec_vavg##BITS)(void *v1, const void *v2, const void *v3, \ 20c1a81d4bSDavid Hildenbrand uint32_t desc) \ 21c1a81d4bSDavid Hildenbrand { \ 22c1a81d4bSDavid Hildenbrand int i; \ 23c1a81d4bSDavid Hildenbrand \ 24c1a81d4bSDavid Hildenbrand for (i = 0; i < (128 / BITS); i++) { \ 25c1a81d4bSDavid Hildenbrand const int32_t a = (int##BITS##_t)s390_vec_read_element##BITS(v2, i); \ 26c1a81d4bSDavid Hildenbrand const int32_t b = (int##BITS##_t)s390_vec_read_element##BITS(v3, i); \ 27c1a81d4bSDavid Hildenbrand \ 28c1a81d4bSDavid Hildenbrand s390_vec_write_element##BITS(v1, i, (a + b + 1) >> 1); \ 29c1a81d4bSDavid Hildenbrand } \ 30c1a81d4bSDavid Hildenbrand } 31c1a81d4bSDavid Hildenbrand DEF_VAVG(8) 32c1a81d4bSDavid Hildenbrand DEF_VAVG(16) 33801aa78bSDavid Hildenbrand 34801aa78bSDavid Hildenbrand #define DEF_VAVGL(BITS) \ 35801aa78bSDavid Hildenbrand void HELPER(gvec_vavgl##BITS)(void *v1, const void *v2, const void *v3, \ 36801aa78bSDavid Hildenbrand uint32_t desc) \ 37801aa78bSDavid Hildenbrand { \ 38801aa78bSDavid Hildenbrand int i; \ 39801aa78bSDavid Hildenbrand \ 40801aa78bSDavid Hildenbrand for (i = 0; i < (128 / BITS); i++) { \ 41801aa78bSDavid Hildenbrand const uint##BITS##_t a = s390_vec_read_element##BITS(v2, i); \ 42801aa78bSDavid Hildenbrand const uint##BITS##_t b = s390_vec_read_element##BITS(v3, i); \ 43801aa78bSDavid Hildenbrand \ 44801aa78bSDavid Hildenbrand s390_vec_write_element##BITS(v1, i, (a + b + 1) >> 1); \ 45801aa78bSDavid Hildenbrand } \ 46801aa78bSDavid Hildenbrand } 47801aa78bSDavid Hildenbrand DEF_VAVGL(8) 48801aa78bSDavid Hildenbrand DEF_VAVGL(16) 49*28863f1dSDavid Hildenbrand 50*28863f1dSDavid Hildenbrand #define DEF_VCLZ(BITS) \ 51*28863f1dSDavid Hildenbrand void HELPER(gvec_vclz##BITS)(void *v1, const void *v2, uint32_t desc) \ 52*28863f1dSDavid Hildenbrand { \ 53*28863f1dSDavid Hildenbrand int i; \ 54*28863f1dSDavid Hildenbrand \ 55*28863f1dSDavid Hildenbrand for (i = 0; i < (128 / BITS); i++) { \ 56*28863f1dSDavid Hildenbrand const uint##BITS##_t a = s390_vec_read_element##BITS(v2, i); \ 57*28863f1dSDavid Hildenbrand \ 58*28863f1dSDavid Hildenbrand s390_vec_write_element##BITS(v1, i, clz32(a) - 32 + BITS); \ 59*28863f1dSDavid Hildenbrand } \ 60*28863f1dSDavid Hildenbrand } 61*28863f1dSDavid Hildenbrand DEF_VCLZ(8) 62*28863f1dSDavid Hildenbrand DEF_VCLZ(16) 63