4 * Copyright (c) 2015 Chen Gang
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.
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.
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>
21 #include "qemu/osdep.h"
23 #include "exec/exec-all.h"
24 #include "exec/helper-proto.h"
25 #include <zlib.h> /* For crc32 */
26 #include "syscall_defs.h"
28 void helper_exception(CPUTLGState
*env
, uint32_t excp
)
30 CPUState
*cs
= env_cpu(env
);
32 cs
->exception_index
= excp
;
36 void helper_ext01_ics(CPUTLGState
*env
)
38 uint64_t val
= env
->spregs
[TILEGX_SPR_EX_CONTEXT_0_1
];
43 env
->spregs
[TILEGX_SPR_CRITICAL_SEC
] = val
;
46 #if defined(CONFIG_USER_ONLY)
47 env
->signo
= TARGET_SIGILL
;
48 env
->sigcode
= TARGET_ILL_ILLOPC
;
49 helper_exception(env
, TILEGX_EXCP_SIGNAL
);
51 helper_exception(env
, TILEGX_EXCP_OPCODE_UNIMPLEMENTED
);
57 uint64_t helper_revbits(uint64_t arg
)
63 * Functional Description
64 * uint64_t a = rf[SrcA];
65 * uint64_t b = rf[SrcB];
66 * uint64_t d = rf[Dest];
67 * uint64_t output = 0;
68 * unsigned int counter;
69 * for (counter = 0; counter < (WORD_SIZE / BYTE_SIZE); counter++)
71 * int sel = getByte (b, counter) & 0xf;
72 * uint8_t byte = (sel < 8) ? getByte (d, sel) : getByte (a, (sel - 8));
73 * output = setByte (output, counter, byte);
77 uint64_t helper_shufflebytes(uint64_t dest
, uint64_t srca
, uint64_t srcb
)
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
;
91 uint64_t helper_crc32_8(uint64_t accum
, uint64_t input
)
95 /* zlib crc32 converts the accumulator and output to one's complement. */
96 return crc32(accum
^ 0xffffffff, &buf
, 1) ^ 0xffffffff;
99 uint64_t helper_crc32_32(uint64_t accum
, uint64_t input
)
103 stl_le_p(buf
, input
);
105 /* zlib crc32 converts the accumulator and output to one's complement. */
106 return crc32(accum
^ 0xffffffff, buf
, 4) ^ 0xffffffff;
109 uint64_t helper_cmula(uint64_t srcd
, uint64_t srca
, uint64_t srcb
)
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
;
120 return deposit64(realr
, 32, 32, imagr
);
123 uint64_t helper_cmulaf(uint64_t srcd
, uint64_t srca
, uint64_t srcb
)
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
;
134 return deposit32((realr
>> 15) + reald
, 16, 16, (imagr
>> 15) + imagd
);
137 uint64_t helper_cmul2(uint64_t srca
, uint64_t srcb
, int shift
, int round
)
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
;
146 return deposit32(realr
>> shift
, 16, 16, imagr
>> shift
);