1fcf5ef2aSThomas Huth /* 2fcf5ef2aSThomas Huth * VIS op helpers 3fcf5ef2aSThomas Huth * 4fcf5ef2aSThomas Huth * Copyright (c) 2003-2005 Fabrice Bellard 5fcf5ef2aSThomas Huth * 6fcf5ef2aSThomas Huth * This library is free software; you can redistribute it and/or 7fcf5ef2aSThomas Huth * modify it under the terms of the GNU Lesser General Public 8fcf5ef2aSThomas Huth * License as published by the Free Software Foundation; either 95650b549SChetan Pant * version 2.1 of the License, or (at your option) any later version. 10fcf5ef2aSThomas Huth * 11fcf5ef2aSThomas Huth * This library is distributed in the hope that it will be useful, 12fcf5ef2aSThomas Huth * but WITHOUT ANY WARRANTY; without even the implied warranty of 13fcf5ef2aSThomas Huth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14fcf5ef2aSThomas Huth * Lesser General Public License for more details. 15fcf5ef2aSThomas Huth * 16fcf5ef2aSThomas Huth * You should have received a copy of the GNU Lesser General Public 17fcf5ef2aSThomas Huth * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18fcf5ef2aSThomas Huth */ 19fcf5ef2aSThomas Huth 20fcf5ef2aSThomas Huth #include "qemu/osdep.h" 21fcf5ef2aSThomas Huth #include "cpu.h" 22fcf5ef2aSThomas Huth #include "exec/helper-proto.h" 23fcf5ef2aSThomas Huth 24fa9079a8SRichard Henderson target_ulong helper_array8(target_ulong rs1, target_ulong rs2) 25fcf5ef2aSThomas Huth { 26fa9079a8SRichard Henderson /* 27fa9079a8SRichard Henderson * From Oracle SPARC Architecture 2015: 28fa9079a8SRichard Henderson * Architecturally, an illegal R[rs2] value (>5) causes the array 29fa9079a8SRichard Henderson * instructions to produce undefined results. For historic reference, 30fa9079a8SRichard Henderson * past implementations of these instructions have ignored R[rs2]{63:3} 31fa9079a8SRichard Henderson * and have treated R[rs2] values of 6 and 7 as if they were 5. 32fa9079a8SRichard Henderson */ 33fa9079a8SRichard Henderson target_ulong n = MIN(rs2 & 7, 5); 34fa9079a8SRichard Henderson 35fa9079a8SRichard Henderson target_ulong x_int = (rs1 >> 11) & 0x7ff; 36fa9079a8SRichard Henderson target_ulong y_int = (rs1 >> 33) & 0x7ff; 37fa9079a8SRichard Henderson target_ulong z_int = rs1 >> 55; 38fa9079a8SRichard Henderson 39fa9079a8SRichard Henderson target_ulong lower_x = x_int & 3; 40fa9079a8SRichard Henderson target_ulong lower_y = y_int & 3; 41fa9079a8SRichard Henderson target_ulong lower_z = z_int & 1; 42fa9079a8SRichard Henderson 43fa9079a8SRichard Henderson target_ulong middle_x = (x_int >> 2) & 15; 44fa9079a8SRichard Henderson target_ulong middle_y = (y_int >> 2) & 15; 45fa9079a8SRichard Henderson target_ulong middle_z = (z_int >> 1) & 15; 46fa9079a8SRichard Henderson 47fa9079a8SRichard Henderson target_ulong upper_x = (x_int >> 6) & ((1 << n) - 1); 48fa9079a8SRichard Henderson target_ulong upper_y = (y_int >> 6) & ((1 << n) - 1); 49fa9079a8SRichard Henderson target_ulong upper_z = z_int >> 5; 50fa9079a8SRichard Henderson 51fa9079a8SRichard Henderson return (upper_z << (17 + 2 * n)) 52fa9079a8SRichard Henderson | (upper_y << (17 + n)) 53fa9079a8SRichard Henderson | (upper_x << 17) 54fa9079a8SRichard Henderson | (middle_z << 13) 55fa9079a8SRichard Henderson | (middle_y << 9) 56fa9079a8SRichard Henderson | (middle_x << 5) 57fa9079a8SRichard Henderson | (lower_z << 4) 58fa9079a8SRichard Henderson | (lower_y << 2) 59fa9079a8SRichard Henderson | lower_x; 60fcf5ef2aSThomas Huth } 61fcf5ef2aSThomas Huth 62e03b5686SMarc-André Lureau #if HOST_BIG_ENDIAN 63fcf5ef2aSThomas Huth #define VIS_B64(n) b[7 - (n)] 64d6f898cfSRichard Henderson #define VIS_SB64(n) sb[7 - (n)] 65fcf5ef2aSThomas Huth #define VIS_W64(n) w[3 - (n)] 66fcf5ef2aSThomas Huth #define VIS_SW64(n) sw[3 - (n)] 67fcf5ef2aSThomas Huth #define VIS_L64(n) l[1 - (n)] 68fcf5ef2aSThomas Huth #define VIS_B32(n) b[3 - (n)] 69fcf5ef2aSThomas Huth #define VIS_W32(n) w[1 - (n)] 70fcf5ef2aSThomas Huth #else 71fcf5ef2aSThomas Huth #define VIS_B64(n) b[n] 72d6f898cfSRichard Henderson #define VIS_SB64(n) sb[n] 73fcf5ef2aSThomas Huth #define VIS_W64(n) w[n] 74fcf5ef2aSThomas Huth #define VIS_SW64(n) sw[n] 75fcf5ef2aSThomas Huth #define VIS_L64(n) l[n] 76fcf5ef2aSThomas Huth #define VIS_B32(n) b[n] 77fcf5ef2aSThomas Huth #define VIS_W32(n) w[n] 78fcf5ef2aSThomas Huth #endif 79fcf5ef2aSThomas Huth 80fcf5ef2aSThomas Huth typedef union { 81fcf5ef2aSThomas Huth uint8_t b[8]; 82d6f898cfSRichard Henderson int8_t sb[8]; 83fcf5ef2aSThomas Huth uint16_t w[4]; 84fcf5ef2aSThomas Huth int16_t sw[4]; 85fcf5ef2aSThomas Huth uint32_t l[2]; 86fcf5ef2aSThomas Huth uint64_t ll; 87fcf5ef2aSThomas Huth float64 d; 88fcf5ef2aSThomas Huth } VIS64; 89fcf5ef2aSThomas Huth 90fcf5ef2aSThomas Huth typedef union { 91fcf5ef2aSThomas Huth uint8_t b[4]; 92fcf5ef2aSThomas Huth uint16_t w[2]; 93fcf5ef2aSThomas Huth uint32_t l; 94fcf5ef2aSThomas Huth float32 f; 95fcf5ef2aSThomas Huth } VIS32; 96fcf5ef2aSThomas Huth 97d3ef26afSRichard Henderson uint64_t helper_fpmerge(uint32_t src1, uint32_t src2) 98fcf5ef2aSThomas Huth { 99d3ef26afSRichard Henderson VIS32 s1, s2; 100d3ef26afSRichard Henderson VIS64 d; 101fcf5ef2aSThomas Huth 102d3ef26afSRichard Henderson s1.l = src1; 103d3ef26afSRichard Henderson s2.l = src2; 104d3ef26afSRichard Henderson d.ll = 0; 105fcf5ef2aSThomas Huth 106d3ef26afSRichard Henderson d.VIS_B64(7) = s1.VIS_B32(3); 107d3ef26afSRichard Henderson d.VIS_B64(6) = s2.VIS_B32(3); 108d3ef26afSRichard Henderson d.VIS_B64(5) = s1.VIS_B32(2); 109d3ef26afSRichard Henderson d.VIS_B64(4) = s2.VIS_B32(2); 110d3ef26afSRichard Henderson d.VIS_B64(3) = s1.VIS_B32(1); 111d3ef26afSRichard Henderson d.VIS_B64(2) = s2.VIS_B32(1); 112d3ef26afSRichard Henderson d.VIS_B64(1) = s1.VIS_B32(0); 113d3ef26afSRichard Henderson d.VIS_B64(0) = s2.VIS_B32(0); 114fcf5ef2aSThomas Huth 115fcf5ef2aSThomas Huth return d.ll; 116fcf5ef2aSThomas Huth } 117fcf5ef2aSThomas Huth 118d6f898cfSRichard Henderson static inline int do_ms16b(int x, int y) 119d6f898cfSRichard Henderson { 120d6f898cfSRichard Henderson return ((x * y) + 0x80) >> 8; 121d6f898cfSRichard Henderson } 122d6f898cfSRichard Henderson 1239157dcccSRichard Henderson uint64_t helper_fmul8x16(uint32_t src1, uint64_t src2) 124fcf5ef2aSThomas Huth { 1259157dcccSRichard Henderson VIS64 d; 1269157dcccSRichard Henderson VIS32 s; 127fcf5ef2aSThomas Huth 1289157dcccSRichard Henderson s.l = src1; 129fcf5ef2aSThomas Huth d.ll = src2; 130fcf5ef2aSThomas Huth 131d6f898cfSRichard Henderson d.VIS_W64(0) = do_ms16b(s.VIS_B32(0), d.VIS_SW64(0)); 132d6f898cfSRichard Henderson d.VIS_W64(1) = do_ms16b(s.VIS_B32(1), d.VIS_SW64(1)); 133d6f898cfSRichard Henderson d.VIS_W64(2) = do_ms16b(s.VIS_B32(2), d.VIS_SW64(2)); 134d6f898cfSRichard Henderson d.VIS_W64(3) = do_ms16b(s.VIS_B32(3), d.VIS_SW64(3)); 135fcf5ef2aSThomas Huth 136fcf5ef2aSThomas Huth return d.ll; 137fcf5ef2aSThomas Huth } 138fcf5ef2aSThomas Huth 139a859602cSRichard Henderson uint64_t helper_fmul8x16a(uint32_t src1, int32_t src2) 140fcf5ef2aSThomas Huth { 141a859602cSRichard Henderson VIS32 s; 142a859602cSRichard Henderson VIS64 d; 143fcf5ef2aSThomas Huth 144a859602cSRichard Henderson s.l = src1; 145a859602cSRichard Henderson d.ll = 0; 146fcf5ef2aSThomas Huth 147d6f898cfSRichard Henderson d.VIS_W64(0) = do_ms16b(s.VIS_B32(0), src2); 148d6f898cfSRichard Henderson d.VIS_W64(1) = do_ms16b(s.VIS_B32(1), src2); 149d6f898cfSRichard Henderson d.VIS_W64(2) = do_ms16b(s.VIS_B32(2), src2); 150d6f898cfSRichard Henderson d.VIS_W64(3) = do_ms16b(s.VIS_B32(3), src2); 151fcf5ef2aSThomas Huth 152fcf5ef2aSThomas Huth return d.ll; 153fcf5ef2aSThomas Huth } 154fcf5ef2aSThomas Huth 155fcf5ef2aSThomas Huth uint64_t helper_fmul8sux16(uint64_t src1, uint64_t src2) 156fcf5ef2aSThomas Huth { 157fcf5ef2aSThomas Huth VIS64 s, d; 158fcf5ef2aSThomas Huth 159fcf5ef2aSThomas Huth s.ll = src1; 160fcf5ef2aSThomas Huth d.ll = src2; 161fcf5ef2aSThomas Huth 162d6f898cfSRichard Henderson d.VIS_W64(0) = do_ms16b(s.VIS_SB64(1), d.VIS_SW64(0)); 163d6f898cfSRichard Henderson d.VIS_W64(1) = do_ms16b(s.VIS_SB64(3), d.VIS_SW64(1)); 164d6f898cfSRichard Henderson d.VIS_W64(2) = do_ms16b(s.VIS_SB64(5), d.VIS_SW64(2)); 165d6f898cfSRichard Henderson d.VIS_W64(3) = do_ms16b(s.VIS_SB64(7), d.VIS_SW64(3)); 166fcf5ef2aSThomas Huth 167fcf5ef2aSThomas Huth return d.ll; 168fcf5ef2aSThomas Huth } 169fcf5ef2aSThomas Huth 170fcf5ef2aSThomas Huth uint64_t helper_fmul8ulx16(uint64_t src1, uint64_t src2) 171fcf5ef2aSThomas Huth { 172fcf5ef2aSThomas Huth VIS64 s, d; 173fcf5ef2aSThomas Huth 174fcf5ef2aSThomas Huth s.ll = src1; 175fcf5ef2aSThomas Huth d.ll = src2; 176fcf5ef2aSThomas Huth 177b5c96047SRichard Henderson d.VIS_W64(0) = (s.VIS_B64(0) * d.VIS_SW64(0) + 0x8000) >> 16; 178b5c96047SRichard Henderson d.VIS_W64(1) = (s.VIS_B64(2) * d.VIS_SW64(1) + 0x8000) >> 16; 179b5c96047SRichard Henderson d.VIS_W64(2) = (s.VIS_B64(4) * d.VIS_SW64(2) + 0x8000) >> 16; 180b5c96047SRichard Henderson d.VIS_W64(3) = (s.VIS_B64(6) * d.VIS_SW64(3) + 0x8000) >> 16; 181fcf5ef2aSThomas Huth 182fcf5ef2aSThomas Huth return d.ll; 183fcf5ef2aSThomas Huth } 184fcf5ef2aSThomas Huth 1857b616f36SRichard Henderson uint64_t helper_fexpand(uint32_t src2) 186fcf5ef2aSThomas Huth { 187fcf5ef2aSThomas Huth VIS32 s; 188fcf5ef2aSThomas Huth VIS64 d; 189fcf5ef2aSThomas Huth 1907b616f36SRichard Henderson s.l = src2; 1917b616f36SRichard Henderson d.ll = 0; 192fcf5ef2aSThomas Huth d.VIS_W64(0) = s.VIS_B32(0) << 4; 193fcf5ef2aSThomas Huth d.VIS_W64(1) = s.VIS_B32(1) << 4; 194fcf5ef2aSThomas Huth d.VIS_W64(2) = s.VIS_B32(2) << 4; 195fcf5ef2aSThomas Huth d.VIS_W64(3) = s.VIS_B32(3) << 4; 196fcf5ef2aSThomas Huth 197fcf5ef2aSThomas Huth return d.ll; 198fcf5ef2aSThomas Huth } 199fcf5ef2aSThomas Huth 200fcf5ef2aSThomas Huth #define VIS_CMPHELPER(name, F) \ 201fcf5ef2aSThomas Huth uint64_t name##16(uint64_t src1, uint64_t src2) \ 202fcf5ef2aSThomas Huth { \ 203fcf5ef2aSThomas Huth VIS64 s, d; \ 204fcf5ef2aSThomas Huth \ 205fcf5ef2aSThomas Huth s.ll = src1; \ 206fcf5ef2aSThomas Huth d.ll = src2; \ 207fcf5ef2aSThomas Huth \ 208fcf5ef2aSThomas Huth d.VIS_W64(0) = F(s.VIS_W64(0), d.VIS_W64(0)) ? 1 : 0; \ 209fcf5ef2aSThomas Huth d.VIS_W64(0) |= F(s.VIS_W64(1), d.VIS_W64(1)) ? 2 : 0; \ 210fcf5ef2aSThomas Huth d.VIS_W64(0) |= F(s.VIS_W64(2), d.VIS_W64(2)) ? 4 : 0; \ 211fcf5ef2aSThomas Huth d.VIS_W64(0) |= F(s.VIS_W64(3), d.VIS_W64(3)) ? 8 : 0; \ 212fcf5ef2aSThomas Huth d.VIS_W64(1) = d.VIS_W64(2) = d.VIS_W64(3) = 0; \ 213fcf5ef2aSThomas Huth \ 214fcf5ef2aSThomas Huth return d.ll; \ 215fcf5ef2aSThomas Huth } \ 216fcf5ef2aSThomas Huth \ 217fcf5ef2aSThomas Huth uint64_t name##32(uint64_t src1, uint64_t src2) \ 218fcf5ef2aSThomas Huth { \ 219fcf5ef2aSThomas Huth VIS64 s, d; \ 220fcf5ef2aSThomas Huth \ 221fcf5ef2aSThomas Huth s.ll = src1; \ 222fcf5ef2aSThomas Huth d.ll = src2; \ 223fcf5ef2aSThomas Huth \ 224fcf5ef2aSThomas Huth d.VIS_L64(0) = F(s.VIS_L64(0), d.VIS_L64(0)) ? 1 : 0; \ 225fcf5ef2aSThomas Huth d.VIS_L64(0) |= F(s.VIS_L64(1), d.VIS_L64(1)) ? 2 : 0; \ 226fcf5ef2aSThomas Huth d.VIS_L64(1) = 0; \ 227fcf5ef2aSThomas Huth \ 228fcf5ef2aSThomas Huth return d.ll; \ 229fcf5ef2aSThomas Huth } 230fcf5ef2aSThomas Huth 231fcf5ef2aSThomas Huth #define FCMPGT(a, b) ((a) > (b)) 232fcf5ef2aSThomas Huth #define FCMPEQ(a, b) ((a) == (b)) 233fcf5ef2aSThomas Huth #define FCMPLE(a, b) ((a) <= (b)) 234fcf5ef2aSThomas Huth #define FCMPNE(a, b) ((a) != (b)) 235fcf5ef2aSThomas Huth 236fcf5ef2aSThomas Huth VIS_CMPHELPER(helper_fcmpgt, FCMPGT) 237fcf5ef2aSThomas Huth VIS_CMPHELPER(helper_fcmpeq, FCMPEQ) 238fcf5ef2aSThomas Huth VIS_CMPHELPER(helper_fcmple, FCMPLE) 239fcf5ef2aSThomas Huth VIS_CMPHELPER(helper_fcmpne, FCMPNE) 240fcf5ef2aSThomas Huth 241fcf5ef2aSThomas Huth uint64_t helper_pdist(uint64_t sum, uint64_t src1, uint64_t src2) 242fcf5ef2aSThomas Huth { 243fcf5ef2aSThomas Huth int i; 244fcf5ef2aSThomas Huth for (i = 0; i < 8; i++) { 245fcf5ef2aSThomas Huth int s1, s2; 246fcf5ef2aSThomas Huth 247fcf5ef2aSThomas Huth s1 = (src1 >> (56 - (i * 8))) & 0xff; 248fcf5ef2aSThomas Huth s2 = (src2 >> (56 - (i * 8))) & 0xff; 249fcf5ef2aSThomas Huth 250fcf5ef2aSThomas Huth /* Absolute value of difference. */ 251fcf5ef2aSThomas Huth s1 -= s2; 252fcf5ef2aSThomas Huth if (s1 < 0) { 253fcf5ef2aSThomas Huth s1 = -s1; 254fcf5ef2aSThomas Huth } 255fcf5ef2aSThomas Huth 256fcf5ef2aSThomas Huth sum += s1; 257fcf5ef2aSThomas Huth } 258fcf5ef2aSThomas Huth 259fcf5ef2aSThomas Huth return sum; 260fcf5ef2aSThomas Huth } 261fcf5ef2aSThomas Huth 262fcf5ef2aSThomas Huth uint32_t helper_fpack16(uint64_t gsr, uint64_t rs2) 263fcf5ef2aSThomas Huth { 264fcf5ef2aSThomas Huth int scale = (gsr >> 3) & 0xf; 265fcf5ef2aSThomas Huth uint32_t ret = 0; 266fcf5ef2aSThomas Huth int byte; 267fcf5ef2aSThomas Huth 268fcf5ef2aSThomas Huth for (byte = 0; byte < 4; byte++) { 269fcf5ef2aSThomas Huth uint32_t val; 270fcf5ef2aSThomas Huth int16_t src = rs2 >> (byte * 16); 271fcf5ef2aSThomas Huth int32_t scaled = src << scale; 272fcf5ef2aSThomas Huth int32_t from_fixed = scaled >> 7; 273fcf5ef2aSThomas Huth 274fcf5ef2aSThomas Huth val = (from_fixed < 0 ? 0 : 275fcf5ef2aSThomas Huth from_fixed > 255 ? 255 : from_fixed); 276fcf5ef2aSThomas Huth 277fcf5ef2aSThomas Huth ret |= val << (8 * byte); 278fcf5ef2aSThomas Huth } 279fcf5ef2aSThomas Huth 280fcf5ef2aSThomas Huth return ret; 281fcf5ef2aSThomas Huth } 282fcf5ef2aSThomas Huth 283fcf5ef2aSThomas Huth uint64_t helper_fpack32(uint64_t gsr, uint64_t rs1, uint64_t rs2) 284fcf5ef2aSThomas Huth { 285fcf5ef2aSThomas Huth int scale = (gsr >> 3) & 0x1f; 286fcf5ef2aSThomas Huth uint64_t ret = 0; 287fcf5ef2aSThomas Huth int word; 288fcf5ef2aSThomas Huth 289fcf5ef2aSThomas Huth ret = (rs1 << 8) & ~(0x000000ff000000ffULL); 290fcf5ef2aSThomas Huth for (word = 0; word < 2; word++) { 291fcf5ef2aSThomas Huth uint64_t val; 292fcf5ef2aSThomas Huth int32_t src = rs2 >> (word * 32); 293fcf5ef2aSThomas Huth int64_t scaled = (int64_t)src << scale; 294fcf5ef2aSThomas Huth int64_t from_fixed = scaled >> 23; 295fcf5ef2aSThomas Huth 296fcf5ef2aSThomas Huth val = (from_fixed < 0 ? 0 : 297fcf5ef2aSThomas Huth (from_fixed > 255) ? 255 : from_fixed); 298fcf5ef2aSThomas Huth 299fcf5ef2aSThomas Huth ret |= val << (32 * word); 300fcf5ef2aSThomas Huth } 301fcf5ef2aSThomas Huth 302fcf5ef2aSThomas Huth return ret; 303fcf5ef2aSThomas Huth } 304fcf5ef2aSThomas Huth 305fcf5ef2aSThomas Huth uint32_t helper_fpackfix(uint64_t gsr, uint64_t rs2) 306fcf5ef2aSThomas Huth { 307fcf5ef2aSThomas Huth int scale = (gsr >> 3) & 0x1f; 308fcf5ef2aSThomas Huth uint32_t ret = 0; 309fcf5ef2aSThomas Huth int word; 310fcf5ef2aSThomas Huth 311fcf5ef2aSThomas Huth for (word = 0; word < 2; word++) { 312fcf5ef2aSThomas Huth uint32_t val; 313fcf5ef2aSThomas Huth int32_t src = rs2 >> (word * 32); 314fcf5ef2aSThomas Huth int64_t scaled = (int64_t)src << scale; 315fcf5ef2aSThomas Huth int64_t from_fixed = scaled >> 16; 316fcf5ef2aSThomas Huth 317fcf5ef2aSThomas Huth val = (from_fixed < -32768 ? -32768 : 318fcf5ef2aSThomas Huth from_fixed > 32767 ? 32767 : from_fixed); 319fcf5ef2aSThomas Huth 320fcf5ef2aSThomas Huth ret |= (val & 0xffff) << (word * 16); 321fcf5ef2aSThomas Huth } 322fcf5ef2aSThomas Huth 323fcf5ef2aSThomas Huth return ret; 324fcf5ef2aSThomas Huth } 325fcf5ef2aSThomas Huth 326fcf5ef2aSThomas Huth uint64_t helper_bshuffle(uint64_t gsr, uint64_t src1, uint64_t src2) 327fcf5ef2aSThomas Huth { 328fcf5ef2aSThomas Huth union { 329fcf5ef2aSThomas Huth uint64_t ll[2]; 330fcf5ef2aSThomas Huth uint8_t b[16]; 331fcf5ef2aSThomas Huth } s; 332fcf5ef2aSThomas Huth VIS64 r; 333fcf5ef2aSThomas Huth uint32_t i, mask, host; 334fcf5ef2aSThomas Huth 335fcf5ef2aSThomas Huth /* Set up S such that we can index across all of the bytes. */ 336e03b5686SMarc-André Lureau #if HOST_BIG_ENDIAN 337fcf5ef2aSThomas Huth s.ll[0] = src1; 338fcf5ef2aSThomas Huth s.ll[1] = src2; 339fcf5ef2aSThomas Huth host = 0; 340fcf5ef2aSThomas Huth #else 341fcf5ef2aSThomas Huth s.ll[1] = src1; 342fcf5ef2aSThomas Huth s.ll[0] = src2; 343fcf5ef2aSThomas Huth host = 15; 344fcf5ef2aSThomas Huth #endif 345fcf5ef2aSThomas Huth mask = gsr >> 32; 346fcf5ef2aSThomas Huth 347fcf5ef2aSThomas Huth for (i = 0; i < 8; ++i) { 348fcf5ef2aSThomas Huth unsigned e = (mask >> (28 - i*4)) & 0xf; 349fcf5ef2aSThomas Huth r.VIS_B64(i) = s.b[e ^ host]; 350fcf5ef2aSThomas Huth } 351fcf5ef2aSThomas Huth 352fcf5ef2aSThomas Huth return r.ll; 353fcf5ef2aSThomas Huth } 354c973b4e8SRichard Henderson 355c973b4e8SRichard Henderson uint64_t helper_cmask8(uint64_t gsr, uint64_t src) 356c973b4e8SRichard Henderson { 357c973b4e8SRichard Henderson uint32_t mask = 0; 358c973b4e8SRichard Henderson 359c973b4e8SRichard Henderson mask |= (src & 0x01 ? 0x00000007 : 0x0000000f); 360c973b4e8SRichard Henderson mask |= (src & 0x02 ? 0x00000060 : 0x000000e0); 361c973b4e8SRichard Henderson mask |= (src & 0x04 ? 0x00000500 : 0x00000d00); 362c973b4e8SRichard Henderson mask |= (src & 0x08 ? 0x00004000 : 0x0000c000); 363c973b4e8SRichard Henderson mask |= (src & 0x10 ? 0x00030000 : 0x000b0000); 364c973b4e8SRichard Henderson mask |= (src & 0x20 ? 0x00200000 : 0x00a00000); 365c973b4e8SRichard Henderson mask |= (src & 0x40 ? 0x01000000 : 0x09000000); 366c973b4e8SRichard Henderson mask |= (src & 0x80 ? 0x00000000 : 0x80000000); 367c973b4e8SRichard Henderson 368c973b4e8SRichard Henderson return deposit64(gsr, 32, 32, mask); 369c973b4e8SRichard Henderson } 370c973b4e8SRichard Henderson 371c973b4e8SRichard Henderson uint64_t helper_cmask16(uint64_t gsr, uint64_t src) 372c973b4e8SRichard Henderson { 373c973b4e8SRichard Henderson uint32_t mask = 0; 374c973b4e8SRichard Henderson 375c973b4e8SRichard Henderson mask |= (src & 0x1 ? 0x00000067 : 0x000000ef); 376c973b4e8SRichard Henderson mask |= (src & 0x2 ? 0x00004500 : 0x0000cd00); 377c973b4e8SRichard Henderson mask |= (src & 0x4 ? 0x00230000 : 0x00ab0000); 378c973b4e8SRichard Henderson mask |= (src & 0x8 ? 0x01000000 : 0x89000000); 379c973b4e8SRichard Henderson 380c973b4e8SRichard Henderson return deposit64(gsr, 32, 32, mask); 381c973b4e8SRichard Henderson } 382c973b4e8SRichard Henderson 383c973b4e8SRichard Henderson uint64_t helper_cmask32(uint64_t gsr, uint64_t src) 384c973b4e8SRichard Henderson { 385c973b4e8SRichard Henderson uint32_t mask = 0; 386c973b4e8SRichard Henderson 387c973b4e8SRichard Henderson mask |= (src & 0x1 ? 0x00004567 : 0x0000cdef); 388c973b4e8SRichard Henderson mask |= (src & 0x2 ? 0x01230000 : 0x89ab0000); 389c973b4e8SRichard Henderson 390c973b4e8SRichard Henderson return deposit64(gsr, 32, 32, mask); 391c973b4e8SRichard Henderson } 3927837185eSRichard Henderson 3937837185eSRichard Henderson static inline uint16_t do_fchksm16(uint16_t src1, uint16_t src2) 3947837185eSRichard Henderson { 3957837185eSRichard Henderson uint16_t a = src1 + src2; 3967837185eSRichard Henderson uint16_t c = a < src1; 3977837185eSRichard Henderson return a + c; 3987837185eSRichard Henderson } 3997837185eSRichard Henderson 4007837185eSRichard Henderson uint64_t helper_fchksm16(uint64_t src1, uint64_t src2) 4017837185eSRichard Henderson { 4027837185eSRichard Henderson VIS64 r, s1, s2; 4037837185eSRichard Henderson 4047837185eSRichard Henderson s1.ll = src1; 4057837185eSRichard Henderson s2.ll = src2; 4067837185eSRichard Henderson r.ll = 0; 4077837185eSRichard Henderson 4087837185eSRichard Henderson r.VIS_W64(0) = do_fchksm16(s1.VIS_W64(0), s2.VIS_W64(0)); 4097837185eSRichard Henderson r.VIS_W64(1) = do_fchksm16(s1.VIS_W64(1), s2.VIS_W64(1)); 4107837185eSRichard Henderson r.VIS_W64(2) = do_fchksm16(s1.VIS_W64(2), s2.VIS_W64(2)); 4117837185eSRichard Henderson r.VIS_W64(3) = do_fchksm16(s1.VIS_W64(3), s2.VIS_W64(3)); 4127837185eSRichard Henderson 4137837185eSRichard Henderson return r.ll; 4147837185eSRichard Henderson } 415*d6ff1ccbSRichard Henderson 416*d6ff1ccbSRichard Henderson static inline int16_t do_fmean16(int16_t src1, int16_t src2) 417*d6ff1ccbSRichard Henderson { 418*d6ff1ccbSRichard Henderson return (src1 + src2 + 1) / 2; 419*d6ff1ccbSRichard Henderson } 420*d6ff1ccbSRichard Henderson 421*d6ff1ccbSRichard Henderson uint64_t helper_fmean16(uint64_t src1, uint64_t src2) 422*d6ff1ccbSRichard Henderson { 423*d6ff1ccbSRichard Henderson VIS64 r, s1, s2; 424*d6ff1ccbSRichard Henderson 425*d6ff1ccbSRichard Henderson s1.ll = src1; 426*d6ff1ccbSRichard Henderson s2.ll = src2; 427*d6ff1ccbSRichard Henderson r.ll = 0; 428*d6ff1ccbSRichard Henderson 429*d6ff1ccbSRichard Henderson r.VIS_SW64(0) = do_fmean16(s1.VIS_SW64(0), s2.VIS_SW64(0)); 430*d6ff1ccbSRichard Henderson r.VIS_SW64(1) = do_fmean16(s1.VIS_SW64(1), s2.VIS_SW64(1)); 431*d6ff1ccbSRichard Henderson r.VIS_SW64(2) = do_fmean16(s1.VIS_SW64(2), s2.VIS_SW64(2)); 432*d6ff1ccbSRichard Henderson r.VIS_SW64(3) = do_fmean16(s1.VIS_SW64(3), s2.VIS_SW64(3)); 433*d6ff1ccbSRichard Henderson 434*d6ff1ccbSRichard Henderson return r.ll; 435*d6ff1ccbSRichard Henderson } 436