blob: 364964d8d4d2e0fd90e478fda90b65e3d3618d91 [file] [log] [blame]
bellardc896fe22008-02-01 10:05:41 +00001/*
2 * Tiny Code Generator for QEMU
3 *
4 * Copyright (c) 2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24#include "tcg.h"
25
bellardc896fe22008-02-01 10:05:41 +000026int gen_new_label(void);
27
Richard Henderson212c3282012-10-02 11:32:28 -070028static inline void tcg_gen_op0(TCGOpcode opc)
29{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040030 *tcg_ctx.gen_opc_ptr++ = opc;
Richard Henderson212c3282012-10-02 11:32:28 -070031}
32
Richard Hendersona9751602010-03-19 11:12:29 -070033static inline void tcg_gen_op1_i32(TCGOpcode opc, TCGv_i32 arg1)
pbrookac56dd42008-02-03 19:56:33 +000034{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040035 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +040036 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
pbrooka7812ae2008-11-17 14:43:54 +000037}
38
Richard Hendersona9751602010-03-19 11:12:29 -070039static inline void tcg_gen_op1_i64(TCGOpcode opc, TCGv_i64 arg1)
pbrooka7812ae2008-11-17 14:43:54 +000040{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040041 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +040042 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
pbrookac56dd42008-02-03 19:56:33 +000043}
44
Richard Hendersona9751602010-03-19 11:12:29 -070045static inline void tcg_gen_op1i(TCGOpcode opc, TCGArg arg1)
bellardc896fe22008-02-01 10:05:41 +000046{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040047 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +040048 *tcg_ctx.gen_opparam_ptr++ = arg1;
bellardc896fe22008-02-01 10:05:41 +000049}
50
Richard Hendersona9751602010-03-19 11:12:29 -070051static inline void tcg_gen_op2_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +000052{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040053 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +040054 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
55 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
pbrookac56dd42008-02-03 19:56:33 +000056}
57
Richard Hendersona9751602010-03-19 11:12:29 -070058static inline void tcg_gen_op2_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2)
pbrookac56dd42008-02-03 19:56:33 +000059{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040060 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +040061 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
62 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
pbrooka7812ae2008-11-17 14:43:54 +000063}
64
Richard Hendersona9751602010-03-19 11:12:29 -070065static inline void tcg_gen_op2i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGArg arg2)
pbrooka7812ae2008-11-17 14:43:54 +000066{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040067 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +040068 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
69 *tcg_ctx.gen_opparam_ptr++ = arg2;
pbrooka7812ae2008-11-17 14:43:54 +000070}
71
Richard Hendersona9751602010-03-19 11:12:29 -070072static inline void tcg_gen_op2i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGArg arg2)
pbrooka7812ae2008-11-17 14:43:54 +000073{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040074 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +040075 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
76 *tcg_ctx.gen_opparam_ptr++ = arg2;
bellardc896fe22008-02-01 10:05:41 +000077}
78
Richard Hendersona9751602010-03-19 11:12:29 -070079static inline void tcg_gen_op2ii(TCGOpcode opc, TCGArg arg1, TCGArg arg2)
pbrookbcb01262008-05-24 02:24:25 +000080{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040081 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +040082 *tcg_ctx.gen_opparam_ptr++ = arg1;
83 *tcg_ctx.gen_opparam_ptr++ = arg2;
pbrookbcb01262008-05-24 02:24:25 +000084}
85
Richard Hendersona9751602010-03-19 11:12:29 -070086static inline void tcg_gen_op3_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +000087 TCGv_i32 arg3)
bellardc896fe22008-02-01 10:05:41 +000088{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040089 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +040090 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
91 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
92 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
pbrookac56dd42008-02-03 19:56:33 +000093}
94
Richard Hendersona9751602010-03-19 11:12:29 -070095static inline void tcg_gen_op3_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +000096 TCGv_i64 arg3)
pbrookac56dd42008-02-03 19:56:33 +000097{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +040098 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +040099 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
100 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
101 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
pbrooka7812ae2008-11-17 14:43:54 +0000102}
103
Richard Hendersona9751602010-03-19 11:12:29 -0700104static inline void tcg_gen_op3i_i32(TCGOpcode opc, TCGv_i32 arg1,
105 TCGv_i32 arg2, TCGArg arg3)
pbrooka7812ae2008-11-17 14:43:54 +0000106{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400107 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400108 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
109 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
110 *tcg_ctx.gen_opparam_ptr++ = arg3;
bellardc896fe22008-02-01 10:05:41 +0000111}
112
Richard Hendersona9751602010-03-19 11:12:29 -0700113static inline void tcg_gen_op3i_i64(TCGOpcode opc, TCGv_i64 arg1,
114 TCGv_i64 arg2, TCGArg arg3)
bellardc896fe22008-02-01 10:05:41 +0000115{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400116 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400117 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
118 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
119 *tcg_ctx.gen_opparam_ptr++ = arg3;
pbrookac56dd42008-02-03 19:56:33 +0000120}
121
Richard Hendersona9751602010-03-19 11:12:29 -0700122static inline void tcg_gen_ldst_op_i32(TCGOpcode opc, TCGv_i32 val,
123 TCGv_ptr base, TCGArg offset)
pbrookac56dd42008-02-03 19:56:33 +0000124{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400125 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400126 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(val);
127 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_PTR(base);
128 *tcg_ctx.gen_opparam_ptr++ = offset;
pbrooka7812ae2008-11-17 14:43:54 +0000129}
130
Richard Hendersona9751602010-03-19 11:12:29 -0700131static inline void tcg_gen_ldst_op_i64(TCGOpcode opc, TCGv_i64 val,
132 TCGv_ptr base, TCGArg offset)
pbrooka7812ae2008-11-17 14:43:54 +0000133{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400134 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400135 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
136 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_PTR(base);
137 *tcg_ctx.gen_opparam_ptr++ = offset;
pbrooka7812ae2008-11-17 14:43:54 +0000138}
139
Richard Hendersona9751602010-03-19 11:12:29 -0700140static inline void tcg_gen_qemu_ldst_op_i64_i32(TCGOpcode opc, TCGv_i64 val,
141 TCGv_i32 addr, TCGArg mem_index)
pbrooka7812ae2008-11-17 14:43:54 +0000142{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400143 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400144 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
145 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(addr);
146 *tcg_ctx.gen_opparam_ptr++ = mem_index;
pbrooka7812ae2008-11-17 14:43:54 +0000147}
148
Richard Hendersona9751602010-03-19 11:12:29 -0700149static inline void tcg_gen_qemu_ldst_op_i64_i64(TCGOpcode opc, TCGv_i64 val,
150 TCGv_i64 addr, TCGArg mem_index)
pbrooka7812ae2008-11-17 14:43:54 +0000151{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400152 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400153 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
154 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(addr);
155 *tcg_ctx.gen_opparam_ptr++ = mem_index;
pbrooka7812ae2008-11-17 14:43:54 +0000156}
157
Richard Hendersona9751602010-03-19 11:12:29 -0700158static inline void tcg_gen_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000159 TCGv_i32 arg3, TCGv_i32 arg4)
160{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400161 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400162 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
163 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
164 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
165 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
pbrooka7812ae2008-11-17 14:43:54 +0000166}
167
Richard Hendersona9751602010-03-19 11:12:29 -0700168static inline void tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
blueswir1a810a2d2008-12-07 17:16:42 +0000169 TCGv_i64 arg3, TCGv_i64 arg4)
pbrooka7812ae2008-11-17 14:43:54 +0000170{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400171 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400172 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
173 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
174 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
175 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
pbrooka7812ae2008-11-17 14:43:54 +0000176}
177
Richard Hendersona9751602010-03-19 11:12:29 -0700178static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000179 TCGv_i32 arg3, TCGArg arg4)
180{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400181 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400182 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
183 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
184 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
185 *tcg_ctx.gen_opparam_ptr++ = arg4;
pbrookac56dd42008-02-03 19:56:33 +0000186}
187
Richard Hendersona9751602010-03-19 11:12:29 -0700188static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000189 TCGv_i64 arg3, TCGArg arg4)
pbrookac56dd42008-02-03 19:56:33 +0000190{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400191 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400192 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
193 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
194 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
195 *tcg_ctx.gen_opparam_ptr++ = arg4;
pbrooka7812ae2008-11-17 14:43:54 +0000196}
197
Richard Hendersona9751602010-03-19 11:12:29 -0700198static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000199 TCGArg arg3, TCGArg arg4)
200{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400201 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400202 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
203 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
204 *tcg_ctx.gen_opparam_ptr++ = arg3;
205 *tcg_ctx.gen_opparam_ptr++ = arg4;
bellardc896fe22008-02-01 10:05:41 +0000206}
207
Richard Hendersona9751602010-03-19 11:12:29 -0700208static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000209 TCGArg arg3, TCGArg arg4)
bellardc896fe22008-02-01 10:05:41 +0000210{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400211 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400212 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
213 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
214 *tcg_ctx.gen_opparam_ptr++ = arg3;
215 *tcg_ctx.gen_opparam_ptr++ = arg4;
pbrookac56dd42008-02-03 19:56:33 +0000216}
217
Richard Hendersona9751602010-03-19 11:12:29 -0700218static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000219 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5)
pbrookac56dd42008-02-03 19:56:33 +0000220{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400221 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400222 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
223 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
224 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
225 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
226 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
pbrooka7812ae2008-11-17 14:43:54 +0000227}
228
Richard Hendersona9751602010-03-19 11:12:29 -0700229static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000230 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5)
231{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400232 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400233 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
234 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
235 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
236 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
237 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
pbrooka7812ae2008-11-17 14:43:54 +0000238}
239
Richard Hendersona9751602010-03-19 11:12:29 -0700240static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000241 TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
242{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400243 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400244 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
245 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
246 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
247 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
248 *tcg_ctx.gen_opparam_ptr++ = arg5;
bellardc896fe22008-02-01 10:05:41 +0000249}
250
Richard Hendersona9751602010-03-19 11:12:29 -0700251static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000252 TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
bellardc896fe22008-02-01 10:05:41 +0000253{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400254 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400255 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
256 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
257 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
258 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
259 *tcg_ctx.gen_opparam_ptr++ = arg5;
pbrookac56dd42008-02-03 19:56:33 +0000260}
261
Richard Hendersonb7767f02011-01-10 19:23:42 -0800262static inline void tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 arg1,
263 TCGv_i32 arg2, TCGv_i32 arg3,
264 TCGArg arg4, TCGArg arg5)
265{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400266 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400267 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
268 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
269 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
270 *tcg_ctx.gen_opparam_ptr++ = arg4;
271 *tcg_ctx.gen_opparam_ptr++ = arg5;
Richard Hendersonb7767f02011-01-10 19:23:42 -0800272}
273
274static inline void tcg_gen_op5ii_i64(TCGOpcode opc, TCGv_i64 arg1,
275 TCGv_i64 arg2, TCGv_i64 arg3,
276 TCGArg arg4, TCGArg arg5)
277{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400278 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400279 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
280 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
281 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
282 *tcg_ctx.gen_opparam_ptr++ = arg4;
283 *tcg_ctx.gen_opparam_ptr++ = arg5;
Richard Hendersonb7767f02011-01-10 19:23:42 -0800284}
285
Richard Hendersona9751602010-03-19 11:12:29 -0700286static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000287 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5,
288 TCGv_i32 arg6)
pbrookac56dd42008-02-03 19:56:33 +0000289{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400290 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400291 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
292 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
293 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
294 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
295 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
296 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg6);
pbrooka7812ae2008-11-17 14:43:54 +0000297}
298
Richard Hendersona9751602010-03-19 11:12:29 -0700299static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000300 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
301 TCGv_i64 arg6)
302{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400303 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400304 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
305 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
306 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
307 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
308 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
309 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg6);
pbrooka7812ae2008-11-17 14:43:54 +0000310}
311
Richard Hendersona9751602010-03-19 11:12:29 -0700312static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
Richard Hendersonbe210ac2010-01-07 10:13:31 -0800313 TCGv_i32 arg3, TCGv_i32 arg4,
314 TCGv_i32 arg5, TCGArg arg6)
315{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400316 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400317 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
318 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
319 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
320 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
321 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
322 *tcg_ctx.gen_opparam_ptr++ = arg6;
Richard Hendersonbe210ac2010-01-07 10:13:31 -0800323}
324
Richard Hendersona9751602010-03-19 11:12:29 -0700325static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
Richard Hendersonbe210ac2010-01-07 10:13:31 -0800326 TCGv_i64 arg3, TCGv_i64 arg4,
327 TCGv_i64 arg5, TCGArg arg6)
328{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400329 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400330 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
331 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
332 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
333 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
334 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
335 *tcg_ctx.gen_opparam_ptr++ = arg6;
Richard Hendersonbe210ac2010-01-07 10:13:31 -0800336}
337
Richard Hendersona9751602010-03-19 11:12:29 -0700338static inline void tcg_gen_op6ii_i32(TCGOpcode opc, TCGv_i32 arg1,
339 TCGv_i32 arg2, TCGv_i32 arg3,
340 TCGv_i32 arg4, TCGArg arg5, TCGArg arg6)
pbrooka7812ae2008-11-17 14:43:54 +0000341{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400342 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400343 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
344 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
345 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
346 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
347 *tcg_ctx.gen_opparam_ptr++ = arg5;
348 *tcg_ctx.gen_opparam_ptr++ = arg6;
pbrooka7812ae2008-11-17 14:43:54 +0000349}
350
Richard Hendersona9751602010-03-19 11:12:29 -0700351static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 arg1,
352 TCGv_i64 arg2, TCGv_i64 arg3,
353 TCGv_i64 arg4, TCGArg arg5, TCGArg arg6)
pbrooka7812ae2008-11-17 14:43:54 +0000354{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400355 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400356 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
357 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
358 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
359 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
360 *tcg_ctx.gen_opparam_ptr++ = arg5;
361 *tcg_ctx.gen_opparam_ptr++ = arg6;
bellardc896fe22008-02-01 10:05:41 +0000362}
363
364static inline void gen_set_label(int n)
365{
pbrookac56dd42008-02-03 19:56:33 +0000366 tcg_gen_op1i(INDEX_op_set_label, n);
bellardc896fe22008-02-01 10:05:41 +0000367}
368
blueswir1fb50d412008-03-21 17:58:45 +0000369static inline void tcg_gen_br(int label)
370{
371 tcg_gen_op1i(INDEX_op_br, label);
372}
373
pbrooka7812ae2008-11-17 14:43:54 +0000374static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +0000375{
aurel32fe75bcf2009-03-10 08:57:16 +0000376 if (!TCGV_EQUAL_I32(ret, arg))
pbrooka7812ae2008-11-17 14:43:54 +0000377 tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000378}
379
pbrooka7812ae2008-11-17 14:43:54 +0000380static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
bellardc896fe22008-02-01 10:05:41 +0000381{
pbrooka7812ae2008-11-17 14:43:54 +0000382 tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000383}
384
Richard Henderson2bece2c2010-06-14 17:35:27 -0700385/* A version of dh_sizemask from def-helper.h that doesn't rely on
386 preprocessor magic. */
387static inline int tcg_gen_sizemask(int n, int is_64bit, int is_signed)
388{
389 return (is_64bit << n*2) | (is_signed << (n*2 + 1));
390}
391
bellardc896fe22008-02-01 10:05:41 +0000392/* helper calls */
pbrooka7812ae2008-11-17 14:43:54 +0000393static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
394 TCGArg ret, int nargs, TCGArg *args)
bellardc896fe22008-02-01 10:05:41 +0000395{
pbrooka7812ae2008-11-17 14:43:54 +0000396 TCGv_ptr fn;
Peter Maydell73f5e312011-12-10 16:35:31 +0000397 fn = tcg_const_ptr(func);
pbrooka7812ae2008-11-17 14:43:54 +0000398 tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
399 nargs, args);
400 tcg_temp_free_ptr(fn);
bellardc896fe22008-02-01 10:05:41 +0000401}
402
Aurelien Jarnodbfff4d2010-03-14 23:01:01 +0100403/* Note: Both tcg_gen_helper32() and tcg_gen_helper64() are currently
Aurelien Jarno78505272012-10-09 21:53:08 +0200404 reserved for helpers in tcg-runtime.c. These helpers all do not read
405 globals and do not have side effects, hence the call to tcg_gen_callN()
406 with TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS. This may need
407 to be adjusted if these functions start to be used with other helpers. */
Richard Henderson2bece2c2010-06-14 17:35:27 -0700408static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret,
Aurelien Jarno31d66552010-03-02 23:16:36 +0100409 TCGv_i32 a, TCGv_i32 b)
410{
411 TCGv_ptr fn;
412 TCGArg args[2];
Peter Maydell73f5e312011-12-10 16:35:31 +0000413 fn = tcg_const_ptr(func);
Aurelien Jarno31d66552010-03-02 23:16:36 +0100414 args[0] = GET_TCGV_I32(a);
415 args[1] = GET_TCGV_I32(b);
Aurelien Jarno78505272012-10-09 21:53:08 +0200416 tcg_gen_callN(&tcg_ctx, fn,
417 TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS,
418 sizemask, GET_TCGV_I32(ret), 2, args);
Aurelien Jarno31d66552010-03-02 23:16:36 +0100419 tcg_temp_free_ptr(fn);
420}
421
Richard Henderson2bece2c2010-06-14 17:35:27 -0700422static inline void tcg_gen_helper64(void *func, int sizemask, TCGv_i64 ret,
pbrooka7812ae2008-11-17 14:43:54 +0000423 TCGv_i64 a, TCGv_i64 b)
bellardc896fe22008-02-01 10:05:41 +0000424{
pbrooka7812ae2008-11-17 14:43:54 +0000425 TCGv_ptr fn;
426 TCGArg args[2];
Peter Maydell73f5e312011-12-10 16:35:31 +0000427 fn = tcg_const_ptr(func);
pbrooka7812ae2008-11-17 14:43:54 +0000428 args[0] = GET_TCGV_I64(a);
429 args[1] = GET_TCGV_I64(b);
Aurelien Jarno78505272012-10-09 21:53:08 +0200430 tcg_gen_callN(&tcg_ctx, fn,
431 TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS,
432 sizemask, GET_TCGV_I64(ret), 2, args);
pbrooka7812ae2008-11-17 14:43:54 +0000433 tcg_temp_free_ptr(fn);
blueswir1f8422f52008-02-24 07:45:43 +0000434}
435
bellardc896fe22008-02-01 10:05:41 +0000436/* 32 bit ops */
437
pbrooka7812ae2008-11-17 14:43:54 +0000438static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000439{
pbrooka7812ae2008-11-17 14:43:54 +0000440 tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000441}
442
pbrooka7812ae2008-11-17 14:43:54 +0000443static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000444{
pbrooka7812ae2008-11-17 14:43:54 +0000445 tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000446}
447
pbrooka7812ae2008-11-17 14:43:54 +0000448static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000449{
pbrooka7812ae2008-11-17 14:43:54 +0000450 tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000451}
452
pbrooka7812ae2008-11-17 14:43:54 +0000453static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000454{
pbrooka7812ae2008-11-17 14:43:54 +0000455 tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000456}
457
pbrooka7812ae2008-11-17 14:43:54 +0000458static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000459{
pbrooka7812ae2008-11-17 14:43:54 +0000460 tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000461}
462
pbrooka7812ae2008-11-17 14:43:54 +0000463static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000464{
pbrooka7812ae2008-11-17 14:43:54 +0000465 tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000466}
467
pbrooka7812ae2008-11-17 14:43:54 +0000468static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000469{
pbrooka7812ae2008-11-17 14:43:54 +0000470 tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000471}
472
pbrooka7812ae2008-11-17 14:43:54 +0000473static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000474{
pbrooka7812ae2008-11-17 14:43:54 +0000475 tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000476}
477
pbrooka7812ae2008-11-17 14:43:54 +0000478static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000479{
pbrooka7812ae2008-11-17 14:43:54 +0000480 tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000481}
482
pbrooka7812ae2008-11-17 14:43:54 +0000483static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000484{
blueswir170894422008-02-20 18:01:23 +0000485 /* some cases can be optimized here */
486 if (arg2 == 0) {
487 tcg_gen_mov_i32(ret, arg1);
488 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000489 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000490 tcg_gen_add_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000491 tcg_temp_free_i32(t0);
blueswir170894422008-02-20 18:01:23 +0000492 }
bellardc896fe22008-02-01 10:05:41 +0000493}
494
pbrooka7812ae2008-11-17 14:43:54 +0000495static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000496{
pbrooka7812ae2008-11-17 14:43:54 +0000497 tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000498}
499
pbrooka7812ae2008-11-17 14:43:54 +0000500static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
aurel3200457342008-11-02 08:23:04 +0000501{
pbrooka7812ae2008-11-17 14:43:54 +0000502 TCGv_i32 t0 = tcg_const_i32(arg1);
aurel3200457342008-11-02 08:23:04 +0000503 tcg_gen_sub_i32(ret, t0, arg2);
pbrooka7812ae2008-11-17 14:43:54 +0000504 tcg_temp_free_i32(t0);
aurel3200457342008-11-02 08:23:04 +0000505}
506
pbrooka7812ae2008-11-17 14:43:54 +0000507static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000508{
blueswir170894422008-02-20 18:01:23 +0000509 /* some cases can be optimized here */
510 if (arg2 == 0) {
511 tcg_gen_mov_i32(ret, arg1);
512 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000513 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000514 tcg_gen_sub_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000515 tcg_temp_free_i32(t0);
blueswir170894422008-02-20 18:01:23 +0000516 }
bellardc896fe22008-02-01 10:05:41 +0000517}
518
pbrooka7812ae2008-11-17 14:43:54 +0000519static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000520{
aurel327fc81052009-03-10 19:37:39 +0000521 if (TCGV_EQUAL_I32(arg1, arg2)) {
522 tcg_gen_mov_i32(ret, arg1);
523 } else {
524 tcg_gen_op3_i32(INDEX_op_and_i32, ret, arg1, arg2);
525 }
bellardc896fe22008-02-01 10:05:41 +0000526}
527
Richard Henderson42ce3e22012-09-21 17:18:10 -0700528static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000529{
Richard Henderson42ce3e22012-09-21 17:18:10 -0700530 TCGv_i32 t0;
531 /* Some cases can be optimized here. */
532 switch (arg2) {
533 case 0:
bellardc896fe22008-02-01 10:05:41 +0000534 tcg_gen_movi_i32(ret, 0);
Richard Henderson42ce3e22012-09-21 17:18:10 -0700535 return;
536 case 0xffffffffu:
bellardc896fe22008-02-01 10:05:41 +0000537 tcg_gen_mov_i32(ret, arg1);
Richard Henderson42ce3e22012-09-21 17:18:10 -0700538 return;
539 case 0xffu:
540 /* Don't recurse with tcg_gen_ext8u_i32. */
541 if (TCG_TARGET_HAS_ext8u_i32) {
542 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg1);
543 return;
544 }
545 break;
546 case 0xffffu:
547 if (TCG_TARGET_HAS_ext16u_i32) {
548 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg1);
549 return;
550 }
551 break;
bellardc896fe22008-02-01 10:05:41 +0000552 }
Richard Henderson42ce3e22012-09-21 17:18:10 -0700553 t0 = tcg_const_i32(arg2);
554 tcg_gen_and_i32(ret, arg1, t0);
555 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000556}
557
pbrooka7812ae2008-11-17 14:43:54 +0000558static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000559{
aurel327fc81052009-03-10 19:37:39 +0000560 if (TCGV_EQUAL_I32(arg1, arg2)) {
561 tcg_gen_mov_i32(ret, arg1);
562 } else {
563 tcg_gen_op3_i32(INDEX_op_or_i32, ret, arg1, arg2);
564 }
bellardc896fe22008-02-01 10:05:41 +0000565}
566
pbrooka7812ae2008-11-17 14:43:54 +0000567static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000568{
Richard Hendersond81ada72012-09-21 17:18:11 -0700569 /* Some cases can be optimized here. */
570 if (arg2 == -1) {
571 tcg_gen_movi_i32(ret, -1);
bellardc896fe22008-02-01 10:05:41 +0000572 } else if (arg2 == 0) {
573 tcg_gen_mov_i32(ret, arg1);
574 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000575 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000576 tcg_gen_or_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000577 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000578 }
579}
580
pbrooka7812ae2008-11-17 14:43:54 +0000581static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000582{
aurel327fc81052009-03-10 19:37:39 +0000583 if (TCGV_EQUAL_I32(arg1, arg2)) {
584 tcg_gen_movi_i32(ret, 0);
585 } else {
586 tcg_gen_op3_i32(INDEX_op_xor_i32, ret, arg1, arg2);
587 }
bellardc896fe22008-02-01 10:05:41 +0000588}
589
pbrooka7812ae2008-11-17 14:43:54 +0000590static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000591{
Richard Henderson6f3bb332012-09-21 17:18:12 -0700592 /* Some cases can be optimized here. */
bellardc896fe22008-02-01 10:05:41 +0000593 if (arg2 == 0) {
594 tcg_gen_mov_i32(ret, arg1);
Richard Henderson6f3bb332012-09-21 17:18:12 -0700595 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i32) {
596 /* Don't recurse with tcg_gen_not_i32. */
597 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg1);
bellardc896fe22008-02-01 10:05:41 +0000598 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000599 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000600 tcg_gen_xor_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000601 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000602 }
603}
604
pbrooka7812ae2008-11-17 14:43:54 +0000605static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000606{
pbrooka7812ae2008-11-17 14:43:54 +0000607 tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000608}
609
pbrooka7812ae2008-11-17 14:43:54 +0000610static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000611{
bellard34151a22008-05-22 13:25:14 +0000612 if (arg2 == 0) {
613 tcg_gen_mov_i32(ret, arg1);
614 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000615 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000616 tcg_gen_shl_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000617 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000618 }
bellardc896fe22008-02-01 10:05:41 +0000619}
620
pbrooka7812ae2008-11-17 14:43:54 +0000621static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000622{
pbrooka7812ae2008-11-17 14:43:54 +0000623 tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000624}
625
pbrooka7812ae2008-11-17 14:43:54 +0000626static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000627{
bellard34151a22008-05-22 13:25:14 +0000628 if (arg2 == 0) {
629 tcg_gen_mov_i32(ret, arg1);
630 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000631 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000632 tcg_gen_shr_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000633 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000634 }
bellardc896fe22008-02-01 10:05:41 +0000635}
636
pbrooka7812ae2008-11-17 14:43:54 +0000637static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000638{
pbrooka7812ae2008-11-17 14:43:54 +0000639 tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000640}
641
pbrooka7812ae2008-11-17 14:43:54 +0000642static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000643{
bellard34151a22008-05-22 13:25:14 +0000644 if (arg2 == 0) {
645 tcg_gen_mov_i32(ret, arg1);
646 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000647 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000648 tcg_gen_sar_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000649 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000650 }
bellardc896fe22008-02-01 10:05:41 +0000651}
652
Richard Henderson8a56e842010-03-19 11:26:05 -0700653static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
654 TCGv_i32 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +0000655{
Richard Henderson0aed2572012-09-24 14:21:40 -0700656 if (cond == TCG_COND_ALWAYS) {
657 tcg_gen_br(label_index);
658 } else if (cond != TCG_COND_NEVER) {
659 tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
660 }
bellardc896fe22008-02-01 10:05:41 +0000661}
662
Richard Henderson8a56e842010-03-19 11:26:05 -0700663static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
664 int32_t arg2, int label_index)
pbrookcb636692008-05-24 02:22:00 +0000665{
Richard Henderson0aed2572012-09-24 14:21:40 -0700666 if (cond == TCG_COND_ALWAYS) {
667 tcg_gen_br(label_index);
668 } else if (cond != TCG_COND_NEVER) {
669 TCGv_i32 t0 = tcg_const_i32(arg2);
670 tcg_gen_brcond_i32(cond, arg1, t0, label_index);
671 tcg_temp_free_i32(t0);
672 }
pbrookcb636692008-05-24 02:22:00 +0000673}
674
Richard Henderson8a56e842010-03-19 11:26:05 -0700675static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +0100676 TCGv_i32 arg1, TCGv_i32 arg2)
677{
Richard Henderson0aed2572012-09-24 14:21:40 -0700678 if (cond == TCG_COND_ALWAYS) {
679 tcg_gen_movi_i32(ret, 1);
680 } else if (cond == TCG_COND_NEVER) {
681 tcg_gen_movi_i32(ret, 0);
682 } else {
683 tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
684 }
Aurelien Jarno5105c552010-02-08 12:10:15 +0100685}
686
Richard Henderson8a56e842010-03-19 11:26:05 -0700687static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
688 TCGv_i32 arg1, int32_t arg2)
Aurelien Jarno5105c552010-02-08 12:10:15 +0100689{
Richard Henderson0aed2572012-09-24 14:21:40 -0700690 if (cond == TCG_COND_ALWAYS) {
691 tcg_gen_movi_i32(ret, 1);
692 } else if (cond == TCG_COND_NEVER) {
693 tcg_gen_movi_i32(ret, 0);
694 } else {
695 TCGv_i32 t0 = tcg_const_i32(arg2);
696 tcg_gen_setcond_i32(cond, ret, arg1, t0);
697 tcg_temp_free_i32(t0);
698 }
Aurelien Jarno5105c552010-02-08 12:10:15 +0100699}
700
pbrooka7812ae2008-11-17 14:43:54 +0000701static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000702{
pbrooka7812ae2008-11-17 14:43:54 +0000703 tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000704}
705
pbrooka7812ae2008-11-17 14:43:54 +0000706static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
thsf730fd22008-05-04 08:14:08 +0000707{
pbrooka7812ae2008-11-17 14:43:54 +0000708 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000709 tcg_gen_mul_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000710 tcg_temp_free_i32(t0);
thsf730fd22008-05-04 08:14:08 +0000711}
712
pbrooka7812ae2008-11-17 14:43:54 +0000713static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000714{
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700715 if (TCG_TARGET_HAS_div_i32) {
716 tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
717 } else if (TCG_TARGET_HAS_div2_i32) {
718 TCGv_i32 t0 = tcg_temp_new_i32();
719 tcg_gen_sari_i32(t0, arg1, 31);
720 tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
721 tcg_temp_free_i32(t0);
722 } else {
723 int sizemask = 0;
724 /* Return value and both arguments are 32-bit and signed. */
725 sizemask |= tcg_gen_sizemask(0, 0, 1);
726 sizemask |= tcg_gen_sizemask(1, 0, 1);
727 sizemask |= tcg_gen_sizemask(2, 0, 1);
728 tcg_gen_helper32(tcg_helper_div_i32, sizemask, ret, arg1, arg2);
729 }
bellardc896fe22008-02-01 10:05:41 +0000730}
731
pbrooka7812ae2008-11-17 14:43:54 +0000732static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000733{
Richard Hendersonca675f42013-03-11 22:41:47 -0700734 if (TCG_TARGET_HAS_rem_i32) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700735 tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
Richard Hendersonca675f42013-03-11 22:41:47 -0700736 } else if (TCG_TARGET_HAS_div_i32) {
737 TCGv_i32 t0 = tcg_temp_new_i32();
738 tcg_gen_op3_i32(INDEX_op_div_i32, t0, arg1, arg2);
739 tcg_gen_mul_i32(t0, t0, arg2);
740 tcg_gen_sub_i32(ret, arg1, t0);
741 tcg_temp_free_i32(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700742 } else if (TCG_TARGET_HAS_div2_i32) {
743 TCGv_i32 t0 = tcg_temp_new_i32();
744 tcg_gen_sari_i32(t0, arg1, 31);
745 tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
746 tcg_temp_free_i32(t0);
747 } else {
748 int sizemask = 0;
749 /* Return value and both arguments are 32-bit and signed. */
750 sizemask |= tcg_gen_sizemask(0, 0, 1);
751 sizemask |= tcg_gen_sizemask(1, 0, 1);
752 sizemask |= tcg_gen_sizemask(2, 0, 1);
753 tcg_gen_helper32(tcg_helper_rem_i32, sizemask, ret, arg1, arg2);
754 }
bellardc896fe22008-02-01 10:05:41 +0000755}
756
pbrooka7812ae2008-11-17 14:43:54 +0000757static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000758{
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700759 if (TCG_TARGET_HAS_div_i32) {
760 tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
761 } else if (TCG_TARGET_HAS_div2_i32) {
762 TCGv_i32 t0 = tcg_temp_new_i32();
763 tcg_gen_movi_i32(t0, 0);
764 tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
765 tcg_temp_free_i32(t0);
766 } else {
767 int sizemask = 0;
768 /* Return value and both arguments are 32-bit and unsigned. */
769 sizemask |= tcg_gen_sizemask(0, 0, 0);
770 sizemask |= tcg_gen_sizemask(1, 0, 0);
771 sizemask |= tcg_gen_sizemask(2, 0, 0);
772 tcg_gen_helper32(tcg_helper_divu_i32, sizemask, ret, arg1, arg2);
773 }
bellardc896fe22008-02-01 10:05:41 +0000774}
775
pbrooka7812ae2008-11-17 14:43:54 +0000776static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000777{
Richard Hendersonca675f42013-03-11 22:41:47 -0700778 if (TCG_TARGET_HAS_rem_i32) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700779 tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
Richard Hendersonca675f42013-03-11 22:41:47 -0700780 } else if (TCG_TARGET_HAS_div_i32) {
781 TCGv_i32 t0 = tcg_temp_new_i32();
782 tcg_gen_op3_i32(INDEX_op_divu_i32, t0, arg1, arg2);
783 tcg_gen_mul_i32(t0, t0, arg2);
784 tcg_gen_sub_i32(ret, arg1, t0);
785 tcg_temp_free_i32(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700786 } else if (TCG_TARGET_HAS_div2_i32) {
787 TCGv_i32 t0 = tcg_temp_new_i32();
788 tcg_gen_movi_i32(t0, 0);
789 tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
790 tcg_temp_free_i32(t0);
791 } else {
792 int sizemask = 0;
793 /* Return value and both arguments are 32-bit and unsigned. */
794 sizemask |= tcg_gen_sizemask(0, 0, 0);
795 sizemask |= tcg_gen_sizemask(1, 0, 0);
796 sizemask |= tcg_gen_sizemask(2, 0, 0);
797 tcg_gen_helper32(tcg_helper_remu_i32, sizemask, ret, arg1, arg2);
798 }
bellardc896fe22008-02-01 10:05:41 +0000799}
bellardc896fe22008-02-01 10:05:41 +0000800
801#if TCG_TARGET_REG_BITS == 32
802
pbrooka7812ae2008-11-17 14:43:54 +0000803static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +0000804{
aurel32fe75bcf2009-03-10 08:57:16 +0000805 if (!TCGV_EQUAL_I64(ret, arg)) {
pbrooka7812ae2008-11-17 14:43:54 +0000806 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
blueswir14d072722008-05-03 20:52:26 +0000807 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
808 }
bellardc896fe22008-02-01 10:05:41 +0000809}
810
pbrooka7812ae2008-11-17 14:43:54 +0000811static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +0000812{
pbrooka7812ae2008-11-17 14:43:54 +0000813 tcg_gen_movi_i32(TCGV_LOW(ret), arg);
pbrookac56dd42008-02-03 19:56:33 +0000814 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
bellardc896fe22008-02-01 10:05:41 +0000815}
816
pbrooka7812ae2008-11-17 14:43:54 +0000817static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
818 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000819{
pbrooka7812ae2008-11-17 14:43:54 +0000820 tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000821 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000822}
823
pbrooka7812ae2008-11-17 14:43:54 +0000824static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
825 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000826{
pbrooka7812ae2008-11-17 14:43:54 +0000827 tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
828 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000829}
830
pbrooka7812ae2008-11-17 14:43:54 +0000831static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
832 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000833{
aurel32a7477232009-02-09 20:43:53 +0000834 tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000835 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000836}
837
pbrooka7812ae2008-11-17 14:43:54 +0000838static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
839 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000840{
pbrooka7812ae2008-11-17 14:43:54 +0000841 tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
842 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000843}
844
pbrooka7812ae2008-11-17 14:43:54 +0000845static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
846 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000847{
pbrooka7812ae2008-11-17 14:43:54 +0000848 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000849 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000850}
851
pbrooka7812ae2008-11-17 14:43:54 +0000852static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
853 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000854{
pbrooka7812ae2008-11-17 14:43:54 +0000855 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
856 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000857}
858
pbrooka7812ae2008-11-17 14:43:54 +0000859static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
860 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000861{
862 /* since arg2 and ret have different types, they cannot be the
863 same temporary */
864#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000865 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
pbrooka7812ae2008-11-17 14:43:54 +0000866 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000867#else
pbrooka7812ae2008-11-17 14:43:54 +0000868 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000869 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000870#endif
871}
872
pbrooka7812ae2008-11-17 14:43:54 +0000873static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
874 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000875{
pbrooka7812ae2008-11-17 14:43:54 +0000876 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000877}
878
pbrooka7812ae2008-11-17 14:43:54 +0000879static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
880 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000881{
pbrooka7812ae2008-11-17 14:43:54 +0000882 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000883}
884
pbrooka7812ae2008-11-17 14:43:54 +0000885static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
886 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000887{
pbrooka7812ae2008-11-17 14:43:54 +0000888 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000889}
890
pbrooka7812ae2008-11-17 14:43:54 +0000891static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
892 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000893{
894#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000895 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
pbrooka7812ae2008-11-17 14:43:54 +0000896 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000897#else
pbrooka7812ae2008-11-17 14:43:54 +0000898 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000899 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000900#endif
901}
902
pbrooka7812ae2008-11-17 14:43:54 +0000903static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000904{
pbrooka7812ae2008-11-17 14:43:54 +0000905 tcg_gen_op6_i32(INDEX_op_add2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
906 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
907 TCGV_HIGH(arg2));
Richard Henderson212c3282012-10-02 11:32:28 -0700908 /* Allow the optimizer room to replace add2 with two moves. */
909 tcg_gen_op0(INDEX_op_nop);
bellardc896fe22008-02-01 10:05:41 +0000910}
911
pbrooka7812ae2008-11-17 14:43:54 +0000912static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000913{
pbrooka7812ae2008-11-17 14:43:54 +0000914 tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
915 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
916 TCGV_HIGH(arg2));
Richard Henderson212c3282012-10-02 11:32:28 -0700917 /* Allow the optimizer room to replace sub2 with two moves. */
918 tcg_gen_op0(INDEX_op_nop);
bellardc896fe22008-02-01 10:05:41 +0000919}
920
pbrooka7812ae2008-11-17 14:43:54 +0000921static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000922{
pbrooka7812ae2008-11-17 14:43:54 +0000923 tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
pbrookac56dd42008-02-03 19:56:33 +0000924 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000925}
926
pbrooka7812ae2008-11-17 14:43:54 +0000927static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000928{
aurel32e5105082009-03-11 02:57:30 +0000929 tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
930 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000931}
932
pbrooka7812ae2008-11-17 14:43:54 +0000933static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000934{
aurel32e5105082009-03-11 02:57:30 +0000935 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
936 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000937}
938
pbrooka7812ae2008-11-17 14:43:54 +0000939static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000940{
pbrooka7812ae2008-11-17 14:43:54 +0000941 tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
pbrookac56dd42008-02-03 19:56:33 +0000942 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000943}
944
pbrooka7812ae2008-11-17 14:43:54 +0000945static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000946{
aurel32e5105082009-03-11 02:57:30 +0000947 tcg_gen_xor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
948 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000949}
950
pbrooka7812ae2008-11-17 14:43:54 +0000951static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000952{
pbrooka7812ae2008-11-17 14:43:54 +0000953 tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
pbrookac56dd42008-02-03 19:56:33 +0000954 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000955}
956
957/* XXX: use generic code when basic block handling is OK or CPU
958 specific code (x86) */
pbrooka7812ae2008-11-17 14:43:54 +0000959static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000960{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700961 int sizemask = 0;
962 /* Return value and both arguments are 64-bit and signed. */
963 sizemask |= tcg_gen_sizemask(0, 1, 1);
964 sizemask |= tcg_gen_sizemask(1, 1, 1);
965 sizemask |= tcg_gen_sizemask(2, 1, 1);
966
967 tcg_gen_helper64(tcg_helper_shl_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000968}
969
pbrooka7812ae2008-11-17 14:43:54 +0000970static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000971{
972 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
973}
974
pbrooka7812ae2008-11-17 14:43:54 +0000975static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000976{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700977 int sizemask = 0;
978 /* Return value and both arguments are 64-bit and signed. */
979 sizemask |= tcg_gen_sizemask(0, 1, 1);
980 sizemask |= tcg_gen_sizemask(1, 1, 1);
981 sizemask |= tcg_gen_sizemask(2, 1, 1);
982
983 tcg_gen_helper64(tcg_helper_shr_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000984}
985
pbrooka7812ae2008-11-17 14:43:54 +0000986static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000987{
988 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
989}
990
pbrooka7812ae2008-11-17 14:43:54 +0000991static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000992{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700993 int sizemask = 0;
994 /* Return value and both arguments are 64-bit and signed. */
995 sizemask |= tcg_gen_sizemask(0, 1, 1);
996 sizemask |= tcg_gen_sizemask(1, 1, 1);
997 sizemask |= tcg_gen_sizemask(2, 1, 1);
998
999 tcg_gen_helper64(tcg_helper_sar_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001000}
1001
pbrooka7812ae2008-11-17 14:43:54 +00001002static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001003{
1004 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
1005}
1006
Richard Henderson8a56e842010-03-19 11:26:05 -07001007static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1008 TCGv_i64 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +00001009{
Richard Henderson0aed2572012-09-24 14:21:40 -07001010 if (cond == TCG_COND_ALWAYS) {
1011 tcg_gen_br(label_index);
1012 } else if (cond != TCG_COND_NEVER) {
1013 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
1014 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
1015 TCGV_HIGH(arg2), cond, label_index);
1016 }
bellardc896fe22008-02-01 10:05:41 +00001017}
1018
Richard Henderson8a56e842010-03-19 11:26:05 -07001019static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +01001020 TCGv_i64 arg1, TCGv_i64 arg2)
1021{
Richard Henderson0aed2572012-09-24 14:21:40 -07001022 if (cond == TCG_COND_ALWAYS) {
1023 tcg_gen_movi_i32(TCGV_LOW(ret), 1);
1024 } else if (cond == TCG_COND_NEVER) {
1025 tcg_gen_movi_i32(TCGV_LOW(ret), 0);
1026 } else {
1027 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
1028 TCGV_LOW(arg1), TCGV_HIGH(arg1),
1029 TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
1030 }
Aurelien Jarno5105c552010-02-08 12:10:15 +01001031 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1032}
1033
pbrooka7812ae2008-11-17 14:43:54 +00001034static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001035{
pbrooka7812ae2008-11-17 14:43:54 +00001036 TCGv_i64 t0;
1037 TCGv_i32 t1;
bellardc896fe22008-02-01 10:05:41 +00001038
pbrooka7812ae2008-11-17 14:43:54 +00001039 t0 = tcg_temp_new_i64();
1040 t1 = tcg_temp_new_i32();
1041
1042 tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
1043 TCGV_LOW(arg1), TCGV_LOW(arg2));
Richard Henderson14149682012-10-02 11:32:30 -07001044 /* Allow the optimizer room to replace mulu2 with two moves. */
1045 tcg_gen_op0(INDEX_op_nop);
pbrooka7812ae2008-11-17 14:43:54 +00001046
1047 tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
pbrookac56dd42008-02-03 19:56:33 +00001048 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
pbrooka7812ae2008-11-17 14:43:54 +00001049 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
pbrookac56dd42008-02-03 19:56:33 +00001050 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
pbrooka7812ae2008-11-17 14:43:54 +00001051
bellardc896fe22008-02-01 10:05:41 +00001052 tcg_gen_mov_i64(ret, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001053 tcg_temp_free_i64(t0);
1054 tcg_temp_free_i32(t1);
bellardc896fe22008-02-01 10:05:41 +00001055}
1056
pbrooka7812ae2008-11-17 14:43:54 +00001057static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001058{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001059 int sizemask = 0;
1060 /* Return value and both arguments are 64-bit and signed. */
1061 sizemask |= tcg_gen_sizemask(0, 1, 1);
1062 sizemask |= tcg_gen_sizemask(1, 1, 1);
1063 sizemask |= tcg_gen_sizemask(2, 1, 1);
1064
1065 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001066}
1067
pbrooka7812ae2008-11-17 14:43:54 +00001068static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001069{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001070 int sizemask = 0;
1071 /* Return value and both arguments are 64-bit and signed. */
1072 sizemask |= tcg_gen_sizemask(0, 1, 1);
1073 sizemask |= tcg_gen_sizemask(1, 1, 1);
1074 sizemask |= tcg_gen_sizemask(2, 1, 1);
1075
1076 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001077}
1078
pbrooka7812ae2008-11-17 14:43:54 +00001079static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001080{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001081 int sizemask = 0;
1082 /* Return value and both arguments are 64-bit and unsigned. */
1083 sizemask |= tcg_gen_sizemask(0, 1, 0);
1084 sizemask |= tcg_gen_sizemask(1, 1, 0);
1085 sizemask |= tcg_gen_sizemask(2, 1, 0);
1086
1087 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001088}
1089
pbrooka7812ae2008-11-17 14:43:54 +00001090static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001091{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001092 int sizemask = 0;
1093 /* Return value and both arguments are 64-bit and unsigned. */
1094 sizemask |= tcg_gen_sizemask(0, 1, 0);
1095 sizemask |= tcg_gen_sizemask(1, 1, 0);
1096 sizemask |= tcg_gen_sizemask(2, 1, 0);
1097
1098 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001099}
1100
1101#else
1102
pbrooka7812ae2008-11-17 14:43:54 +00001103static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001104{
aurel32fe75bcf2009-03-10 08:57:16 +00001105 if (!TCGV_EQUAL_I64(ret, arg))
pbrooka7812ae2008-11-17 14:43:54 +00001106 tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001107}
1108
pbrooka7812ae2008-11-17 14:43:54 +00001109static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +00001110{
pbrooka7812ae2008-11-17 14:43:54 +00001111 tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001112}
1113
Peter Maydell6bd4b082011-05-27 13:12:12 +01001114static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001115 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001116{
pbrooka7812ae2008-11-17 14:43:54 +00001117 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001118}
1119
Peter Maydell6bd4b082011-05-27 13:12:12 +01001120static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001121 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001122{
pbrooka7812ae2008-11-17 14:43:54 +00001123 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001124}
1125
Peter Maydell6bd4b082011-05-27 13:12:12 +01001126static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001127 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001128{
pbrooka7812ae2008-11-17 14:43:54 +00001129 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001130}
1131
Peter Maydell6bd4b082011-05-27 13:12:12 +01001132static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001133 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001134{
pbrooka7812ae2008-11-17 14:43:54 +00001135 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001136}
1137
Peter Maydell6bd4b082011-05-27 13:12:12 +01001138static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001139 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001140{
pbrooka7812ae2008-11-17 14:43:54 +00001141 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001142}
1143
Peter Maydell6bd4b082011-05-27 13:12:12 +01001144static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001145 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001146{
pbrooka7812ae2008-11-17 14:43:54 +00001147 tcg_gen_ldst_op_i64(INDEX_op_ld32s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001148}
1149
Peter Maydell6bd4b082011-05-27 13:12:12 +01001150static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001151{
pbrooka7812ae2008-11-17 14:43:54 +00001152 tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001153}
1154
Peter Maydell6bd4b082011-05-27 13:12:12 +01001155static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001156 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001157{
pbrooka7812ae2008-11-17 14:43:54 +00001158 tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001159}
1160
Peter Maydell6bd4b082011-05-27 13:12:12 +01001161static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001162 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001163{
pbrooka7812ae2008-11-17 14:43:54 +00001164 tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001165}
1166
Peter Maydell6bd4b082011-05-27 13:12:12 +01001167static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001168 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001169{
pbrooka7812ae2008-11-17 14:43:54 +00001170 tcg_gen_ldst_op_i64(INDEX_op_st32_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001171}
1172
Peter Maydell6bd4b082011-05-27 13:12:12 +01001173static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001174{
pbrooka7812ae2008-11-17 14:43:54 +00001175 tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001176}
1177
pbrooka7812ae2008-11-17 14:43:54 +00001178static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001179{
pbrooka7812ae2008-11-17 14:43:54 +00001180 tcg_gen_op3_i64(INDEX_op_add_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001181}
1182
pbrooka7812ae2008-11-17 14:43:54 +00001183static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001184{
pbrooka7812ae2008-11-17 14:43:54 +00001185 tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001186}
1187
pbrooka7812ae2008-11-17 14:43:54 +00001188static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001189{
aurel327fc81052009-03-10 19:37:39 +00001190 if (TCGV_EQUAL_I64(arg1, arg2)) {
1191 tcg_gen_mov_i64(ret, arg1);
1192 } else {
1193 tcg_gen_op3_i64(INDEX_op_and_i64, ret, arg1, arg2);
1194 }
bellardc896fe22008-02-01 10:05:41 +00001195}
1196
Richard Henderson42ce3e22012-09-21 17:18:10 -07001197static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001198{
Richard Henderson42ce3e22012-09-21 17:18:10 -07001199 TCGv_i64 t0;
1200 /* Some cases can be optimized here. */
1201 switch (arg2) {
1202 case 0:
1203 tcg_gen_movi_i64(ret, 0);
1204 return;
1205 case 0xffffffffffffffffull:
1206 tcg_gen_mov_i64(ret, arg1);
1207 return;
1208 case 0xffull:
1209 /* Don't recurse with tcg_gen_ext8u_i32. */
1210 if (TCG_TARGET_HAS_ext8u_i64) {
1211 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg1);
1212 return;
1213 }
1214 break;
1215 case 0xffffu:
1216 if (TCG_TARGET_HAS_ext16u_i64) {
1217 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg1);
1218 return;
1219 }
1220 break;
1221 case 0xffffffffull:
1222 if (TCG_TARGET_HAS_ext32u_i64) {
1223 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg1);
1224 return;
1225 }
1226 break;
1227 }
1228 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001229 tcg_gen_and_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001230 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001231}
1232
pbrooka7812ae2008-11-17 14:43:54 +00001233static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001234{
aurel327fc81052009-03-10 19:37:39 +00001235 if (TCGV_EQUAL_I64(arg1, arg2)) {
1236 tcg_gen_mov_i64(ret, arg1);
1237 } else {
1238 tcg_gen_op3_i64(INDEX_op_or_i64, ret, arg1, arg2);
1239 }
bellardc896fe22008-02-01 10:05:41 +00001240}
1241
pbrooka7812ae2008-11-17 14:43:54 +00001242static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001243{
Richard Hendersond81ada72012-09-21 17:18:11 -07001244 /* Some cases can be optimized here. */
1245 if (arg2 == -1) {
1246 tcg_gen_movi_i64(ret, -1);
1247 } else if (arg2 == 0) {
1248 tcg_gen_mov_i64(ret, arg1);
1249 } else {
1250 TCGv_i64 t0 = tcg_const_i64(arg2);
1251 tcg_gen_or_i64(ret, arg1, t0);
1252 tcg_temp_free_i64(t0);
1253 }
bellardc896fe22008-02-01 10:05:41 +00001254}
1255
pbrooka7812ae2008-11-17 14:43:54 +00001256static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001257{
aurel327fc81052009-03-10 19:37:39 +00001258 if (TCGV_EQUAL_I64(arg1, arg2)) {
1259 tcg_gen_movi_i64(ret, 0);
1260 } else {
1261 tcg_gen_op3_i64(INDEX_op_xor_i64, ret, arg1, arg2);
1262 }
bellardc896fe22008-02-01 10:05:41 +00001263}
1264
pbrooka7812ae2008-11-17 14:43:54 +00001265static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001266{
Richard Henderson6f3bb332012-09-21 17:18:12 -07001267 /* Some cases can be optimized here. */
1268 if (arg2 == 0) {
1269 tcg_gen_mov_i64(ret, arg1);
1270 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i64) {
1271 /* Don't recurse with tcg_gen_not_i64. */
1272 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg1);
1273 } else {
1274 TCGv_i64 t0 = tcg_const_i64(arg2);
1275 tcg_gen_xor_i64(ret, arg1, t0);
1276 tcg_temp_free_i64(t0);
1277 }
bellardc896fe22008-02-01 10:05:41 +00001278}
1279
pbrooka7812ae2008-11-17 14:43:54 +00001280static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001281{
pbrooka7812ae2008-11-17 14:43:54 +00001282 tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001283}
1284
pbrooka7812ae2008-11-17 14:43:54 +00001285static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001286{
bellard34151a22008-05-22 13:25:14 +00001287 if (arg2 == 0) {
1288 tcg_gen_mov_i64(ret, arg1);
1289 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001290 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001291 tcg_gen_shl_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001292 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001293 }
bellardc896fe22008-02-01 10:05:41 +00001294}
1295
pbrooka7812ae2008-11-17 14:43:54 +00001296static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001297{
pbrooka7812ae2008-11-17 14:43:54 +00001298 tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001299}
1300
pbrooka7812ae2008-11-17 14:43:54 +00001301static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001302{
bellard34151a22008-05-22 13:25:14 +00001303 if (arg2 == 0) {
1304 tcg_gen_mov_i64(ret, arg1);
1305 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001306 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001307 tcg_gen_shr_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001308 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001309 }
bellardc896fe22008-02-01 10:05:41 +00001310}
1311
pbrooka7812ae2008-11-17 14:43:54 +00001312static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001313{
pbrooka7812ae2008-11-17 14:43:54 +00001314 tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001315}
1316
pbrooka7812ae2008-11-17 14:43:54 +00001317static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001318{
bellard34151a22008-05-22 13:25:14 +00001319 if (arg2 == 0) {
1320 tcg_gen_mov_i64(ret, arg1);
1321 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001322 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001323 tcg_gen_sar_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001324 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001325 }
bellardc896fe22008-02-01 10:05:41 +00001326}
1327
Richard Henderson8a56e842010-03-19 11:26:05 -07001328static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1329 TCGv_i64 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +00001330{
Richard Henderson0aed2572012-09-24 14:21:40 -07001331 if (cond == TCG_COND_ALWAYS) {
1332 tcg_gen_br(label_index);
1333 } else if (cond != TCG_COND_NEVER) {
1334 tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
1335 }
bellardc896fe22008-02-01 10:05:41 +00001336}
1337
Richard Henderson8a56e842010-03-19 11:26:05 -07001338static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +01001339 TCGv_i64 arg1, TCGv_i64 arg2)
1340{
Richard Henderson0aed2572012-09-24 14:21:40 -07001341 if (cond == TCG_COND_ALWAYS) {
1342 tcg_gen_movi_i64(ret, 1);
1343 } else if (cond == TCG_COND_NEVER) {
1344 tcg_gen_movi_i64(ret, 0);
1345 } else {
1346 tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
1347 }
Aurelien Jarno5105c552010-02-08 12:10:15 +01001348}
1349
pbrooka7812ae2008-11-17 14:43:54 +00001350static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001351{
pbrooka7812ae2008-11-17 14:43:54 +00001352 tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001353}
1354
pbrooka7812ae2008-11-17 14:43:54 +00001355static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001356{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001357 if (TCG_TARGET_HAS_div_i64) {
1358 tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
1359 } else if (TCG_TARGET_HAS_div2_i64) {
1360 TCGv_i64 t0 = tcg_temp_new_i64();
1361 tcg_gen_sari_i64(t0, arg1, 63);
1362 tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
1363 tcg_temp_free_i64(t0);
1364 } else {
1365 int sizemask = 0;
1366 /* Return value and both arguments are 64-bit and signed. */
1367 sizemask |= tcg_gen_sizemask(0, 1, 1);
1368 sizemask |= tcg_gen_sizemask(1, 1, 1);
1369 sizemask |= tcg_gen_sizemask(2, 1, 1);
1370 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
1371 }
bellardc896fe22008-02-01 10:05:41 +00001372}
1373
pbrooka7812ae2008-11-17 14:43:54 +00001374static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001375{
Richard Hendersonca675f42013-03-11 22:41:47 -07001376 if (TCG_TARGET_HAS_rem_i64) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001377 tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
Richard Hendersonca675f42013-03-11 22:41:47 -07001378 } else if (TCG_TARGET_HAS_div_i64) {
1379 TCGv_i64 t0 = tcg_temp_new_i64();
1380 tcg_gen_op3_i64(INDEX_op_div_i64, t0, arg1, arg2);
1381 tcg_gen_mul_i64(t0, t0, arg2);
1382 tcg_gen_sub_i64(ret, arg1, t0);
1383 tcg_temp_free_i64(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001384 } else if (TCG_TARGET_HAS_div2_i64) {
1385 TCGv_i64 t0 = tcg_temp_new_i64();
1386 tcg_gen_sari_i64(t0, arg1, 63);
1387 tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
1388 tcg_temp_free_i64(t0);
1389 } else {
1390 int sizemask = 0;
1391 /* Return value and both arguments are 64-bit and signed. */
1392 sizemask |= tcg_gen_sizemask(0, 1, 1);
1393 sizemask |= tcg_gen_sizemask(1, 1, 1);
1394 sizemask |= tcg_gen_sizemask(2, 1, 1);
1395 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
1396 }
bellardc896fe22008-02-01 10:05:41 +00001397}
1398
pbrooka7812ae2008-11-17 14:43:54 +00001399static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001400{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001401 if (TCG_TARGET_HAS_div_i64) {
1402 tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
1403 } else if (TCG_TARGET_HAS_div2_i64) {
1404 TCGv_i64 t0 = tcg_temp_new_i64();
1405 tcg_gen_movi_i64(t0, 0);
1406 tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
1407 tcg_temp_free_i64(t0);
1408 } else {
1409 int sizemask = 0;
1410 /* Return value and both arguments are 64-bit and unsigned. */
1411 sizemask |= tcg_gen_sizemask(0, 1, 0);
1412 sizemask |= tcg_gen_sizemask(1, 1, 0);
1413 sizemask |= tcg_gen_sizemask(2, 1, 0);
1414 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
1415 }
bellardc896fe22008-02-01 10:05:41 +00001416}
1417
pbrooka7812ae2008-11-17 14:43:54 +00001418static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001419{
Richard Hendersonca675f42013-03-11 22:41:47 -07001420 if (TCG_TARGET_HAS_rem_i64) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001421 tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
Richard Hendersonca675f42013-03-11 22:41:47 -07001422 } else if (TCG_TARGET_HAS_div_i64) {
1423 TCGv_i64 t0 = tcg_temp_new_i64();
1424 tcg_gen_op3_i64(INDEX_op_divu_i64, t0, arg1, arg2);
1425 tcg_gen_mul_i64(t0, t0, arg2);
1426 tcg_gen_sub_i64(ret, arg1, t0);
1427 tcg_temp_free_i64(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001428 } else if (TCG_TARGET_HAS_div2_i64) {
1429 TCGv_i64 t0 = tcg_temp_new_i64();
1430 tcg_gen_movi_i64(t0, 0);
1431 tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
1432 tcg_temp_free_i64(t0);
1433 } else {
1434 int sizemask = 0;
1435 /* Return value and both arguments are 64-bit and unsigned. */
1436 sizemask |= tcg_gen_sizemask(0, 1, 0);
1437 sizemask |= tcg_gen_sizemask(1, 1, 0);
1438 sizemask |= tcg_gen_sizemask(2, 1, 0);
1439 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
1440 }
bellardc896fe22008-02-01 10:05:41 +00001441}
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001442#endif /* TCG_TARGET_REG_BITS == 32 */
bellardc896fe22008-02-01 10:05:41 +00001443
pbrooka7812ae2008-11-17 14:43:54 +00001444static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3263597062008-11-02 08:22:54 +00001445{
1446 /* some cases can be optimized here */
1447 if (arg2 == 0) {
1448 tcg_gen_mov_i64(ret, arg1);
1449 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001450 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel3263597062008-11-02 08:22:54 +00001451 tcg_gen_add_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001452 tcg_temp_free_i64(t0);
aurel3263597062008-11-02 08:22:54 +00001453 }
1454}
1455
pbrooka7812ae2008-11-17 14:43:54 +00001456static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
aurel3200457342008-11-02 08:23:04 +00001457{
pbrooka7812ae2008-11-17 14:43:54 +00001458 TCGv_i64 t0 = tcg_const_i64(arg1);
aurel3200457342008-11-02 08:23:04 +00001459 tcg_gen_sub_i64(ret, t0, arg2);
pbrooka7812ae2008-11-17 14:43:54 +00001460 tcg_temp_free_i64(t0);
aurel3200457342008-11-02 08:23:04 +00001461}
1462
pbrooka7812ae2008-11-17 14:43:54 +00001463static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3263597062008-11-02 08:22:54 +00001464{
1465 /* some cases can be optimized here */
1466 if (arg2 == 0) {
1467 tcg_gen_mov_i64(ret, arg1);
1468 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001469 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel3263597062008-11-02 08:22:54 +00001470 tcg_gen_sub_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001471 tcg_temp_free_i64(t0);
aurel3263597062008-11-02 08:22:54 +00001472 }
1473}
Richard Henderson8a56e842010-03-19 11:26:05 -07001474static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
1475 int64_t arg2, int label_index)
aurel32f02bb952008-11-03 07:08:26 +00001476{
Richard Henderson0aed2572012-09-24 14:21:40 -07001477 if (cond == TCG_COND_ALWAYS) {
1478 tcg_gen_br(label_index);
1479 } else if (cond != TCG_COND_NEVER) {
1480 TCGv_i64 t0 = tcg_const_i64(arg2);
1481 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
1482 tcg_temp_free_i64(t0);
1483 }
aurel32f02bb952008-11-03 07:08:26 +00001484}
1485
Richard Henderson8a56e842010-03-19 11:26:05 -07001486static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
1487 TCGv_i64 arg1, int64_t arg2)
Aurelien Jarno5105c552010-02-08 12:10:15 +01001488{
1489 TCGv_i64 t0 = tcg_const_i64(arg2);
1490 tcg_gen_setcond_i64(cond, ret, arg1, t0);
1491 tcg_temp_free_i64(t0);
1492}
1493
pbrooka7812ae2008-11-17 14:43:54 +00001494static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel32f02bb952008-11-03 07:08:26 +00001495{
pbrooka7812ae2008-11-17 14:43:54 +00001496 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel32f02bb952008-11-03 07:08:26 +00001497 tcg_gen_mul_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001498 tcg_temp_free_i64(t0);
aurel32f02bb952008-11-03 07:08:26 +00001499}
1500
aurel3263597062008-11-02 08:22:54 +00001501
bellardc896fe22008-02-01 10:05:41 +00001502/***************************************/
1503/* optional operations */
1504
pbrooka7812ae2008-11-17 14:43:54 +00001505static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001506{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001507 if (TCG_TARGET_HAS_ext8s_i32) {
1508 tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
1509 } else {
1510 tcg_gen_shli_i32(ret, arg, 24);
1511 tcg_gen_sari_i32(ret, ret, 24);
1512 }
bellardc896fe22008-02-01 10:05:41 +00001513}
1514
pbrooka7812ae2008-11-17 14:43:54 +00001515static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001516{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001517 if (TCG_TARGET_HAS_ext16s_i32) {
1518 tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
1519 } else {
1520 tcg_gen_shli_i32(ret, arg, 16);
1521 tcg_gen_sari_i32(ret, ret, 16);
1522 }
bellardc896fe22008-02-01 10:05:41 +00001523}
1524
pbrooka7812ae2008-11-17 14:43:54 +00001525static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook86831432008-05-11 12:22:01 +00001526{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001527 if (TCG_TARGET_HAS_ext8u_i32) {
1528 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
1529 } else {
1530 tcg_gen_andi_i32(ret, arg, 0xffu);
1531 }
pbrook86831432008-05-11 12:22:01 +00001532}
1533
pbrooka7812ae2008-11-17 14:43:54 +00001534static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook86831432008-05-11 12:22:01 +00001535{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001536 if (TCG_TARGET_HAS_ext16u_i32) {
1537 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
1538 } else {
1539 tcg_gen_andi_i32(ret, arg, 0xffffu);
1540 }
pbrook86831432008-05-11 12:22:01 +00001541}
1542
bellardc896fe22008-02-01 10:05:41 +00001543/* Note: we assume the two high bytes are set to zero */
pbrooka7812ae2008-11-17 14:43:54 +00001544static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001545{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001546 if (TCG_TARGET_HAS_bswap16_i32) {
1547 tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
1548 } else {
1549 TCGv_i32 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001550
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001551 tcg_gen_ext8u_i32(t0, arg);
1552 tcg_gen_shli_i32(t0, t0, 8);
1553 tcg_gen_shri_i32(ret, arg, 8);
1554 tcg_gen_or_i32(ret, ret, t0);
1555 tcg_temp_free_i32(t0);
1556 }
bellardc896fe22008-02-01 10:05:41 +00001557}
1558
aurel3266896cb2009-03-13 09:34:48 +00001559static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001560{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001561 if (TCG_TARGET_HAS_bswap32_i32) {
1562 tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
1563 } else {
1564 TCGv_i32 t0, t1;
1565 t0 = tcg_temp_new_i32();
1566 t1 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001567
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001568 tcg_gen_shli_i32(t0, arg, 24);
bellardc896fe22008-02-01 10:05:41 +00001569
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001570 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1571 tcg_gen_shli_i32(t1, t1, 8);
1572 tcg_gen_or_i32(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001573
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001574 tcg_gen_shri_i32(t1, arg, 8);
1575 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1576 tcg_gen_or_i32(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001577
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001578 tcg_gen_shri_i32(t1, arg, 24);
1579 tcg_gen_or_i32(ret, t0, t1);
1580 tcg_temp_free_i32(t0);
1581 tcg_temp_free_i32(t1);
1582 }
bellardc896fe22008-02-01 10:05:41 +00001583}
1584
1585#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001586static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001587{
pbrooka7812ae2008-11-17 14:43:54 +00001588 tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1589 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001590}
1591
pbrooka7812ae2008-11-17 14:43:54 +00001592static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001593{
pbrooka7812ae2008-11-17 14:43:54 +00001594 tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1595 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001596}
1597
pbrooka7812ae2008-11-17 14:43:54 +00001598static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001599{
pbrooka7812ae2008-11-17 14:43:54 +00001600 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1601 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001602}
1603
pbrooka7812ae2008-11-17 14:43:54 +00001604static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001605{
pbrooka7812ae2008-11-17 14:43:54 +00001606 tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001607 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1608}
1609
pbrooka7812ae2008-11-17 14:43:54 +00001610static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001611{
pbrooka7812ae2008-11-17 14:43:54 +00001612 tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001613 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1614}
1615
pbrooka7812ae2008-11-17 14:43:54 +00001616static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001617{
pbrooka7812ae2008-11-17 14:43:54 +00001618 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001619 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1620}
1621
pbrooka7812ae2008-11-17 14:43:54 +00001622static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001623{
pbrooka7812ae2008-11-17 14:43:54 +00001624 tcg_gen_mov_i32(ret, TCGV_LOW(arg));
bellardc896fe22008-02-01 10:05:41 +00001625}
1626
pbrooka7812ae2008-11-17 14:43:54 +00001627static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001628{
pbrooka7812ae2008-11-17 14:43:54 +00001629 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
pbrookac56dd42008-02-03 19:56:33 +00001630 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001631}
1632
pbrooka7812ae2008-11-17 14:43:54 +00001633static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001634{
pbrooka7812ae2008-11-17 14:43:54 +00001635 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1636 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001637}
1638
aurel329a5c57f2009-03-13 09:35:12 +00001639/* Note: we assume the six high bytes are set to zero */
1640static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1641{
1642 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1643 tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1644}
1645
1646/* Note: we assume the four high bytes are set to zero */
1647static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1648{
1649 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1650 tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1651}
1652
aurel3266896cb2009-03-13 09:34:48 +00001653static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001654{
pbrooka7812ae2008-11-17 14:43:54 +00001655 TCGv_i32 t0, t1;
1656 t0 = tcg_temp_new_i32();
1657 t1 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001658
aurel3266896cb2009-03-13 09:34:48 +00001659 tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
1660 tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
pbrooka7812ae2008-11-17 14:43:54 +00001661 tcg_gen_mov_i32(TCGV_LOW(ret), t1);
pbrookac56dd42008-02-03 19:56:33 +00001662 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
pbrooka7812ae2008-11-17 14:43:54 +00001663 tcg_temp_free_i32(t0);
1664 tcg_temp_free_i32(t1);
bellardc896fe22008-02-01 10:05:41 +00001665}
1666#else
1667
pbrooka7812ae2008-11-17 14:43:54 +00001668static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001669{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001670 if (TCG_TARGET_HAS_ext8s_i64) {
1671 tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
1672 } else {
1673 tcg_gen_shli_i64(ret, arg, 56);
1674 tcg_gen_sari_i64(ret, ret, 56);
1675 }
bellardc896fe22008-02-01 10:05:41 +00001676}
1677
pbrooka7812ae2008-11-17 14:43:54 +00001678static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001679{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001680 if (TCG_TARGET_HAS_ext16s_i64) {
1681 tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
1682 } else {
1683 tcg_gen_shli_i64(ret, arg, 48);
1684 tcg_gen_sari_i64(ret, ret, 48);
1685 }
bellardc896fe22008-02-01 10:05:41 +00001686}
1687
pbrooka7812ae2008-11-17 14:43:54 +00001688static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001689{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001690 if (TCG_TARGET_HAS_ext32s_i64) {
1691 tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
1692 } else {
1693 tcg_gen_shli_i64(ret, arg, 32);
1694 tcg_gen_sari_i64(ret, ret, 32);
1695 }
bellardc896fe22008-02-01 10:05:41 +00001696}
1697
pbrooka7812ae2008-11-17 14:43:54 +00001698static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001699{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001700 if (TCG_TARGET_HAS_ext8u_i64) {
1701 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
1702 } else {
1703 tcg_gen_andi_i64(ret, arg, 0xffu);
1704 }
pbrook86831432008-05-11 12:22:01 +00001705}
1706
pbrooka7812ae2008-11-17 14:43:54 +00001707static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001708{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001709 if (TCG_TARGET_HAS_ext16u_i64) {
1710 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
1711 } else {
1712 tcg_gen_andi_i64(ret, arg, 0xffffu);
1713 }
pbrook86831432008-05-11 12:22:01 +00001714}
1715
pbrooka7812ae2008-11-17 14:43:54 +00001716static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001717{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001718 if (TCG_TARGET_HAS_ext32u_i64) {
1719 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
1720 } else {
1721 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1722 }
pbrook86831432008-05-11 12:22:01 +00001723}
1724
bellardc896fe22008-02-01 10:05:41 +00001725/* Note: we assume the target supports move between 32 and 64 bit
pbrookac56dd42008-02-03 19:56:33 +00001726 registers. This will probably break MIPS64 targets. */
pbrooka7812ae2008-11-17 14:43:54 +00001727static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001728{
pbrooka7812ae2008-11-17 14:43:54 +00001729 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
bellardc896fe22008-02-01 10:05:41 +00001730}
1731
1732/* Note: we assume the target supports move between 32 and 64 bit
1733 registers */
pbrooka7812ae2008-11-17 14:43:54 +00001734static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001735{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001736 tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
bellardc896fe22008-02-01 10:05:41 +00001737}
1738
1739/* Note: we assume the target supports move between 32 and 64 bit
1740 registers */
pbrooka7812ae2008-11-17 14:43:54 +00001741static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001742{
pbrooka7812ae2008-11-17 14:43:54 +00001743 tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
bellardc896fe22008-02-01 10:05:41 +00001744}
1745
aurel329a5c57f2009-03-13 09:35:12 +00001746/* Note: we assume the six high bytes are set to zero */
1747static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1748{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001749 if (TCG_TARGET_HAS_bswap16_i64) {
1750 tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
1751 } else {
1752 TCGv_i64 t0 = tcg_temp_new_i64();
aurel329a5c57f2009-03-13 09:35:12 +00001753
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001754 tcg_gen_ext8u_i64(t0, arg);
1755 tcg_gen_shli_i64(t0, t0, 8);
1756 tcg_gen_shri_i64(ret, arg, 8);
1757 tcg_gen_or_i64(ret, ret, t0);
1758 tcg_temp_free_i64(t0);
1759 }
aurel329a5c57f2009-03-13 09:35:12 +00001760}
1761
1762/* Note: we assume the four high bytes are set to zero */
1763static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1764{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001765 if (TCG_TARGET_HAS_bswap32_i64) {
1766 tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
1767 } else {
1768 TCGv_i64 t0, t1;
1769 t0 = tcg_temp_new_i64();
1770 t1 = tcg_temp_new_i64();
aurel329a5c57f2009-03-13 09:35:12 +00001771
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001772 tcg_gen_shli_i64(t0, arg, 24);
1773 tcg_gen_ext32u_i64(t0, t0);
aurel329a5c57f2009-03-13 09:35:12 +00001774
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001775 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1776 tcg_gen_shli_i64(t1, t1, 8);
1777 tcg_gen_or_i64(t0, t0, t1);
aurel329a5c57f2009-03-13 09:35:12 +00001778
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001779 tcg_gen_shri_i64(t1, arg, 8);
1780 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1781 tcg_gen_or_i64(t0, t0, t1);
aurel329a5c57f2009-03-13 09:35:12 +00001782
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001783 tcg_gen_shri_i64(t1, arg, 24);
1784 tcg_gen_or_i64(ret, t0, t1);
1785 tcg_temp_free_i64(t0);
1786 tcg_temp_free_i64(t1);
1787 }
aurel329a5c57f2009-03-13 09:35:12 +00001788}
1789
aurel3266896cb2009-03-13 09:34:48 +00001790static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001791{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001792 if (TCG_TARGET_HAS_bswap64_i64) {
1793 tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
1794 } else {
1795 TCGv_i64 t0 = tcg_temp_new_i64();
1796 TCGv_i64 t1 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001797
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001798 tcg_gen_shli_i64(t0, arg, 56);
bellardc896fe22008-02-01 10:05:41 +00001799
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001800 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1801 tcg_gen_shli_i64(t1, t1, 40);
1802 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001803
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001804 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1805 tcg_gen_shli_i64(t1, t1, 24);
1806 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001807
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001808 tcg_gen_andi_i64(t1, arg, 0xff000000);
1809 tcg_gen_shli_i64(t1, t1, 8);
1810 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001811
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001812 tcg_gen_shri_i64(t1, arg, 8);
1813 tcg_gen_andi_i64(t1, t1, 0xff000000);
1814 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001815
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001816 tcg_gen_shri_i64(t1, arg, 24);
1817 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1818 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001819
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001820 tcg_gen_shri_i64(t1, arg, 40);
1821 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1822 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001823
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001824 tcg_gen_shri_i64(t1, arg, 56);
1825 tcg_gen_or_i64(ret, t0, t1);
1826 tcg_temp_free_i64(t0);
1827 tcg_temp_free_i64(t1);
1828 }
bellardc896fe22008-02-01 10:05:41 +00001829}
1830
1831#endif
1832
pbrooka7812ae2008-11-17 14:43:54 +00001833static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook390efc52008-05-11 14:35:37 +00001834{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001835 if (TCG_TARGET_HAS_neg_i32) {
1836 tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
1837 } else {
1838 TCGv_i32 t0 = tcg_const_i32(0);
1839 tcg_gen_sub_i32(ret, t0, arg);
1840 tcg_temp_free_i32(t0);
1841 }
pbrook390efc52008-05-11 14:35:37 +00001842}
1843
pbrooka7812ae2008-11-17 14:43:54 +00001844static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook390efc52008-05-11 14:35:37 +00001845{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001846 if (TCG_TARGET_HAS_neg_i64) {
1847 tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
1848 } else {
1849 TCGv_i64 t0 = tcg_const_i64(0);
1850 tcg_gen_sub_i64(ret, t0, arg);
1851 tcg_temp_free_i64(t0);
1852 }
pbrook390efc52008-05-11 14:35:37 +00001853}
1854
pbrooka7812ae2008-11-17 14:43:54 +00001855static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
bellard0b6ce4c2008-05-17 12:40:44 +00001856{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001857 if (TCG_TARGET_HAS_not_i32) {
1858 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
1859 } else {
1860 tcg_gen_xori_i32(ret, arg, -1);
1861 }
bellard0b6ce4c2008-05-17 12:40:44 +00001862}
1863
pbrooka7812ae2008-11-17 14:43:54 +00001864static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
bellard0b6ce4c2008-05-17 12:40:44 +00001865{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001866#if TCG_TARGET_REG_BITS == 64
1867 if (TCG_TARGET_HAS_not_i64) {
1868 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
1869 } else {
1870 tcg_gen_xori_i64(ret, arg, -1);
1871 }
1872#else
Richard Hendersona10f9f42010-03-19 12:44:47 -07001873 tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1874 tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
aurel32d2604282009-03-09 22:35:13 +00001875#endif
bellard0b6ce4c2008-05-17 12:40:44 +00001876}
bellard5ff9d6a2008-02-04 00:37:54 +00001877
pbrooka7812ae2008-11-17 14:43:54 +00001878static inline void tcg_gen_discard_i32(TCGv_i32 arg)
bellard5ff9d6a2008-02-04 00:37:54 +00001879{
pbrooka7812ae2008-11-17 14:43:54 +00001880 tcg_gen_op1_i32(INDEX_op_discard, arg);
bellard5ff9d6a2008-02-04 00:37:54 +00001881}
1882
pbrooka7812ae2008-11-17 14:43:54 +00001883static inline void tcg_gen_discard_i64(TCGv_i64 arg)
bellard5ff9d6a2008-02-04 00:37:54 +00001884{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001885#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001886 tcg_gen_discard_i32(TCGV_LOW(arg));
bellard5ff9d6a2008-02-04 00:37:54 +00001887 tcg_gen_discard_i32(TCGV_HIGH(arg));
bellard5ff9d6a2008-02-04 00:37:54 +00001888#else
pbrooka7812ae2008-11-17 14:43:54 +00001889 tcg_gen_op1_i64(INDEX_op_discard, arg);
bellard5ff9d6a2008-02-04 00:37:54 +00001890#endif
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001891}
bellard5ff9d6a2008-02-04 00:37:54 +00001892
pbrooka7812ae2008-11-17 14:43:54 +00001893static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001894{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001895 if (TCG_TARGET_HAS_andc_i32) {
1896 tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
1897 } else {
1898 TCGv_i32 t0 = tcg_temp_new_i32();
1899 tcg_gen_not_i32(t0, arg2);
1900 tcg_gen_and_i32(ret, arg1, t0);
1901 tcg_temp_free_i32(t0);
1902 }
aurel32f24cb332008-10-21 11:28:59 +00001903}
1904
pbrooka7812ae2008-11-17 14:43:54 +00001905static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001906{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001907#if TCG_TARGET_REG_BITS == 64
1908 if (TCG_TARGET_HAS_andc_i64) {
1909 tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
1910 } else {
1911 TCGv_i64 t0 = tcg_temp_new_i64();
1912 tcg_gen_not_i64(t0, arg2);
1913 tcg_gen_and_i64(ret, arg1, t0);
1914 tcg_temp_free_i64(t0);
1915 }
1916#else
Richard Henderson241cbed2010-02-16 14:10:13 -08001917 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1918 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
Richard Henderson241cbed2010-02-16 14:10:13 -08001919#endif
aurel32f24cb332008-10-21 11:28:59 +00001920}
1921
pbrooka7812ae2008-11-17 14:43:54 +00001922static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001923{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001924 if (TCG_TARGET_HAS_eqv_i32) {
1925 tcg_gen_op3_i32(INDEX_op_eqv_i32, ret, arg1, arg2);
1926 } else {
1927 tcg_gen_xor_i32(ret, arg1, arg2);
1928 tcg_gen_not_i32(ret, ret);
1929 }
aurel32f24cb332008-10-21 11:28:59 +00001930}
1931
pbrooka7812ae2008-11-17 14:43:54 +00001932static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001933{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001934#if TCG_TARGET_REG_BITS == 64
1935 if (TCG_TARGET_HAS_eqv_i64) {
1936 tcg_gen_op3_i64(INDEX_op_eqv_i64, ret, arg1, arg2);
1937 } else {
1938 tcg_gen_xor_i64(ret, arg1, arg2);
1939 tcg_gen_not_i64(ret, ret);
1940 }
1941#else
Richard Henderson8d625cf2010-03-19 13:02:02 -07001942 tcg_gen_eqv_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1943 tcg_gen_eqv_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
Richard Henderson8d625cf2010-03-19 13:02:02 -07001944#endif
aurel32f24cb332008-10-21 11:28:59 +00001945}
1946
pbrooka7812ae2008-11-17 14:43:54 +00001947static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001948{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001949 if (TCG_TARGET_HAS_nand_i32) {
1950 tcg_gen_op3_i32(INDEX_op_nand_i32, ret, arg1, arg2);
1951 } else {
1952 tcg_gen_and_i32(ret, arg1, arg2);
1953 tcg_gen_not_i32(ret, ret);
1954 }
aurel32f24cb332008-10-21 11:28:59 +00001955}
1956
pbrooka7812ae2008-11-17 14:43:54 +00001957static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001958{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001959#if TCG_TARGET_REG_BITS == 64
1960 if (TCG_TARGET_HAS_nand_i64) {
1961 tcg_gen_op3_i64(INDEX_op_nand_i64, ret, arg1, arg2);
1962 } else {
1963 tcg_gen_and_i64(ret, arg1, arg2);
1964 tcg_gen_not_i64(ret, ret);
1965 }
1966#else
Richard Henderson9940a962010-03-19 13:03:58 -07001967 tcg_gen_nand_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1968 tcg_gen_nand_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
Richard Henderson9940a962010-03-19 13:03:58 -07001969#endif
aurel32f24cb332008-10-21 11:28:59 +00001970}
1971
pbrooka7812ae2008-11-17 14:43:54 +00001972static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001973{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001974 if (TCG_TARGET_HAS_nor_i32) {
1975 tcg_gen_op3_i32(INDEX_op_nor_i32, ret, arg1, arg2);
1976 } else {
1977 tcg_gen_or_i32(ret, arg1, arg2);
1978 tcg_gen_not_i32(ret, ret);
1979 }
aurel32f24cb332008-10-21 11:28:59 +00001980}
1981
pbrooka7812ae2008-11-17 14:43:54 +00001982static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001983{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001984#if TCG_TARGET_REG_BITS == 64
1985 if (TCG_TARGET_HAS_nor_i64) {
1986 tcg_gen_op3_i64(INDEX_op_nor_i64, ret, arg1, arg2);
1987 } else {
1988 tcg_gen_or_i64(ret, arg1, arg2);
1989 tcg_gen_not_i64(ret, ret);
1990 }
1991#else
Richard Henderson32d98fb2010-03-19 13:08:56 -07001992 tcg_gen_nor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1993 tcg_gen_nor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
Richard Henderson32d98fb2010-03-19 13:08:56 -07001994#endif
aurel32f24cb332008-10-21 11:28:59 +00001995}
1996
pbrooka7812ae2008-11-17 14:43:54 +00001997static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001998{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001999 if (TCG_TARGET_HAS_orc_i32) {
2000 tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
2001 } else {
2002 TCGv_i32 t0 = tcg_temp_new_i32();
2003 tcg_gen_not_i32(t0, arg2);
2004 tcg_gen_or_i32(ret, arg1, t0);
2005 tcg_temp_free_i32(t0);
2006 }
aurel32f24cb332008-10-21 11:28:59 +00002007}
2008
pbrooka7812ae2008-11-17 14:43:54 +00002009static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00002010{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002011#if TCG_TARGET_REG_BITS == 64
2012 if (TCG_TARGET_HAS_orc_i64) {
2013 tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
2014 } else {
2015 TCGv_i64 t0 = tcg_temp_new_i64();
2016 tcg_gen_not_i64(t0, arg2);
2017 tcg_gen_or_i64(ret, arg1, t0);
2018 tcg_temp_free_i64(t0);
2019 }
2020#else
Richard Henderson791d1262010-02-16 14:15:28 -08002021 tcg_gen_orc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
2022 tcg_gen_orc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
Richard Henderson791d1262010-02-16 14:15:28 -08002023#endif
aurel32f24cb332008-10-21 11:28:59 +00002024}
2025
pbrooka7812ae2008-11-17 14:43:54 +00002026static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3215824572008-11-03 07:08:36 +00002027{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002028 if (TCG_TARGET_HAS_rot_i32) {
2029 tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
2030 } else {
2031 TCGv_i32 t0, t1;
aurel3215824572008-11-03 07:08:36 +00002032
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002033 t0 = tcg_temp_new_i32();
2034 t1 = tcg_temp_new_i32();
2035 tcg_gen_shl_i32(t0, arg1, arg2);
2036 tcg_gen_subfi_i32(t1, 32, arg2);
2037 tcg_gen_shr_i32(t1, arg1, t1);
2038 tcg_gen_or_i32(ret, t0, t1);
2039 tcg_temp_free_i32(t0);
2040 tcg_temp_free_i32(t1);
2041 }
aurel3215824572008-11-03 07:08:36 +00002042}
2043
pbrooka7812ae2008-11-17 14:43:54 +00002044static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel3215824572008-11-03 07:08:36 +00002045{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002046 if (TCG_TARGET_HAS_rot_i64) {
2047 tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
2048 } else {
2049 TCGv_i64 t0, t1;
2050 t0 = tcg_temp_new_i64();
2051 t1 = tcg_temp_new_i64();
2052 tcg_gen_shl_i64(t0, arg1, arg2);
2053 tcg_gen_subfi_i64(t1, 64, arg2);
2054 tcg_gen_shr_i64(t1, arg1, t1);
2055 tcg_gen_or_i64(ret, t0, t1);
2056 tcg_temp_free_i64(t0);
2057 tcg_temp_free_i64(t1);
2058 }
aurel3215824572008-11-03 07:08:36 +00002059}
2060
pbrooka7812ae2008-11-17 14:43:54 +00002061static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
aurel3215824572008-11-03 07:08:36 +00002062{
2063 /* some cases can be optimized here */
2064 if (arg2 == 0) {
2065 tcg_gen_mov_i32(ret, arg1);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002066 } else if (TCG_TARGET_HAS_rot_i32) {
aurel32d42f1832009-03-09 18:50:53 +00002067 TCGv_i32 t0 = tcg_const_i32(arg2);
2068 tcg_gen_rotl_i32(ret, arg1, t0);
2069 tcg_temp_free_i32(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002070 } else {
pbrooka7812ae2008-11-17 14:43:54 +00002071 TCGv_i32 t0, t1;
2072 t0 = tcg_temp_new_i32();
2073 t1 = tcg_temp_new_i32();
aurel3215824572008-11-03 07:08:36 +00002074 tcg_gen_shli_i32(t0, arg1, arg2);
2075 tcg_gen_shri_i32(t1, arg1, 32 - arg2);
2076 tcg_gen_or_i32(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00002077 tcg_temp_free_i32(t0);
2078 tcg_temp_free_i32(t1);
aurel3215824572008-11-03 07:08:36 +00002079 }
2080}
2081
pbrooka7812ae2008-11-17 14:43:54 +00002082static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3215824572008-11-03 07:08:36 +00002083{
2084 /* some cases can be optimized here */
2085 if (arg2 == 0) {
2086 tcg_gen_mov_i64(ret, arg1);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002087 } else if (TCG_TARGET_HAS_rot_i64) {
aurel32d42f1832009-03-09 18:50:53 +00002088 TCGv_i64 t0 = tcg_const_i64(arg2);
2089 tcg_gen_rotl_i64(ret, arg1, t0);
2090 tcg_temp_free_i64(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002091 } else {
pbrooka7812ae2008-11-17 14:43:54 +00002092 TCGv_i64 t0, t1;
2093 t0 = tcg_temp_new_i64();
2094 t1 = tcg_temp_new_i64();
aurel3215824572008-11-03 07:08:36 +00002095 tcg_gen_shli_i64(t0, arg1, arg2);
2096 tcg_gen_shri_i64(t1, arg1, 64 - arg2);
2097 tcg_gen_or_i64(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00002098 tcg_temp_free_i64(t0);
2099 tcg_temp_free_i64(t1);
aurel3215824572008-11-03 07:08:36 +00002100 }
2101}
2102
pbrooka7812ae2008-11-17 14:43:54 +00002103static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3215824572008-11-03 07:08:36 +00002104{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002105 if (TCG_TARGET_HAS_rot_i32) {
2106 tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
2107 } else {
2108 TCGv_i32 t0, t1;
aurel3215824572008-11-03 07:08:36 +00002109
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002110 t0 = tcg_temp_new_i32();
2111 t1 = tcg_temp_new_i32();
2112 tcg_gen_shr_i32(t0, arg1, arg2);
2113 tcg_gen_subfi_i32(t1, 32, arg2);
2114 tcg_gen_shl_i32(t1, arg1, t1);
2115 tcg_gen_or_i32(ret, t0, t1);
2116 tcg_temp_free_i32(t0);
2117 tcg_temp_free_i32(t1);
2118 }
aurel3215824572008-11-03 07:08:36 +00002119}
2120
pbrooka7812ae2008-11-17 14:43:54 +00002121static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel3215824572008-11-03 07:08:36 +00002122{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002123 if (TCG_TARGET_HAS_rot_i64) {
2124 tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
2125 } else {
2126 TCGv_i64 t0, t1;
2127 t0 = tcg_temp_new_i64();
2128 t1 = tcg_temp_new_i64();
2129 tcg_gen_shr_i64(t0, arg1, arg2);
2130 tcg_gen_subfi_i64(t1, 64, arg2);
2131 tcg_gen_shl_i64(t1, arg1, t1);
2132 tcg_gen_or_i64(ret, t0, t1);
2133 tcg_temp_free_i64(t0);
2134 tcg_temp_free_i64(t1);
2135 }
aurel3215824572008-11-03 07:08:36 +00002136}
2137
pbrooka7812ae2008-11-17 14:43:54 +00002138static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
aurel3215824572008-11-03 07:08:36 +00002139{
2140 /* some cases can be optimized here */
2141 if (arg2 == 0) {
2142 tcg_gen_mov_i32(ret, arg1);
2143 } else {
2144 tcg_gen_rotli_i32(ret, arg1, 32 - arg2);
2145 }
2146}
2147
pbrooka7812ae2008-11-17 14:43:54 +00002148static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3215824572008-11-03 07:08:36 +00002149{
2150 /* some cases can be optimized here */
2151 if (arg2 == 0) {
pbrookde3526b2008-11-03 13:30:50 +00002152 tcg_gen_mov_i64(ret, arg1);
aurel3215824572008-11-03 07:08:36 +00002153 } else {
2154 tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
2155 }
2156}
2157
Richard Hendersonb7767f02011-01-10 19:23:42 -08002158static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
Richard Henderson0756e712011-11-01 15:06:43 -07002159 TCGv_i32 arg2, unsigned int ofs,
2160 unsigned int len)
Richard Hendersonb7767f02011-01-10 19:23:42 -08002161{
Richard Hendersondf072772011-10-27 14:15:00 -07002162 uint32_t mask;
2163 TCGv_i32 t1;
2164
Richard Henderson717e7032012-09-21 17:18:15 -07002165 tcg_debug_assert(ofs < 32);
2166 tcg_debug_assert(len <= 32);
2167 tcg_debug_assert(ofs + len <= 32);
2168
Richard Hendersondf072772011-10-27 14:15:00 -07002169 if (ofs == 0 && len == 32) {
2170 tcg_gen_mov_i32(ret, arg2);
2171 return;
2172 }
Jan Kiszkaa4773322011-09-29 18:52:11 +02002173 if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002174 tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
Richard Hendersondf072772011-10-27 14:15:00 -07002175 return;
2176 }
Richard Hendersonb7767f02011-01-10 19:23:42 -08002177
Richard Hendersondf072772011-10-27 14:15:00 -07002178 mask = (1u << len) - 1;
2179 t1 = tcg_temp_new_i32();
2180
2181 if (ofs + len < 32) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002182 tcg_gen_andi_i32(t1, arg2, mask);
2183 tcg_gen_shli_i32(t1, t1, ofs);
Richard Hendersondf072772011-10-27 14:15:00 -07002184 } else {
2185 tcg_gen_shli_i32(t1, arg2, ofs);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002186 }
Richard Hendersondf072772011-10-27 14:15:00 -07002187 tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
2188 tcg_gen_or_i32(ret, ret, t1);
2189
2190 tcg_temp_free_i32(t1);
Richard Hendersonb7767f02011-01-10 19:23:42 -08002191}
2192
2193static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
Richard Henderson0756e712011-11-01 15:06:43 -07002194 TCGv_i64 arg2, unsigned int ofs,
2195 unsigned int len)
Richard Hendersonb7767f02011-01-10 19:23:42 -08002196{
Richard Hendersondf072772011-10-27 14:15:00 -07002197 uint64_t mask;
2198 TCGv_i64 t1;
2199
Richard Henderson717e7032012-09-21 17:18:15 -07002200 tcg_debug_assert(ofs < 64);
2201 tcg_debug_assert(len <= 64);
2202 tcg_debug_assert(ofs + len <= 64);
2203
Richard Hendersondf072772011-10-27 14:15:00 -07002204 if (ofs == 0 && len == 64) {
2205 tcg_gen_mov_i64(ret, arg2);
2206 return;
2207 }
Jan Kiszkaa4773322011-09-29 18:52:11 +02002208 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002209 tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
Richard Hendersondf072772011-10-27 14:15:00 -07002210 return;
2211 }
Richard Hendersonb7767f02011-01-10 19:23:42 -08002212
Richard Hendersondf072772011-10-27 14:15:00 -07002213#if TCG_TARGET_REG_BITS == 32
2214 if (ofs >= 32) {
2215 tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1),
2216 TCGV_LOW(arg2), ofs - 32, len);
Aurelien Jarnoed605122013-04-21 00:42:56 +02002217 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
Richard Hendersondf072772011-10-27 14:15:00 -07002218 return;
2219 }
2220 if (ofs + len <= 32) {
2221 tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
2222 TCGV_LOW(arg2), ofs, len);
Richard Henderson2f98c9d2011-11-01 15:06:42 -07002223 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
Richard Hendersondf072772011-10-27 14:15:00 -07002224 return;
2225 }
2226#endif
2227
2228 mask = (1ull << len) - 1;
2229 t1 = tcg_temp_new_i64();
2230
2231 if (ofs + len < 64) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002232 tcg_gen_andi_i64(t1, arg2, mask);
2233 tcg_gen_shli_i64(t1, t1, ofs);
Richard Hendersondf072772011-10-27 14:15:00 -07002234 } else {
2235 tcg_gen_shli_i64(t1, arg2, ofs);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002236 }
Richard Hendersondf072772011-10-27 14:15:00 -07002237 tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
2238 tcg_gen_or_i64(ret, ret, t1);
2239
2240 tcg_temp_free_i64(t1);
Richard Hendersonb7767f02011-01-10 19:23:42 -08002241}
2242
Richard Henderson77276f62012-09-21 17:18:13 -07002243static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low,
2244 TCGv_i32 high)
2245{
2246#if TCG_TARGET_REG_BITS == 32
2247 tcg_gen_mov_i32(TCGV_LOW(dest), low);
2248 tcg_gen_mov_i32(TCGV_HIGH(dest), high);
2249#else
2250 TCGv_i64 tmp = tcg_temp_new_i64();
2251 /* These extensions are only needed for type correctness.
2252 We may be able to do better given target specific information. */
2253 tcg_gen_extu_i32_i64(tmp, high);
2254 tcg_gen_extu_i32_i64(dest, low);
2255 /* If deposit is available, use it. Otherwise use the extra
2256 knowledge that we have of the zero-extensions above. */
2257 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(32, 32)) {
2258 tcg_gen_deposit_i64(dest, dest, tmp, 32, 32);
2259 } else {
2260 tcg_gen_shli_i64(tmp, tmp, 32);
2261 tcg_gen_or_i64(dest, dest, tmp);
2262 }
2263 tcg_temp_free_i64(tmp);
2264#endif
2265}
2266
2267static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low,
2268 TCGv_i64 high)
2269{
2270 tcg_gen_deposit_i64(dest, low, high, 32, 32);
2271}
2272
Richard Henderson3c51a982013-02-19 23:51:54 -08002273static inline void tcg_gen_extr_i64_i32(TCGv_i32 lo, TCGv_i32 hi, TCGv_i64 arg)
2274{
2275#if TCG_TARGET_REG_BITS == 32
2276 tcg_gen_mov_i32(lo, TCGV_LOW(arg));
2277 tcg_gen_mov_i32(hi, TCGV_HIGH(arg));
2278#else
2279 TCGv_i64 t0 = tcg_temp_new_i64();
2280 tcg_gen_trunc_i64_i32(lo, arg);
2281 tcg_gen_shri_i64(t0, arg, 32);
2282 tcg_gen_trunc_i64_i32(hi, t0);
2283 tcg_temp_free_i64(t0);
2284#endif
2285}
2286
2287static inline void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg)
2288{
2289 tcg_gen_ext32u_i64(lo, arg);
2290 tcg_gen_shri_i64(hi, arg, 32);
2291}
2292
Richard Hendersonffc5ea02012-09-21 10:13:34 -07002293static inline void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret,
2294 TCGv_i32 c1, TCGv_i32 c2,
2295 TCGv_i32 v1, TCGv_i32 v2)
2296{
2297 if (TCG_TARGET_HAS_movcond_i32) {
2298 tcg_gen_op6i_i32(INDEX_op_movcond_i32, ret, c1, c2, v1, v2, cond);
2299 } else {
2300 TCGv_i32 t0 = tcg_temp_new_i32();
2301 TCGv_i32 t1 = tcg_temp_new_i32();
2302 tcg_gen_setcond_i32(cond, t0, c1, c2);
2303 tcg_gen_neg_i32(t0, t0);
2304 tcg_gen_and_i32(t1, v1, t0);
2305 tcg_gen_andc_i32(ret, v2, t0);
2306 tcg_gen_or_i32(ret, ret, t1);
2307 tcg_temp_free_i32(t0);
2308 tcg_temp_free_i32(t1);
2309 }
2310}
2311
2312static inline void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret,
2313 TCGv_i64 c1, TCGv_i64 c2,
2314 TCGv_i64 v1, TCGv_i64 v2)
2315{
Richard Hendersona4631332012-09-24 13:44:59 -07002316#if TCG_TARGET_REG_BITS == 32
2317 TCGv_i32 t0 = tcg_temp_new_i32();
2318 TCGv_i32 t1 = tcg_temp_new_i32();
2319 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0,
2320 TCGV_LOW(c1), TCGV_HIGH(c1),
2321 TCGV_LOW(c2), TCGV_HIGH(c2), cond);
Richard Hendersona4631332012-09-24 13:44:59 -07002322
Richard Hendersona80a6b62012-09-24 13:45:00 -07002323 if (TCG_TARGET_HAS_movcond_i32) {
2324 tcg_gen_movi_i32(t1, 0);
2325 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_LOW(ret), t0, t1,
2326 TCGV_LOW(v1), TCGV_LOW(v2));
2327 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_HIGH(ret), t0, t1,
2328 TCGV_HIGH(v1), TCGV_HIGH(v2));
2329 } else {
2330 tcg_gen_neg_i32(t0, t0);
Richard Hendersona4631332012-09-24 13:44:59 -07002331
Richard Hendersona80a6b62012-09-24 13:45:00 -07002332 tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
2333 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
2334 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
Richard Hendersona4631332012-09-24 13:44:59 -07002335
Richard Hendersona80a6b62012-09-24 13:45:00 -07002336 tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
2337 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
2338 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
2339 }
Richard Hendersona4631332012-09-24 13:44:59 -07002340 tcg_temp_free_i32(t0);
2341 tcg_temp_free_i32(t1);
2342#else
Richard Hendersonffc5ea02012-09-21 10:13:34 -07002343 if (TCG_TARGET_HAS_movcond_i64) {
2344 tcg_gen_op6i_i64(INDEX_op_movcond_i64, ret, c1, c2, v1, v2, cond);
2345 } else {
2346 TCGv_i64 t0 = tcg_temp_new_i64();
2347 TCGv_i64 t1 = tcg_temp_new_i64();
2348 tcg_gen_setcond_i64(cond, t0, c1, c2);
2349 tcg_gen_neg_i64(t0, t0);
2350 tcg_gen_and_i64(t1, v1, t0);
2351 tcg_gen_andc_i64(ret, v2, t0);
2352 tcg_gen_or_i64(ret, ret, t1);
2353 tcg_temp_free_i64(t0);
2354 tcg_temp_free_i64(t1);
2355 }
Richard Hendersona4631332012-09-24 13:44:59 -07002356#endif
Richard Hendersonffc5ea02012-09-21 10:13:34 -07002357}
2358
Richard Hendersonf6953a72013-02-19 23:51:56 -08002359static inline void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2360 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2361{
2362 if (TCG_TARGET_HAS_add2_i32) {
2363 tcg_gen_op6_i32(INDEX_op_add2_i32, rl, rh, al, ah, bl, bh);
2364 /* Allow the optimizer room to replace add2 with two moves. */
2365 tcg_gen_op0(INDEX_op_nop);
2366 } else {
2367 TCGv_i64 t0 = tcg_temp_new_i64();
2368 TCGv_i64 t1 = tcg_temp_new_i64();
2369 tcg_gen_concat_i32_i64(t0, al, ah);
2370 tcg_gen_concat_i32_i64(t1, bl, bh);
2371 tcg_gen_add_i64(t0, t0, t1);
2372 tcg_gen_extr_i64_i32(rl, rh, t0);
2373 tcg_temp_free_i64(t0);
2374 tcg_temp_free_i64(t1);
2375 }
2376}
2377
2378static inline void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2379 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2380{
2381 if (TCG_TARGET_HAS_sub2_i32) {
2382 tcg_gen_op6_i32(INDEX_op_sub2_i32, rl, rh, al, ah, bl, bh);
2383 /* Allow the optimizer room to replace sub2 with two moves. */
2384 tcg_gen_op0(INDEX_op_nop);
2385 } else {
2386 TCGv_i64 t0 = tcg_temp_new_i64();
2387 TCGv_i64 t1 = tcg_temp_new_i64();
2388 tcg_gen_concat_i32_i64(t0, al, ah);
2389 tcg_gen_concat_i32_i64(t1, bl, bh);
2390 tcg_gen_sub_i64(t0, t0, t1);
2391 tcg_gen_extr_i64_i32(rl, rh, t0);
2392 tcg_temp_free_i64(t0);
2393 tcg_temp_free_i64(t1);
2394 }
2395}
2396
Richard Henderson696a8be2013-02-19 23:51:55 -08002397static inline void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh,
2398 TCGv_i32 arg1, TCGv_i32 arg2)
2399{
2400 if (TCG_TARGET_HAS_mulu2_i32) {
2401 tcg_gen_op4_i32(INDEX_op_mulu2_i32, rl, rh, arg1, arg2);
2402 /* Allow the optimizer room to replace mulu2 with two moves. */
2403 tcg_gen_op0(INDEX_op_nop);
2404 } else {
2405 TCGv_i64 t0 = tcg_temp_new_i64();
2406 TCGv_i64 t1 = tcg_temp_new_i64();
2407 tcg_gen_extu_i32_i64(t0, arg1);
2408 tcg_gen_extu_i32_i64(t1, arg2);
2409 tcg_gen_mul_i64(t0, t0, t1);
2410 tcg_gen_extr_i64_i32(rl, rh, t0);
2411 tcg_temp_free_i64(t0);
2412 tcg_temp_free_i64(t1);
2413 }
2414}
2415
2416static inline void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh,
2417 TCGv_i32 arg1, TCGv_i32 arg2)
2418{
2419 if (TCG_TARGET_HAS_muls2_i32) {
2420 tcg_gen_op4_i32(INDEX_op_muls2_i32, rl, rh, arg1, arg2);
2421 /* Allow the optimizer room to replace muls2 with two moves. */
2422 tcg_gen_op0(INDEX_op_nop);
Richard Hendersonf402f382013-02-19 23:52:01 -08002423 } else if (TCG_TARGET_REG_BITS == 32 && TCG_TARGET_HAS_mulu2_i32) {
2424 TCGv_i32 t0 = tcg_temp_new_i32();
2425 TCGv_i32 t1 = tcg_temp_new_i32();
2426 TCGv_i32 t2 = tcg_temp_new_i32();
2427 TCGv_i32 t3 = tcg_temp_new_i32();
2428 tcg_gen_op4_i32(INDEX_op_mulu2_i32, t0, t1, arg1, arg2);
2429 /* Allow the optimizer room to replace mulu2 with two moves. */
2430 tcg_gen_op0(INDEX_op_nop);
2431 /* Adjust for negative inputs. */
2432 tcg_gen_sari_i32(t2, arg1, 31);
2433 tcg_gen_sari_i32(t3, arg2, 31);
2434 tcg_gen_and_i32(t2, t2, arg2);
2435 tcg_gen_and_i32(t3, t3, arg1);
2436 tcg_gen_sub_i32(rh, t1, t2);
2437 tcg_gen_sub_i32(rh, rh, t3);
2438 tcg_gen_mov_i32(rl, t0);
2439 tcg_temp_free_i32(t0);
2440 tcg_temp_free_i32(t1);
2441 tcg_temp_free_i32(t2);
2442 tcg_temp_free_i32(t3);
Richard Henderson696a8be2013-02-19 23:51:55 -08002443 } else {
2444 TCGv_i64 t0 = tcg_temp_new_i64();
2445 TCGv_i64 t1 = tcg_temp_new_i64();
2446 tcg_gen_ext_i32_i64(t0, arg1);
2447 tcg_gen_ext_i32_i64(t1, arg2);
2448 tcg_gen_mul_i64(t0, t0, t1);
2449 tcg_gen_extr_i64_i32(rl, rh, t0);
2450 tcg_temp_free_i64(t0);
2451 tcg_temp_free_i64(t1);
2452 }
2453}
2454
Richard Hendersonf6953a72013-02-19 23:51:56 -08002455static inline void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2456 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2457{
2458 if (TCG_TARGET_HAS_add2_i64) {
2459 tcg_gen_op6_i64(INDEX_op_add2_i64, rl, rh, al, ah, bl, bh);
2460 /* Allow the optimizer room to replace add2 with two moves. */
2461 tcg_gen_op0(INDEX_op_nop);
2462 } else {
2463 TCGv_i64 t0 = tcg_temp_new_i64();
2464 TCGv_i64 t1 = tcg_temp_new_i64();
2465 tcg_gen_add_i64(t0, al, bl);
2466 tcg_gen_setcond_i64(TCG_COND_LTU, t1, t0, al);
2467 tcg_gen_add_i64(rh, ah, bh);
2468 tcg_gen_add_i64(rh, rh, t1);
2469 tcg_gen_mov_i64(rl, t0);
2470 tcg_temp_free_i64(t0);
2471 tcg_temp_free_i64(t1);
2472 }
2473}
2474
2475static inline void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2476 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2477{
2478 if (TCG_TARGET_HAS_sub2_i64) {
2479 tcg_gen_op6_i64(INDEX_op_sub2_i64, rl, rh, al, ah, bl, bh);
2480 /* Allow the optimizer room to replace sub2 with two moves. */
2481 tcg_gen_op0(INDEX_op_nop);
2482 } else {
2483 TCGv_i64 t0 = tcg_temp_new_i64();
2484 TCGv_i64 t1 = tcg_temp_new_i64();
2485 tcg_gen_sub_i64(t0, al, bl);
2486 tcg_gen_setcond_i64(TCG_COND_LTU, t1, al, bl);
2487 tcg_gen_sub_i64(rh, ah, bh);
2488 tcg_gen_sub_i64(rh, rh, t1);
2489 tcg_gen_mov_i64(rl, t0);
2490 tcg_temp_free_i64(t0);
2491 tcg_temp_free_i64(t1);
2492 }
2493}
2494
Richard Henderson696a8be2013-02-19 23:51:55 -08002495static inline void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh,
2496 TCGv_i64 arg1, TCGv_i64 arg2)
2497{
2498 if (TCG_TARGET_HAS_mulu2_i64) {
2499 tcg_gen_op4_i64(INDEX_op_mulu2_i64, rl, rh, arg1, arg2);
2500 /* Allow the optimizer room to replace mulu2 with two moves. */
2501 tcg_gen_op0(INDEX_op_nop);
Richard Hendersonf402f382013-02-19 23:52:01 -08002502 } else if (TCG_TARGET_HAS_mulu2_i64) {
2503 TCGv_i64 t0 = tcg_temp_new_i64();
2504 TCGv_i64 t1 = tcg_temp_new_i64();
2505 TCGv_i64 t2 = tcg_temp_new_i64();
2506 TCGv_i64 t3 = tcg_temp_new_i64();
2507 tcg_gen_op4_i64(INDEX_op_mulu2_i64, t0, t1, arg1, arg2);
2508 /* Allow the optimizer room to replace mulu2 with two moves. */
2509 tcg_gen_op0(INDEX_op_nop);
2510 /* Adjust for negative inputs. */
2511 tcg_gen_sari_i64(t2, arg1, 63);
2512 tcg_gen_sari_i64(t3, arg2, 63);
2513 tcg_gen_and_i64(t2, t2, arg2);
2514 tcg_gen_and_i64(t3, t3, arg1);
2515 tcg_gen_sub_i64(rh, t1, t2);
2516 tcg_gen_sub_i64(rh, rh, t3);
2517 tcg_gen_mov_i64(rl, t0);
2518 tcg_temp_free_i64(t0);
2519 tcg_temp_free_i64(t1);
2520 tcg_temp_free_i64(t2);
2521 tcg_temp_free_i64(t3);
Richard Henderson696a8be2013-02-19 23:51:55 -08002522 } else {
2523 TCGv_i64 t0 = tcg_temp_new_i64();
2524 int sizemask = 0;
2525 /* Return value and both arguments are 64-bit and unsigned. */
2526 sizemask |= tcg_gen_sizemask(0, 1, 0);
2527 sizemask |= tcg_gen_sizemask(1, 1, 0);
2528 sizemask |= tcg_gen_sizemask(2, 1, 0);
2529 tcg_gen_mul_i64(t0, arg1, arg2);
2530 tcg_gen_helper64(tcg_helper_muluh_i64, sizemask, rh, arg1, arg2);
2531 tcg_gen_mov_i64(rl, t0);
2532 tcg_temp_free_i64(t0);
2533 }
2534}
2535
2536static inline void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh,
2537 TCGv_i64 arg1, TCGv_i64 arg2)
2538{
2539 if (TCG_TARGET_HAS_muls2_i64) {
2540 tcg_gen_op4_i64(INDEX_op_muls2_i64, rl, rh, arg1, arg2);
2541 /* Allow the optimizer room to replace muls2 with two moves. */
2542 tcg_gen_op0(INDEX_op_nop);
2543 } else {
2544 TCGv_i64 t0 = tcg_temp_new_i64();
2545 int sizemask = 0;
2546 /* Return value and both arguments are 64-bit and signed. */
2547 sizemask |= tcg_gen_sizemask(0, 1, 1);
2548 sizemask |= tcg_gen_sizemask(1, 1, 1);
2549 sizemask |= tcg_gen_sizemask(2, 1, 1);
2550 tcg_gen_mul_i64(t0, arg1, arg2);
2551 tcg_gen_helper64(tcg_helper_mulsh_i64, sizemask, rh, arg1, arg2);
2552 tcg_gen_mov_i64(rl, t0);
2553 tcg_temp_free_i64(t0);
2554 }
2555}
2556
bellardc896fe22008-02-01 10:05:41 +00002557/***************************************/
bellardc896fe22008-02-01 10:05:41 +00002558/* QEMU specific operations. Their type depend on the QEMU CPU
2559 type. */
2560#ifndef TARGET_LONG_BITS
2561#error must include QEMU headers
2562#endif
2563
pbrooka7812ae2008-11-17 14:43:54 +00002564#if TARGET_LONG_BITS == 32
2565#define TCGv TCGv_i32
2566#define tcg_temp_new() tcg_temp_new_i32()
2567#define tcg_global_reg_new tcg_global_reg_new_i32
2568#define tcg_global_mem_new tcg_global_mem_new_i32
aurel32df9247b2009-01-01 14:09:05 +00002569#define tcg_temp_local_new() tcg_temp_local_new_i32()
pbrooka7812ae2008-11-17 14:43:54 +00002570#define tcg_temp_free tcg_temp_free_i32
2571#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i32
2572#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i32
2573#define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
Richard Hendersonafcb92b2012-12-07 15:07:17 -06002574#define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I32(x)
aurel32fe75bcf2009-03-10 08:57:16 +00002575#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
pbrooka7812ae2008-11-17 14:43:54 +00002576#else
2577#define TCGv TCGv_i64
2578#define tcg_temp_new() tcg_temp_new_i64()
2579#define tcg_global_reg_new tcg_global_reg_new_i64
2580#define tcg_global_mem_new tcg_global_mem_new_i64
aurel32df9247b2009-01-01 14:09:05 +00002581#define tcg_temp_local_new() tcg_temp_local_new_i64()
pbrooka7812ae2008-11-17 14:43:54 +00002582#define tcg_temp_free tcg_temp_free_i64
2583#define tcg_gen_qemu_ldst_op tcg_gen_op3i_i64
2584#define tcg_gen_qemu_ldst_op_i64 tcg_gen_qemu_ldst_op_i64_i64
2585#define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
Richard Hendersonafcb92b2012-12-07 15:07:17 -06002586#define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I64(x)
aurel32fe75bcf2009-03-10 08:57:16 +00002587#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
pbrooka7812ae2008-11-17 14:43:54 +00002588#endif
2589
bellard7e4597d2008-05-22 16:56:05 +00002590/* debug info: write the PC of the corresponding QEMU CPU instruction */
2591static inline void tcg_gen_debug_insn_start(uint64_t pc)
2592{
2593 /* XXX: must really use a 32 bit size for TCGArg in all cases */
2594#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
pbrookbcb01262008-05-24 02:24:25 +00002595 tcg_gen_op2ii(INDEX_op_debug_insn_start,
2596 (uint32_t)(pc), (uint32_t)(pc >> 32));
bellard7e4597d2008-05-22 16:56:05 +00002597#else
2598 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
2599#endif
2600}
2601
bellardc896fe22008-02-01 10:05:41 +00002602static inline void tcg_gen_exit_tb(tcg_target_long val)
2603{
pbrookac56dd42008-02-03 19:56:33 +00002604 tcg_gen_op1i(INDEX_op_exit_tb, val);
bellardc896fe22008-02-01 10:05:41 +00002605}
2606
Richard Henderson0a209d42012-09-21 17:18:16 -07002607static inline void tcg_gen_goto_tb(unsigned idx)
bellardc896fe22008-02-01 10:05:41 +00002608{
Richard Henderson0a209d42012-09-21 17:18:16 -07002609 /* We only support two chained exits. */
2610 tcg_debug_assert(idx <= 1);
2611#ifdef CONFIG_DEBUG_TCG
2612 /* Verify that we havn't seen this numbered exit before. */
2613 tcg_debug_assert((tcg_ctx.goto_tb_issue_mask & (1 << idx)) == 0);
2614 tcg_ctx.goto_tb_issue_mask |= 1 << idx;
2615#endif
pbrookac56dd42008-02-03 19:56:33 +00002616 tcg_gen_op1i(INDEX_op_goto_tb, idx);
bellardc896fe22008-02-01 10:05:41 +00002617}
2618
2619#if TCG_TARGET_REG_BITS == 32
pbrookac56dd42008-02-03 19:56:33 +00002620static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002621{
2622#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002623 tcg_gen_op3i_i32(INDEX_op_qemu_ld8u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002624#else
pbrooka7812ae2008-11-17 14:43:54 +00002625 tcg_gen_op4i_i32(INDEX_op_qemu_ld8u, TCGV_LOW(ret), TCGV_LOW(addr),
2626 TCGV_HIGH(addr), mem_index);
pbrookac56dd42008-02-03 19:56:33 +00002627 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00002628#endif
2629}
2630
pbrookac56dd42008-02-03 19:56:33 +00002631static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002632{
2633#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002634 tcg_gen_op3i_i32(INDEX_op_qemu_ld8s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002635#else
pbrooka7812ae2008-11-17 14:43:54 +00002636 tcg_gen_op4i_i32(INDEX_op_qemu_ld8s, TCGV_LOW(ret), TCGV_LOW(addr),
2637 TCGV_HIGH(addr), mem_index);
2638 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00002639#endif
2640}
2641
pbrookac56dd42008-02-03 19:56:33 +00002642static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002643{
2644#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002645 tcg_gen_op3i_i32(INDEX_op_qemu_ld16u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002646#else
pbrooka7812ae2008-11-17 14:43:54 +00002647 tcg_gen_op4i_i32(INDEX_op_qemu_ld16u, TCGV_LOW(ret), TCGV_LOW(addr),
2648 TCGV_HIGH(addr), mem_index);
pbrookac56dd42008-02-03 19:56:33 +00002649 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00002650#endif
2651}
2652
pbrookac56dd42008-02-03 19:56:33 +00002653static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002654{
2655#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002656 tcg_gen_op3i_i32(INDEX_op_qemu_ld16s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002657#else
pbrooka7812ae2008-11-17 14:43:54 +00002658 tcg_gen_op4i_i32(INDEX_op_qemu_ld16s, TCGV_LOW(ret), TCGV_LOW(addr),
2659 TCGV_HIGH(addr), mem_index);
2660 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00002661#endif
2662}
2663
pbrookac56dd42008-02-03 19:56:33 +00002664static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002665{
2666#if TARGET_LONG_BITS == 32
Richard Henderson86feb1c2010-03-19 12:00:26 -07002667 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002668#else
Richard Henderson86feb1c2010-03-19 12:00:26 -07002669 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
pbrooka7812ae2008-11-17 14:43:54 +00002670 TCGV_HIGH(addr), mem_index);
pbrookac56dd42008-02-03 19:56:33 +00002671 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00002672#endif
2673}
2674
pbrookac56dd42008-02-03 19:56:33 +00002675static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002676{
2677#if TARGET_LONG_BITS == 32
Richard Henderson86feb1c2010-03-19 12:00:26 -07002678 tcg_gen_op3i_i32(INDEX_op_qemu_ld32, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002679#else
Richard Henderson86feb1c2010-03-19 12:00:26 -07002680 tcg_gen_op4i_i32(INDEX_op_qemu_ld32, TCGV_LOW(ret), TCGV_LOW(addr),
pbrooka7812ae2008-11-17 14:43:54 +00002681 TCGV_HIGH(addr), mem_index);
2682 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00002683#endif
2684}
2685
pbrooka7812ae2008-11-17 14:43:54 +00002686static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002687{
2688#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002689 tcg_gen_op4i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret), addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002690#else
pbrooka7812ae2008-11-17 14:43:54 +00002691 tcg_gen_op5i_i32(INDEX_op_qemu_ld64, TCGV_LOW(ret), TCGV_HIGH(ret),
2692 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002693#endif
2694}
2695
pbrookac56dd42008-02-03 19:56:33 +00002696static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002697{
2698#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002699 tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002700#else
pbrooka7812ae2008-11-17 14:43:54 +00002701 tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr),
2702 TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002703#endif
2704}
2705
pbrookac56dd42008-02-03 19:56:33 +00002706static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002707{
2708#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002709 tcg_gen_op3i_i32(INDEX_op_qemu_st16, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002710#else
pbrooka7812ae2008-11-17 14:43:54 +00002711 tcg_gen_op4i_i32(INDEX_op_qemu_st16, TCGV_LOW(arg), TCGV_LOW(addr),
2712 TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002713#endif
2714}
2715
pbrookac56dd42008-02-03 19:56:33 +00002716static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002717{
2718#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002719 tcg_gen_op3i_i32(INDEX_op_qemu_st32, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002720#else
pbrooka7812ae2008-11-17 14:43:54 +00002721 tcg_gen_op4i_i32(INDEX_op_qemu_st32, TCGV_LOW(arg), TCGV_LOW(addr),
2722 TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002723#endif
2724}
2725
pbrooka7812ae2008-11-17 14:43:54 +00002726static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002727{
2728#if TARGET_LONG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00002729 tcg_gen_op4i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg), addr,
2730 mem_index);
bellardc896fe22008-02-01 10:05:41 +00002731#else
pbrooka7812ae2008-11-17 14:43:54 +00002732 tcg_gen_op5i_i32(INDEX_op_qemu_st64, TCGV_LOW(arg), TCGV_HIGH(arg),
2733 TCGV_LOW(addr), TCGV_HIGH(addr), mem_index);
bellardc896fe22008-02-01 10:05:41 +00002734#endif
2735}
2736
Peter Maydellebecf362011-05-27 13:12:13 +01002737#define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O))
2738#define tcg_gen_discard_ptr(A) tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))
blueswir1f8422f52008-02-24 07:45:43 +00002739
bellardc896fe22008-02-01 10:05:41 +00002740#else /* TCG_TARGET_REG_BITS == 32 */
2741
pbrookac56dd42008-02-03 19:56:33 +00002742static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002743{
pbrooka7812ae2008-11-17 14:43:54 +00002744 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002745}
2746
pbrookac56dd42008-02-03 19:56:33 +00002747static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002748{
pbrooka7812ae2008-11-17 14:43:54 +00002749 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld8s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002750}
2751
pbrookac56dd42008-02-03 19:56:33 +00002752static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002753{
pbrooka7812ae2008-11-17 14:43:54 +00002754 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16u, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002755}
2756
pbrookac56dd42008-02-03 19:56:33 +00002757static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002758{
pbrooka7812ae2008-11-17 14:43:54 +00002759 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld16s, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002760}
2761
pbrookac56dd42008-02-03 19:56:33 +00002762static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002763{
Richard Henderson3e1dbad2010-05-03 16:30:48 -07002764#if TARGET_LONG_BITS == 32
2765 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2766#else
pbrooka7812ae2008-11-17 14:43:54 +00002767 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32u, ret, addr, mem_index);
Richard Henderson3e1dbad2010-05-03 16:30:48 -07002768#endif
bellardc896fe22008-02-01 10:05:41 +00002769}
2770
pbrookac56dd42008-02-03 19:56:33 +00002771static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002772{
Richard Henderson3e1dbad2010-05-03 16:30:48 -07002773#if TARGET_LONG_BITS == 32
2774 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32, ret, addr, mem_index);
2775#else
pbrooka7812ae2008-11-17 14:43:54 +00002776 tcg_gen_qemu_ldst_op(INDEX_op_qemu_ld32s, ret, addr, mem_index);
Richard Henderson3e1dbad2010-05-03 16:30:48 -07002777#endif
bellardc896fe22008-02-01 10:05:41 +00002778}
2779
pbrooka7812ae2008-11-17 14:43:54 +00002780static inline void tcg_gen_qemu_ld64(TCGv_i64 ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002781{
pbrooka7812ae2008-11-17 14:43:54 +00002782 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_ld64, ret, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002783}
2784
pbrookac56dd42008-02-03 19:56:33 +00002785static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002786{
pbrooka7812ae2008-11-17 14:43:54 +00002787 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st8, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002788}
2789
pbrookac56dd42008-02-03 19:56:33 +00002790static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002791{
pbrooka7812ae2008-11-17 14:43:54 +00002792 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st16, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002793}
2794
pbrookac56dd42008-02-03 19:56:33 +00002795static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002796{
pbrooka7812ae2008-11-17 14:43:54 +00002797 tcg_gen_qemu_ldst_op(INDEX_op_qemu_st32, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002798}
2799
pbrooka7812ae2008-11-17 14:43:54 +00002800static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002801{
pbrooka7812ae2008-11-17 14:43:54 +00002802 tcg_gen_qemu_ldst_op_i64(INDEX_op_qemu_st64, arg, addr, mem_index);
bellardc896fe22008-02-01 10:05:41 +00002803}
2804
Peter Maydellebecf362011-05-27 13:12:13 +01002805#define tcg_gen_ld_ptr(R, A, O) tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O))
2806#define tcg_gen_discard_ptr(A) tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))
blueswir1f8422f52008-02-24 07:45:43 +00002807
bellardc896fe22008-02-01 10:05:41 +00002808#endif /* TCG_TARGET_REG_BITS != 32 */
blueswir1f8422f52008-02-24 07:45:43 +00002809
2810#if TARGET_LONG_BITS == 64
blueswir1f8422f52008-02-24 07:45:43 +00002811#define tcg_gen_movi_tl tcg_gen_movi_i64
2812#define tcg_gen_mov_tl tcg_gen_mov_i64
2813#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2814#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2815#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2816#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2817#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2818#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2819#define tcg_gen_ld_tl tcg_gen_ld_i64
2820#define tcg_gen_st8_tl tcg_gen_st8_i64
2821#define tcg_gen_st16_tl tcg_gen_st16_i64
2822#define tcg_gen_st32_tl tcg_gen_st32_i64
2823#define tcg_gen_st_tl tcg_gen_st_i64
2824#define tcg_gen_add_tl tcg_gen_add_i64
2825#define tcg_gen_addi_tl tcg_gen_addi_i64
2826#define tcg_gen_sub_tl tcg_gen_sub_i64
pbrook390efc52008-05-11 14:35:37 +00002827#define tcg_gen_neg_tl tcg_gen_neg_i64
pbrook10460c82008-11-02 13:26:16 +00002828#define tcg_gen_subfi_tl tcg_gen_subfi_i64
blueswir1f8422f52008-02-24 07:45:43 +00002829#define tcg_gen_subi_tl tcg_gen_subi_i64
2830#define tcg_gen_and_tl tcg_gen_and_i64
2831#define tcg_gen_andi_tl tcg_gen_andi_i64
2832#define tcg_gen_or_tl tcg_gen_or_i64
2833#define tcg_gen_ori_tl tcg_gen_ori_i64
2834#define tcg_gen_xor_tl tcg_gen_xor_i64
2835#define tcg_gen_xori_tl tcg_gen_xori_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002836#define tcg_gen_not_tl tcg_gen_not_i64
blueswir1f8422f52008-02-24 07:45:43 +00002837#define tcg_gen_shl_tl tcg_gen_shl_i64
2838#define tcg_gen_shli_tl tcg_gen_shli_i64
2839#define tcg_gen_shr_tl tcg_gen_shr_i64
2840#define tcg_gen_shri_tl tcg_gen_shri_i64
2841#define tcg_gen_sar_tl tcg_gen_sar_i64
2842#define tcg_gen_sari_tl tcg_gen_sari_i64
blueswir10cf767d2008-03-02 18:20:59 +00002843#define tcg_gen_brcond_tl tcg_gen_brcond_i64
pbrookcb636692008-05-24 02:22:00 +00002844#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
Richard Hendersonbe210ac2010-01-07 10:13:31 -08002845#define tcg_gen_setcond_tl tcg_gen_setcond_i64
Aurelien Jarnoadd1e7e2010-02-08 12:06:05 +01002846#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
thsf730fd22008-05-04 08:14:08 +00002847#define tcg_gen_mul_tl tcg_gen_mul_i64
2848#define tcg_gen_muli_tl tcg_gen_muli_i64
aurel32ab364212009-03-29 01:19:22 +00002849#define tcg_gen_div_tl tcg_gen_div_i64
2850#define tcg_gen_rem_tl tcg_gen_rem_i64
aurel32864951a2009-03-29 14:08:54 +00002851#define tcg_gen_divu_tl tcg_gen_divu_i64
2852#define tcg_gen_remu_tl tcg_gen_remu_i64
blueswir1a768e4b2008-03-16 19:16:37 +00002853#define tcg_gen_discard_tl tcg_gen_discard_i64
blueswir1e4290732008-03-22 08:39:04 +00002854#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2855#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2856#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2857#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2858#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2859#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002860#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2861#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2862#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2863#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2864#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2865#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
aurel32911d79b2009-03-13 09:35:19 +00002866#define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2867#define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2868#define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
blueswir1945ca822008-09-21 18:32:28 +00002869#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
Richard Henderson3c51a982013-02-19 23:51:54 -08002870#define tcg_gen_extr_i64_tl tcg_gen_extr32_i64
aurel32f24cb332008-10-21 11:28:59 +00002871#define tcg_gen_andc_tl tcg_gen_andc_i64
2872#define tcg_gen_eqv_tl tcg_gen_eqv_i64
2873#define tcg_gen_nand_tl tcg_gen_nand_i64
2874#define tcg_gen_nor_tl tcg_gen_nor_i64
2875#define tcg_gen_orc_tl tcg_gen_orc_i64
aurel3215824572008-11-03 07:08:36 +00002876#define tcg_gen_rotl_tl tcg_gen_rotl_i64
2877#define tcg_gen_rotli_tl tcg_gen_rotli_i64
2878#define tcg_gen_rotr_tl tcg_gen_rotr_i64
2879#define tcg_gen_rotri_tl tcg_gen_rotri_i64
Richard Hendersonb7767f02011-01-10 19:23:42 -08002880#define tcg_gen_deposit_tl tcg_gen_deposit_i64
blueswir1a98824a2008-03-13 20:46:42 +00002881#define tcg_const_tl tcg_const_i64
aurel32bdffd4a2008-10-21 11:30:45 +00002882#define tcg_const_local_tl tcg_const_local_i64
Richard Hendersonffc5ea02012-09-21 10:13:34 -07002883#define tcg_gen_movcond_tl tcg_gen_movcond_i64
Richard Hendersonf6953a72013-02-19 23:51:56 -08002884#define tcg_gen_add2_tl tcg_gen_add2_i64
2885#define tcg_gen_sub2_tl tcg_gen_sub2_i64
Richard Henderson696a8be2013-02-19 23:51:55 -08002886#define tcg_gen_mulu2_tl tcg_gen_mulu2_i64
2887#define tcg_gen_muls2_tl tcg_gen_muls2_i64
blueswir1f8422f52008-02-24 07:45:43 +00002888#else
blueswir1f8422f52008-02-24 07:45:43 +00002889#define tcg_gen_movi_tl tcg_gen_movi_i32
2890#define tcg_gen_mov_tl tcg_gen_mov_i32
2891#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2892#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2893#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2894#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2895#define tcg_gen_ld32u_tl tcg_gen_ld_i32
2896#define tcg_gen_ld32s_tl tcg_gen_ld_i32
2897#define tcg_gen_ld_tl tcg_gen_ld_i32
2898#define tcg_gen_st8_tl tcg_gen_st8_i32
2899#define tcg_gen_st16_tl tcg_gen_st16_i32
2900#define tcg_gen_st32_tl tcg_gen_st_i32
2901#define tcg_gen_st_tl tcg_gen_st_i32
2902#define tcg_gen_add_tl tcg_gen_add_i32
2903#define tcg_gen_addi_tl tcg_gen_addi_i32
2904#define tcg_gen_sub_tl tcg_gen_sub_i32
pbrook390efc52008-05-11 14:35:37 +00002905#define tcg_gen_neg_tl tcg_gen_neg_i32
aurel3200457342008-11-02 08:23:04 +00002906#define tcg_gen_subfi_tl tcg_gen_subfi_i32
blueswir1f8422f52008-02-24 07:45:43 +00002907#define tcg_gen_subi_tl tcg_gen_subi_i32
2908#define tcg_gen_and_tl tcg_gen_and_i32
2909#define tcg_gen_andi_tl tcg_gen_andi_i32
2910#define tcg_gen_or_tl tcg_gen_or_i32
2911#define tcg_gen_ori_tl tcg_gen_ori_i32
2912#define tcg_gen_xor_tl tcg_gen_xor_i32
2913#define tcg_gen_xori_tl tcg_gen_xori_i32
bellard0b6ce4c2008-05-17 12:40:44 +00002914#define tcg_gen_not_tl tcg_gen_not_i32
blueswir1f8422f52008-02-24 07:45:43 +00002915#define tcg_gen_shl_tl tcg_gen_shl_i32
2916#define tcg_gen_shli_tl tcg_gen_shli_i32
2917#define tcg_gen_shr_tl tcg_gen_shr_i32
2918#define tcg_gen_shri_tl tcg_gen_shri_i32
2919#define tcg_gen_sar_tl tcg_gen_sar_i32
2920#define tcg_gen_sari_tl tcg_gen_sari_i32
blueswir10cf767d2008-03-02 18:20:59 +00002921#define tcg_gen_brcond_tl tcg_gen_brcond_i32
pbrookcb636692008-05-24 02:22:00 +00002922#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
Richard Hendersonbe210ac2010-01-07 10:13:31 -08002923#define tcg_gen_setcond_tl tcg_gen_setcond_i32
Aurelien Jarnoadd1e7e2010-02-08 12:06:05 +01002924#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
thsf730fd22008-05-04 08:14:08 +00002925#define tcg_gen_mul_tl tcg_gen_mul_i32
2926#define tcg_gen_muli_tl tcg_gen_muli_i32
aurel32ab364212009-03-29 01:19:22 +00002927#define tcg_gen_div_tl tcg_gen_div_i32
2928#define tcg_gen_rem_tl tcg_gen_rem_i32
aurel32864951a2009-03-29 14:08:54 +00002929#define tcg_gen_divu_tl tcg_gen_divu_i32
2930#define tcg_gen_remu_tl tcg_gen_remu_i32
blueswir1a768e4b2008-03-16 19:16:37 +00002931#define tcg_gen_discard_tl tcg_gen_discard_i32
blueswir1e4290732008-03-22 08:39:04 +00002932#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2933#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2934#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2935#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2936#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2937#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002938#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2939#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2940#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2941#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2942#define tcg_gen_ext32u_tl tcg_gen_mov_i32
2943#define tcg_gen_ext32s_tl tcg_gen_mov_i32
aurel32911d79b2009-03-13 09:35:19 +00002944#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2945#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
blueswir1945ca822008-09-21 18:32:28 +00002946#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
Richard Henderson3c51a982013-02-19 23:51:54 -08002947#define tcg_gen_extr_tl_i64 tcg_gen_extr_i32_i64
aurel32f24cb332008-10-21 11:28:59 +00002948#define tcg_gen_andc_tl tcg_gen_andc_i32
2949#define tcg_gen_eqv_tl tcg_gen_eqv_i32
2950#define tcg_gen_nand_tl tcg_gen_nand_i32
2951#define tcg_gen_nor_tl tcg_gen_nor_i32
2952#define tcg_gen_orc_tl tcg_gen_orc_i32
aurel3215824572008-11-03 07:08:36 +00002953#define tcg_gen_rotl_tl tcg_gen_rotl_i32
2954#define tcg_gen_rotli_tl tcg_gen_rotli_i32
2955#define tcg_gen_rotr_tl tcg_gen_rotr_i32
2956#define tcg_gen_rotri_tl tcg_gen_rotri_i32
Richard Hendersonb7767f02011-01-10 19:23:42 -08002957#define tcg_gen_deposit_tl tcg_gen_deposit_i32
blueswir1a98824a2008-03-13 20:46:42 +00002958#define tcg_const_tl tcg_const_i32
aurel32bdffd4a2008-10-21 11:30:45 +00002959#define tcg_const_local_tl tcg_const_local_i32
Richard Hendersonffc5ea02012-09-21 10:13:34 -07002960#define tcg_gen_movcond_tl tcg_gen_movcond_i32
Richard Hendersonf6953a72013-02-19 23:51:56 -08002961#define tcg_gen_add2_tl tcg_gen_add2_i32
2962#define tcg_gen_sub2_tl tcg_gen_sub2_i32
Richard Henderson696a8be2013-02-19 23:51:55 -08002963#define tcg_gen_mulu2_tl tcg_gen_mulu2_i32
2964#define tcg_gen_muls2_tl tcg_gen_muls2_i32
blueswir1f8422f52008-02-24 07:45:43 +00002965#endif
pbrook6ddbc6e2008-03-31 03:46:33 +00002966
2967#if TCG_TARGET_REG_BITS == 32
Peter Maydellebecf362011-05-27 13:12:13 +01002968#define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), \
2969 TCGV_PTR_TO_NAT(A), \
2970 TCGV_PTR_TO_NAT(B))
2971#define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), \
2972 TCGV_PTR_TO_NAT(A), (B))
2973#define tcg_gen_ext_i32_ptr(R, A) tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))
pbrook6ddbc6e2008-03-31 03:46:33 +00002974#else /* TCG_TARGET_REG_BITS == 32 */
Peter Maydellebecf362011-05-27 13:12:13 +01002975#define tcg_gen_add_ptr(R, A, B) tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), \
2976 TCGV_PTR_TO_NAT(A), \
2977 TCGV_PTR_TO_NAT(B))
2978#define tcg_gen_addi_ptr(R, A, B) tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R), \
2979 TCGV_PTR_TO_NAT(A), (B))
2980#define tcg_gen_ext_i32_ptr(R, A) tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))
pbrook6ddbc6e2008-03-31 03:46:33 +00002981#endif /* TCG_TARGET_REG_BITS != 32 */