]> Git Repo - qemu.git/blob - target-tilegx/helper.c
target-tilegx: Handle bitfield instructions
[qemu.git] / target-tilegx / helper.c
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
25 void 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
33 uint64_t helper_cntlz(uint64_t arg)
34 {
35     return clz64(arg);
36 }
37
38 uint64_t helper_cnttz(uint64_t arg)
39 {
40     return ctz64(arg);
41 }
42
43 uint64_t helper_pcnt(uint64_t arg)
44 {
45     return ctpop64(arg);
46 }
47
48 uint64_t helper_revbits(uint64_t arg)
49 {
50     return revbit64(arg);
51 }
52
53 /*
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;
67  */
68 uint64_t helper_shufflebytes(uint64_t dest, uint64_t srca, uint64_t srcb)
69 {
70     uint64_t vdst = 0;
71     int count;
72
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;
77     }
78
79     return vdst;
80 }
This page took 0.028827 seconds and 4 git commands to generate.