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_HELPER(name, F) \
279 uint64_t name##16(uint64_t src1, uint64_t src2) \
286 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
287 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
288 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
289 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
294 uint32_t name##16s(uint32_t src1, uint32_t src2) \
301 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
302 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
307 uint64_t name##32(uint64_t src1, uint64_t src2) \
314 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
315 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
320 uint32_t name##32s(uint32_t src1, uint32_t src2) \
332 #define FADD(a, b) ((a) + (b))
333 #define FSUB(a, b) ((a) - (b))
334 VIS_HELPER(helper_fpadd
, FADD
)
335 VIS_HELPER(helper_fpsub
, FSUB
)
337 #define VIS_CMPHELPER(name, F) \
338 uint64_t name##16(uint64_t src1, uint64_t src2) \
345 d.VIS_W64(0) = F(s.VIS_W64(0), d.VIS_W64(0)) ? 1 : 0; \
346 d.VIS_W64(0) |= F(s.VIS_W64(1), d.VIS_W64(1)) ? 2 : 0; \
347 d.VIS_W64(0) |= F(s.VIS_W64(2), d.VIS_W64(2)) ? 4 : 0; \
348 d.VIS_W64(0) |= F(s.VIS_W64(3), d.VIS_W64(3)) ? 8 : 0; \
349 d.VIS_W64(1) = d.VIS_W64(2) = d.VIS_W64(3) = 0; \
354 uint64_t name##32(uint64_t src1, uint64_t src2) \
361 d.VIS_L64(0) = F(s.VIS_L64(0), d.VIS_L64(0)) ? 1 : 0; \
362 d.VIS_L64(0) |= F(s.VIS_L64(1), d.VIS_L64(1)) ? 2 : 0; \
368 #define FCMPGT(a, b) ((a) > (b))
369 #define FCMPEQ(a, b) ((a) == (b))
370 #define FCMPLE(a, b) ((a) <= (b))
371 #define FCMPNE(a, b) ((a) != (b))
373 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
374 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
375 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
376 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
378 uint64_t helper_pdist(uint64_t sum
, uint64_t src1
, uint64_t src2
)
381 for (i
= 0; i
< 8; i
++) {
384 s1
= (src1
>> (56 - (i
* 8))) & 0xff;
385 s2
= (src2
>> (56 - (i
* 8))) & 0xff;
387 /* Absolute value of difference. */
399 uint32_t helper_fpack16(uint64_t gsr
, uint64_t rs2
)
401 int scale
= (gsr
>> 3) & 0xf;
405 for (byte
= 0; byte
< 4; byte
++) {
407 int16_t src
= rs2
>> (byte
* 16);
408 int32_t scaled
= src
<< scale
;
409 int32_t from_fixed
= scaled
>> 7;
411 val
= (from_fixed
< 0 ? 0 :
412 from_fixed
> 255 ? 255 : from_fixed
);
414 ret
|= val
<< (8 * byte
);
420 uint64_t helper_fpack32(uint64_t gsr
, uint64_t rs1
, uint64_t rs2
)
422 int scale
= (gsr
>> 3) & 0x1f;
426 ret
= (rs1
<< 8) & ~(0x000000ff000000ffULL
);
427 for (word
= 0; word
< 2; word
++) {
429 int32_t src
= rs2
>> (word
* 32);
430 int64_t scaled
= (int64_t)src
<< scale
;
431 int64_t from_fixed
= scaled
>> 23;
433 val
= (from_fixed
< 0 ? 0 :
434 (from_fixed
> 255) ? 255 : from_fixed
);
436 ret
|= val
<< (32 * word
);
442 uint32_t helper_fpackfix(uint64_t gsr
, uint64_t rs2
)
444 int scale
= (gsr
>> 3) & 0x1f;
448 for (word
= 0; word
< 2; word
++) {
450 int32_t src
= rs2
>> (word
* 32);
451 int64_t scaled
= (int64_t)src
<< scale
;
452 int64_t from_fixed
= scaled
>> 16;
454 val
= (from_fixed
< -32768 ? -32768 :
455 from_fixed
> 32767 ? 32767 : from_fixed
);
457 ret
|= (val
& 0xffff) << (word
* 16);
463 uint64_t helper_bshuffle(uint64_t gsr
, uint64_t src1
, uint64_t src2
)
470 uint32_t i
, mask
, host
;
472 /* Set up S such that we can index across all of the bytes. */
484 for (i
= 0; i
< 8; ++i
) {
485 unsigned e
= (mask
>> (28 - i
*4)) & 0xf;
486 r
.VIS_B64(i
) = s
.b
[e
^ host
];