1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "qemu/osdep.h"
22#include "cpu.h"
23#include "exec/exec-all.h"
24#include "exec/helper-proto.h"
25#include <zlib.h>
26#include "syscall_defs.h"
27
28void helper_exception(CPUTLGState *env, uint32_t excp)
29{
30 CPUState *cs = env_cpu(env);
31
32 cs->exception_index = excp;
33 cpu_loop_exit(cs);
34}
35
36void helper_ext01_ics(CPUTLGState *env)
37{
38 uint64_t val = env->spregs[TILEGX_SPR_EX_CONTEXT_0_1];
39
40 switch (val) {
41 case 0:
42 case 1:
43 env->spregs[TILEGX_SPR_CRITICAL_SEC] = val;
44 break;
45 default:
46#if defined(CONFIG_USER_ONLY)
47 env->signo = TARGET_SIGILL;
48 env->sigcode = TARGET_ILL_ILLOPC;
49 helper_exception(env, TILEGX_EXCP_SIGNAL);
50#else
51 helper_exception(env, TILEGX_EXCP_OPCODE_UNIMPLEMENTED);
52#endif
53 break;
54 }
55}
56
57uint64_t helper_revbits(uint64_t arg)
58{
59 return revbit64(arg);
60}
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77uint64_t helper_shufflebytes(uint64_t dest, uint64_t srca, uint64_t srcb)
78{
79 uint64_t vdst = 0;
80 int count;
81
82 for (count = 0; count < 64; count += 8) {
83 uint64_t sel = srcb >> count;
84 uint64_t src = (sel & 8) ? srca : dest;
85 vdst |= extract64(src, (sel & 7) * 8, 8) << count;
86 }
87
88 return vdst;
89}
90
91uint64_t helper_crc32_8(uint64_t accum, uint64_t input)
92{
93 uint8_t buf = input;
94
95
96 return crc32(accum ^ 0xffffffff, &buf, 1) ^ 0xffffffff;
97}
98
99uint64_t helper_crc32_32(uint64_t accum, uint64_t input)
100{
101 uint8_t buf[4];
102
103 stl_le_p(buf, input);
104
105
106 return crc32(accum ^ 0xffffffff, buf, 4) ^ 0xffffffff;
107}
108
109uint64_t helper_cmula(uint64_t srcd, uint64_t srca, uint64_t srcb)
110{
111 uint32_t reala = (int16_t)srca;
112 uint32_t imaga = (int16_t)(srca >> 16);
113 uint32_t realb = (int16_t)srcb;
114 uint32_t imagb = (int16_t)(srcb >> 16);
115 uint32_t reald = srcd;
116 uint32_t imagd = srcd >> 32;
117 uint32_t realr = reala * realb - imaga * imagb + reald;
118 uint32_t imagr = reala * imagb + imaga * realb + imagd;
119
120 return deposit64(realr, 32, 32, imagr);
121}
122
123uint64_t helper_cmulaf(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 = (int16_t)srcd;
130 uint32_t imagd = (int16_t)(srcd >> 16);
131 int32_t realr = reala * realb - imaga * imagb;
132 int32_t imagr = reala * imagb + imaga * realb;
133
134 return deposit32((realr >> 15) + reald, 16, 16, (imagr >> 15) + imagd);
135}
136
137uint64_t helper_cmul2(uint64_t srca, uint64_t srcb, int shift, int round)
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 int32_t realr = reala * realb - imaga * imagb + round;
144 int32_t imagr = reala * imagb + imaga * realb + round;
145
146 return deposit32(realr >> shift, 16, 16, imagr >> shift);
147}
148