target-tilegx: Tidy simd_helper.c
[qemu/ar7.git] / target-tilegx / simd_helper.c
blobf573f9b51a16383a1f500a1b22f754103ea8d3b1
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 "cpu.h"
22 #include "qemu-common.h"
23 #include "exec/helper-proto.h"
26 /* Broadcast a value to all elements of a vector. */
27 #define V1(X) (((X) & 0xff) * 0x0101010101010101ull)
30 uint64_t helper_v1shl(uint64_t a, uint64_t b)
32 uint64_t m;
34 b &= 7;
35 m = V1(0xff >> b);
36 return (a & m) << b;
39 uint64_t helper_v1shru(uint64_t a, uint64_t b)
41 uint64_t m;
43 b &= 7;
44 m = V1(0xff << b);
45 return (a & m) >> b;
48 uint64_t helper_v1shrs(uint64_t a, uint64_t b)
50 uint64_t r = 0;
51 int i;
53 b &= 7;
54 for (i = 0; i < 64; i += 8) {
55 r = deposit64(r, i, 8, sextract64(a, i + b, 8 - b));
57 return r;