4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
22 #include "exec/helper-proto.h"
24 /* This function uses non-native bit order */
25 #define GET_FIELD(X, FROM, TO) \
26 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
28 /* This function uses the order in the manuals, i.e. bit 0 is 2^0 */
29 #define GET_FIELD_SP(X, FROM, TO) \
30 GET_FIELD(X, 63 - (TO), 63 - (FROM))
32 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
34 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
35 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
36 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
37 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
38 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
39 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
40 (((pixel_addr
>> 55) & 1) << 4) |
41 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
42 GET_FIELD_SP(pixel_addr
, 11, 12);
46 #define VIS_B64(n) b[7 - (n)]
47 #define VIS_W64(n) w[3 - (n)]
48 #define VIS_SW64(n) sw[3 - (n)]
49 #define VIS_L64(n) l[1 - (n)]
50 #define VIS_B32(n) b[3 - (n)]
51 #define VIS_W32(n) w[1 - (n)]
53 #define VIS_B64(n) b[n]
54 #define VIS_W64(n) w[n]
55 #define VIS_SW64(n) sw[n]
56 #define VIS_L64(n) l[n]
57 #define VIS_B32(n) b[n]
58 #define VIS_W32(n) w[n]
77 uint64_t helper_fpmerge(uint64_t src1
, uint64_t src2
)
84 /* Reverse calculation order to handle overlap */
85 d
.VIS_B64(7) = s
.VIS_B64(3);
86 d
.VIS_B64(6) = d
.VIS_B64(3);
87 d
.VIS_B64(5) = s
.VIS_B64(2);
88 d
.VIS_B64(4) = d
.VIS_B64(2);
89 d
.VIS_B64(3) = s
.VIS_B64(1);
90 d
.VIS_B64(2) = d
.VIS_B64(1);
91 d
.VIS_B64(1) = s
.VIS_B64(0);
92 /* d.VIS_B64(0) = d.VIS_B64(0); */
97 uint64_t helper_fmul8x16(uint64_t src1
, uint64_t src2
)
106 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
107 if ((tmp & 0xff) > 0x7f) { \
110 d.VIS_W64(r) = tmp >> 8;
121 uint64_t helper_fmul8x16al(uint64_t src1
, uint64_t src2
)
130 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
131 if ((tmp & 0xff) > 0x7f) { \
134 d.VIS_W64(r) = tmp >> 8;
145 uint64_t helper_fmul8x16au(uint64_t src1
, uint64_t src2
)
154 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
155 if ((tmp & 0xff) > 0x7f) { \
158 d.VIS_W64(r) = tmp >> 8;
169 uint64_t helper_fmul8sux16(uint64_t src1
, uint64_t src2
)
178 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
179 if ((tmp & 0xff) > 0x7f) { \
182 d.VIS_W64(r) = tmp >> 8;
193 uint64_t helper_fmul8ulx16(uint64_t src1
, uint64_t src2
)
202 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
203 if ((tmp & 0xff) > 0x7f) { \
206 d.VIS_W64(r) = tmp >> 8;
217 uint64_t helper_fmuld8sux16(uint64_t src1
, uint64_t src2
)
226 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
227 if ((tmp & 0xff) > 0x7f) { \
232 /* Reverse calculation order to handle overlap */
240 uint64_t helper_fmuld8ulx16(uint64_t src1
, uint64_t src2
)
249 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
250 if ((tmp & 0xff) > 0x7f) { \
255 /* Reverse calculation order to handle overlap */
263 uint64_t helper_fexpand(uint64_t src1
, uint64_t src2
)
268 s
.l
= (uint32_t)src1
;
270 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
271 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
272 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
273 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
278 #define VIS_CMPHELPER(name, F) \
279 uint64_t name##16(uint64_t src1, uint64_t src2) \
286 d.VIS_W64(0) = F(s.VIS_W64(0), d.VIS_W64(0)) ? 1 : 0; \
287 d.VIS_W64(0) |= F(s.VIS_W64(1), d.VIS_W64(1)) ? 2 : 0; \
288 d.VIS_W64(0) |= F(s.VIS_W64(2), d.VIS_W64(2)) ? 4 : 0; \
289 d.VIS_W64(0) |= F(s.VIS_W64(3), d.VIS_W64(3)) ? 8 : 0; \
290 d.VIS_W64(1) = d.VIS_W64(2) = d.VIS_W64(3) = 0; \
295 uint64_t name##32(uint64_t src1, uint64_t src2) \
302 d.VIS_L64(0) = F(s.VIS_L64(0), d.VIS_L64(0)) ? 1 : 0; \
303 d.VIS_L64(0) |= F(s.VIS_L64(1), d.VIS_L64(1)) ? 2 : 0; \
309 #define FCMPGT(a, b) ((a) > (b))
310 #define FCMPEQ(a, b) ((a) == (b))
311 #define FCMPLE(a, b) ((a) <= (b))
312 #define FCMPNE(a, b) ((a) != (b))
314 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
315 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
316 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
317 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
319 uint64_t helper_pdist(uint64_t sum
, uint64_t src1
, uint64_t src2
)
322 for (i
= 0; i
< 8; i
++) {
325 s1
= (src1
>> (56 - (i
* 8))) & 0xff;
326 s2
= (src2
>> (56 - (i
* 8))) & 0xff;
328 /* Absolute value of difference. */
340 uint32_t helper_fpack16(uint64_t gsr
, uint64_t rs2
)
342 int scale
= (gsr
>> 3) & 0xf;
346 for (byte
= 0; byte
< 4; byte
++) {
348 int16_t src
= rs2
>> (byte
* 16);
349 int32_t scaled
= src
<< scale
;
350 int32_t from_fixed
= scaled
>> 7;
352 val
= (from_fixed
< 0 ? 0 :
353 from_fixed
> 255 ? 255 : from_fixed
);
355 ret
|= val
<< (8 * byte
);
361 uint64_t helper_fpack32(uint64_t gsr
, uint64_t rs1
, uint64_t rs2
)
363 int scale
= (gsr
>> 3) & 0x1f;
367 ret
= (rs1
<< 8) & ~(0x000000ff000000ffULL
);
368 for (word
= 0; word
< 2; word
++) {
370 int32_t src
= rs2
>> (word
* 32);
371 int64_t scaled
= (int64_t)src
<< scale
;
372 int64_t from_fixed
= scaled
>> 23;
374 val
= (from_fixed
< 0 ? 0 :
375 (from_fixed
> 255) ? 255 : from_fixed
);
377 ret
|= val
<< (32 * word
);
383 uint32_t helper_fpackfix(uint64_t gsr
, uint64_t rs2
)
385 int scale
= (gsr
>> 3) & 0x1f;
389 for (word
= 0; word
< 2; word
++) {
391 int32_t src
= rs2
>> (word
* 32);
392 int64_t scaled
= (int64_t)src
<< scale
;
393 int64_t from_fixed
= scaled
>> 16;
395 val
= (from_fixed
< -32768 ? -32768 :
396 from_fixed
> 32767 ? 32767 : from_fixed
);
398 ret
|= (val
& 0xffff) << (word
* 16);
404 uint64_t helper_bshuffle(uint64_t gsr
, uint64_t src1
, uint64_t src2
)
411 uint32_t i
, mask
, host
;
413 /* Set up S such that we can index across all of the bytes. */
425 for (i
= 0; i
< 8; ++i
) {
426 unsigned e
= (mask
>> (28 - i
*4)) & 0xf;
427 r
.VIS_B64(i
) = s
.b
[e
^ host
];