]> git.proxmox.com Git - mirror_qemu.git/blame - target-tilegx/helper.c
target-tilegx: Add several helpers for instructions translation
[mirror_qemu.git] / target-tilegx / helper.c
CommitLineData
5b212be6
CG
1/*
2 * QEMU TILE-Gx helpers
3 *
4 * Copyright (c) 2015 Chen Gang
5 *
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.
10 *
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.
15 *
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>
19 */
20
21#include "cpu.h"
22#include "qemu-common.h"
23#include "exec/helper-proto.h"
24
25void helper_exception(CPUTLGState *env, uint32_t excp)
26{
27 CPUState *cs = CPU(tilegx_env_get_cpu(env));
28
29 cs->exception_index = excp;
30 cpu_loop_exit(cs);
31}
32
33uint64_t helper_cntlz(uint64_t arg)
34{
35 return clz64(arg);
36}
37
38uint64_t helper_cnttz(uint64_t arg)
39{
40 return ctz64(arg);
41}
42
43/*
44 * Functional Description
45 * uint64_t a = rf[SrcA];
46 * uint64_t b = rf[SrcB];
47 * uint64_t d = rf[Dest];
48 * uint64_t output = 0;
49 * unsigned int counter;
50 * for (counter = 0; counter < (WORD_SIZE / BYTE_SIZE); counter++)
51 * {
52 * int sel = getByte (b, counter) & 0xf;
53 * uint8_t byte = (sel < 8) ? getByte (d, sel) : getByte (a, (sel - 8));
54 * output = setByte (output, counter, byte);
55 * }
56 * rf[Dest] = output;
57 */
58uint64_t helper_shufflebytes(uint64_t dest, uint64_t srca, uint64_t srcb)
59{
60 uint64_t vdst = 0;
61 int count;
62
63 for (count = 0; count < 64; count += 8) {
64 uint64_t sel = srcb >> count;
65 uint64_t src = (sel & 8) ? srca : dest;
66 vdst |= extract64(src, (sel & 7) * 8, 8) << count;
67 }
68
69 return vdst;
70}