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 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/>.
23 /* This function uses non-native bit order */
24 #define GET_FIELD(X, FROM, TO) \
25 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
27 /* This function uses the order in the manuals, i.e. bit 0 is 2^0 */
28 #define GET_FIELD_SP(X, FROM, TO) \
29 GET_FIELD(X, 63 - (TO), 63 - (FROM))
31 target_ulong
helper_array8(target_ulong pixel_addr
, target_ulong cubesize
)
33 return (GET_FIELD_SP(pixel_addr
, 60, 63) << (17 + 2 * cubesize
)) |
34 (GET_FIELD_SP(pixel_addr
, 39, 39 + cubesize
- 1) << (17 + cubesize
)) |
35 (GET_FIELD_SP(pixel_addr
, 17 + cubesize
- 1, 17) << 17) |
36 (GET_FIELD_SP(pixel_addr
, 56, 59) << 13) |
37 (GET_FIELD_SP(pixel_addr
, 35, 38) << 9) |
38 (GET_FIELD_SP(pixel_addr
, 13, 16) << 5) |
39 (((pixel_addr
>> 55) & 1) << 4) |
40 (GET_FIELD_SP(pixel_addr
, 33, 34) << 2) |
41 GET_FIELD_SP(pixel_addr
, 11, 12);
44 #ifdef HOST_WORDS_BIGENDIAN
45 #define VIS_B64(n) b[7 - (n)]
46 #define VIS_W64(n) w[3 - (n)]
47 #define VIS_SW64(n) sw[3 - (n)]
48 #define VIS_L64(n) l[1 - (n)]
49 #define VIS_B32(n) b[3 - (n)]
50 #define VIS_W32(n) w[1 - (n)]
52 #define VIS_B64(n) b[n]
53 #define VIS_W64(n) w[n]
54 #define VIS_SW64(n) sw[n]
55 #define VIS_L64(n) l[n]
56 #define VIS_B32(n) b[n]
57 #define VIS_W32(n) w[n]
76 uint64_t helper_fpmerge(uint64_t src1
, uint64_t src2
)
83 /* Reverse calculation order to handle overlap */
84 d
.VIS_B64(7) = s
.VIS_B64(3);
85 d
.VIS_B64(6) = d
.VIS_B64(3);
86 d
.VIS_B64(5) = s
.VIS_B64(2);
87 d
.VIS_B64(4) = d
.VIS_B64(2);
88 d
.VIS_B64(3) = s
.VIS_B64(1);
89 d
.VIS_B64(2) = d
.VIS_B64(1);
90 d
.VIS_B64(1) = s
.VIS_B64(0);
91 /* d.VIS_B64(0) = d.VIS_B64(0); */
96 uint64_t helper_fmul8x16(uint64_t src1
, uint64_t src2
)
105 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
106 if ((tmp & 0xff) > 0x7f) { \
109 d.VIS_W64(r) = tmp >> 8;
120 uint64_t helper_fmul8x16al(uint64_t src1
, uint64_t src2
)
129 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
130 if ((tmp & 0xff) > 0x7f) { \
133 d.VIS_W64(r) = tmp >> 8;
144 uint64_t helper_fmul8x16au(uint64_t src1
, uint64_t src2
)
153 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
154 if ((tmp & 0xff) > 0x7f) { \
157 d.VIS_W64(r) = tmp >> 8;
168 uint64_t helper_fmul8sux16(uint64_t src1
, uint64_t src2
)
177 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
178 if ((tmp & 0xff) > 0x7f) { \
181 d.VIS_W64(r) = tmp >> 8;
192 uint64_t helper_fmul8ulx16(uint64_t src1
, uint64_t src2
)
201 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
202 if ((tmp & 0xff) > 0x7f) { \
205 d.VIS_W64(r) = tmp >> 8;
216 uint64_t helper_fmuld8sux16(uint64_t src1
, uint64_t src2
)
225 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
226 if ((tmp & 0xff) > 0x7f) { \
231 /* Reverse calculation order to handle overlap */
239 uint64_t helper_fmuld8ulx16(uint64_t src1
, uint64_t src2
)
248 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
249 if ((tmp & 0xff) > 0x7f) { \
254 /* Reverse calculation order to handle overlap */
262 uint64_t helper_fexpand(uint64_t src1
, uint64_t src2
)
267 s
.l
= (uint32_t)src1
;
269 d
.VIS_W64(0) = s
.VIS_B32(0) << 4;
270 d
.VIS_W64(1) = s
.VIS_B32(1) << 4;
271 d
.VIS_W64(2) = s
.VIS_B32(2) << 4;
272 d
.VIS_W64(3) = s
.VIS_B32(3) << 4;
277 #define VIS_HELPER(name, F) \
278 uint64_t name##16(uint64_t src1, uint64_t src2) \
285 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
286 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
287 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
288 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
293 uint32_t name##16s(uint32_t src1, uint32_t src2) \
300 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
301 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
306 uint64_t name##32(uint64_t src1, uint64_t src2) \
313 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
314 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
319 uint32_t name##32s(uint32_t src1, uint32_t src2) \
331 #define FADD(a, b) ((a) + (b))
332 #define FSUB(a, b) ((a) - (b))
333 VIS_HELPER(helper_fpadd
, FADD
)
334 VIS_HELPER(helper_fpsub
, FSUB
)
336 #define VIS_CMPHELPER(name, F) \
337 uint64_t name##16(uint64_t src1, uint64_t src2) \
344 d.VIS_W64(0) = F(s.VIS_W64(0), d.VIS_W64(0)) ? 1 : 0; \
345 d.VIS_W64(0) |= F(s.VIS_W64(1), d.VIS_W64(1)) ? 2 : 0; \
346 d.VIS_W64(0) |= F(s.VIS_W64(2), d.VIS_W64(2)) ? 4 : 0; \
347 d.VIS_W64(0) |= F(s.VIS_W64(3), d.VIS_W64(3)) ? 8 : 0; \
348 d.VIS_W64(1) = d.VIS_W64(2) = d.VIS_W64(3) = 0; \
353 uint64_t name##32(uint64_t src1, uint64_t src2) \
360 d.VIS_L64(0) = F(s.VIS_L64(0), d.VIS_L64(0)) ? 1 : 0; \
361 d.VIS_L64(0) |= F(s.VIS_L64(1), d.VIS_L64(1)) ? 2 : 0; \
367 #define FCMPGT(a, b) ((a) > (b))
368 #define FCMPEQ(a, b) ((a) == (b))
369 #define FCMPLE(a, b) ((a) <= (b))
370 #define FCMPNE(a, b) ((a) != (b))
372 VIS_CMPHELPER(helper_fcmpgt
, FCMPGT
)
373 VIS_CMPHELPER(helper_fcmpeq
, FCMPEQ
)
374 VIS_CMPHELPER(helper_fcmple
, FCMPLE
)
375 VIS_CMPHELPER(helper_fcmpne
, FCMPNE
)
377 uint64_t helper_pdist(uint64_t sum
, uint64_t src1
, uint64_t src2
)
380 for (i
= 0; i
< 8; i
++) {
383 s1
= (src1
>> (56 - (i
* 8))) & 0xff;
384 s2
= (src2
>> (56 - (i
* 8))) & 0xff;
386 /* Absolute value of difference. */
398 uint32_t helper_fpack16(uint64_t gsr
, uint64_t rs2
)
400 int scale
= (gsr
>> 3) & 0xf;
404 for (byte
= 0; byte
< 4; byte
++) {
406 int16_t src
= rs2
>> (byte
* 16);
407 int32_t scaled
= src
<< scale
;
408 int32_t from_fixed
= scaled
>> 7;
410 val
= (from_fixed
< 0 ? 0 :
411 from_fixed
> 255 ? 255 : from_fixed
);
413 ret
|= val
<< (8 * byte
);
419 uint64_t helper_fpack32(uint64_t gsr
, uint64_t rs1
, uint64_t rs2
)
421 int scale
= (gsr
>> 3) & 0x1f;
425 ret
= (rs1
<< 8) & ~(0x000000ff000000ffULL
);
426 for (word
= 0; word
< 2; word
++) {
428 int32_t src
= rs2
>> (word
* 32);
429 int64_t scaled
= (int64_t)src
<< scale
;
430 int64_t from_fixed
= scaled
>> 23;
432 val
= (from_fixed
< 0 ? 0 :
433 (from_fixed
> 255) ? 255 : from_fixed
);
435 ret
|= val
<< (32 * word
);
441 uint32_t helper_fpackfix(uint64_t gsr
, uint64_t rs2
)
443 int scale
= (gsr
>> 3) & 0x1f;
447 for (word
= 0; word
< 2; word
++) {
449 int32_t src
= rs2
>> (word
* 32);
450 int64_t scaled
= src
<< scale
;
451 int64_t from_fixed
= scaled
>> 16;
453 val
= (from_fixed
< -32768 ? -32768 :
454 from_fixed
> 32767 ? 32767 : from_fixed
);
456 ret
|= (val
& 0xffff) << (word
* 16);
462 uint64_t helper_bshuffle(uint64_t gsr
, uint64_t src1
, uint64_t src2
)
469 uint32_t i
, mask
, host
;
471 /* Set up S such that we can index across all of the bytes. */
472 #ifdef HOST_WORDS_BIGENDIAN
483 for (i
= 0; i
< 8; ++i
) {
484 unsigned e
= (mask
>> (28 - i
*4)) & 0xf;
485 r
.VIS_B64(i
) = s
.b
[e
^ host
];