]>
Commit | Line | Data |
---|---|---|
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 | ||
b98ba684 | 21 | #include "qemu/osdep.h" |
5b212be6 | 22 | #include "cpu.h" |
63c91552 | 23 | #include "exec/exec-all.h" |
5b212be6 CG |
24 | #include "qemu-common.h" |
25 | #include "exec/helper-proto.h" | |
ba1fc78f | 26 | #include <zlib.h> /* For crc32 */ |
fec7daab | 27 | #include "syscall_defs.h" |
5b212be6 CG |
28 | |
29 | void helper_exception(CPUTLGState *env, uint32_t excp) | |
30 | { | |
31 | CPUState *cs = CPU(tilegx_env_get_cpu(env)); | |
32 | ||
33 | cs->exception_index = excp; | |
34 | cpu_loop_exit(cs); | |
35 | } | |
36 | ||
fec7daab CG |
37 | void helper_ext01_ics(CPUTLGState *env) |
38 | { | |
39 | uint64_t val = env->spregs[TILEGX_SPR_EX_CONTEXT_0_1]; | |
40 | ||
41 | switch (val) { | |
42 | case 0: | |
43 | case 1: | |
44 | env->spregs[TILEGX_SPR_CRITICAL_SEC] = val; | |
45 | break; | |
46 | default: | |
47 | #if defined(CONFIG_USER_ONLY) | |
48 | env->signo = TARGET_SIGILL; | |
49 | env->sigcode = TARGET_ILL_ILLOPC; | |
50 | helper_exception(env, TILEGX_EXCP_SIGNAL); | |
51 | #else | |
52 | helper_exception(env, TILEGX_EXCP_OPCODE_UNIMPLEMENTED); | |
53 | #endif | |
54 | break; | |
55 | } | |
56 | } | |
57 | ||
5b212be6 CG |
58 | uint64_t helper_cntlz(uint64_t arg) |
59 | { | |
60 | return clz64(arg); | |
61 | } | |
62 | ||
63 | uint64_t helper_cnttz(uint64_t arg) | |
64 | { | |
65 | return ctz64(arg); | |
66 | } | |
67 | ||
7f41a8d6 RH |
68 | uint64_t helper_pcnt(uint64_t arg) |
69 | { | |
70 | return ctpop64(arg); | |
71 | } | |
72 | ||
73 | uint64_t helper_revbits(uint64_t arg) | |
74 | { | |
75 | return revbit64(arg); | |
76 | } | |
77 | ||
5b212be6 CG |
78 | /* |
79 | * Functional Description | |
80 | * uint64_t a = rf[SrcA]; | |
81 | * uint64_t b = rf[SrcB]; | |
82 | * uint64_t d = rf[Dest]; | |
83 | * uint64_t output = 0; | |
84 | * unsigned int counter; | |
85 | * for (counter = 0; counter < (WORD_SIZE / BYTE_SIZE); counter++) | |
86 | * { | |
87 | * int sel = getByte (b, counter) & 0xf; | |
88 | * uint8_t byte = (sel < 8) ? getByte (d, sel) : getByte (a, (sel - 8)); | |
89 | * output = setByte (output, counter, byte); | |
90 | * } | |
91 | * rf[Dest] = output; | |
92 | */ | |
93 | uint64_t helper_shufflebytes(uint64_t dest, uint64_t srca, uint64_t srcb) | |
94 | { | |
95 | uint64_t vdst = 0; | |
96 | int count; | |
97 | ||
98 | for (count = 0; count < 64; count += 8) { | |
99 | uint64_t sel = srcb >> count; | |
100 | uint64_t src = (sel & 8) ? srca : dest; | |
101 | vdst |= extract64(src, (sel & 7) * 8, 8) << count; | |
102 | } | |
103 | ||
104 | return vdst; | |
105 | } | |
ba1fc78f RH |
106 | |
107 | uint64_t helper_crc32_8(uint64_t accum, uint64_t input) | |
108 | { | |
109 | uint8_t buf = input; | |
110 | ||
111 | /* zlib crc32 converts the accumulator and output to one's complement. */ | |
112 | return crc32(accum ^ 0xffffffff, &buf, 1) ^ 0xffffffff; | |
113 | } | |
114 | ||
115 | uint64_t helper_crc32_32(uint64_t accum, uint64_t input) | |
116 | { | |
117 | uint8_t buf[4]; | |
118 | ||
119 | stl_le_p(buf, input); | |
120 | ||
121 | /* zlib crc32 converts the accumulator and output to one's complement. */ | |
122 | return crc32(accum ^ 0xffffffff, buf, 4) ^ 0xffffffff; | |
123 | } | |
9ff5b57c RH |
124 | |
125 | uint64_t helper_cmula(uint64_t srcd, uint64_t srca, uint64_t srcb) | |
126 | { | |
127 | uint32_t reala = (int16_t)srca; | |
128 | uint32_t imaga = (int16_t)(srca >> 16); | |
129 | uint32_t realb = (int16_t)srcb; | |
130 | uint32_t imagb = (int16_t)(srcb >> 16); | |
131 | uint32_t reald = srcd; | |
132 | uint32_t imagd = srcd >> 32; | |
133 | uint32_t realr = reala * realb - imaga * imagb + reald; | |
134 | uint32_t imagr = reala * imagb + imaga * realb + imagd; | |
135 | ||
136 | return deposit64(realr, 32, 32, imagr); | |
137 | } | |
138 | ||
139 | uint64_t helper_cmulaf(uint64_t srcd, uint64_t srca, uint64_t srcb) | |
140 | { | |
141 | uint32_t reala = (int16_t)srca; | |
142 | uint32_t imaga = (int16_t)(srca >> 16); | |
143 | uint32_t realb = (int16_t)srcb; | |
144 | uint32_t imagb = (int16_t)(srcb >> 16); | |
145 | uint32_t reald = (int16_t)srcd; | |
146 | uint32_t imagd = (int16_t)(srcd >> 16); | |
147 | int32_t realr = reala * realb - imaga * imagb; | |
148 | int32_t imagr = reala * imagb + imaga * realb; | |
149 | ||
150 | return deposit32((realr >> 15) + reald, 16, 16, (imagr >> 15) + imagd); | |
151 | } | |
152 | ||
153 | uint64_t helper_cmul2(uint64_t srca, uint64_t srcb, int shift, int round) | |
154 | { | |
155 | uint32_t reala = (int16_t)srca; | |
156 | uint32_t imaga = (int16_t)(srca >> 16); | |
157 | uint32_t realb = (int16_t)srcb; | |
158 | uint32_t imagb = (int16_t)(srcb >> 16); | |
159 | int32_t realr = reala * realb - imaga * imagb + round; | |
160 | int32_t imagr = reala * imagb + imaga * realb + round; | |
161 | ||
162 | return deposit32(realr >> shift, 16, 16, imagr >> shift); | |
163 | } |