2 * QEMU TCG support -- s390x vector utilitites
4 * Copyright (C) 2019 Red Hat Inc
7 * David Hildenbrand <david@redhat.com>
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.
15 typedef union S390Vector
{
16 uint64_t doubleword
[2];
23 * Each vector is stored as two 64bit host values. So when talking about
24 * byte/halfword/word numbers, we have to take care of proper translation
25 * between element numbers.
27 * Big Endian (target/possible host)
28 * B: [ 0][ 1][ 2][ 3][ 4][ 5][ 6][ 7] - [ 8][ 9][10][11][12][13][14][15]
29 * HW: [ 0][ 1][ 2][ 3] - [ 4][ 5][ 6][ 7]
30 * W: [ 0][ 1] - [ 2][ 3]
33 * Little Endian (possible host)
34 * B: [ 7][ 6][ 5][ 4][ 3][ 2][ 1][ 0] - [15][14][13][12][11][10][ 9][ 8]
35 * HW: [ 3][ 2][ 1][ 0] - [ 7][ 6][ 5][ 4]
36 * W: [ 1][ 0] - [ 3][ 2]
39 #ifndef HOST_WORDS_BIGENDIAN
40 #define H1(x) ((x) ^ 7)
41 #define H2(x) ((x) ^ 3)
42 #define H4(x) ((x) ^ 1)
49 static inline uint8_t s390_vec_read_element8(const S390Vector
*v
, uint8_t enr
)
52 return v
->byte
[H1(enr
)];
55 static inline uint16_t s390_vec_read_element16(const S390Vector
*v
, uint8_t enr
)
58 return v
->halfword
[H2(enr
)];
61 static inline uint32_t s390_vec_read_element32(const S390Vector
*v
, uint8_t enr
)
64 return v
->word
[H4(enr
)];
67 static inline uint64_t s390_vec_read_element64(const S390Vector
*v
, uint8_t enr
)
70 return v
->doubleword
[enr
];
73 static inline void s390_vec_write_element8(S390Vector
*v
, uint8_t enr
,
77 v
->byte
[H1(enr
)] = data
;
80 static inline void s390_vec_write_element16(S390Vector
*v
, uint8_t enr
,
84 v
->halfword
[H2(enr
)] = data
;
87 static inline void s390_vec_write_element32(S390Vector
*v
, uint8_t enr
,
91 v
->word
[H4(enr
)] = data
;
94 static inline void s390_vec_write_element64(S390Vector
*v
, uint8_t enr
,
98 v
->doubleword
[enr
] = data
;
101 #endif /* S390X_VEC_H */