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