MAINTAINERS: add IPack section
[qemu/ar7.git] / target-tilegx / helper.c
bloba01bb8d5139e59c07cc6e9e401bcf59628cc8563
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"
25 void helper_exception(CPUTLGState *env, uint32_t excp)
27 CPUState *cs = CPU(tilegx_env_get_cpu(env));
29 cs->exception_index = excp;
30 cpu_loop_exit(cs);
33 uint64_t helper_cntlz(uint64_t arg)
35 return clz64(arg);
38 uint64_t helper_cnttz(uint64_t arg)
40 return ctz64(arg);
43 uint64_t helper_pcnt(uint64_t arg)
45 return ctpop64(arg);
48 uint64_t helper_revbits(uint64_t arg)
50 return revbit64(arg);
54 * Functional Description
55 * uint64_t a = rf[SrcA];
56 * uint64_t b = rf[SrcB];
57 * uint64_t d = rf[Dest];
58 * uint64_t output = 0;
59 * unsigned int counter;
60 * for (counter = 0; counter < (WORD_SIZE / BYTE_SIZE); counter++)
61 * {
62 * int sel = getByte (b, counter) & 0xf;
63 * uint8_t byte = (sel < 8) ? getByte (d, sel) : getByte (a, (sel - 8));
64 * output = setByte (output, counter, byte);
65 * }
66 * rf[Dest] = output;
68 uint64_t helper_shufflebytes(uint64_t dest, uint64_t srca, uint64_t srcb)
70 uint64_t vdst = 0;
71 int count;
73 for (count = 0; count < 64; count += 8) {
74 uint64_t sel = srcb >> count;
75 uint64_t src = (sel & 8) ? srca : dest;
76 vdst |= extract64(src, (sel & 7) * 8, 8) << count;
79 return vdst;