1 /*
2 * RISC-V Vector Extension Internals
3 *
4 * Copyright (c) 2020 T-Head Semiconductor Co., Ltd. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2 or later, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "vector_internals.h"
20
21 /* set agnostic elements to 1s */
vext_set_elems_1s(void * base,uint32_t is_agnostic,uint32_t cnt,uint32_t tot)22 void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt,
23 uint32_t tot)
24 {
25 if (is_agnostic == 0) {
26 /* policy undisturbed */
27 return;
28 }
29 if (tot - cnt == 0) {
30 return ;
31 }
32 memset(base + cnt, -1, tot - cnt);
33 }
34
do_vext_vv(void * vd,void * v0,void * vs1,void * vs2,CPURISCVState * env,uint32_t desc,opivv2_fn * fn,uint32_t esz)35 void do_vext_vv(void *vd, void *v0, void *vs1, void *vs2,
36 CPURISCVState *env, uint32_t desc,
37 opivv2_fn *fn, uint32_t esz)
38 {
39 uint32_t vm = vext_vm(desc);
40 uint32_t vl = env->vl;
41 uint32_t total_elems = vext_get_total_elems(env, desc, esz);
42 uint32_t vta = vext_vta(desc);
43 uint32_t vma = vext_vma(desc);
44 uint32_t i;
45
46 for (i = env->vstart; i < vl; i++) {
47 if (!vm && !vext_elem_mask(v0, i)) {
48 /* set masked-off elements to 1s */
49 vext_set_elems_1s(vd, vma, i * esz, (i + 1) * esz);
50 continue;
51 }
52 fn(vd, vs1, vs2, i);
53 }
54 env->vstart = 0;
55 /* set tail elements to 1s */
56 vext_set_elems_1s(vd, vta, vl * esz, total_elems * esz);
57 }
58
do_vext_vx(void * vd,void * v0,target_long s1,void * vs2,CPURISCVState * env,uint32_t desc,opivx2_fn fn,uint32_t esz)59 void do_vext_vx(void *vd, void *v0, target_long s1, void *vs2,
60 CPURISCVState *env, uint32_t desc,
61 opivx2_fn fn, uint32_t esz)
62 {
63 uint32_t vm = vext_vm(desc);
64 uint32_t vl = env->vl;
65 uint32_t total_elems = vext_get_total_elems(env, desc, esz);
66 uint32_t vta = vext_vta(desc);
67 uint32_t vma = vext_vma(desc);
68 uint32_t i;
69
70 for (i = env->vstart; i < vl; i++) {
71 if (!vm && !vext_elem_mask(v0, i)) {
72 /* set masked-off elements to 1s */
73 vext_set_elems_1s(vd, vma, i * esz, (i + 1) * esz);
74 continue;
75 }
76 fn(vd, s1, vs2, i);
77 }
78 env->vstart = 0;
79 /* set tail elements to 1s */
80 vext_set_elems_1s(vd, vta, vl * esz, total_elems * esz);
81 }
82