11bccec25SBlue Swirl /* 21bccec25SBlue Swirl * VIS op helpers 31bccec25SBlue Swirl * 41bccec25SBlue Swirl * Copyright (c) 2003-2005 Fabrice Bellard 51bccec25SBlue Swirl * 61bccec25SBlue Swirl * This library is free software; you can redistribute it and/or 71bccec25SBlue Swirl * modify it under the terms of the GNU Lesser General Public 81bccec25SBlue Swirl * License as published by the Free Software Foundation; either 95650b549SChetan Pant * version 2.1 of the License, or (at your option) any later version. 101bccec25SBlue Swirl * 111bccec25SBlue Swirl * This library is distributed in the hope that it will be useful, 121bccec25SBlue Swirl * but WITHOUT ANY WARRANTY; without even the implied warranty of 131bccec25SBlue Swirl * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 141bccec25SBlue Swirl * Lesser General Public License for more details. 151bccec25SBlue Swirl * 161bccec25SBlue Swirl * You should have received a copy of the GNU Lesser General Public 171bccec25SBlue Swirl * License along with this library; if not, see <http://www.gnu.org/licenses/>. 181bccec25SBlue Swirl */ 191bccec25SBlue Swirl 20db5ebe5fSPeter Maydell #include "qemu/osdep.h" 211bccec25SBlue Swirl #include "cpu.h" 222ef6175aSRichard Henderson #include "exec/helper-proto.h" 231bccec25SBlue Swirl 241bccec25SBlue Swirl /* This function uses non-native bit order */ 251bccec25SBlue Swirl #define GET_FIELD(X, FROM, TO) \ 261bccec25SBlue Swirl ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1)) 271bccec25SBlue Swirl 281bccec25SBlue Swirl /* This function uses the order in the manuals, i.e. bit 0 is 2^0 */ 291bccec25SBlue Swirl #define GET_FIELD_SP(X, FROM, TO) \ 301bccec25SBlue Swirl GET_FIELD(X, 63 - (TO), 63 - (FROM)) 311bccec25SBlue Swirl 32f027c3b1SRichard Henderson target_ulong helper_array8(target_ulong pixel_addr, target_ulong cubesize) 331bccec25SBlue Swirl { 341bccec25SBlue Swirl return (GET_FIELD_SP(pixel_addr, 60, 63) << (17 + 2 * cubesize)) | 351bccec25SBlue Swirl (GET_FIELD_SP(pixel_addr, 39, 39 + cubesize - 1) << (17 + cubesize)) | 361bccec25SBlue Swirl (GET_FIELD_SP(pixel_addr, 17 + cubesize - 1, 17) << 17) | 371bccec25SBlue Swirl (GET_FIELD_SP(pixel_addr, 56, 59) << 13) | 381bccec25SBlue Swirl (GET_FIELD_SP(pixel_addr, 35, 38) << 9) | 391bccec25SBlue Swirl (GET_FIELD_SP(pixel_addr, 13, 16) << 5) | 401bccec25SBlue Swirl (((pixel_addr >> 55) & 1) << 4) | 411bccec25SBlue Swirl (GET_FIELD_SP(pixel_addr, 33, 34) << 2) | 421bccec25SBlue Swirl GET_FIELD_SP(pixel_addr, 11, 12); 431bccec25SBlue Swirl } 441bccec25SBlue Swirl 45e03b5686SMarc-André Lureau #if HOST_BIG_ENDIAN 461bccec25SBlue Swirl #define VIS_B64(n) b[7 - (n)] 471bccec25SBlue Swirl #define VIS_W64(n) w[3 - (n)] 481bccec25SBlue Swirl #define VIS_SW64(n) sw[3 - (n)] 491bccec25SBlue Swirl #define VIS_L64(n) l[1 - (n)] 501bccec25SBlue Swirl #define VIS_B32(n) b[3 - (n)] 511bccec25SBlue Swirl #define VIS_W32(n) w[1 - (n)] 521bccec25SBlue Swirl #else 531bccec25SBlue Swirl #define VIS_B64(n) b[n] 541bccec25SBlue Swirl #define VIS_W64(n) w[n] 551bccec25SBlue Swirl #define VIS_SW64(n) sw[n] 561bccec25SBlue Swirl #define VIS_L64(n) l[n] 571bccec25SBlue Swirl #define VIS_B32(n) b[n] 581bccec25SBlue Swirl #define VIS_W32(n) w[n] 591bccec25SBlue Swirl #endif 601bccec25SBlue Swirl 611bccec25SBlue Swirl typedef union { 621bccec25SBlue Swirl uint8_t b[8]; 631bccec25SBlue Swirl uint16_t w[4]; 641bccec25SBlue Swirl int16_t sw[4]; 651bccec25SBlue Swirl uint32_t l[2]; 661bccec25SBlue Swirl uint64_t ll; 671bccec25SBlue Swirl float64 d; 681bccec25SBlue Swirl } VIS64; 691bccec25SBlue Swirl 701bccec25SBlue Swirl typedef union { 711bccec25SBlue Swirl uint8_t b[4]; 721bccec25SBlue Swirl uint16_t w[2]; 731bccec25SBlue Swirl uint32_t l; 741bccec25SBlue Swirl float32 f; 751bccec25SBlue Swirl } VIS32; 761bccec25SBlue Swirl 77f027c3b1SRichard Henderson uint64_t helper_fpmerge(uint64_t src1, uint64_t src2) 781bccec25SBlue Swirl { 791bccec25SBlue Swirl VIS64 s, d; 801bccec25SBlue Swirl 8103fb8cfcSRichard Henderson s.ll = src1; 8203fb8cfcSRichard Henderson d.ll = src2; 831bccec25SBlue Swirl 841bccec25SBlue Swirl /* Reverse calculation order to handle overlap */ 851bccec25SBlue Swirl d.VIS_B64(7) = s.VIS_B64(3); 861bccec25SBlue Swirl d.VIS_B64(6) = d.VIS_B64(3); 871bccec25SBlue Swirl d.VIS_B64(5) = s.VIS_B64(2); 881bccec25SBlue Swirl d.VIS_B64(4) = d.VIS_B64(2); 891bccec25SBlue Swirl d.VIS_B64(3) = s.VIS_B64(1); 901bccec25SBlue Swirl d.VIS_B64(2) = d.VIS_B64(1); 911bccec25SBlue Swirl d.VIS_B64(1) = s.VIS_B64(0); 921bccec25SBlue Swirl /* d.VIS_B64(0) = d.VIS_B64(0); */ 931bccec25SBlue Swirl 9403fb8cfcSRichard Henderson return d.ll; 951bccec25SBlue Swirl } 961bccec25SBlue Swirl 979157dcccSRichard Henderson uint64_t helper_fmul8x16(uint32_t src1, uint64_t src2) 981bccec25SBlue Swirl { 999157dcccSRichard Henderson VIS64 d; 1009157dcccSRichard Henderson VIS32 s; 1011bccec25SBlue Swirl uint32_t tmp; 1021bccec25SBlue Swirl 1039157dcccSRichard Henderson s.l = src1; 10403fb8cfcSRichard Henderson d.ll = src2; 1051bccec25SBlue Swirl 1061bccec25SBlue Swirl #define PMUL(r) \ 1079157dcccSRichard Henderson tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B32(r); \ 1081bccec25SBlue Swirl if ((tmp & 0xff) > 0x7f) { \ 1091bccec25SBlue Swirl tmp += 0x100; \ 1101bccec25SBlue Swirl } \ 1111bccec25SBlue Swirl d.VIS_W64(r) = tmp >> 8; 1121bccec25SBlue Swirl 1131bccec25SBlue Swirl PMUL(0); 1141bccec25SBlue Swirl PMUL(1); 1151bccec25SBlue Swirl PMUL(2); 1161bccec25SBlue Swirl PMUL(3); 1171bccec25SBlue Swirl #undef PMUL 1181bccec25SBlue Swirl 11903fb8cfcSRichard Henderson return d.ll; 1201bccec25SBlue Swirl } 1211bccec25SBlue Swirl 122*a859602cSRichard Henderson uint64_t helper_fmul8x16a(uint32_t src1, int32_t src2) 1231bccec25SBlue Swirl { 124*a859602cSRichard Henderson VIS32 s; 125*a859602cSRichard Henderson VIS64 d; 1261bccec25SBlue Swirl uint32_t tmp; 1271bccec25SBlue Swirl 128*a859602cSRichard Henderson s.l = src1; 129*a859602cSRichard Henderson d.ll = 0; 1301bccec25SBlue Swirl 1311bccec25SBlue Swirl #define PMUL(r) \ 132*a859602cSRichard Henderson do { \ 133*a859602cSRichard Henderson tmp = src2 * (int32_t)s.VIS_B32(r); \ 1341bccec25SBlue Swirl if ((tmp & 0xff) > 0x7f) { \ 1351bccec25SBlue Swirl tmp += 0x100; \ 1361bccec25SBlue Swirl } \ 137*a859602cSRichard Henderson d.VIS_W64(r) = tmp >> 8; \ 138*a859602cSRichard Henderson } while (0) 1391bccec25SBlue Swirl 1401bccec25SBlue Swirl PMUL(0); 1411bccec25SBlue Swirl PMUL(1); 1421bccec25SBlue Swirl PMUL(2); 1431bccec25SBlue Swirl PMUL(3); 1441bccec25SBlue Swirl #undef PMUL 1451bccec25SBlue Swirl 14603fb8cfcSRichard Henderson return d.ll; 1471bccec25SBlue Swirl } 1481bccec25SBlue Swirl 149f027c3b1SRichard Henderson uint64_t helper_fmul8sux16(uint64_t src1, uint64_t src2) 1501bccec25SBlue Swirl { 1511bccec25SBlue Swirl VIS64 s, d; 1521bccec25SBlue Swirl uint32_t tmp; 1531bccec25SBlue Swirl 15403fb8cfcSRichard Henderson s.ll = src1; 15503fb8cfcSRichard Henderson d.ll = src2; 1561bccec25SBlue Swirl 1571bccec25SBlue Swirl #define PMUL(r) \ 1581bccec25SBlue Swirl tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \ 1591bccec25SBlue Swirl if ((tmp & 0xff) > 0x7f) { \ 1601bccec25SBlue Swirl tmp += 0x100; \ 1611bccec25SBlue Swirl } \ 1621bccec25SBlue Swirl d.VIS_W64(r) = tmp >> 8; 1631bccec25SBlue Swirl 1641bccec25SBlue Swirl PMUL(0); 1651bccec25SBlue Swirl PMUL(1); 1661bccec25SBlue Swirl PMUL(2); 1671bccec25SBlue Swirl PMUL(3); 1681bccec25SBlue Swirl #undef PMUL 1691bccec25SBlue Swirl 17003fb8cfcSRichard Henderson return d.ll; 1711bccec25SBlue Swirl } 1721bccec25SBlue Swirl 173f027c3b1SRichard Henderson uint64_t helper_fmul8ulx16(uint64_t src1, uint64_t src2) 1741bccec25SBlue Swirl { 1751bccec25SBlue Swirl VIS64 s, d; 1761bccec25SBlue Swirl uint32_t tmp; 1771bccec25SBlue Swirl 17803fb8cfcSRichard Henderson s.ll = src1; 17903fb8cfcSRichard Henderson d.ll = src2; 1801bccec25SBlue Swirl 1811bccec25SBlue Swirl #define PMUL(r) \ 1821bccec25SBlue Swirl tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \ 1831bccec25SBlue Swirl if ((tmp & 0xff) > 0x7f) { \ 1841bccec25SBlue Swirl tmp += 0x100; \ 1851bccec25SBlue Swirl } \ 1861bccec25SBlue Swirl d.VIS_W64(r) = tmp >> 8; 1871bccec25SBlue Swirl 1881bccec25SBlue Swirl PMUL(0); 1891bccec25SBlue Swirl PMUL(1); 1901bccec25SBlue Swirl PMUL(2); 1911bccec25SBlue Swirl PMUL(3); 1921bccec25SBlue Swirl #undef PMUL 1931bccec25SBlue Swirl 19403fb8cfcSRichard Henderson return d.ll; 1951bccec25SBlue Swirl } 1961bccec25SBlue Swirl 197f027c3b1SRichard Henderson uint64_t helper_fmuld8sux16(uint64_t src1, uint64_t src2) 1981bccec25SBlue Swirl { 1991bccec25SBlue Swirl VIS64 s, d; 2001bccec25SBlue Swirl uint32_t tmp; 2011bccec25SBlue Swirl 20203fb8cfcSRichard Henderson s.ll = src1; 20303fb8cfcSRichard Henderson d.ll = src2; 2041bccec25SBlue Swirl 2051bccec25SBlue Swirl #define PMUL(r) \ 2061bccec25SBlue Swirl tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \ 2071bccec25SBlue Swirl if ((tmp & 0xff) > 0x7f) { \ 2081bccec25SBlue Swirl tmp += 0x100; \ 2091bccec25SBlue Swirl } \ 2101bccec25SBlue Swirl d.VIS_L64(r) = tmp; 2111bccec25SBlue Swirl 2121bccec25SBlue Swirl /* Reverse calculation order to handle overlap */ 2131bccec25SBlue Swirl PMUL(1); 2141bccec25SBlue Swirl PMUL(0); 2151bccec25SBlue Swirl #undef PMUL 2161bccec25SBlue Swirl 21703fb8cfcSRichard Henderson return d.ll; 2181bccec25SBlue Swirl } 2191bccec25SBlue Swirl 220f027c3b1SRichard Henderson uint64_t helper_fmuld8ulx16(uint64_t src1, uint64_t src2) 2211bccec25SBlue Swirl { 2221bccec25SBlue Swirl VIS64 s, d; 2231bccec25SBlue Swirl uint32_t tmp; 2241bccec25SBlue Swirl 22503fb8cfcSRichard Henderson s.ll = src1; 22603fb8cfcSRichard Henderson d.ll = src2; 2271bccec25SBlue Swirl 2281bccec25SBlue Swirl #define PMUL(r) \ 2291bccec25SBlue Swirl tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \ 2301bccec25SBlue Swirl if ((tmp & 0xff) > 0x7f) { \ 2311bccec25SBlue Swirl tmp += 0x100; \ 2321bccec25SBlue Swirl } \ 2331bccec25SBlue Swirl d.VIS_L64(r) = tmp; 2341bccec25SBlue Swirl 2351bccec25SBlue Swirl /* Reverse calculation order to handle overlap */ 2361bccec25SBlue Swirl PMUL(1); 2371bccec25SBlue Swirl PMUL(0); 2381bccec25SBlue Swirl #undef PMUL 2391bccec25SBlue Swirl 24003fb8cfcSRichard Henderson return d.ll; 2411bccec25SBlue Swirl } 2421bccec25SBlue Swirl 2437b616f36SRichard Henderson uint64_t helper_fexpand(uint32_t src2) 2441bccec25SBlue Swirl { 2451bccec25SBlue Swirl VIS32 s; 2461bccec25SBlue Swirl VIS64 d; 2471bccec25SBlue Swirl 2487b616f36SRichard Henderson s.l = src2; 2497b616f36SRichard Henderson d.ll = 0; 2501bccec25SBlue Swirl d.VIS_W64(0) = s.VIS_B32(0) << 4; 2511bccec25SBlue Swirl d.VIS_W64(1) = s.VIS_B32(1) << 4; 2521bccec25SBlue Swirl d.VIS_W64(2) = s.VIS_B32(2) << 4; 2531bccec25SBlue Swirl d.VIS_W64(3) = s.VIS_B32(3) << 4; 2541bccec25SBlue Swirl 25503fb8cfcSRichard Henderson return d.ll; 2561bccec25SBlue Swirl } 2571bccec25SBlue Swirl 2581bccec25SBlue Swirl #define VIS_CMPHELPER(name, F) \ 259f027c3b1SRichard Henderson uint64_t name##16(uint64_t src1, uint64_t src2) \ 2601bccec25SBlue Swirl { \ 2611bccec25SBlue Swirl VIS64 s, d; \ 2621bccec25SBlue Swirl \ 26303fb8cfcSRichard Henderson s.ll = src1; \ 26403fb8cfcSRichard Henderson d.ll = src2; \ 2651bccec25SBlue Swirl \ 2661bccec25SBlue Swirl d.VIS_W64(0) = F(s.VIS_W64(0), d.VIS_W64(0)) ? 1 : 0; \ 2671bccec25SBlue Swirl d.VIS_W64(0) |= F(s.VIS_W64(1), d.VIS_W64(1)) ? 2 : 0; \ 2681bccec25SBlue Swirl d.VIS_W64(0) |= F(s.VIS_W64(2), d.VIS_W64(2)) ? 4 : 0; \ 2691bccec25SBlue Swirl d.VIS_W64(0) |= F(s.VIS_W64(3), d.VIS_W64(3)) ? 8 : 0; \ 2701bccec25SBlue Swirl d.VIS_W64(1) = d.VIS_W64(2) = d.VIS_W64(3) = 0; \ 2711bccec25SBlue Swirl \ 2721bccec25SBlue Swirl return d.ll; \ 2731bccec25SBlue Swirl } \ 2741bccec25SBlue Swirl \ 275f027c3b1SRichard Henderson uint64_t name##32(uint64_t src1, uint64_t src2) \ 2761bccec25SBlue Swirl { \ 2771bccec25SBlue Swirl VIS64 s, d; \ 2781bccec25SBlue Swirl \ 27903fb8cfcSRichard Henderson s.ll = src1; \ 28003fb8cfcSRichard Henderson d.ll = src2; \ 2811bccec25SBlue Swirl \ 2821bccec25SBlue Swirl d.VIS_L64(0) = F(s.VIS_L64(0), d.VIS_L64(0)) ? 1 : 0; \ 2831bccec25SBlue Swirl d.VIS_L64(0) |= F(s.VIS_L64(1), d.VIS_L64(1)) ? 2 : 0; \ 2841bccec25SBlue Swirl d.VIS_L64(1) = 0; \ 2851bccec25SBlue Swirl \ 2861bccec25SBlue Swirl return d.ll; \ 2871bccec25SBlue Swirl } 2881bccec25SBlue Swirl 2891bccec25SBlue Swirl #define FCMPGT(a, b) ((a) > (b)) 2901bccec25SBlue Swirl #define FCMPEQ(a, b) ((a) == (b)) 2911bccec25SBlue Swirl #define FCMPLE(a, b) ((a) <= (b)) 2921bccec25SBlue Swirl #define FCMPNE(a, b) ((a) != (b)) 2931bccec25SBlue Swirl 2941bccec25SBlue Swirl VIS_CMPHELPER(helper_fcmpgt, FCMPGT) 2951bccec25SBlue Swirl VIS_CMPHELPER(helper_fcmpeq, FCMPEQ) 2961bccec25SBlue Swirl VIS_CMPHELPER(helper_fcmple, FCMPLE) 2971bccec25SBlue Swirl VIS_CMPHELPER(helper_fcmpne, FCMPNE) 298f888300bSRichard Henderson 299f888300bSRichard Henderson uint64_t helper_pdist(uint64_t sum, uint64_t src1, uint64_t src2) 300f888300bSRichard Henderson { 301f888300bSRichard Henderson int i; 302f888300bSRichard Henderson for (i = 0; i < 8; i++) { 303f888300bSRichard Henderson int s1, s2; 304f888300bSRichard Henderson 305f888300bSRichard Henderson s1 = (src1 >> (56 - (i * 8))) & 0xff; 306f888300bSRichard Henderson s2 = (src2 >> (56 - (i * 8))) & 0xff; 307f888300bSRichard Henderson 308f888300bSRichard Henderson /* Absolute value of difference. */ 309f888300bSRichard Henderson s1 -= s2; 310f888300bSRichard Henderson if (s1 < 0) { 311f888300bSRichard Henderson s1 = -s1; 312f888300bSRichard Henderson } 313f888300bSRichard Henderson 314f888300bSRichard Henderson sum += s1; 315f888300bSRichard Henderson } 316f888300bSRichard Henderson 317f888300bSRichard Henderson return sum; 318f888300bSRichard Henderson } 3192dedf314SRichard Henderson 3202dedf314SRichard Henderson uint32_t helper_fpack16(uint64_t gsr, uint64_t rs2) 3212dedf314SRichard Henderson { 3222dedf314SRichard Henderson int scale = (gsr >> 3) & 0xf; 3232dedf314SRichard Henderson uint32_t ret = 0; 3242dedf314SRichard Henderson int byte; 3252dedf314SRichard Henderson 3262dedf314SRichard Henderson for (byte = 0; byte < 4; byte++) { 3272dedf314SRichard Henderson uint32_t val; 3282dedf314SRichard Henderson int16_t src = rs2 >> (byte * 16); 3292dedf314SRichard Henderson int32_t scaled = src << scale; 3302dedf314SRichard Henderson int32_t from_fixed = scaled >> 7; 3312dedf314SRichard Henderson 3322dedf314SRichard Henderson val = (from_fixed < 0 ? 0 : 3332dedf314SRichard Henderson from_fixed > 255 ? 255 : from_fixed); 3342dedf314SRichard Henderson 3352dedf314SRichard Henderson ret |= val << (8 * byte); 3362dedf314SRichard Henderson } 3372dedf314SRichard Henderson 3382dedf314SRichard Henderson return ret; 3392dedf314SRichard Henderson } 3402dedf314SRichard Henderson 3412dedf314SRichard Henderson uint64_t helper_fpack32(uint64_t gsr, uint64_t rs1, uint64_t rs2) 3422dedf314SRichard Henderson { 3432dedf314SRichard Henderson int scale = (gsr >> 3) & 0x1f; 3442dedf314SRichard Henderson uint64_t ret = 0; 3452dedf314SRichard Henderson int word; 3462dedf314SRichard Henderson 3472dedf314SRichard Henderson ret = (rs1 << 8) & ~(0x000000ff000000ffULL); 3482dedf314SRichard Henderson for (word = 0; word < 2; word++) { 3492dedf314SRichard Henderson uint64_t val; 3502dedf314SRichard Henderson int32_t src = rs2 >> (word * 32); 3512dedf314SRichard Henderson int64_t scaled = (int64_t)src << scale; 3522dedf314SRichard Henderson int64_t from_fixed = scaled >> 23; 3532dedf314SRichard Henderson 3542dedf314SRichard Henderson val = (from_fixed < 0 ? 0 : 3552dedf314SRichard Henderson (from_fixed > 255) ? 255 : from_fixed); 3562dedf314SRichard Henderson 3572dedf314SRichard Henderson ret |= val << (32 * word); 3582dedf314SRichard Henderson } 3592dedf314SRichard Henderson 3602dedf314SRichard Henderson return ret; 3612dedf314SRichard Henderson } 3622dedf314SRichard Henderson 3632dedf314SRichard Henderson uint32_t helper_fpackfix(uint64_t gsr, uint64_t rs2) 3642dedf314SRichard Henderson { 3652dedf314SRichard Henderson int scale = (gsr >> 3) & 0x1f; 3662dedf314SRichard Henderson uint32_t ret = 0; 3672dedf314SRichard Henderson int word; 3682dedf314SRichard Henderson 3692dedf314SRichard Henderson for (word = 0; word < 2; word++) { 3702dedf314SRichard Henderson uint32_t val; 3712dedf314SRichard Henderson int32_t src = rs2 >> (word * 32); 37212a3567cSPaolo Bonzini int64_t scaled = (int64_t)src << scale; 3732dedf314SRichard Henderson int64_t from_fixed = scaled >> 16; 3742dedf314SRichard Henderson 3752dedf314SRichard Henderson val = (from_fixed < -32768 ? -32768 : 3762dedf314SRichard Henderson from_fixed > 32767 ? 32767 : from_fixed); 3772dedf314SRichard Henderson 3782dedf314SRichard Henderson ret |= (val & 0xffff) << (word * 16); 3792dedf314SRichard Henderson } 3802dedf314SRichard Henderson 3812dedf314SRichard Henderson return ret; 3822dedf314SRichard Henderson } 383793a137aSRichard Henderson 384520c0d8dSAndreas Färber uint64_t helper_bshuffle(uint64_t gsr, uint64_t src1, uint64_t src2) 385793a137aSRichard Henderson { 386793a137aSRichard Henderson union { 387793a137aSRichard Henderson uint64_t ll[2]; 388793a137aSRichard Henderson uint8_t b[16]; 389793a137aSRichard Henderson } s; 390793a137aSRichard Henderson VIS64 r; 391793a137aSRichard Henderson uint32_t i, mask, host; 392793a137aSRichard Henderson 393793a137aSRichard Henderson /* Set up S such that we can index across all of the bytes. */ 394e03b5686SMarc-André Lureau #if HOST_BIG_ENDIAN 395793a137aSRichard Henderson s.ll[0] = src1; 396793a137aSRichard Henderson s.ll[1] = src2; 397793a137aSRichard Henderson host = 0; 398793a137aSRichard Henderson #else 399793a137aSRichard Henderson s.ll[1] = src1; 400793a137aSRichard Henderson s.ll[0] = src2; 401793a137aSRichard Henderson host = 15; 402793a137aSRichard Henderson #endif 403793a137aSRichard Henderson mask = gsr >> 32; 404793a137aSRichard Henderson 405793a137aSRichard Henderson for (i = 0; i < 8; ++i) { 406793a137aSRichard Henderson unsigned e = (mask >> (28 - i*4)) & 0xf; 407793a137aSRichard Henderson r.VIS_B64(i) = s.b[e ^ host]; 408793a137aSRichard Henderson } 409793a137aSRichard Henderson 410793a137aSRichard Henderson return r.ll; 411793a137aSRichard Henderson } 412