1d3582cfdSPhilippe Mathieu-Daudé /*
2d3582cfdSPhilippe Mathieu-Daudé * Generic vector operation descriptor
3d3582cfdSPhilippe Mathieu-Daudé *
4d3582cfdSPhilippe Mathieu-Daudé * Copyright (c) 2018 Linaro
5d3582cfdSPhilippe Mathieu-Daudé *
6d3582cfdSPhilippe Mathieu-Daudé * This library is free software; you can redistribute it and/or
7d3582cfdSPhilippe Mathieu-Daudé * modify it under the terms of the GNU Lesser General Public
8d3582cfdSPhilippe Mathieu-Daudé * License as published by the Free Software Foundation; either
9d3582cfdSPhilippe Mathieu-Daudé * version 2.1 of the License, or (at your option) any later version.
10d3582cfdSPhilippe Mathieu-Daudé *
11d3582cfdSPhilippe Mathieu-Daudé * This library is distributed in the hope that it will be useful,
12d3582cfdSPhilippe Mathieu-Daudé * but WITHOUT ANY WARRANTY; without even the implied warranty of
13d3582cfdSPhilippe Mathieu-Daudé * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14d3582cfdSPhilippe Mathieu-Daudé * Lesser General Public License for more details.
15d3582cfdSPhilippe Mathieu-Daudé *
16d3582cfdSPhilippe Mathieu-Daudé * You should have received a copy of the GNU Lesser General Public
17d3582cfdSPhilippe Mathieu-Daudé * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18d3582cfdSPhilippe Mathieu-Daudé */
19d3582cfdSPhilippe Mathieu-Daudé
20d3582cfdSPhilippe Mathieu-Daudé #ifndef TCG_TCG_GVEC_DESC_H
21d3582cfdSPhilippe Mathieu-Daudé #define TCG_TCG_GVEC_DESC_H
22d3582cfdSPhilippe Mathieu-Daudé
23*e2e7168aSRichard Henderson /*
24*e2e7168aSRichard Henderson * This configuration allows MAXSZ to represent 2048 bytes, and
25*e2e7168aSRichard Henderson * OPRSZ to match MAXSZ, or represent the smaller values 8, 16, or 32.
26*e2e7168aSRichard Henderson *
27*e2e7168aSRichard Henderson * Encode this with:
28*e2e7168aSRichard Henderson * 0, 1, 3 -> 8, 16, 32
29*e2e7168aSRichard Henderson * 2 -> maxsz
30*e2e7168aSRichard Henderson *
31*e2e7168aSRichard Henderson * This steals the input that would otherwise map to 24 to match maxsz.
32*e2e7168aSRichard Henderson */
33*e2e7168aSRichard Henderson #define SIMD_MAXSZ_SHIFT 0
34*e2e7168aSRichard Henderson #define SIMD_MAXSZ_BITS 8
35d3582cfdSPhilippe Mathieu-Daudé
36*e2e7168aSRichard Henderson #define SIMD_OPRSZ_SHIFT (SIMD_MAXSZ_SHIFT + SIMD_MAXSZ_BITS)
37*e2e7168aSRichard Henderson #define SIMD_OPRSZ_BITS 2
38d3582cfdSPhilippe Mathieu-Daudé
39*e2e7168aSRichard Henderson #define SIMD_DATA_SHIFT (SIMD_OPRSZ_SHIFT + SIMD_OPRSZ_BITS)
40d3582cfdSPhilippe Mathieu-Daudé #define SIMD_DATA_BITS (32 - SIMD_DATA_SHIFT)
41d3582cfdSPhilippe Mathieu-Daudé
42d3582cfdSPhilippe Mathieu-Daudé /* Create a descriptor from components. */
43d3582cfdSPhilippe Mathieu-Daudé uint32_t simd_desc(uint32_t oprsz, uint32_t maxsz, int32_t data);
44d3582cfdSPhilippe Mathieu-Daudé
45d3582cfdSPhilippe Mathieu-Daudé /* Extract the max vector size from a descriptor. */
simd_maxsz(uint32_t desc)46d3582cfdSPhilippe Mathieu-Daudé static inline intptr_t simd_maxsz(uint32_t desc)
47d3582cfdSPhilippe Mathieu-Daudé {
48*e2e7168aSRichard Henderson return extract32(desc, SIMD_MAXSZ_SHIFT, SIMD_MAXSZ_BITS) * 8 + 8;
49*e2e7168aSRichard Henderson }
50*e2e7168aSRichard Henderson
51*e2e7168aSRichard Henderson /* Extract the operation size from a descriptor. */
simd_oprsz(uint32_t desc)52*e2e7168aSRichard Henderson static inline intptr_t simd_oprsz(uint32_t desc)
53*e2e7168aSRichard Henderson {
54*e2e7168aSRichard Henderson uint32_t f = extract32(desc, SIMD_OPRSZ_SHIFT, SIMD_OPRSZ_BITS);
55*e2e7168aSRichard Henderson intptr_t o = f * 8 + 8;
56*e2e7168aSRichard Henderson intptr_t m = simd_maxsz(desc);
57*e2e7168aSRichard Henderson return f == 2 ? m : o;
58d3582cfdSPhilippe Mathieu-Daudé }
59d3582cfdSPhilippe Mathieu-Daudé
60d3582cfdSPhilippe Mathieu-Daudé /* Extract the operation-specific data from a descriptor. */
simd_data(uint32_t desc)61d3582cfdSPhilippe Mathieu-Daudé static inline int32_t simd_data(uint32_t desc)
62d3582cfdSPhilippe Mathieu-Daudé {
63d3582cfdSPhilippe Mathieu-Daudé return sextract32(desc, SIMD_DATA_SHIFT, SIMD_DATA_BITS);
64d3582cfdSPhilippe Mathieu-Daudé }
65d3582cfdSPhilippe Mathieu-Daudé
66d3582cfdSPhilippe Mathieu-Daudé #endif
67