2 * QEMU TCG support -- s390x vector utilitites
4 * Copyright (C) 2019 Red Hat Inc
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
17 typedef union S390Vector {
18 uint64_t doubleword[2];
25 * Each vector is stored as two 64bit host values. So when talking about
26 * byte/halfword/word numbers, we have to take care of proper translation
27 * between element numbers.
29 * Big Endian (target/possible host)
30 * B: [ 0][ 1][ 2][ 3][ 4][ 5][ 6][ 7] - [ 8][ 9][10][11][12][13][14][15]
31 * HW: [ 0][ 1][ 2][ 3] - [ 4][ 5][ 6][ 7]
32 * W: [ 0][ 1] - [ 2][ 3]
35 * Little Endian (possible host)
36 * B: [ 7][ 6][ 5][ 4][ 3][ 2][ 1][ 0] - [15][14][13][12][11][10][ 9][ 8]
37 * HW: [ 3][ 2][ 1][ 0] - [ 7][ 6][ 5][ 4]
38 * W: [ 1][ 0] - [ 3][ 2]
41 #ifndef HOST_WORDS_BIGENDIAN
42 #define H1(x) ((x) ^ 7)
43 #define H2(x) ((x) ^ 3)
44 #define H4(x) ((x) ^ 1)
51 static inline uint8_t s390_vec_read_element8(const S390Vector *v, uint8_t enr)
54 return v->byte[H1(enr)];
57 static inline uint16_t s390_vec_read_element16(const S390Vector *v, uint8_t enr)
60 return v->halfword[H2(enr)];
63 static inline uint32_t s390_vec_read_element32(const S390Vector *v, uint8_t enr)
66 return v->word[H4(enr)];
69 static inline uint64_t s390_vec_read_element64(const S390Vector *v, uint8_t enr)
72 return v->doubleword[enr];
75 static inline uint64_t s390_vec_read_element(const S390Vector *v, uint8_t enr,
80 return s390_vec_read_element8(v, enr);
82 return s390_vec_read_element16(v, enr);
84 return s390_vec_read_element32(v, enr);
86 return s390_vec_read_element64(v, enr);
88 g_assert_not_reached();
92 static inline void s390_vec_write_element8(S390Vector *v, uint8_t enr,
96 v->byte[H1(enr)] = data;
99 static inline void s390_vec_write_element16(S390Vector *v, uint8_t enr,
103 v->halfword[H2(enr)] = data;
106 static inline void s390_vec_write_element32(S390Vector *v, uint8_t enr,
110 v->word[H4(enr)] = data;
113 static inline void s390_vec_write_element64(S390Vector *v, uint8_t enr,
117 v->doubleword[enr] = data;
120 static inline void s390_vec_write_element(S390Vector *v, uint8_t enr,
121 uint8_t es, uint64_t data)
125 s390_vec_write_element8(v, enr, data);
128 s390_vec_write_element16(v, enr, data);
131 s390_vec_write_element32(v, enr, data);
134 s390_vec_write_element64(v, enr, data);
137 g_assert_not_reached();
141 #endif /* S390X_VEC_H */