util: retry getaddrinfo if getting EAI_BADFLAGS with AI_V4MAPPED
[qemu/kevin.git] / target-tilegx / simd_helper.c
blob2d40ddb63e1dedc4883c55d175e241813bd93325
1 /*
2 * QEMU TILE-Gx helpers
4 * Copyright (c) 2015 Chen Gang
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
18 * <http://www.gnu.org/licenses/lgpl-2.1.html>
21 #include "qemu/osdep.h"
22 #include "cpu.h"
23 #include "qemu-common.h"
24 #include "exec/helper-proto.h"
27 /* Broadcast a value to all elements of a vector. */
28 #define V1(X) (((X) & 0xff) * 0x0101010101010101ull)
29 #define V2(X) (((X) & 0xffff) * 0x0001000100010001ull)
32 uint64_t helper_v1multu(uint64_t a, uint64_t b)
34 uint64_t r = 0;
35 int i;
37 for (i = 0; i < 64; i += 8) {
38 unsigned ae = extract64(a, i, 8);
39 unsigned be = extract64(b, i, 8);
40 r = deposit64(r, i, 8, ae * be);
42 return r;
45 uint64_t helper_v2mults(uint64_t a, uint64_t b)
47 uint64_t r = 0;
48 int i;
50 /* While the instruction talks about signed inputs, with a
51 truncated result the sign of the inputs doesn't matter. */
52 for (i = 0; i < 64; i += 16) {
53 unsigned ae = extract64(a, i, 16);
54 unsigned be = extract64(b, i, 16);
55 r = deposit64(r, i, 16, ae * be);
57 return r;
60 uint64_t helper_v1shl(uint64_t a, uint64_t b)
62 uint64_t m;
64 b &= 7;
65 m = V1(0xff >> b);
66 return (a & m) << b;
69 uint64_t helper_v2shl(uint64_t a, uint64_t b)
71 uint64_t m;
73 b &= 15;
74 m = V2(0xffff >> b);
75 return (a & m) << b;
78 uint64_t helper_v1shru(uint64_t a, uint64_t b)
80 uint64_t m;
82 b &= 7;
83 m = V1(0xff << b);
84 return (a & m) >> b;
87 uint64_t helper_v2shru(uint64_t a, uint64_t b)
89 uint64_t m;
91 b &= 15;
92 m = V2(0xffff << b);
93 return (a & m) >> b;
96 uint64_t helper_v1shrs(uint64_t a, uint64_t b)
98 uint64_t r = 0;
99 int i;
101 b &= 7;
102 for (i = 0; i < 64; i += 8) {
103 r = deposit64(r, i, 8, sextract64(a, i + b, 8 - b));
105 return r;
108 uint64_t helper_v2shrs(uint64_t a, uint64_t b)
110 uint64_t r = 0;
111 int i;
113 b &= 15;
114 for (i = 0; i < 64; i += 16) {
115 r = deposit64(r, i, 16, sextract64(a, i + b, 16 - b));
117 return r;
120 uint64_t helper_v1int_h(uint64_t a, uint64_t b)
122 uint64_t r = 0;
123 int i;
125 for (i = 0; i < 32; i += 8) {
126 r = deposit64(r, 2 * i + 8, 8, extract64(a, i + 32, 8));
127 r = deposit64(r, 2 * i, 8, extract64(b, i + 32, 8));
129 return r;
132 uint64_t helper_v1int_l(uint64_t a, uint64_t b)
134 uint64_t r = 0;
135 int i;
137 for (i = 0; i < 32; i += 8) {
138 r = deposit64(r, 2 * i + 8, 8, extract64(a, i, 8));
139 r = deposit64(r, 2 * i, 8, extract64(b, i, 8));
141 return r;
144 uint64_t helper_v2int_h(uint64_t a, uint64_t b)
146 uint64_t r = 0;
147 int i;
149 for (i = 0; i < 32; i += 16) {
150 r = deposit64(r, 2 * i + 16, 16, extract64(a, i + 32, 16));
151 r = deposit64(r, 2 * i, 16, extract64(b, i + 32, 16));
153 return r;
156 uint64_t helper_v2int_l(uint64_t a, uint64_t b)
158 uint64_t r = 0;
159 int i;
161 for (i = 0; i < 32; i += 16) {
162 r = deposit64(r, 2 * i + 16, 16, extract64(a, i, 16));
163 r = deposit64(r, 2 * i, 16, extract64(b, i, 16));
165 return r;