blob: 7eabf22f0144235d816c3a4795b138fe14ebbf89 [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_op4_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000141 TCGv_i32 arg3, TCGv_i32 arg4)
142{
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_I32(arg1);
145 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
146 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
147 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
pbrooka7812ae2008-11-17 14:43:54 +0000148}
149
Richard Hendersona9751602010-03-19 11:12:29 -0700150static inline void tcg_gen_op4_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
blueswir1a810a2d2008-12-07 17:16:42 +0000151 TCGv_i64 arg3, TCGv_i64 arg4)
pbrooka7812ae2008-11-17 14:43:54 +0000152{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400153 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400154 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
155 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
156 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
157 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
pbrooka7812ae2008-11-17 14:43:54 +0000158}
159
Richard Hendersona9751602010-03-19 11:12:29 -0700160static inline void tcg_gen_op4i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000161 TCGv_i32 arg3, TCGArg arg4)
162{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400163 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400164 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
165 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
166 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
167 *tcg_ctx.gen_opparam_ptr++ = arg4;
pbrookac56dd42008-02-03 19:56:33 +0000168}
169
Richard Hendersona9751602010-03-19 11:12:29 -0700170static inline void tcg_gen_op4i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000171 TCGv_i64 arg3, TCGArg arg4)
pbrookac56dd42008-02-03 19:56:33 +0000172{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400173 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400174 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
175 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
176 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
177 *tcg_ctx.gen_opparam_ptr++ = arg4;
pbrooka7812ae2008-11-17 14:43:54 +0000178}
179
Richard Hendersona9751602010-03-19 11:12:29 -0700180static inline void tcg_gen_op4ii_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000181 TCGArg arg3, TCGArg arg4)
182{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400183 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400184 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
185 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
186 *tcg_ctx.gen_opparam_ptr++ = arg3;
187 *tcg_ctx.gen_opparam_ptr++ = arg4;
bellardc896fe22008-02-01 10:05:41 +0000188}
189
Richard Hendersona9751602010-03-19 11:12:29 -0700190static inline void tcg_gen_op4ii_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000191 TCGArg arg3, TCGArg arg4)
bellardc896fe22008-02-01 10:05:41 +0000192{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400193 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400194 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
195 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
196 *tcg_ctx.gen_opparam_ptr++ = arg3;
197 *tcg_ctx.gen_opparam_ptr++ = arg4;
pbrookac56dd42008-02-03 19:56:33 +0000198}
199
Richard Hendersona9751602010-03-19 11:12:29 -0700200static inline void tcg_gen_op5_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000201 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5)
pbrookac56dd42008-02-03 19:56:33 +0000202{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400203 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400204 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
205 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
206 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
207 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
208 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
pbrooka7812ae2008-11-17 14:43:54 +0000209}
210
Richard Hendersona9751602010-03-19 11:12:29 -0700211static inline void tcg_gen_op5_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000212 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5)
213{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400214 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400215 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
216 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
217 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
218 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
219 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
pbrooka7812ae2008-11-17 14:43:54 +0000220}
221
Richard Hendersona9751602010-03-19 11:12:29 -0700222static inline void tcg_gen_op5i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000223 TCGv_i32 arg3, TCGv_i32 arg4, TCGArg arg5)
224{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400225 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400226 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
227 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
228 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
229 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
230 *tcg_ctx.gen_opparam_ptr++ = arg5;
bellardc896fe22008-02-01 10:05:41 +0000231}
232
Richard Hendersona9751602010-03-19 11:12:29 -0700233static inline void tcg_gen_op5i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000234 TCGv_i64 arg3, TCGv_i64 arg4, TCGArg arg5)
bellardc896fe22008-02-01 10:05:41 +0000235{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400236 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400237 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
238 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
239 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
240 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
241 *tcg_ctx.gen_opparam_ptr++ = arg5;
pbrookac56dd42008-02-03 19:56:33 +0000242}
243
Richard Hendersonb7767f02011-01-10 19:23:42 -0800244static inline void tcg_gen_op5ii_i32(TCGOpcode opc, TCGv_i32 arg1,
245 TCGv_i32 arg2, TCGv_i32 arg3,
246 TCGArg arg4, TCGArg arg5)
247{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400248 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400249 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
250 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
251 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
252 *tcg_ctx.gen_opparam_ptr++ = arg4;
253 *tcg_ctx.gen_opparam_ptr++ = arg5;
Richard Hendersonb7767f02011-01-10 19:23:42 -0800254}
255
256static inline void tcg_gen_op5ii_i64(TCGOpcode opc, TCGv_i64 arg1,
257 TCGv_i64 arg2, TCGv_i64 arg3,
258 TCGArg arg4, TCGArg arg5)
259{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400260 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400261 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
262 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
263 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
264 *tcg_ctx.gen_opparam_ptr++ = arg4;
265 *tcg_ctx.gen_opparam_ptr++ = arg5;
Richard Hendersonb7767f02011-01-10 19:23:42 -0800266}
267
Richard Hendersona9751602010-03-19 11:12:29 -0700268static inline void tcg_gen_op6_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000269 TCGv_i32 arg3, TCGv_i32 arg4, TCGv_i32 arg5,
270 TCGv_i32 arg6)
pbrookac56dd42008-02-03 19:56:33 +0000271{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400272 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400273 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
274 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
275 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
276 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
277 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
278 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg6);
pbrooka7812ae2008-11-17 14:43:54 +0000279}
280
Richard Hendersona9751602010-03-19 11:12:29 -0700281static inline void tcg_gen_op6_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
pbrooka7812ae2008-11-17 14:43:54 +0000282 TCGv_i64 arg3, TCGv_i64 arg4, TCGv_i64 arg5,
283 TCGv_i64 arg6)
284{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400285 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400286 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
287 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
288 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
289 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
290 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
291 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg6);
pbrooka7812ae2008-11-17 14:43:54 +0000292}
293
Richard Hendersona9751602010-03-19 11:12:29 -0700294static inline void tcg_gen_op6i_i32(TCGOpcode opc, TCGv_i32 arg1, TCGv_i32 arg2,
Richard Hendersonbe210ac2010-01-07 10:13:31 -0800295 TCGv_i32 arg3, TCGv_i32 arg4,
296 TCGv_i32 arg5, TCGArg arg6)
297{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400298 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400299 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
300 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
301 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
302 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
303 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg5);
304 *tcg_ctx.gen_opparam_ptr++ = arg6;
Richard Hendersonbe210ac2010-01-07 10:13:31 -0800305}
306
Richard Hendersona9751602010-03-19 11:12:29 -0700307static inline void tcg_gen_op6i_i64(TCGOpcode opc, TCGv_i64 arg1, TCGv_i64 arg2,
Richard Hendersonbe210ac2010-01-07 10:13:31 -0800308 TCGv_i64 arg3, TCGv_i64 arg4,
309 TCGv_i64 arg5, TCGArg arg6)
310{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400311 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400312 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
313 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
314 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
315 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
316 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg5);
317 *tcg_ctx.gen_opparam_ptr++ = arg6;
Richard Hendersonbe210ac2010-01-07 10:13:31 -0800318}
319
Richard Hendersona9751602010-03-19 11:12:29 -0700320static inline void tcg_gen_op6ii_i32(TCGOpcode opc, TCGv_i32 arg1,
321 TCGv_i32 arg2, TCGv_i32 arg3,
322 TCGv_i32 arg4, TCGArg arg5, TCGArg arg6)
pbrooka7812ae2008-11-17 14:43:54 +0000323{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400324 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400325 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg1);
326 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg2);
327 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg3);
328 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(arg4);
329 *tcg_ctx.gen_opparam_ptr++ = arg5;
330 *tcg_ctx.gen_opparam_ptr++ = arg6;
pbrooka7812ae2008-11-17 14:43:54 +0000331}
332
Richard Hendersona9751602010-03-19 11:12:29 -0700333static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCGv_i64 arg1,
334 TCGv_i64 arg2, TCGv_i64 arg3,
335 TCGv_i64 arg4, TCGArg arg5, TCGArg arg6)
pbrooka7812ae2008-11-17 14:43:54 +0000336{
Evgeny Voevodinefd7f482012-11-12 13:27:45 +0400337 *tcg_ctx.gen_opc_ptr++ = opc;
Evgeny Voevodinc4afe5c2012-11-12 13:27:46 +0400338 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg1);
339 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg2);
340 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg3);
341 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(arg4);
342 *tcg_ctx.gen_opparam_ptr++ = arg5;
343 *tcg_ctx.gen_opparam_ptr++ = arg6;
bellardc896fe22008-02-01 10:05:41 +0000344}
345
Richard Hendersonf713d6a2013-09-04 08:11:05 -0700346static inline void tcg_add_param_i32(TCGv_i32 val)
347{
348 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(val);
349}
350
351static inline void tcg_add_param_i64(TCGv_i64 val)
352{
353#if TCG_TARGET_REG_BITS == 32
354 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(TCGV_LOW(val));
355 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I32(TCGV_HIGH(val));
356#else
357 *tcg_ctx.gen_opparam_ptr++ = GET_TCGV_I64(val);
358#endif
359}
360
bellardc896fe22008-02-01 10:05:41 +0000361static inline void gen_set_label(int n)
362{
pbrookac56dd42008-02-03 19:56:33 +0000363 tcg_gen_op1i(INDEX_op_set_label, n);
bellardc896fe22008-02-01 10:05:41 +0000364}
365
blueswir1fb50d412008-03-21 17:58:45 +0000366static inline void tcg_gen_br(int label)
367{
368 tcg_gen_op1i(INDEX_op_br, label);
369}
370
pbrooka7812ae2008-11-17 14:43:54 +0000371static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +0000372{
aurel32fe75bcf2009-03-10 08:57:16 +0000373 if (!TCGV_EQUAL_I32(ret, arg))
pbrooka7812ae2008-11-17 14:43:54 +0000374 tcg_gen_op2_i32(INDEX_op_mov_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000375}
376
pbrooka7812ae2008-11-17 14:43:54 +0000377static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
bellardc896fe22008-02-01 10:05:41 +0000378{
pbrooka7812ae2008-11-17 14:43:54 +0000379 tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
bellardc896fe22008-02-01 10:05:41 +0000380}
381
Richard Henderson2bece2c2010-06-14 17:35:27 -0700382/* A version of dh_sizemask from def-helper.h that doesn't rely on
383 preprocessor magic. */
384static inline int tcg_gen_sizemask(int n, int is_64bit, int is_signed)
385{
386 return (is_64bit << n*2) | (is_signed << (n*2 + 1));
387}
388
bellardc896fe22008-02-01 10:05:41 +0000389/* helper calls */
pbrooka7812ae2008-11-17 14:43:54 +0000390static inline void tcg_gen_helperN(void *func, int flags, int sizemask,
391 TCGArg ret, int nargs, TCGArg *args)
bellardc896fe22008-02-01 10:05:41 +0000392{
pbrooka7812ae2008-11-17 14:43:54 +0000393 TCGv_ptr fn;
Peter Maydell73f5e312011-12-10 16:35:31 +0000394 fn = tcg_const_ptr(func);
pbrooka7812ae2008-11-17 14:43:54 +0000395 tcg_gen_callN(&tcg_ctx, fn, flags, sizemask, ret,
396 nargs, args);
397 tcg_temp_free_ptr(fn);
bellardc896fe22008-02-01 10:05:41 +0000398}
399
Aurelien Jarnodbfff4d2010-03-14 23:01:01 +0100400/* Note: Both tcg_gen_helper32() and tcg_gen_helper64() are currently
Aurelien Jarno78505272012-10-09 21:53:08 +0200401 reserved for helpers in tcg-runtime.c. These helpers all do not read
402 globals and do not have side effects, hence the call to tcg_gen_callN()
403 with TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS. This may need
404 to be adjusted if these functions start to be used with other helpers. */
Richard Henderson2bece2c2010-06-14 17:35:27 -0700405static inline void tcg_gen_helper32(void *func, int sizemask, TCGv_i32 ret,
Aurelien Jarno31d66552010-03-02 23:16:36 +0100406 TCGv_i32 a, TCGv_i32 b)
407{
408 TCGv_ptr fn;
409 TCGArg args[2];
Peter Maydell73f5e312011-12-10 16:35:31 +0000410 fn = tcg_const_ptr(func);
Aurelien Jarno31d66552010-03-02 23:16:36 +0100411 args[0] = GET_TCGV_I32(a);
412 args[1] = GET_TCGV_I32(b);
Aurelien Jarno78505272012-10-09 21:53:08 +0200413 tcg_gen_callN(&tcg_ctx, fn,
414 TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS,
415 sizemask, GET_TCGV_I32(ret), 2, args);
Aurelien Jarno31d66552010-03-02 23:16:36 +0100416 tcg_temp_free_ptr(fn);
417}
418
Richard Henderson2bece2c2010-06-14 17:35:27 -0700419static inline void tcg_gen_helper64(void *func, int sizemask, TCGv_i64 ret,
pbrooka7812ae2008-11-17 14:43:54 +0000420 TCGv_i64 a, TCGv_i64 b)
bellardc896fe22008-02-01 10:05:41 +0000421{
pbrooka7812ae2008-11-17 14:43:54 +0000422 TCGv_ptr fn;
423 TCGArg args[2];
Peter Maydell73f5e312011-12-10 16:35:31 +0000424 fn = tcg_const_ptr(func);
pbrooka7812ae2008-11-17 14:43:54 +0000425 args[0] = GET_TCGV_I64(a);
426 args[1] = GET_TCGV_I64(b);
Aurelien Jarno78505272012-10-09 21:53:08 +0200427 tcg_gen_callN(&tcg_ctx, fn,
428 TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_SIDE_EFFECTS,
429 sizemask, GET_TCGV_I64(ret), 2, args);
pbrooka7812ae2008-11-17 14:43:54 +0000430 tcg_temp_free_ptr(fn);
blueswir1f8422f52008-02-24 07:45:43 +0000431}
432
bellardc896fe22008-02-01 10:05:41 +0000433/* 32 bit ops */
434
pbrooka7812ae2008-11-17 14:43:54 +0000435static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000436{
pbrooka7812ae2008-11-17 14:43:54 +0000437 tcg_gen_ldst_op_i32(INDEX_op_ld8u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000438}
439
pbrooka7812ae2008-11-17 14:43:54 +0000440static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000441{
pbrooka7812ae2008-11-17 14:43:54 +0000442 tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000443}
444
pbrooka7812ae2008-11-17 14:43:54 +0000445static inline void tcg_gen_ld16u_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000446{
pbrooka7812ae2008-11-17 14:43:54 +0000447 tcg_gen_ldst_op_i32(INDEX_op_ld16u_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000448}
449
pbrooka7812ae2008-11-17 14:43:54 +0000450static inline void tcg_gen_ld16s_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000451{
pbrooka7812ae2008-11-17 14:43:54 +0000452 tcg_gen_ldst_op_i32(INDEX_op_ld16s_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000453}
454
pbrooka7812ae2008-11-17 14:43:54 +0000455static inline void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000456{
pbrooka7812ae2008-11-17 14:43:54 +0000457 tcg_gen_ldst_op_i32(INDEX_op_ld_i32, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000458}
459
pbrooka7812ae2008-11-17 14:43:54 +0000460static inline void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000461{
pbrooka7812ae2008-11-17 14:43:54 +0000462 tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000463}
464
pbrooka7812ae2008-11-17 14:43:54 +0000465static inline void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000466{
pbrooka7812ae2008-11-17 14:43:54 +0000467 tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000468}
469
pbrooka7812ae2008-11-17 14:43:54 +0000470static inline void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000471{
pbrooka7812ae2008-11-17 14:43:54 +0000472 tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000473}
474
pbrooka7812ae2008-11-17 14:43:54 +0000475static inline void tcg_gen_add_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000476{
pbrooka7812ae2008-11-17 14:43:54 +0000477 tcg_gen_op3_i32(INDEX_op_add_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000478}
479
pbrooka7812ae2008-11-17 14:43:54 +0000480static inline void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000481{
blueswir170894422008-02-20 18:01:23 +0000482 /* some cases can be optimized here */
483 if (arg2 == 0) {
484 tcg_gen_mov_i32(ret, arg1);
485 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000486 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000487 tcg_gen_add_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000488 tcg_temp_free_i32(t0);
blueswir170894422008-02-20 18:01:23 +0000489 }
bellardc896fe22008-02-01 10:05:41 +0000490}
491
pbrooka7812ae2008-11-17 14:43:54 +0000492static inline void tcg_gen_sub_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000493{
pbrooka7812ae2008-11-17 14:43:54 +0000494 tcg_gen_op3_i32(INDEX_op_sub_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000495}
496
pbrooka7812ae2008-11-17 14:43:54 +0000497static inline void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
aurel3200457342008-11-02 08:23:04 +0000498{
pbrooka7812ae2008-11-17 14:43:54 +0000499 TCGv_i32 t0 = tcg_const_i32(arg1);
aurel3200457342008-11-02 08:23:04 +0000500 tcg_gen_sub_i32(ret, t0, arg2);
pbrooka7812ae2008-11-17 14:43:54 +0000501 tcg_temp_free_i32(t0);
aurel3200457342008-11-02 08:23:04 +0000502}
503
pbrooka7812ae2008-11-17 14:43:54 +0000504static inline void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000505{
blueswir170894422008-02-20 18:01:23 +0000506 /* some cases can be optimized here */
507 if (arg2 == 0) {
508 tcg_gen_mov_i32(ret, arg1);
509 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000510 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000511 tcg_gen_sub_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000512 tcg_temp_free_i32(t0);
blueswir170894422008-02-20 18:01:23 +0000513 }
bellardc896fe22008-02-01 10:05:41 +0000514}
515
pbrooka7812ae2008-11-17 14:43:54 +0000516static inline void tcg_gen_and_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000517{
aurel327fc81052009-03-10 19:37:39 +0000518 if (TCGV_EQUAL_I32(arg1, arg2)) {
519 tcg_gen_mov_i32(ret, arg1);
520 } else {
521 tcg_gen_op3_i32(INDEX_op_and_i32, ret, arg1, arg2);
522 }
bellardc896fe22008-02-01 10:05:41 +0000523}
524
Richard Henderson42ce3e22012-09-21 17:18:10 -0700525static inline void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000526{
Richard Henderson42ce3e22012-09-21 17:18:10 -0700527 TCGv_i32 t0;
528 /* Some cases can be optimized here. */
529 switch (arg2) {
530 case 0:
bellardc896fe22008-02-01 10:05:41 +0000531 tcg_gen_movi_i32(ret, 0);
Richard Henderson42ce3e22012-09-21 17:18:10 -0700532 return;
533 case 0xffffffffu:
bellardc896fe22008-02-01 10:05:41 +0000534 tcg_gen_mov_i32(ret, arg1);
Richard Henderson42ce3e22012-09-21 17:18:10 -0700535 return;
536 case 0xffu:
537 /* Don't recurse with tcg_gen_ext8u_i32. */
538 if (TCG_TARGET_HAS_ext8u_i32) {
539 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg1);
540 return;
541 }
542 break;
543 case 0xffffu:
544 if (TCG_TARGET_HAS_ext16u_i32) {
545 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg1);
546 return;
547 }
548 break;
bellardc896fe22008-02-01 10:05:41 +0000549 }
Richard Henderson42ce3e22012-09-21 17:18:10 -0700550 t0 = tcg_const_i32(arg2);
551 tcg_gen_and_i32(ret, arg1, t0);
552 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000553}
554
pbrooka7812ae2008-11-17 14:43:54 +0000555static inline void tcg_gen_or_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000556{
aurel327fc81052009-03-10 19:37:39 +0000557 if (TCGV_EQUAL_I32(arg1, arg2)) {
558 tcg_gen_mov_i32(ret, arg1);
559 } else {
560 tcg_gen_op3_i32(INDEX_op_or_i32, ret, arg1, arg2);
561 }
bellardc896fe22008-02-01 10:05:41 +0000562}
563
pbrooka7812ae2008-11-17 14:43:54 +0000564static inline void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000565{
Richard Hendersond81ada72012-09-21 17:18:11 -0700566 /* Some cases can be optimized here. */
567 if (arg2 == -1) {
568 tcg_gen_movi_i32(ret, -1);
bellardc896fe22008-02-01 10:05:41 +0000569 } else if (arg2 == 0) {
570 tcg_gen_mov_i32(ret, arg1);
571 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000572 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000573 tcg_gen_or_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000574 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000575 }
576}
577
pbrooka7812ae2008-11-17 14:43:54 +0000578static inline void tcg_gen_xor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000579{
aurel327fc81052009-03-10 19:37:39 +0000580 if (TCGV_EQUAL_I32(arg1, arg2)) {
581 tcg_gen_movi_i32(ret, 0);
582 } else {
583 tcg_gen_op3_i32(INDEX_op_xor_i32, ret, arg1, arg2);
584 }
bellardc896fe22008-02-01 10:05:41 +0000585}
586
pbrooka7812ae2008-11-17 14:43:54 +0000587static inline void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000588{
Richard Henderson6f3bb332012-09-21 17:18:12 -0700589 /* Some cases can be optimized here. */
bellardc896fe22008-02-01 10:05:41 +0000590 if (arg2 == 0) {
591 tcg_gen_mov_i32(ret, arg1);
Richard Henderson6f3bb332012-09-21 17:18:12 -0700592 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i32) {
593 /* Don't recurse with tcg_gen_not_i32. */
594 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg1);
bellardc896fe22008-02-01 10:05:41 +0000595 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000596 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000597 tcg_gen_xor_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000598 tcg_temp_free_i32(t0);
bellardc896fe22008-02-01 10:05:41 +0000599 }
600}
601
pbrooka7812ae2008-11-17 14:43:54 +0000602static inline void tcg_gen_shl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000603{
pbrooka7812ae2008-11-17 14:43:54 +0000604 tcg_gen_op3_i32(INDEX_op_shl_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000605}
606
pbrooka7812ae2008-11-17 14:43:54 +0000607static inline void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000608{
bellard34151a22008-05-22 13:25:14 +0000609 if (arg2 == 0) {
610 tcg_gen_mov_i32(ret, arg1);
611 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000612 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000613 tcg_gen_shl_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000614 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000615 }
bellardc896fe22008-02-01 10:05:41 +0000616}
617
pbrooka7812ae2008-11-17 14:43:54 +0000618static inline void tcg_gen_shr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000619{
pbrooka7812ae2008-11-17 14:43:54 +0000620 tcg_gen_op3_i32(INDEX_op_shr_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000621}
622
pbrooka7812ae2008-11-17 14:43:54 +0000623static inline void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000624{
bellard34151a22008-05-22 13:25:14 +0000625 if (arg2 == 0) {
626 tcg_gen_mov_i32(ret, arg1);
627 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000628 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000629 tcg_gen_shr_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000630 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000631 }
bellardc896fe22008-02-01 10:05:41 +0000632}
633
pbrooka7812ae2008-11-17 14:43:54 +0000634static inline void tcg_gen_sar_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000635{
pbrooka7812ae2008-11-17 14:43:54 +0000636 tcg_gen_op3_i32(INDEX_op_sar_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000637}
638
pbrooka7812ae2008-11-17 14:43:54 +0000639static inline void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000640{
bellard34151a22008-05-22 13:25:14 +0000641 if (arg2 == 0) {
642 tcg_gen_mov_i32(ret, arg1);
643 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000644 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000645 tcg_gen_sar_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000646 tcg_temp_free_i32(t0);
bellard34151a22008-05-22 13:25:14 +0000647 }
bellardc896fe22008-02-01 10:05:41 +0000648}
649
Richard Henderson8a56e842010-03-19 11:26:05 -0700650static inline void tcg_gen_brcond_i32(TCGCond cond, TCGv_i32 arg1,
651 TCGv_i32 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +0000652{
Richard Henderson0aed2572012-09-24 14:21:40 -0700653 if (cond == TCG_COND_ALWAYS) {
654 tcg_gen_br(label_index);
655 } else if (cond != TCG_COND_NEVER) {
656 tcg_gen_op4ii_i32(INDEX_op_brcond_i32, arg1, arg2, cond, label_index);
657 }
bellardc896fe22008-02-01 10:05:41 +0000658}
659
Richard Henderson8a56e842010-03-19 11:26:05 -0700660static inline void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1,
661 int32_t arg2, int label_index)
pbrookcb636692008-05-24 02:22:00 +0000662{
Richard Henderson0aed2572012-09-24 14:21:40 -0700663 if (cond == TCG_COND_ALWAYS) {
664 tcg_gen_br(label_index);
665 } else if (cond != TCG_COND_NEVER) {
666 TCGv_i32 t0 = tcg_const_i32(arg2);
667 tcg_gen_brcond_i32(cond, arg1, t0, label_index);
668 tcg_temp_free_i32(t0);
669 }
pbrookcb636692008-05-24 02:22:00 +0000670}
671
Richard Henderson8a56e842010-03-19 11:26:05 -0700672static inline void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +0100673 TCGv_i32 arg1, TCGv_i32 arg2)
674{
Richard Henderson0aed2572012-09-24 14:21:40 -0700675 if (cond == TCG_COND_ALWAYS) {
676 tcg_gen_movi_i32(ret, 1);
677 } else if (cond == TCG_COND_NEVER) {
678 tcg_gen_movi_i32(ret, 0);
679 } else {
680 tcg_gen_op4i_i32(INDEX_op_setcond_i32, ret, arg1, arg2, cond);
681 }
Aurelien Jarno5105c552010-02-08 12:10:15 +0100682}
683
Richard Henderson8a56e842010-03-19 11:26:05 -0700684static inline void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
685 TCGv_i32 arg1, int32_t arg2)
Aurelien Jarno5105c552010-02-08 12:10:15 +0100686{
Richard Henderson0aed2572012-09-24 14:21:40 -0700687 if (cond == TCG_COND_ALWAYS) {
688 tcg_gen_movi_i32(ret, 1);
689 } else if (cond == TCG_COND_NEVER) {
690 tcg_gen_movi_i32(ret, 0);
691 } else {
692 TCGv_i32 t0 = tcg_const_i32(arg2);
693 tcg_gen_setcond_i32(cond, ret, arg1, t0);
694 tcg_temp_free_i32(t0);
695 }
Aurelien Jarno5105c552010-02-08 12:10:15 +0100696}
697
pbrooka7812ae2008-11-17 14:43:54 +0000698static inline void tcg_gen_mul_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000699{
pbrooka7812ae2008-11-17 14:43:54 +0000700 tcg_gen_op3_i32(INDEX_op_mul_i32, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000701}
702
pbrooka7812ae2008-11-17 14:43:54 +0000703static inline void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
thsf730fd22008-05-04 08:14:08 +0000704{
pbrooka7812ae2008-11-17 14:43:54 +0000705 TCGv_i32 t0 = tcg_const_i32(arg2);
bellarde8996ee2008-05-23 17:33:39 +0000706 tcg_gen_mul_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000707 tcg_temp_free_i32(t0);
thsf730fd22008-05-04 08:14:08 +0000708}
709
pbrooka7812ae2008-11-17 14:43:54 +0000710static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000711{
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700712 if (TCG_TARGET_HAS_div_i32) {
713 tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2);
714 } else if (TCG_TARGET_HAS_div2_i32) {
715 TCGv_i32 t0 = tcg_temp_new_i32();
716 tcg_gen_sari_i32(t0, arg1, 31);
717 tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2);
718 tcg_temp_free_i32(t0);
719 } else {
720 int sizemask = 0;
721 /* Return value and both arguments are 32-bit and signed. */
722 sizemask |= tcg_gen_sizemask(0, 0, 1);
723 sizemask |= tcg_gen_sizemask(1, 0, 1);
724 sizemask |= tcg_gen_sizemask(2, 0, 1);
725 tcg_gen_helper32(tcg_helper_div_i32, sizemask, ret, arg1, arg2);
726 }
bellardc896fe22008-02-01 10:05:41 +0000727}
728
pbrooka7812ae2008-11-17 14:43:54 +0000729static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000730{
Richard Hendersonca675f42013-03-11 22:41:47 -0700731 if (TCG_TARGET_HAS_rem_i32) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700732 tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2);
Richard Hendersonca675f42013-03-11 22:41:47 -0700733 } else if (TCG_TARGET_HAS_div_i32) {
734 TCGv_i32 t0 = tcg_temp_new_i32();
735 tcg_gen_op3_i32(INDEX_op_div_i32, t0, arg1, arg2);
736 tcg_gen_mul_i32(t0, t0, arg2);
737 tcg_gen_sub_i32(ret, arg1, t0);
738 tcg_temp_free_i32(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700739 } else if (TCG_TARGET_HAS_div2_i32) {
740 TCGv_i32 t0 = tcg_temp_new_i32();
741 tcg_gen_sari_i32(t0, arg1, 31);
742 tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2);
743 tcg_temp_free_i32(t0);
744 } else {
745 int sizemask = 0;
746 /* Return value and both arguments are 32-bit and signed. */
747 sizemask |= tcg_gen_sizemask(0, 0, 1);
748 sizemask |= tcg_gen_sizemask(1, 0, 1);
749 sizemask |= tcg_gen_sizemask(2, 0, 1);
750 tcg_gen_helper32(tcg_helper_rem_i32, sizemask, ret, arg1, arg2);
751 }
bellardc896fe22008-02-01 10:05:41 +0000752}
753
pbrooka7812ae2008-11-17 14:43:54 +0000754static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000755{
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700756 if (TCG_TARGET_HAS_div_i32) {
757 tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2);
758 } else if (TCG_TARGET_HAS_div2_i32) {
759 TCGv_i32 t0 = tcg_temp_new_i32();
760 tcg_gen_movi_i32(t0, 0);
761 tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2);
762 tcg_temp_free_i32(t0);
763 } else {
764 int sizemask = 0;
765 /* Return value and both arguments are 32-bit and unsigned. */
766 sizemask |= tcg_gen_sizemask(0, 0, 0);
767 sizemask |= tcg_gen_sizemask(1, 0, 0);
768 sizemask |= tcg_gen_sizemask(2, 0, 0);
769 tcg_gen_helper32(tcg_helper_divu_i32, sizemask, ret, arg1, arg2);
770 }
bellardc896fe22008-02-01 10:05:41 +0000771}
772
pbrooka7812ae2008-11-17 14:43:54 +0000773static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
bellardc896fe22008-02-01 10:05:41 +0000774{
Richard Hendersonca675f42013-03-11 22:41:47 -0700775 if (TCG_TARGET_HAS_rem_i32) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700776 tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2);
Richard Hendersonca675f42013-03-11 22:41:47 -0700777 } else if (TCG_TARGET_HAS_div_i32) {
778 TCGv_i32 t0 = tcg_temp_new_i32();
779 tcg_gen_op3_i32(INDEX_op_divu_i32, t0, arg1, arg2);
780 tcg_gen_mul_i32(t0, t0, arg2);
781 tcg_gen_sub_i32(ret, arg1, t0);
782 tcg_temp_free_i32(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700783 } else if (TCG_TARGET_HAS_div2_i32) {
784 TCGv_i32 t0 = tcg_temp_new_i32();
785 tcg_gen_movi_i32(t0, 0);
786 tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2);
787 tcg_temp_free_i32(t0);
788 } else {
789 int sizemask = 0;
790 /* Return value and both arguments are 32-bit and unsigned. */
791 sizemask |= tcg_gen_sizemask(0, 0, 0);
792 sizemask |= tcg_gen_sizemask(1, 0, 0);
793 sizemask |= tcg_gen_sizemask(2, 0, 0);
794 tcg_gen_helper32(tcg_helper_remu_i32, sizemask, ret, arg1, arg2);
795 }
bellardc896fe22008-02-01 10:05:41 +0000796}
bellardc896fe22008-02-01 10:05:41 +0000797
798#if TCG_TARGET_REG_BITS == 32
799
pbrooka7812ae2008-11-17 14:43:54 +0000800static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +0000801{
aurel32fe75bcf2009-03-10 08:57:16 +0000802 if (!TCGV_EQUAL_I64(ret, arg)) {
pbrooka7812ae2008-11-17 14:43:54 +0000803 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
blueswir14d072722008-05-03 20:52:26 +0000804 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
805 }
bellardc896fe22008-02-01 10:05:41 +0000806}
807
pbrooka7812ae2008-11-17 14:43:54 +0000808static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +0000809{
pbrooka7812ae2008-11-17 14:43:54 +0000810 tcg_gen_movi_i32(TCGV_LOW(ret), arg);
pbrookac56dd42008-02-03 19:56:33 +0000811 tcg_gen_movi_i32(TCGV_HIGH(ret), arg >> 32);
bellardc896fe22008-02-01 10:05:41 +0000812}
813
pbrooka7812ae2008-11-17 14:43:54 +0000814static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
815 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000816{
pbrooka7812ae2008-11-17 14:43:54 +0000817 tcg_gen_ld8u_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000818 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000819}
820
pbrooka7812ae2008-11-17 14:43:54 +0000821static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
822 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000823{
pbrooka7812ae2008-11-17 14:43:54 +0000824 tcg_gen_ld8s_i32(TCGV_LOW(ret), arg2, offset);
825 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000826}
827
pbrooka7812ae2008-11-17 14:43:54 +0000828static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
829 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000830{
aurel32a7477232009-02-09 20:43:53 +0000831 tcg_gen_ld16u_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000832 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000833}
834
pbrooka7812ae2008-11-17 14:43:54 +0000835static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
836 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000837{
pbrooka7812ae2008-11-17 14:43:54 +0000838 tcg_gen_ld16s_i32(TCGV_LOW(ret), arg2, offset);
839 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000840}
841
pbrooka7812ae2008-11-17 14:43:54 +0000842static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
843 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000844{
pbrooka7812ae2008-11-17 14:43:54 +0000845 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000846 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +0000847}
848
pbrooka7812ae2008-11-17 14:43:54 +0000849static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
850 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000851{
pbrooka7812ae2008-11-17 14:43:54 +0000852 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
853 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +0000854}
855
pbrooka7812ae2008-11-17 14:43:54 +0000856static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2,
857 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000858{
859 /* since arg2 and ret have different types, they cannot be the
860 same temporary */
861#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000862 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset);
pbrooka7812ae2008-11-17 14:43:54 +0000863 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000864#else
pbrooka7812ae2008-11-17 14:43:54 +0000865 tcg_gen_ld_i32(TCGV_LOW(ret), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000866 tcg_gen_ld_i32(TCGV_HIGH(ret), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000867#endif
868}
869
pbrooka7812ae2008-11-17 14:43:54 +0000870static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
871 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000872{
pbrooka7812ae2008-11-17 14:43:54 +0000873 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000874}
875
pbrooka7812ae2008-11-17 14:43:54 +0000876static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
877 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000878{
pbrooka7812ae2008-11-17 14:43:54 +0000879 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000880}
881
pbrooka7812ae2008-11-17 14:43:54 +0000882static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
883 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000884{
pbrooka7812ae2008-11-17 14:43:54 +0000885 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
bellardc896fe22008-02-01 10:05:41 +0000886}
887
pbrooka7812ae2008-11-17 14:43:54 +0000888static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2,
889 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +0000890{
891#ifdef TCG_TARGET_WORDS_BIGENDIAN
pbrookac56dd42008-02-03 19:56:33 +0000892 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset);
pbrooka7812ae2008-11-17 14:43:54 +0000893 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000894#else
pbrooka7812ae2008-11-17 14:43:54 +0000895 tcg_gen_st_i32(TCGV_LOW(arg1), arg2, offset);
pbrookac56dd42008-02-03 19:56:33 +0000896 tcg_gen_st_i32(TCGV_HIGH(arg1), arg2, offset + 4);
bellardc896fe22008-02-01 10:05:41 +0000897#endif
898}
899
pbrooka7812ae2008-11-17 14:43:54 +0000900static inline void tcg_gen_add_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000901{
pbrooka7812ae2008-11-17 14:43:54 +0000902 tcg_gen_op6_i32(INDEX_op_add2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
903 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
904 TCGV_HIGH(arg2));
Richard Henderson212c3282012-10-02 11:32:28 -0700905 /* Allow the optimizer room to replace add2 with two moves. */
906 tcg_gen_op0(INDEX_op_nop);
bellardc896fe22008-02-01 10:05:41 +0000907}
908
pbrooka7812ae2008-11-17 14:43:54 +0000909static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000910{
pbrooka7812ae2008-11-17 14:43:54 +0000911 tcg_gen_op6_i32(INDEX_op_sub2_i32, TCGV_LOW(ret), TCGV_HIGH(ret),
912 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
913 TCGV_HIGH(arg2));
Richard Henderson212c3282012-10-02 11:32:28 -0700914 /* Allow the optimizer room to replace sub2 with two moves. */
915 tcg_gen_op0(INDEX_op_nop);
bellardc896fe22008-02-01 10:05:41 +0000916}
917
pbrooka7812ae2008-11-17 14:43:54 +0000918static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000919{
pbrooka7812ae2008-11-17 14:43:54 +0000920 tcg_gen_and_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
pbrookac56dd42008-02-03 19:56:33 +0000921 tcg_gen_and_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000922}
923
pbrooka7812ae2008-11-17 14:43:54 +0000924static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000925{
aurel32e5105082009-03-11 02:57:30 +0000926 tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
927 tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000928}
929
pbrooka7812ae2008-11-17 14:43:54 +0000930static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000931{
aurel32e5105082009-03-11 02:57:30 +0000932 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
933 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000934}
935
pbrooka7812ae2008-11-17 14:43:54 +0000936static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000937{
pbrooka7812ae2008-11-17 14:43:54 +0000938 tcg_gen_ori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
pbrookac56dd42008-02-03 19:56:33 +0000939 tcg_gen_ori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000940}
941
pbrooka7812ae2008-11-17 14:43:54 +0000942static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000943{
aurel32e5105082009-03-11 02:57:30 +0000944 tcg_gen_xor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
945 tcg_gen_xor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
bellardc896fe22008-02-01 10:05:41 +0000946}
947
pbrooka7812ae2008-11-17 14:43:54 +0000948static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000949{
pbrooka7812ae2008-11-17 14:43:54 +0000950 tcg_gen_xori_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
pbrookac56dd42008-02-03 19:56:33 +0000951 tcg_gen_xori_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
bellardc896fe22008-02-01 10:05:41 +0000952}
953
954/* XXX: use generic code when basic block handling is OK or CPU
955 specific code (x86) */
pbrooka7812ae2008-11-17 14:43:54 +0000956static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000957{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700958 int sizemask = 0;
959 /* Return value and both arguments are 64-bit and signed. */
960 sizemask |= tcg_gen_sizemask(0, 1, 1);
961 sizemask |= tcg_gen_sizemask(1, 1, 1);
962 sizemask |= tcg_gen_sizemask(2, 1, 1);
963
964 tcg_gen_helper64(tcg_helper_shl_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000965}
966
pbrooka7812ae2008-11-17 14:43:54 +0000967static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000968{
969 tcg_gen_shifti_i64(ret, arg1, arg2, 0, 0);
970}
971
pbrooka7812ae2008-11-17 14:43:54 +0000972static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000973{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700974 int sizemask = 0;
975 /* Return value and both arguments are 64-bit and signed. */
976 sizemask |= tcg_gen_sizemask(0, 1, 1);
977 sizemask |= tcg_gen_sizemask(1, 1, 1);
978 sizemask |= tcg_gen_sizemask(2, 1, 1);
979
980 tcg_gen_helper64(tcg_helper_shr_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000981}
982
pbrooka7812ae2008-11-17 14:43:54 +0000983static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +0000984{
985 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 0);
986}
987
pbrooka7812ae2008-11-17 14:43:54 +0000988static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +0000989{
Richard Henderson2bece2c2010-06-14 17:35:27 -0700990 int sizemask = 0;
991 /* Return value and both arguments are 64-bit and signed. */
992 sizemask |= tcg_gen_sizemask(0, 1, 1);
993 sizemask |= tcg_gen_sizemask(1, 1, 1);
994 sizemask |= tcg_gen_sizemask(2, 1, 1);
995
996 tcg_gen_helper64(tcg_helper_sar_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +0000997}
998
pbrooka7812ae2008-11-17 14:43:54 +0000999static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001000{
1001 tcg_gen_shifti_i64(ret, arg1, arg2, 1, 1);
1002}
1003
Richard Henderson8a56e842010-03-19 11:26:05 -07001004static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1005 TCGv_i64 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +00001006{
Richard Henderson0aed2572012-09-24 14:21:40 -07001007 if (cond == TCG_COND_ALWAYS) {
1008 tcg_gen_br(label_index);
1009 } else if (cond != TCG_COND_NEVER) {
1010 tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
1011 TCGV_LOW(arg1), TCGV_HIGH(arg1), TCGV_LOW(arg2),
1012 TCGV_HIGH(arg2), cond, label_index);
1013 }
bellardc896fe22008-02-01 10:05:41 +00001014}
1015
Richard Henderson8a56e842010-03-19 11:26:05 -07001016static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +01001017 TCGv_i64 arg1, TCGv_i64 arg2)
1018{
Richard Henderson0aed2572012-09-24 14:21:40 -07001019 if (cond == TCG_COND_ALWAYS) {
1020 tcg_gen_movi_i32(TCGV_LOW(ret), 1);
1021 } else if (cond == TCG_COND_NEVER) {
1022 tcg_gen_movi_i32(TCGV_LOW(ret), 0);
1023 } else {
1024 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
1025 TCGV_LOW(arg1), TCGV_HIGH(arg1),
1026 TCGV_LOW(arg2), TCGV_HIGH(arg2), cond);
1027 }
Aurelien Jarno5105c552010-02-08 12:10:15 +01001028 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1029}
1030
pbrooka7812ae2008-11-17 14:43:54 +00001031static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001032{
pbrooka7812ae2008-11-17 14:43:54 +00001033 TCGv_i64 t0;
1034 TCGv_i32 t1;
bellardc896fe22008-02-01 10:05:41 +00001035
pbrooka7812ae2008-11-17 14:43:54 +00001036 t0 = tcg_temp_new_i64();
1037 t1 = tcg_temp_new_i32();
1038
Richard Henderson03271522013-08-14 14:35:56 -07001039 if (TCG_TARGET_HAS_mulu2_i32) {
1040 tcg_gen_op4_i32(INDEX_op_mulu2_i32, TCGV_LOW(t0), TCGV_HIGH(t0),
1041 TCGV_LOW(arg1), TCGV_LOW(arg2));
1042 /* Allow the optimizer room to replace mulu2 with two moves. */
1043 tcg_gen_op0(INDEX_op_nop);
1044 } else {
1045 tcg_debug_assert(TCG_TARGET_HAS_muluh_i32);
1046 tcg_gen_op3_i32(INDEX_op_mul_i32, TCGV_LOW(t0),
1047 TCGV_LOW(arg1), TCGV_LOW(arg2));
1048 tcg_gen_op3_i32(INDEX_op_muluh_i32, TCGV_HIGH(t0),
1049 TCGV_LOW(arg1), TCGV_LOW(arg2));
1050 }
pbrooka7812ae2008-11-17 14:43:54 +00001051
1052 tcg_gen_mul_i32(t1, TCGV_LOW(arg1), TCGV_HIGH(arg2));
pbrookac56dd42008-02-03 19:56:33 +00001053 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
pbrooka7812ae2008-11-17 14:43:54 +00001054 tcg_gen_mul_i32(t1, TCGV_HIGH(arg1), TCGV_LOW(arg2));
pbrookac56dd42008-02-03 19:56:33 +00001055 tcg_gen_add_i32(TCGV_HIGH(t0), TCGV_HIGH(t0), t1);
pbrooka7812ae2008-11-17 14:43:54 +00001056
bellardc896fe22008-02-01 10:05:41 +00001057 tcg_gen_mov_i64(ret, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001058 tcg_temp_free_i64(t0);
1059 tcg_temp_free_i32(t1);
bellardc896fe22008-02-01 10:05:41 +00001060}
1061
pbrooka7812ae2008-11-17 14:43:54 +00001062static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001063{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001064 int sizemask = 0;
1065 /* Return value and both arguments are 64-bit and signed. */
1066 sizemask |= tcg_gen_sizemask(0, 1, 1);
1067 sizemask |= tcg_gen_sizemask(1, 1, 1);
1068 sizemask |= tcg_gen_sizemask(2, 1, 1);
1069
1070 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001071}
1072
pbrooka7812ae2008-11-17 14:43:54 +00001073static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001074{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001075 int sizemask = 0;
1076 /* Return value and both arguments are 64-bit and signed. */
1077 sizemask |= tcg_gen_sizemask(0, 1, 1);
1078 sizemask |= tcg_gen_sizemask(1, 1, 1);
1079 sizemask |= tcg_gen_sizemask(2, 1, 1);
1080
1081 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001082}
1083
pbrooka7812ae2008-11-17 14:43:54 +00001084static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001085{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001086 int sizemask = 0;
1087 /* Return value and both arguments are 64-bit and unsigned. */
1088 sizemask |= tcg_gen_sizemask(0, 1, 0);
1089 sizemask |= tcg_gen_sizemask(1, 1, 0);
1090 sizemask |= tcg_gen_sizemask(2, 1, 0);
1091
1092 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001093}
1094
pbrooka7812ae2008-11-17 14:43:54 +00001095static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001096{
Richard Henderson2bece2c2010-06-14 17:35:27 -07001097 int sizemask = 0;
1098 /* Return value and both arguments are 64-bit and unsigned. */
1099 sizemask |= tcg_gen_sizemask(0, 1, 0);
1100 sizemask |= tcg_gen_sizemask(1, 1, 0);
1101 sizemask |= tcg_gen_sizemask(2, 1, 0);
1102
1103 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001104}
1105
1106#else
1107
pbrooka7812ae2008-11-17 14:43:54 +00001108static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001109{
aurel32fe75bcf2009-03-10 08:57:16 +00001110 if (!TCGV_EQUAL_I64(ret, arg))
pbrooka7812ae2008-11-17 14:43:54 +00001111 tcg_gen_op2_i64(INDEX_op_mov_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001112}
1113
pbrooka7812ae2008-11-17 14:43:54 +00001114static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
bellardc896fe22008-02-01 10:05:41 +00001115{
pbrooka7812ae2008-11-17 14:43:54 +00001116 tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
bellardc896fe22008-02-01 10:05:41 +00001117}
1118
Peter Maydell6bd4b082011-05-27 13:12:12 +01001119static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001120 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001121{
pbrooka7812ae2008-11-17 14:43:54 +00001122 tcg_gen_ldst_op_i64(INDEX_op_ld8u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001123}
1124
Peter Maydell6bd4b082011-05-27 13:12:12 +01001125static inline void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001126 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001127{
pbrooka7812ae2008-11-17 14:43:54 +00001128 tcg_gen_ldst_op_i64(INDEX_op_ld8s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001129}
1130
Peter Maydell6bd4b082011-05-27 13:12:12 +01001131static inline void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001132 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001133{
pbrooka7812ae2008-11-17 14:43:54 +00001134 tcg_gen_ldst_op_i64(INDEX_op_ld16u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001135}
1136
Peter Maydell6bd4b082011-05-27 13:12:12 +01001137static inline void tcg_gen_ld16s_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001138 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001139{
pbrooka7812ae2008-11-17 14:43:54 +00001140 tcg_gen_ldst_op_i64(INDEX_op_ld16s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001141}
1142
Peter Maydell6bd4b082011-05-27 13:12:12 +01001143static inline void tcg_gen_ld32u_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001144 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001145{
pbrooka7812ae2008-11-17 14:43:54 +00001146 tcg_gen_ldst_op_i64(INDEX_op_ld32u_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001147}
1148
Peter Maydell6bd4b082011-05-27 13:12:12 +01001149static inline void tcg_gen_ld32s_i64(TCGv_i64 ret, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001150 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_ld32s_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001153}
1154
Peter Maydell6bd4b082011-05-27 13:12:12 +01001155static inline void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001156{
pbrooka7812ae2008-11-17 14:43:54 +00001157 tcg_gen_ldst_op_i64(INDEX_op_ld_i64, ret, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001158}
1159
Peter Maydell6bd4b082011-05-27 13:12:12 +01001160static inline void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001161 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001162{
pbrooka7812ae2008-11-17 14:43:54 +00001163 tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001164}
1165
Peter Maydell6bd4b082011-05-27 13:12:12 +01001166static inline void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001167 tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001168{
pbrooka7812ae2008-11-17 14:43:54 +00001169 tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001170}
1171
Peter Maydell6bd4b082011-05-27 13:12:12 +01001172static inline void tcg_gen_st32_i64(TCGv_i64 arg1, TCGv_ptr arg2,
pbrookac56dd42008-02-03 19:56:33 +00001173 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_st32_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001176}
1177
Peter Maydell6bd4b082011-05-27 13:12:12 +01001178static inline void tcg_gen_st_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
bellardc896fe22008-02-01 10:05:41 +00001179{
pbrooka7812ae2008-11-17 14:43:54 +00001180 tcg_gen_ldst_op_i64(INDEX_op_st_i64, arg1, arg2, offset);
bellardc896fe22008-02-01 10:05:41 +00001181}
1182
pbrooka7812ae2008-11-17 14:43:54 +00001183static inline void tcg_gen_add_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_add_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001186}
1187
pbrooka7812ae2008-11-17 14:43:54 +00001188static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001189{
pbrooka7812ae2008-11-17 14:43:54 +00001190 tcg_gen_op3_i64(INDEX_op_sub_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001191}
1192
pbrooka7812ae2008-11-17 14:43:54 +00001193static inline void tcg_gen_and_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001194{
aurel327fc81052009-03-10 19:37:39 +00001195 if (TCGV_EQUAL_I64(arg1, arg2)) {
1196 tcg_gen_mov_i64(ret, arg1);
1197 } else {
1198 tcg_gen_op3_i64(INDEX_op_and_i64, ret, arg1, arg2);
1199 }
bellardc896fe22008-02-01 10:05:41 +00001200}
1201
Richard Henderson42ce3e22012-09-21 17:18:10 -07001202static inline void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001203{
Richard Henderson42ce3e22012-09-21 17:18:10 -07001204 TCGv_i64 t0;
1205 /* Some cases can be optimized here. */
1206 switch (arg2) {
1207 case 0:
1208 tcg_gen_movi_i64(ret, 0);
1209 return;
1210 case 0xffffffffffffffffull:
1211 tcg_gen_mov_i64(ret, arg1);
1212 return;
1213 case 0xffull:
1214 /* Don't recurse with tcg_gen_ext8u_i32. */
1215 if (TCG_TARGET_HAS_ext8u_i64) {
1216 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg1);
1217 return;
1218 }
1219 break;
1220 case 0xffffu:
1221 if (TCG_TARGET_HAS_ext16u_i64) {
1222 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg1);
1223 return;
1224 }
1225 break;
1226 case 0xffffffffull:
1227 if (TCG_TARGET_HAS_ext32u_i64) {
1228 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg1);
1229 return;
1230 }
1231 break;
1232 }
1233 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001234 tcg_gen_and_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001235 tcg_temp_free_i64(t0);
bellardc896fe22008-02-01 10:05:41 +00001236}
1237
pbrooka7812ae2008-11-17 14:43:54 +00001238static inline void tcg_gen_or_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001239{
aurel327fc81052009-03-10 19:37:39 +00001240 if (TCGV_EQUAL_I64(arg1, arg2)) {
1241 tcg_gen_mov_i64(ret, arg1);
1242 } else {
1243 tcg_gen_op3_i64(INDEX_op_or_i64, ret, arg1, arg2);
1244 }
bellardc896fe22008-02-01 10:05:41 +00001245}
1246
pbrooka7812ae2008-11-17 14:43:54 +00001247static inline void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001248{
Richard Hendersond81ada72012-09-21 17:18:11 -07001249 /* Some cases can be optimized here. */
1250 if (arg2 == -1) {
1251 tcg_gen_movi_i64(ret, -1);
1252 } else if (arg2 == 0) {
1253 tcg_gen_mov_i64(ret, arg1);
1254 } else {
1255 TCGv_i64 t0 = tcg_const_i64(arg2);
1256 tcg_gen_or_i64(ret, arg1, t0);
1257 tcg_temp_free_i64(t0);
1258 }
bellardc896fe22008-02-01 10:05:41 +00001259}
1260
pbrooka7812ae2008-11-17 14:43:54 +00001261static inline void tcg_gen_xor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001262{
aurel327fc81052009-03-10 19:37:39 +00001263 if (TCGV_EQUAL_I64(arg1, arg2)) {
1264 tcg_gen_movi_i64(ret, 0);
1265 } else {
1266 tcg_gen_op3_i64(INDEX_op_xor_i64, ret, arg1, arg2);
1267 }
bellardc896fe22008-02-01 10:05:41 +00001268}
1269
pbrooka7812ae2008-11-17 14:43:54 +00001270static inline void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001271{
Richard Henderson6f3bb332012-09-21 17:18:12 -07001272 /* Some cases can be optimized here. */
1273 if (arg2 == 0) {
1274 tcg_gen_mov_i64(ret, arg1);
1275 } else if (arg2 == -1 && TCG_TARGET_HAS_not_i64) {
1276 /* Don't recurse with tcg_gen_not_i64. */
1277 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg1);
1278 } else {
1279 TCGv_i64 t0 = tcg_const_i64(arg2);
1280 tcg_gen_xor_i64(ret, arg1, t0);
1281 tcg_temp_free_i64(t0);
1282 }
bellardc896fe22008-02-01 10:05:41 +00001283}
1284
pbrooka7812ae2008-11-17 14:43:54 +00001285static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001286{
pbrooka7812ae2008-11-17 14:43:54 +00001287 tcg_gen_op3_i64(INDEX_op_shl_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001288}
1289
pbrooka7812ae2008-11-17 14:43:54 +00001290static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001291{
bellard34151a22008-05-22 13:25:14 +00001292 if (arg2 == 0) {
1293 tcg_gen_mov_i64(ret, arg1);
1294 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001295 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001296 tcg_gen_shl_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001297 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001298 }
bellardc896fe22008-02-01 10:05:41 +00001299}
1300
pbrooka7812ae2008-11-17 14:43:54 +00001301static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001302{
pbrooka7812ae2008-11-17 14:43:54 +00001303 tcg_gen_op3_i64(INDEX_op_shr_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001304}
1305
pbrooka7812ae2008-11-17 14:43:54 +00001306static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001307{
bellard34151a22008-05-22 13:25:14 +00001308 if (arg2 == 0) {
1309 tcg_gen_mov_i64(ret, arg1);
1310 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001311 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001312 tcg_gen_shr_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001313 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001314 }
bellardc896fe22008-02-01 10:05:41 +00001315}
1316
pbrooka7812ae2008-11-17 14:43:54 +00001317static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001318{
pbrooka7812ae2008-11-17 14:43:54 +00001319 tcg_gen_op3_i64(INDEX_op_sar_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001320}
1321
pbrooka7812ae2008-11-17 14:43:54 +00001322static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
bellardc896fe22008-02-01 10:05:41 +00001323{
bellard34151a22008-05-22 13:25:14 +00001324 if (arg2 == 0) {
1325 tcg_gen_mov_i64(ret, arg1);
1326 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001327 TCGv_i64 t0 = tcg_const_i64(arg2);
bellarde8996ee2008-05-23 17:33:39 +00001328 tcg_gen_sar_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001329 tcg_temp_free_i64(t0);
bellard34151a22008-05-22 13:25:14 +00001330 }
bellardc896fe22008-02-01 10:05:41 +00001331}
1332
Richard Henderson8a56e842010-03-19 11:26:05 -07001333static inline void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1,
1334 TCGv_i64 arg2, int label_index)
bellardc896fe22008-02-01 10:05:41 +00001335{
Richard Henderson0aed2572012-09-24 14:21:40 -07001336 if (cond == TCG_COND_ALWAYS) {
1337 tcg_gen_br(label_index);
1338 } else if (cond != TCG_COND_NEVER) {
1339 tcg_gen_op4ii_i64(INDEX_op_brcond_i64, arg1, arg2, cond, label_index);
1340 }
bellardc896fe22008-02-01 10:05:41 +00001341}
1342
Richard Henderson8a56e842010-03-19 11:26:05 -07001343static inline void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
Aurelien Jarno5105c552010-02-08 12:10:15 +01001344 TCGv_i64 arg1, TCGv_i64 arg2)
1345{
Richard Henderson0aed2572012-09-24 14:21:40 -07001346 if (cond == TCG_COND_ALWAYS) {
1347 tcg_gen_movi_i64(ret, 1);
1348 } else if (cond == TCG_COND_NEVER) {
1349 tcg_gen_movi_i64(ret, 0);
1350 } else {
1351 tcg_gen_op4i_i64(INDEX_op_setcond_i64, ret, arg1, arg2, cond);
1352 }
Aurelien Jarno5105c552010-02-08 12:10:15 +01001353}
1354
pbrooka7812ae2008-11-17 14:43:54 +00001355static inline void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001356{
pbrooka7812ae2008-11-17 14:43:54 +00001357 tcg_gen_op3_i64(INDEX_op_mul_i64, ret, arg1, arg2);
bellardc896fe22008-02-01 10:05:41 +00001358}
1359
pbrooka7812ae2008-11-17 14:43:54 +00001360static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001361{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001362 if (TCG_TARGET_HAS_div_i64) {
1363 tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2);
1364 } else if (TCG_TARGET_HAS_div2_i64) {
1365 TCGv_i64 t0 = tcg_temp_new_i64();
1366 tcg_gen_sari_i64(t0, arg1, 63);
1367 tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2);
1368 tcg_temp_free_i64(t0);
1369 } else {
1370 int sizemask = 0;
1371 /* Return value and both arguments are 64-bit and signed. */
1372 sizemask |= tcg_gen_sizemask(0, 1, 1);
1373 sizemask |= tcg_gen_sizemask(1, 1, 1);
1374 sizemask |= tcg_gen_sizemask(2, 1, 1);
1375 tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2);
1376 }
bellardc896fe22008-02-01 10:05:41 +00001377}
1378
pbrooka7812ae2008-11-17 14:43:54 +00001379static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001380{
Richard Hendersonca675f42013-03-11 22:41:47 -07001381 if (TCG_TARGET_HAS_rem_i64) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001382 tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2);
Richard Hendersonca675f42013-03-11 22:41:47 -07001383 } else if (TCG_TARGET_HAS_div_i64) {
1384 TCGv_i64 t0 = tcg_temp_new_i64();
1385 tcg_gen_op3_i64(INDEX_op_div_i64, t0, arg1, arg2);
1386 tcg_gen_mul_i64(t0, t0, arg2);
1387 tcg_gen_sub_i64(ret, arg1, t0);
1388 tcg_temp_free_i64(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001389 } else if (TCG_TARGET_HAS_div2_i64) {
1390 TCGv_i64 t0 = tcg_temp_new_i64();
1391 tcg_gen_sari_i64(t0, arg1, 63);
1392 tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2);
1393 tcg_temp_free_i64(t0);
1394 } else {
1395 int sizemask = 0;
1396 /* Return value and both arguments are 64-bit and signed. */
1397 sizemask |= tcg_gen_sizemask(0, 1, 1);
1398 sizemask |= tcg_gen_sizemask(1, 1, 1);
1399 sizemask |= tcg_gen_sizemask(2, 1, 1);
1400 tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2);
1401 }
bellardc896fe22008-02-01 10:05:41 +00001402}
1403
pbrooka7812ae2008-11-17 14:43:54 +00001404static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001405{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001406 if (TCG_TARGET_HAS_div_i64) {
1407 tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2);
1408 } else if (TCG_TARGET_HAS_div2_i64) {
1409 TCGv_i64 t0 = tcg_temp_new_i64();
1410 tcg_gen_movi_i64(t0, 0);
1411 tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2);
1412 tcg_temp_free_i64(t0);
1413 } else {
1414 int sizemask = 0;
1415 /* Return value and both arguments are 64-bit and unsigned. */
1416 sizemask |= tcg_gen_sizemask(0, 1, 0);
1417 sizemask |= tcg_gen_sizemask(1, 1, 0);
1418 sizemask |= tcg_gen_sizemask(2, 1, 0);
1419 tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2);
1420 }
bellardc896fe22008-02-01 10:05:41 +00001421}
1422
pbrooka7812ae2008-11-17 14:43:54 +00001423static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
bellardc896fe22008-02-01 10:05:41 +00001424{
Richard Hendersonca675f42013-03-11 22:41:47 -07001425 if (TCG_TARGET_HAS_rem_i64) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001426 tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2);
Richard Hendersonca675f42013-03-11 22:41:47 -07001427 } else if (TCG_TARGET_HAS_div_i64) {
1428 TCGv_i64 t0 = tcg_temp_new_i64();
1429 tcg_gen_op3_i64(INDEX_op_divu_i64, t0, arg1, arg2);
1430 tcg_gen_mul_i64(t0, t0, arg2);
1431 tcg_gen_sub_i64(ret, arg1, t0);
1432 tcg_temp_free_i64(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001433 } else if (TCG_TARGET_HAS_div2_i64) {
1434 TCGv_i64 t0 = tcg_temp_new_i64();
1435 tcg_gen_movi_i64(t0, 0);
1436 tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2);
1437 tcg_temp_free_i64(t0);
1438 } else {
1439 int sizemask = 0;
1440 /* Return value and both arguments are 64-bit and unsigned. */
1441 sizemask |= tcg_gen_sizemask(0, 1, 0);
1442 sizemask |= tcg_gen_sizemask(1, 1, 0);
1443 sizemask |= tcg_gen_sizemask(2, 1, 0);
1444 tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2);
1445 }
bellardc896fe22008-02-01 10:05:41 +00001446}
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001447#endif /* TCG_TARGET_REG_BITS == 32 */
bellardc896fe22008-02-01 10:05:41 +00001448
pbrooka7812ae2008-11-17 14:43:54 +00001449static inline void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3263597062008-11-02 08:22:54 +00001450{
1451 /* some cases can be optimized here */
1452 if (arg2 == 0) {
1453 tcg_gen_mov_i64(ret, arg1);
1454 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001455 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel3263597062008-11-02 08:22:54 +00001456 tcg_gen_add_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001457 tcg_temp_free_i64(t0);
aurel3263597062008-11-02 08:22:54 +00001458 }
1459}
1460
pbrooka7812ae2008-11-17 14:43:54 +00001461static inline void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
aurel3200457342008-11-02 08:23:04 +00001462{
pbrooka7812ae2008-11-17 14:43:54 +00001463 TCGv_i64 t0 = tcg_const_i64(arg1);
aurel3200457342008-11-02 08:23:04 +00001464 tcg_gen_sub_i64(ret, t0, arg2);
pbrooka7812ae2008-11-17 14:43:54 +00001465 tcg_temp_free_i64(t0);
aurel3200457342008-11-02 08:23:04 +00001466}
1467
pbrooka7812ae2008-11-17 14:43:54 +00001468static inline void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3263597062008-11-02 08:22:54 +00001469{
1470 /* some cases can be optimized here */
1471 if (arg2 == 0) {
1472 tcg_gen_mov_i64(ret, arg1);
1473 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001474 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel3263597062008-11-02 08:22:54 +00001475 tcg_gen_sub_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001476 tcg_temp_free_i64(t0);
aurel3263597062008-11-02 08:22:54 +00001477 }
1478}
Richard Henderson8a56e842010-03-19 11:26:05 -07001479static inline void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1,
1480 int64_t arg2, int label_index)
aurel32f02bb952008-11-03 07:08:26 +00001481{
Richard Henderson0aed2572012-09-24 14:21:40 -07001482 if (cond == TCG_COND_ALWAYS) {
1483 tcg_gen_br(label_index);
1484 } else if (cond != TCG_COND_NEVER) {
1485 TCGv_i64 t0 = tcg_const_i64(arg2);
1486 tcg_gen_brcond_i64(cond, arg1, t0, label_index);
1487 tcg_temp_free_i64(t0);
1488 }
aurel32f02bb952008-11-03 07:08:26 +00001489}
1490
Richard Henderson8a56e842010-03-19 11:26:05 -07001491static inline void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
1492 TCGv_i64 arg1, int64_t arg2)
Aurelien Jarno5105c552010-02-08 12:10:15 +01001493{
1494 TCGv_i64 t0 = tcg_const_i64(arg2);
1495 tcg_gen_setcond_i64(cond, ret, arg1, t0);
1496 tcg_temp_free_i64(t0);
1497}
1498
pbrooka7812ae2008-11-17 14:43:54 +00001499static inline void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel32f02bb952008-11-03 07:08:26 +00001500{
pbrooka7812ae2008-11-17 14:43:54 +00001501 TCGv_i64 t0 = tcg_const_i64(arg2);
aurel32f02bb952008-11-03 07:08:26 +00001502 tcg_gen_mul_i64(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001503 tcg_temp_free_i64(t0);
aurel32f02bb952008-11-03 07:08:26 +00001504}
1505
aurel3263597062008-11-02 08:22:54 +00001506
bellardc896fe22008-02-01 10:05:41 +00001507/***************************************/
1508/* optional operations */
1509
pbrooka7812ae2008-11-17 14:43:54 +00001510static inline void tcg_gen_ext8s_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001511{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001512 if (TCG_TARGET_HAS_ext8s_i32) {
1513 tcg_gen_op2_i32(INDEX_op_ext8s_i32, ret, arg);
1514 } else {
1515 tcg_gen_shli_i32(ret, arg, 24);
1516 tcg_gen_sari_i32(ret, ret, 24);
1517 }
bellardc896fe22008-02-01 10:05:41 +00001518}
1519
pbrooka7812ae2008-11-17 14:43:54 +00001520static inline void tcg_gen_ext16s_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001521{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001522 if (TCG_TARGET_HAS_ext16s_i32) {
1523 tcg_gen_op2_i32(INDEX_op_ext16s_i32, ret, arg);
1524 } else {
1525 tcg_gen_shli_i32(ret, arg, 16);
1526 tcg_gen_sari_i32(ret, ret, 16);
1527 }
bellardc896fe22008-02-01 10:05:41 +00001528}
1529
pbrooka7812ae2008-11-17 14:43:54 +00001530static inline void tcg_gen_ext8u_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook86831432008-05-11 12:22:01 +00001531{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001532 if (TCG_TARGET_HAS_ext8u_i32) {
1533 tcg_gen_op2_i32(INDEX_op_ext8u_i32, ret, arg);
1534 } else {
1535 tcg_gen_andi_i32(ret, arg, 0xffu);
1536 }
pbrook86831432008-05-11 12:22:01 +00001537}
1538
pbrooka7812ae2008-11-17 14:43:54 +00001539static inline void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook86831432008-05-11 12:22:01 +00001540{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001541 if (TCG_TARGET_HAS_ext16u_i32) {
1542 tcg_gen_op2_i32(INDEX_op_ext16u_i32, ret, arg);
1543 } else {
1544 tcg_gen_andi_i32(ret, arg, 0xffffu);
1545 }
pbrook86831432008-05-11 12:22:01 +00001546}
1547
bellardc896fe22008-02-01 10:05:41 +00001548/* Note: we assume the two high bytes are set to zero */
pbrooka7812ae2008-11-17 14:43:54 +00001549static inline void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001550{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001551 if (TCG_TARGET_HAS_bswap16_i32) {
1552 tcg_gen_op2_i32(INDEX_op_bswap16_i32, ret, arg);
1553 } else {
1554 TCGv_i32 t0 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001555
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001556 tcg_gen_ext8u_i32(t0, arg);
1557 tcg_gen_shli_i32(t0, t0, 8);
1558 tcg_gen_shri_i32(ret, arg, 8);
1559 tcg_gen_or_i32(ret, ret, t0);
1560 tcg_temp_free_i32(t0);
1561 }
bellardc896fe22008-02-01 10:05:41 +00001562}
1563
aurel3266896cb2009-03-13 09:34:48 +00001564static inline void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001565{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001566 if (TCG_TARGET_HAS_bswap32_i32) {
1567 tcg_gen_op2_i32(INDEX_op_bswap32_i32, ret, arg);
1568 } else {
1569 TCGv_i32 t0, t1;
1570 t0 = tcg_temp_new_i32();
1571 t1 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001572
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001573 tcg_gen_shli_i32(t0, arg, 24);
bellardc896fe22008-02-01 10:05:41 +00001574
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001575 tcg_gen_andi_i32(t1, arg, 0x0000ff00);
1576 tcg_gen_shli_i32(t1, t1, 8);
1577 tcg_gen_or_i32(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001578
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001579 tcg_gen_shri_i32(t1, arg, 8);
1580 tcg_gen_andi_i32(t1, t1, 0x0000ff00);
1581 tcg_gen_or_i32(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001582
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001583 tcg_gen_shri_i32(t1, arg, 24);
1584 tcg_gen_or_i32(ret, t0, t1);
1585 tcg_temp_free_i32(t0);
1586 tcg_temp_free_i32(t1);
1587 }
bellardc896fe22008-02-01 10:05:41 +00001588}
1589
1590#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001591static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001592{
pbrooka7812ae2008-11-17 14:43:54 +00001593 tcg_gen_ext8s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1594 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001595}
1596
pbrooka7812ae2008-11-17 14:43:54 +00001597static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001598{
pbrooka7812ae2008-11-17 14:43:54 +00001599 tcg_gen_ext16s_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1600 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001601}
1602
pbrooka7812ae2008-11-17 14:43:54 +00001603static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001604{
pbrooka7812ae2008-11-17 14:43:54 +00001605 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1606 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001607}
1608
pbrooka7812ae2008-11-17 14:43:54 +00001609static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001610{
pbrooka7812ae2008-11-17 14:43:54 +00001611 tcg_gen_ext8u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001612 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1613}
1614
pbrooka7812ae2008-11-17 14:43:54 +00001615static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001616{
pbrooka7812ae2008-11-17 14:43:54 +00001617 tcg_gen_ext16u_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001618 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1619}
1620
pbrooka7812ae2008-11-17 14:43:54 +00001621static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001622{
pbrooka7812ae2008-11-17 14:43:54 +00001623 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
pbrook86831432008-05-11 12:22:01 +00001624 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
1625}
1626
pbrooka7812ae2008-11-17 14:43:54 +00001627static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001628{
pbrooka7812ae2008-11-17 14:43:54 +00001629 tcg_gen_mov_i32(ret, TCGV_LOW(arg));
bellardc896fe22008-02-01 10:05:41 +00001630}
1631
pbrooka7812ae2008-11-17 14:43:54 +00001632static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001633{
pbrooka7812ae2008-11-17 14:43:54 +00001634 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
pbrookac56dd42008-02-03 19:56:33 +00001635 tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
bellardc896fe22008-02-01 10:05:41 +00001636}
1637
pbrooka7812ae2008-11-17 14:43:54 +00001638static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001639{
pbrooka7812ae2008-11-17 14:43:54 +00001640 tcg_gen_mov_i32(TCGV_LOW(ret), arg);
1641 tcg_gen_sari_i32(TCGV_HIGH(ret), TCGV_LOW(ret), 31);
bellardc896fe22008-02-01 10:05:41 +00001642}
1643
aurel329a5c57f2009-03-13 09:35:12 +00001644/* Note: we assume the six high bytes are set to zero */
1645static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1646{
1647 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1648 tcg_gen_bswap16_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1649}
1650
1651/* Note: we assume the four high bytes are set to zero */
1652static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1653{
1654 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
1655 tcg_gen_bswap32_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1656}
1657
aurel3266896cb2009-03-13 09:34:48 +00001658static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001659{
pbrooka7812ae2008-11-17 14:43:54 +00001660 TCGv_i32 t0, t1;
1661 t0 = tcg_temp_new_i32();
1662 t1 = tcg_temp_new_i32();
bellardc896fe22008-02-01 10:05:41 +00001663
aurel3266896cb2009-03-13 09:34:48 +00001664 tcg_gen_bswap32_i32(t0, TCGV_LOW(arg));
1665 tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg));
pbrooka7812ae2008-11-17 14:43:54 +00001666 tcg_gen_mov_i32(TCGV_LOW(ret), t1);
pbrookac56dd42008-02-03 19:56:33 +00001667 tcg_gen_mov_i32(TCGV_HIGH(ret), t0);
pbrooka7812ae2008-11-17 14:43:54 +00001668 tcg_temp_free_i32(t0);
1669 tcg_temp_free_i32(t1);
bellardc896fe22008-02-01 10:05:41 +00001670}
1671#else
1672
pbrooka7812ae2008-11-17 14:43:54 +00001673static inline void tcg_gen_ext8s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001674{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001675 if (TCG_TARGET_HAS_ext8s_i64) {
1676 tcg_gen_op2_i64(INDEX_op_ext8s_i64, ret, arg);
1677 } else {
1678 tcg_gen_shli_i64(ret, arg, 56);
1679 tcg_gen_sari_i64(ret, ret, 56);
1680 }
bellardc896fe22008-02-01 10:05:41 +00001681}
1682
pbrooka7812ae2008-11-17 14:43:54 +00001683static inline void tcg_gen_ext16s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001684{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001685 if (TCG_TARGET_HAS_ext16s_i64) {
1686 tcg_gen_op2_i64(INDEX_op_ext16s_i64, ret, arg);
1687 } else {
1688 tcg_gen_shli_i64(ret, arg, 48);
1689 tcg_gen_sari_i64(ret, ret, 48);
1690 }
bellardc896fe22008-02-01 10:05:41 +00001691}
1692
pbrooka7812ae2008-11-17 14:43:54 +00001693static inline void tcg_gen_ext32s_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001694{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001695 if (TCG_TARGET_HAS_ext32s_i64) {
1696 tcg_gen_op2_i64(INDEX_op_ext32s_i64, ret, arg);
1697 } else {
1698 tcg_gen_shli_i64(ret, arg, 32);
1699 tcg_gen_sari_i64(ret, ret, 32);
1700 }
bellardc896fe22008-02-01 10:05:41 +00001701}
1702
pbrooka7812ae2008-11-17 14:43:54 +00001703static inline void tcg_gen_ext8u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001704{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001705 if (TCG_TARGET_HAS_ext8u_i64) {
1706 tcg_gen_op2_i64(INDEX_op_ext8u_i64, ret, arg);
1707 } else {
1708 tcg_gen_andi_i64(ret, arg, 0xffu);
1709 }
pbrook86831432008-05-11 12:22:01 +00001710}
1711
pbrooka7812ae2008-11-17 14:43:54 +00001712static inline void tcg_gen_ext16u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001713{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001714 if (TCG_TARGET_HAS_ext16u_i64) {
1715 tcg_gen_op2_i64(INDEX_op_ext16u_i64, ret, arg);
1716 } else {
1717 tcg_gen_andi_i64(ret, arg, 0xffffu);
1718 }
pbrook86831432008-05-11 12:22:01 +00001719}
1720
pbrooka7812ae2008-11-17 14:43:54 +00001721static inline void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook86831432008-05-11 12:22:01 +00001722{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001723 if (TCG_TARGET_HAS_ext32u_i64) {
1724 tcg_gen_op2_i64(INDEX_op_ext32u_i64, ret, arg);
1725 } else {
1726 tcg_gen_andi_i64(ret, arg, 0xffffffffu);
1727 }
pbrook86831432008-05-11 12:22:01 +00001728}
1729
bellardc896fe22008-02-01 10:05:41 +00001730/* Note: we assume the target supports move between 32 and 64 bit
pbrookac56dd42008-02-03 19:56:33 +00001731 registers. This will probably break MIPS64 targets. */
pbrooka7812ae2008-11-17 14:43:54 +00001732static inline void tcg_gen_trunc_i64_i32(TCGv_i32 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001733{
pbrooka7812ae2008-11-17 14:43:54 +00001734 tcg_gen_mov_i32(ret, MAKE_TCGV_I32(GET_TCGV_I64(arg)));
bellardc896fe22008-02-01 10:05:41 +00001735}
1736
1737/* Note: we assume the target supports move between 32 and 64 bit
1738 registers */
pbrooka7812ae2008-11-17 14:43:54 +00001739static inline void tcg_gen_extu_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001740{
Aurelien Jarnocfc86982009-09-30 23:09:35 +02001741 tcg_gen_ext32u_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
bellardc896fe22008-02-01 10:05:41 +00001742}
1743
1744/* Note: we assume the target supports move between 32 and 64 bit
1745 registers */
pbrooka7812ae2008-11-17 14:43:54 +00001746static inline void tcg_gen_ext_i32_i64(TCGv_i64 ret, TCGv_i32 arg)
bellardc896fe22008-02-01 10:05:41 +00001747{
pbrooka7812ae2008-11-17 14:43:54 +00001748 tcg_gen_ext32s_i64(ret, MAKE_TCGV_I64(GET_TCGV_I32(arg)));
bellardc896fe22008-02-01 10:05:41 +00001749}
1750
aurel329a5c57f2009-03-13 09:35:12 +00001751/* Note: we assume the six high bytes are set to zero */
1752static inline void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg)
1753{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001754 if (TCG_TARGET_HAS_bswap16_i64) {
1755 tcg_gen_op2_i64(INDEX_op_bswap16_i64, ret, arg);
1756 } else {
1757 TCGv_i64 t0 = tcg_temp_new_i64();
aurel329a5c57f2009-03-13 09:35:12 +00001758
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001759 tcg_gen_ext8u_i64(t0, arg);
1760 tcg_gen_shli_i64(t0, t0, 8);
1761 tcg_gen_shri_i64(ret, arg, 8);
1762 tcg_gen_or_i64(ret, ret, t0);
1763 tcg_temp_free_i64(t0);
1764 }
aurel329a5c57f2009-03-13 09:35:12 +00001765}
1766
1767/* Note: we assume the four high bytes are set to zero */
1768static inline void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
1769{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001770 if (TCG_TARGET_HAS_bswap32_i64) {
1771 tcg_gen_op2_i64(INDEX_op_bswap32_i64, ret, arg);
1772 } else {
1773 TCGv_i64 t0, t1;
1774 t0 = tcg_temp_new_i64();
1775 t1 = tcg_temp_new_i64();
aurel329a5c57f2009-03-13 09:35:12 +00001776
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001777 tcg_gen_shli_i64(t0, arg, 24);
1778 tcg_gen_ext32u_i64(t0, t0);
aurel329a5c57f2009-03-13 09:35:12 +00001779
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001780 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1781 tcg_gen_shli_i64(t1, t1, 8);
1782 tcg_gen_or_i64(t0, t0, t1);
aurel329a5c57f2009-03-13 09:35:12 +00001783
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001784 tcg_gen_shri_i64(t1, arg, 8);
1785 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1786 tcg_gen_or_i64(t0, t0, t1);
aurel329a5c57f2009-03-13 09:35:12 +00001787
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001788 tcg_gen_shri_i64(t1, arg, 24);
1789 tcg_gen_or_i64(ret, t0, t1);
1790 tcg_temp_free_i64(t0);
1791 tcg_temp_free_i64(t1);
1792 }
aurel329a5c57f2009-03-13 09:35:12 +00001793}
1794
aurel3266896cb2009-03-13 09:34:48 +00001795static inline void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg)
bellardc896fe22008-02-01 10:05:41 +00001796{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001797 if (TCG_TARGET_HAS_bswap64_i64) {
1798 tcg_gen_op2_i64(INDEX_op_bswap64_i64, ret, arg);
1799 } else {
1800 TCGv_i64 t0 = tcg_temp_new_i64();
1801 TCGv_i64 t1 = tcg_temp_new_i64();
bellardc896fe22008-02-01 10:05:41 +00001802
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001803 tcg_gen_shli_i64(t0, arg, 56);
bellardc896fe22008-02-01 10:05:41 +00001804
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001805 tcg_gen_andi_i64(t1, arg, 0x0000ff00);
1806 tcg_gen_shli_i64(t1, t1, 40);
1807 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001808
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001809 tcg_gen_andi_i64(t1, arg, 0x00ff0000);
1810 tcg_gen_shli_i64(t1, t1, 24);
1811 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001812
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001813 tcg_gen_andi_i64(t1, arg, 0xff000000);
1814 tcg_gen_shli_i64(t1, t1, 8);
1815 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001816
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001817 tcg_gen_shri_i64(t1, arg, 8);
1818 tcg_gen_andi_i64(t1, t1, 0xff000000);
1819 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001820
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001821 tcg_gen_shri_i64(t1, arg, 24);
1822 tcg_gen_andi_i64(t1, t1, 0x00ff0000);
1823 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001824
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001825 tcg_gen_shri_i64(t1, arg, 40);
1826 tcg_gen_andi_i64(t1, t1, 0x0000ff00);
1827 tcg_gen_or_i64(t0, t0, t1);
bellardc896fe22008-02-01 10:05:41 +00001828
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001829 tcg_gen_shri_i64(t1, arg, 56);
1830 tcg_gen_or_i64(ret, t0, t1);
1831 tcg_temp_free_i64(t0);
1832 tcg_temp_free_i64(t1);
1833 }
bellardc896fe22008-02-01 10:05:41 +00001834}
1835
1836#endif
1837
pbrooka7812ae2008-11-17 14:43:54 +00001838static inline void tcg_gen_neg_i32(TCGv_i32 ret, TCGv_i32 arg)
pbrook390efc52008-05-11 14:35:37 +00001839{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001840 if (TCG_TARGET_HAS_neg_i32) {
1841 tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg);
1842 } else {
1843 TCGv_i32 t0 = tcg_const_i32(0);
1844 tcg_gen_sub_i32(ret, t0, arg);
1845 tcg_temp_free_i32(t0);
1846 }
pbrook390efc52008-05-11 14:35:37 +00001847}
1848
pbrooka7812ae2008-11-17 14:43:54 +00001849static inline void tcg_gen_neg_i64(TCGv_i64 ret, TCGv_i64 arg)
pbrook390efc52008-05-11 14:35:37 +00001850{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001851 if (TCG_TARGET_HAS_neg_i64) {
1852 tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg);
1853 } else {
1854 TCGv_i64 t0 = tcg_const_i64(0);
1855 tcg_gen_sub_i64(ret, t0, arg);
1856 tcg_temp_free_i64(t0);
1857 }
pbrook390efc52008-05-11 14:35:37 +00001858}
1859
pbrooka7812ae2008-11-17 14:43:54 +00001860static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
bellard0b6ce4c2008-05-17 12:40:44 +00001861{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001862 if (TCG_TARGET_HAS_not_i32) {
1863 tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg);
1864 } else {
1865 tcg_gen_xori_i32(ret, arg, -1);
1866 }
bellard0b6ce4c2008-05-17 12:40:44 +00001867}
1868
pbrooka7812ae2008-11-17 14:43:54 +00001869static inline void tcg_gen_not_i64(TCGv_i64 ret, TCGv_i64 arg)
bellard0b6ce4c2008-05-17 12:40:44 +00001870{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001871#if TCG_TARGET_REG_BITS == 64
1872 if (TCG_TARGET_HAS_not_i64) {
1873 tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg);
1874 } else {
1875 tcg_gen_xori_i64(ret, arg, -1);
1876 }
1877#else
Richard Hendersona10f9f42010-03-19 12:44:47 -07001878 tcg_gen_not_i32(TCGV_LOW(ret), TCGV_LOW(arg));
1879 tcg_gen_not_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
aurel32d2604282009-03-09 22:35:13 +00001880#endif
bellard0b6ce4c2008-05-17 12:40:44 +00001881}
bellard5ff9d6a2008-02-04 00:37:54 +00001882
pbrooka7812ae2008-11-17 14:43:54 +00001883static inline void tcg_gen_discard_i32(TCGv_i32 arg)
bellard5ff9d6a2008-02-04 00:37:54 +00001884{
pbrooka7812ae2008-11-17 14:43:54 +00001885 tcg_gen_op1_i32(INDEX_op_discard, arg);
bellard5ff9d6a2008-02-04 00:37:54 +00001886}
1887
pbrooka7812ae2008-11-17 14:43:54 +00001888static inline void tcg_gen_discard_i64(TCGv_i64 arg)
bellard5ff9d6a2008-02-04 00:37:54 +00001889{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001890#if TCG_TARGET_REG_BITS == 32
pbrooka7812ae2008-11-17 14:43:54 +00001891 tcg_gen_discard_i32(TCGV_LOW(arg));
bellard5ff9d6a2008-02-04 00:37:54 +00001892 tcg_gen_discard_i32(TCGV_HIGH(arg));
bellard5ff9d6a2008-02-04 00:37:54 +00001893#else
pbrooka7812ae2008-11-17 14:43:54 +00001894 tcg_gen_op1_i64(INDEX_op_discard, arg);
bellard5ff9d6a2008-02-04 00:37:54 +00001895#endif
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001896}
bellard5ff9d6a2008-02-04 00:37:54 +00001897
pbrooka7812ae2008-11-17 14:43:54 +00001898static inline void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001899{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001900 if (TCG_TARGET_HAS_andc_i32) {
1901 tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2);
1902 } else {
1903 TCGv_i32 t0 = tcg_temp_new_i32();
1904 tcg_gen_not_i32(t0, arg2);
1905 tcg_gen_and_i32(ret, arg1, t0);
1906 tcg_temp_free_i32(t0);
1907 }
aurel32f24cb332008-10-21 11:28:59 +00001908}
1909
pbrooka7812ae2008-11-17 14:43:54 +00001910static inline void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001911{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001912#if TCG_TARGET_REG_BITS == 64
1913 if (TCG_TARGET_HAS_andc_i64) {
1914 tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2);
1915 } else {
1916 TCGv_i64 t0 = tcg_temp_new_i64();
1917 tcg_gen_not_i64(t0, arg2);
1918 tcg_gen_and_i64(ret, arg1, t0);
1919 tcg_temp_free_i64(t0);
1920 }
1921#else
Richard Henderson241cbed2010-02-16 14:10:13 -08001922 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1923 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
Richard Henderson241cbed2010-02-16 14:10:13 -08001924#endif
aurel32f24cb332008-10-21 11:28:59 +00001925}
1926
pbrooka7812ae2008-11-17 14:43:54 +00001927static inline void tcg_gen_eqv_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001928{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001929 if (TCG_TARGET_HAS_eqv_i32) {
1930 tcg_gen_op3_i32(INDEX_op_eqv_i32, ret, arg1, arg2);
1931 } else {
1932 tcg_gen_xor_i32(ret, arg1, arg2);
1933 tcg_gen_not_i32(ret, ret);
1934 }
aurel32f24cb332008-10-21 11:28:59 +00001935}
1936
pbrooka7812ae2008-11-17 14:43:54 +00001937static inline void tcg_gen_eqv_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001938{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001939#if TCG_TARGET_REG_BITS == 64
1940 if (TCG_TARGET_HAS_eqv_i64) {
1941 tcg_gen_op3_i64(INDEX_op_eqv_i64, ret, arg1, arg2);
1942 } else {
1943 tcg_gen_xor_i64(ret, arg1, arg2);
1944 tcg_gen_not_i64(ret, ret);
1945 }
1946#else
Richard Henderson8d625cf2010-03-19 13:02:02 -07001947 tcg_gen_eqv_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1948 tcg_gen_eqv_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
Richard Henderson8d625cf2010-03-19 13:02:02 -07001949#endif
aurel32f24cb332008-10-21 11:28:59 +00001950}
1951
pbrooka7812ae2008-11-17 14:43:54 +00001952static inline void tcg_gen_nand_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001953{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001954 if (TCG_TARGET_HAS_nand_i32) {
1955 tcg_gen_op3_i32(INDEX_op_nand_i32, ret, arg1, arg2);
1956 } else {
1957 tcg_gen_and_i32(ret, arg1, arg2);
1958 tcg_gen_not_i32(ret, ret);
1959 }
aurel32f24cb332008-10-21 11:28:59 +00001960}
1961
pbrooka7812ae2008-11-17 14:43:54 +00001962static inline void tcg_gen_nand_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001963{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001964#if TCG_TARGET_REG_BITS == 64
1965 if (TCG_TARGET_HAS_nand_i64) {
1966 tcg_gen_op3_i64(INDEX_op_nand_i64, ret, arg1, arg2);
1967 } else {
1968 tcg_gen_and_i64(ret, arg1, arg2);
1969 tcg_gen_not_i64(ret, ret);
1970 }
1971#else
Richard Henderson9940a962010-03-19 13:03:58 -07001972 tcg_gen_nand_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1973 tcg_gen_nand_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
Richard Henderson9940a962010-03-19 13:03:58 -07001974#endif
aurel32f24cb332008-10-21 11:28:59 +00001975}
1976
pbrooka7812ae2008-11-17 14:43:54 +00001977static inline void tcg_gen_nor_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001978{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001979 if (TCG_TARGET_HAS_nor_i32) {
1980 tcg_gen_op3_i32(INDEX_op_nor_i32, ret, arg1, arg2);
1981 } else {
1982 tcg_gen_or_i32(ret, arg1, arg2);
1983 tcg_gen_not_i32(ret, ret);
1984 }
aurel32f24cb332008-10-21 11:28:59 +00001985}
1986
pbrooka7812ae2008-11-17 14:43:54 +00001987static inline void tcg_gen_nor_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00001988{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001989#if TCG_TARGET_REG_BITS == 64
1990 if (TCG_TARGET_HAS_nor_i64) {
1991 tcg_gen_op3_i64(INDEX_op_nor_i64, ret, arg1, arg2);
1992 } else {
1993 tcg_gen_or_i64(ret, arg1, arg2);
1994 tcg_gen_not_i64(ret, ret);
1995 }
1996#else
Richard Henderson32d98fb2010-03-19 13:08:56 -07001997 tcg_gen_nor_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
1998 tcg_gen_nor_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
Richard Henderson32d98fb2010-03-19 13:08:56 -07001999#endif
aurel32f24cb332008-10-21 11:28:59 +00002000}
2001
pbrooka7812ae2008-11-17 14:43:54 +00002002static inline void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel32f24cb332008-10-21 11:28:59 +00002003{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002004 if (TCG_TARGET_HAS_orc_i32) {
2005 tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2);
2006 } else {
2007 TCGv_i32 t0 = tcg_temp_new_i32();
2008 tcg_gen_not_i32(t0, arg2);
2009 tcg_gen_or_i32(ret, arg1, t0);
2010 tcg_temp_free_i32(t0);
2011 }
aurel32f24cb332008-10-21 11:28:59 +00002012}
2013
pbrooka7812ae2008-11-17 14:43:54 +00002014static inline void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel32f24cb332008-10-21 11:28:59 +00002015{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002016#if TCG_TARGET_REG_BITS == 64
2017 if (TCG_TARGET_HAS_orc_i64) {
2018 tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2);
2019 } else {
2020 TCGv_i64 t0 = tcg_temp_new_i64();
2021 tcg_gen_not_i64(t0, arg2);
2022 tcg_gen_or_i64(ret, arg1, t0);
2023 tcg_temp_free_i64(t0);
2024 }
2025#else
Richard Henderson791d1262010-02-16 14:15:28 -08002026 tcg_gen_orc_i32(TCGV_LOW(ret), TCGV_LOW(arg1), TCGV_LOW(arg2));
2027 tcg_gen_orc_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), TCGV_HIGH(arg2));
Richard Henderson791d1262010-02-16 14:15:28 -08002028#endif
aurel32f24cb332008-10-21 11:28:59 +00002029}
2030
pbrooka7812ae2008-11-17 14:43:54 +00002031static inline void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3215824572008-11-03 07:08:36 +00002032{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002033 if (TCG_TARGET_HAS_rot_i32) {
2034 tcg_gen_op3_i32(INDEX_op_rotl_i32, ret, arg1, arg2);
2035 } else {
2036 TCGv_i32 t0, t1;
aurel3215824572008-11-03 07:08:36 +00002037
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002038 t0 = tcg_temp_new_i32();
2039 t1 = tcg_temp_new_i32();
2040 tcg_gen_shl_i32(t0, arg1, arg2);
2041 tcg_gen_subfi_i32(t1, 32, arg2);
2042 tcg_gen_shr_i32(t1, arg1, t1);
2043 tcg_gen_or_i32(ret, t0, t1);
2044 tcg_temp_free_i32(t0);
2045 tcg_temp_free_i32(t1);
2046 }
aurel3215824572008-11-03 07:08:36 +00002047}
2048
pbrooka7812ae2008-11-17 14:43:54 +00002049static inline void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel3215824572008-11-03 07:08:36 +00002050{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002051 if (TCG_TARGET_HAS_rot_i64) {
2052 tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2);
2053 } else {
2054 TCGv_i64 t0, t1;
2055 t0 = tcg_temp_new_i64();
2056 t1 = tcg_temp_new_i64();
2057 tcg_gen_shl_i64(t0, arg1, arg2);
2058 tcg_gen_subfi_i64(t1, 64, arg2);
2059 tcg_gen_shr_i64(t1, arg1, t1);
2060 tcg_gen_or_i64(ret, t0, t1);
2061 tcg_temp_free_i64(t0);
2062 tcg_temp_free_i64(t1);
2063 }
aurel3215824572008-11-03 07:08:36 +00002064}
2065
pbrooka7812ae2008-11-17 14:43:54 +00002066static inline void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
aurel3215824572008-11-03 07:08:36 +00002067{
2068 /* some cases can be optimized here */
2069 if (arg2 == 0) {
2070 tcg_gen_mov_i32(ret, arg1);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002071 } else if (TCG_TARGET_HAS_rot_i32) {
aurel32d42f1832009-03-09 18:50:53 +00002072 TCGv_i32 t0 = tcg_const_i32(arg2);
2073 tcg_gen_rotl_i32(ret, arg1, t0);
2074 tcg_temp_free_i32(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002075 } else {
pbrooka7812ae2008-11-17 14:43:54 +00002076 TCGv_i32 t0, t1;
2077 t0 = tcg_temp_new_i32();
2078 t1 = tcg_temp_new_i32();
aurel3215824572008-11-03 07:08:36 +00002079 tcg_gen_shli_i32(t0, arg1, arg2);
2080 tcg_gen_shri_i32(t1, arg1, 32 - arg2);
2081 tcg_gen_or_i32(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00002082 tcg_temp_free_i32(t0);
2083 tcg_temp_free_i32(t1);
aurel3215824572008-11-03 07:08:36 +00002084 }
2085}
2086
pbrooka7812ae2008-11-17 14:43:54 +00002087static inline void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3215824572008-11-03 07:08:36 +00002088{
2089 /* some cases can be optimized here */
2090 if (arg2 == 0) {
2091 tcg_gen_mov_i64(ret, arg1);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002092 } else if (TCG_TARGET_HAS_rot_i64) {
aurel32d42f1832009-03-09 18:50:53 +00002093 TCGv_i64 t0 = tcg_const_i64(arg2);
2094 tcg_gen_rotl_i64(ret, arg1, t0);
2095 tcg_temp_free_i64(t0);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002096 } else {
pbrooka7812ae2008-11-17 14:43:54 +00002097 TCGv_i64 t0, t1;
2098 t0 = tcg_temp_new_i64();
2099 t1 = tcg_temp_new_i64();
aurel3215824572008-11-03 07:08:36 +00002100 tcg_gen_shli_i64(t0, arg1, arg2);
2101 tcg_gen_shri_i64(t1, arg1, 64 - arg2);
2102 tcg_gen_or_i64(ret, t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00002103 tcg_temp_free_i64(t0);
2104 tcg_temp_free_i64(t1);
aurel3215824572008-11-03 07:08:36 +00002105 }
2106}
2107
pbrooka7812ae2008-11-17 14:43:54 +00002108static inline void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3215824572008-11-03 07:08:36 +00002109{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002110 if (TCG_TARGET_HAS_rot_i32) {
2111 tcg_gen_op3_i32(INDEX_op_rotr_i32, ret, arg1, arg2);
2112 } else {
2113 TCGv_i32 t0, t1;
aurel3215824572008-11-03 07:08:36 +00002114
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002115 t0 = tcg_temp_new_i32();
2116 t1 = tcg_temp_new_i32();
2117 tcg_gen_shr_i32(t0, arg1, arg2);
2118 tcg_gen_subfi_i32(t1, 32, arg2);
2119 tcg_gen_shl_i32(t1, arg1, t1);
2120 tcg_gen_or_i32(ret, t0, t1);
2121 tcg_temp_free_i32(t0);
2122 tcg_temp_free_i32(t1);
2123 }
aurel3215824572008-11-03 07:08:36 +00002124}
2125
pbrooka7812ae2008-11-17 14:43:54 +00002126static inline void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
aurel3215824572008-11-03 07:08:36 +00002127{
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002128 if (TCG_TARGET_HAS_rot_i64) {
2129 tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2);
2130 } else {
2131 TCGv_i64 t0, t1;
2132 t0 = tcg_temp_new_i64();
2133 t1 = tcg_temp_new_i64();
2134 tcg_gen_shr_i64(t0, arg1, arg2);
2135 tcg_gen_subfi_i64(t1, 64, arg2);
2136 tcg_gen_shl_i64(t1, arg1, t1);
2137 tcg_gen_or_i64(ret, t0, t1);
2138 tcg_temp_free_i64(t0);
2139 tcg_temp_free_i64(t1);
2140 }
aurel3215824572008-11-03 07:08:36 +00002141}
2142
pbrooka7812ae2008-11-17 14:43:54 +00002143static inline void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
aurel3215824572008-11-03 07:08:36 +00002144{
2145 /* some cases can be optimized here */
2146 if (arg2 == 0) {
2147 tcg_gen_mov_i32(ret, arg1);
2148 } else {
2149 tcg_gen_rotli_i32(ret, arg1, 32 - arg2);
2150 }
2151}
2152
pbrooka7812ae2008-11-17 14:43:54 +00002153static inline void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
aurel3215824572008-11-03 07:08:36 +00002154{
2155 /* some cases can be optimized here */
2156 if (arg2 == 0) {
pbrookde3526b2008-11-03 13:30:50 +00002157 tcg_gen_mov_i64(ret, arg1);
aurel3215824572008-11-03 07:08:36 +00002158 } else {
2159 tcg_gen_rotli_i64(ret, arg1, 64 - arg2);
2160 }
2161}
2162
Richard Hendersonb7767f02011-01-10 19:23:42 -08002163static inline void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1,
Richard Henderson0756e712011-11-01 15:06:43 -07002164 TCGv_i32 arg2, unsigned int ofs,
2165 unsigned int len)
Richard Hendersonb7767f02011-01-10 19:23:42 -08002166{
Richard Hendersondf072772011-10-27 14:15:00 -07002167 uint32_t mask;
2168 TCGv_i32 t1;
2169
Richard Henderson717e7032012-09-21 17:18:15 -07002170 tcg_debug_assert(ofs < 32);
2171 tcg_debug_assert(len <= 32);
2172 tcg_debug_assert(ofs + len <= 32);
2173
Richard Hendersondf072772011-10-27 14:15:00 -07002174 if (ofs == 0 && len == 32) {
2175 tcg_gen_mov_i32(ret, arg2);
2176 return;
2177 }
Jan Kiszkaa4773322011-09-29 18:52:11 +02002178 if (TCG_TARGET_HAS_deposit_i32 && TCG_TARGET_deposit_i32_valid(ofs, len)) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002179 tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, arg1, arg2, ofs, len);
Richard Hendersondf072772011-10-27 14:15:00 -07002180 return;
2181 }
Richard Hendersonb7767f02011-01-10 19:23:42 -08002182
Richard Hendersondf072772011-10-27 14:15:00 -07002183 mask = (1u << len) - 1;
2184 t1 = tcg_temp_new_i32();
2185
2186 if (ofs + len < 32) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002187 tcg_gen_andi_i32(t1, arg2, mask);
2188 tcg_gen_shli_i32(t1, t1, ofs);
Richard Hendersondf072772011-10-27 14:15:00 -07002189 } else {
2190 tcg_gen_shli_i32(t1, arg2, ofs);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002191 }
Richard Hendersondf072772011-10-27 14:15:00 -07002192 tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
2193 tcg_gen_or_i32(ret, ret, t1);
2194
2195 tcg_temp_free_i32(t1);
Richard Hendersonb7767f02011-01-10 19:23:42 -08002196}
2197
2198static inline void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1,
Richard Henderson0756e712011-11-01 15:06:43 -07002199 TCGv_i64 arg2, unsigned int ofs,
2200 unsigned int len)
Richard Hendersonb7767f02011-01-10 19:23:42 -08002201{
Richard Hendersondf072772011-10-27 14:15:00 -07002202 uint64_t mask;
2203 TCGv_i64 t1;
2204
Richard Henderson717e7032012-09-21 17:18:15 -07002205 tcg_debug_assert(ofs < 64);
2206 tcg_debug_assert(len <= 64);
2207 tcg_debug_assert(ofs + len <= 64);
2208
Richard Hendersondf072772011-10-27 14:15:00 -07002209 if (ofs == 0 && len == 64) {
2210 tcg_gen_mov_i64(ret, arg2);
2211 return;
2212 }
Jan Kiszkaa4773322011-09-29 18:52:11 +02002213 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(ofs, len)) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002214 tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, arg1, arg2, ofs, len);
Richard Hendersondf072772011-10-27 14:15:00 -07002215 return;
2216 }
Richard Hendersonb7767f02011-01-10 19:23:42 -08002217
Richard Hendersondf072772011-10-27 14:15:00 -07002218#if TCG_TARGET_REG_BITS == 32
2219 if (ofs >= 32) {
2220 tcg_gen_deposit_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1),
2221 TCGV_LOW(arg2), ofs - 32, len);
Aurelien Jarnoed605122013-04-21 00:42:56 +02002222 tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg1));
Richard Hendersondf072772011-10-27 14:15:00 -07002223 return;
2224 }
2225 if (ofs + len <= 32) {
2226 tcg_gen_deposit_i32(TCGV_LOW(ret), TCGV_LOW(arg1),
2227 TCGV_LOW(arg2), ofs, len);
Richard Henderson2f98c9d2011-11-01 15:06:42 -07002228 tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1));
Richard Hendersondf072772011-10-27 14:15:00 -07002229 return;
2230 }
2231#endif
2232
2233 mask = (1ull << len) - 1;
2234 t1 = tcg_temp_new_i64();
2235
2236 if (ofs + len < 64) {
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002237 tcg_gen_andi_i64(t1, arg2, mask);
2238 tcg_gen_shli_i64(t1, t1, ofs);
Richard Hendersondf072772011-10-27 14:15:00 -07002239 } else {
2240 tcg_gen_shli_i64(t1, arg2, ofs);
Richard Henderson25c4d9c2011-08-17 14:11:46 -07002241 }
Richard Hendersondf072772011-10-27 14:15:00 -07002242 tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
2243 tcg_gen_or_i64(ret, ret, t1);
2244
2245 tcg_temp_free_i64(t1);
Richard Hendersonb7767f02011-01-10 19:23:42 -08002246}
2247
Richard Henderson77276f62012-09-21 17:18:13 -07002248static inline void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low,
2249 TCGv_i32 high)
2250{
2251#if TCG_TARGET_REG_BITS == 32
2252 tcg_gen_mov_i32(TCGV_LOW(dest), low);
2253 tcg_gen_mov_i32(TCGV_HIGH(dest), high);
2254#else
2255 TCGv_i64 tmp = tcg_temp_new_i64();
2256 /* These extensions are only needed for type correctness.
2257 We may be able to do better given target specific information. */
2258 tcg_gen_extu_i32_i64(tmp, high);
2259 tcg_gen_extu_i32_i64(dest, low);
2260 /* If deposit is available, use it. Otherwise use the extra
2261 knowledge that we have of the zero-extensions above. */
2262 if (TCG_TARGET_HAS_deposit_i64 && TCG_TARGET_deposit_i64_valid(32, 32)) {
2263 tcg_gen_deposit_i64(dest, dest, tmp, 32, 32);
2264 } else {
2265 tcg_gen_shli_i64(tmp, tmp, 32);
2266 tcg_gen_or_i64(dest, dest, tmp);
2267 }
2268 tcg_temp_free_i64(tmp);
2269#endif
2270}
2271
2272static inline void tcg_gen_concat32_i64(TCGv_i64 dest, TCGv_i64 low,
2273 TCGv_i64 high)
2274{
2275 tcg_gen_deposit_i64(dest, low, high, 32, 32);
2276}
2277
Richard Henderson3c51a982013-02-19 23:51:54 -08002278static inline void tcg_gen_extr_i64_i32(TCGv_i32 lo, TCGv_i32 hi, TCGv_i64 arg)
2279{
2280#if TCG_TARGET_REG_BITS == 32
2281 tcg_gen_mov_i32(lo, TCGV_LOW(arg));
2282 tcg_gen_mov_i32(hi, TCGV_HIGH(arg));
2283#else
2284 TCGv_i64 t0 = tcg_temp_new_i64();
2285 tcg_gen_trunc_i64_i32(lo, arg);
2286 tcg_gen_shri_i64(t0, arg, 32);
2287 tcg_gen_trunc_i64_i32(hi, t0);
2288 tcg_temp_free_i64(t0);
2289#endif
2290}
2291
2292static inline void tcg_gen_extr32_i64(TCGv_i64 lo, TCGv_i64 hi, TCGv_i64 arg)
2293{
2294 tcg_gen_ext32u_i64(lo, arg);
2295 tcg_gen_shri_i64(hi, arg, 32);
2296}
2297
Richard Hendersonffc5ea02012-09-21 10:13:34 -07002298static inline void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret,
2299 TCGv_i32 c1, TCGv_i32 c2,
2300 TCGv_i32 v1, TCGv_i32 v2)
2301{
2302 if (TCG_TARGET_HAS_movcond_i32) {
2303 tcg_gen_op6i_i32(INDEX_op_movcond_i32, ret, c1, c2, v1, v2, cond);
2304 } else {
2305 TCGv_i32 t0 = tcg_temp_new_i32();
2306 TCGv_i32 t1 = tcg_temp_new_i32();
2307 tcg_gen_setcond_i32(cond, t0, c1, c2);
2308 tcg_gen_neg_i32(t0, t0);
2309 tcg_gen_and_i32(t1, v1, t0);
2310 tcg_gen_andc_i32(ret, v2, t0);
2311 tcg_gen_or_i32(ret, ret, t1);
2312 tcg_temp_free_i32(t0);
2313 tcg_temp_free_i32(t1);
2314 }
2315}
2316
2317static inline void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret,
2318 TCGv_i64 c1, TCGv_i64 c2,
2319 TCGv_i64 v1, TCGv_i64 v2)
2320{
Richard Hendersona4631332012-09-24 13:44:59 -07002321#if TCG_TARGET_REG_BITS == 32
2322 TCGv_i32 t0 = tcg_temp_new_i32();
2323 TCGv_i32 t1 = tcg_temp_new_i32();
2324 tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0,
2325 TCGV_LOW(c1), TCGV_HIGH(c1),
2326 TCGV_LOW(c2), TCGV_HIGH(c2), cond);
Richard Hendersona4631332012-09-24 13:44:59 -07002327
Richard Hendersona80a6b62012-09-24 13:45:00 -07002328 if (TCG_TARGET_HAS_movcond_i32) {
2329 tcg_gen_movi_i32(t1, 0);
2330 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_LOW(ret), t0, t1,
2331 TCGV_LOW(v1), TCGV_LOW(v2));
2332 tcg_gen_movcond_i32(TCG_COND_NE, TCGV_HIGH(ret), t0, t1,
2333 TCGV_HIGH(v1), TCGV_HIGH(v2));
2334 } else {
2335 tcg_gen_neg_i32(t0, t0);
Richard Hendersona4631332012-09-24 13:44:59 -07002336
Richard Hendersona80a6b62012-09-24 13:45:00 -07002337 tcg_gen_and_i32(t1, TCGV_LOW(v1), t0);
2338 tcg_gen_andc_i32(TCGV_LOW(ret), TCGV_LOW(v2), t0);
2339 tcg_gen_or_i32(TCGV_LOW(ret), TCGV_LOW(ret), t1);
Richard Hendersona4631332012-09-24 13:44:59 -07002340
Richard Hendersona80a6b62012-09-24 13:45:00 -07002341 tcg_gen_and_i32(t1, TCGV_HIGH(v1), t0);
2342 tcg_gen_andc_i32(TCGV_HIGH(ret), TCGV_HIGH(v2), t0);
2343 tcg_gen_or_i32(TCGV_HIGH(ret), TCGV_HIGH(ret), t1);
2344 }
Richard Hendersona4631332012-09-24 13:44:59 -07002345 tcg_temp_free_i32(t0);
2346 tcg_temp_free_i32(t1);
2347#else
Richard Hendersonffc5ea02012-09-21 10:13:34 -07002348 if (TCG_TARGET_HAS_movcond_i64) {
2349 tcg_gen_op6i_i64(INDEX_op_movcond_i64, ret, c1, c2, v1, v2, cond);
2350 } else {
2351 TCGv_i64 t0 = tcg_temp_new_i64();
2352 TCGv_i64 t1 = tcg_temp_new_i64();
2353 tcg_gen_setcond_i64(cond, t0, c1, c2);
2354 tcg_gen_neg_i64(t0, t0);
2355 tcg_gen_and_i64(t1, v1, t0);
2356 tcg_gen_andc_i64(ret, v2, t0);
2357 tcg_gen_or_i64(ret, ret, t1);
2358 tcg_temp_free_i64(t0);
2359 tcg_temp_free_i64(t1);
2360 }
Richard Hendersona4631332012-09-24 13:44:59 -07002361#endif
Richard Hendersonffc5ea02012-09-21 10:13:34 -07002362}
2363
Richard Hendersonf6953a72013-02-19 23:51:56 -08002364static inline void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2365 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2366{
2367 if (TCG_TARGET_HAS_add2_i32) {
2368 tcg_gen_op6_i32(INDEX_op_add2_i32, rl, rh, al, ah, bl, bh);
2369 /* Allow the optimizer room to replace add2 with two moves. */
2370 tcg_gen_op0(INDEX_op_nop);
2371 } else {
2372 TCGv_i64 t0 = tcg_temp_new_i64();
2373 TCGv_i64 t1 = tcg_temp_new_i64();
2374 tcg_gen_concat_i32_i64(t0, al, ah);
2375 tcg_gen_concat_i32_i64(t1, bl, bh);
2376 tcg_gen_add_i64(t0, t0, t1);
2377 tcg_gen_extr_i64_i32(rl, rh, t0);
2378 tcg_temp_free_i64(t0);
2379 tcg_temp_free_i64(t1);
2380 }
2381}
2382
2383static inline void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al,
2384 TCGv_i32 ah, TCGv_i32 bl, TCGv_i32 bh)
2385{
2386 if (TCG_TARGET_HAS_sub2_i32) {
2387 tcg_gen_op6_i32(INDEX_op_sub2_i32, rl, rh, al, ah, bl, bh);
2388 /* Allow the optimizer room to replace sub2 with two moves. */
2389 tcg_gen_op0(INDEX_op_nop);
2390 } else {
2391 TCGv_i64 t0 = tcg_temp_new_i64();
2392 TCGv_i64 t1 = tcg_temp_new_i64();
2393 tcg_gen_concat_i32_i64(t0, al, ah);
2394 tcg_gen_concat_i32_i64(t1, bl, bh);
2395 tcg_gen_sub_i64(t0, t0, t1);
2396 tcg_gen_extr_i64_i32(rl, rh, t0);
2397 tcg_temp_free_i64(t0);
2398 tcg_temp_free_i64(t1);
2399 }
2400}
2401
Richard Henderson696a8be2013-02-19 23:51:55 -08002402static inline void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh,
2403 TCGv_i32 arg1, TCGv_i32 arg2)
2404{
2405 if (TCG_TARGET_HAS_mulu2_i32) {
2406 tcg_gen_op4_i32(INDEX_op_mulu2_i32, rl, rh, arg1, arg2);
2407 /* Allow the optimizer room to replace mulu2 with two moves. */
2408 tcg_gen_op0(INDEX_op_nop);
Richard Henderson03271522013-08-14 14:35:56 -07002409 } else if (TCG_TARGET_HAS_muluh_i32) {
2410 TCGv_i32 t = tcg_temp_new_i32();
2411 tcg_gen_op3_i32(INDEX_op_mul_i32, t, arg1, arg2);
2412 tcg_gen_op3_i32(INDEX_op_muluh_i32, rh, arg1, arg2);
2413 tcg_gen_mov_i32(rl, t);
2414 tcg_temp_free_i32(t);
Richard Henderson696a8be2013-02-19 23:51:55 -08002415 } else {
2416 TCGv_i64 t0 = tcg_temp_new_i64();
2417 TCGv_i64 t1 = tcg_temp_new_i64();
2418 tcg_gen_extu_i32_i64(t0, arg1);
2419 tcg_gen_extu_i32_i64(t1, arg2);
2420 tcg_gen_mul_i64(t0, t0, t1);
2421 tcg_gen_extr_i64_i32(rl, rh, t0);
2422 tcg_temp_free_i64(t0);
2423 tcg_temp_free_i64(t1);
2424 }
2425}
2426
2427static inline void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh,
2428 TCGv_i32 arg1, TCGv_i32 arg2)
2429{
2430 if (TCG_TARGET_HAS_muls2_i32) {
2431 tcg_gen_op4_i32(INDEX_op_muls2_i32, rl, rh, arg1, arg2);
2432 /* Allow the optimizer room to replace muls2 with two moves. */
2433 tcg_gen_op0(INDEX_op_nop);
Richard Henderson03271522013-08-14 14:35:56 -07002434 } else if (TCG_TARGET_HAS_mulsh_i32) {
2435 TCGv_i32 t = tcg_temp_new_i32();
2436 tcg_gen_op3_i32(INDEX_op_mul_i32, t, arg1, arg2);
2437 tcg_gen_op3_i32(INDEX_op_mulsh_i32, rh, arg1, arg2);
2438 tcg_gen_mov_i32(rl, t);
2439 tcg_temp_free_i32(t);
Richard Hendersonf402f382013-02-19 23:52:01 -08002440 } else if (TCG_TARGET_REG_BITS == 32 && TCG_TARGET_HAS_mulu2_i32) {
2441 TCGv_i32 t0 = tcg_temp_new_i32();
2442 TCGv_i32 t1 = tcg_temp_new_i32();
2443 TCGv_i32 t2 = tcg_temp_new_i32();
2444 TCGv_i32 t3 = tcg_temp_new_i32();
2445 tcg_gen_op4_i32(INDEX_op_mulu2_i32, t0, t1, arg1, arg2);
2446 /* Allow the optimizer room to replace mulu2 with two moves. */
2447 tcg_gen_op0(INDEX_op_nop);
2448 /* Adjust for negative inputs. */
2449 tcg_gen_sari_i32(t2, arg1, 31);
2450 tcg_gen_sari_i32(t3, arg2, 31);
2451 tcg_gen_and_i32(t2, t2, arg2);
2452 tcg_gen_and_i32(t3, t3, arg1);
2453 tcg_gen_sub_i32(rh, t1, t2);
2454 tcg_gen_sub_i32(rh, rh, t3);
2455 tcg_gen_mov_i32(rl, t0);
2456 tcg_temp_free_i32(t0);
2457 tcg_temp_free_i32(t1);
2458 tcg_temp_free_i32(t2);
2459 tcg_temp_free_i32(t3);
Richard Henderson696a8be2013-02-19 23:51:55 -08002460 } else {
2461 TCGv_i64 t0 = tcg_temp_new_i64();
2462 TCGv_i64 t1 = tcg_temp_new_i64();
2463 tcg_gen_ext_i32_i64(t0, arg1);
2464 tcg_gen_ext_i32_i64(t1, arg2);
2465 tcg_gen_mul_i64(t0, t0, t1);
2466 tcg_gen_extr_i64_i32(rl, rh, t0);
2467 tcg_temp_free_i64(t0);
2468 tcg_temp_free_i64(t1);
2469 }
2470}
2471
Richard Hendersonf6953a72013-02-19 23:51:56 -08002472static inline void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2473 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2474{
2475 if (TCG_TARGET_HAS_add2_i64) {
2476 tcg_gen_op6_i64(INDEX_op_add2_i64, rl, rh, al, ah, bl, bh);
2477 /* Allow the optimizer room to replace add2 with two moves. */
2478 tcg_gen_op0(INDEX_op_nop);
2479 } else {
2480 TCGv_i64 t0 = tcg_temp_new_i64();
2481 TCGv_i64 t1 = tcg_temp_new_i64();
2482 tcg_gen_add_i64(t0, al, bl);
2483 tcg_gen_setcond_i64(TCG_COND_LTU, t1, t0, al);
2484 tcg_gen_add_i64(rh, ah, bh);
2485 tcg_gen_add_i64(rh, rh, t1);
2486 tcg_gen_mov_i64(rl, t0);
2487 tcg_temp_free_i64(t0);
2488 tcg_temp_free_i64(t1);
2489 }
2490}
2491
2492static inline void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al,
2493 TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh)
2494{
2495 if (TCG_TARGET_HAS_sub2_i64) {
2496 tcg_gen_op6_i64(INDEX_op_sub2_i64, rl, rh, al, ah, bl, bh);
2497 /* Allow the optimizer room to replace sub2 with two moves. */
2498 tcg_gen_op0(INDEX_op_nop);
2499 } else {
2500 TCGv_i64 t0 = tcg_temp_new_i64();
2501 TCGv_i64 t1 = tcg_temp_new_i64();
2502 tcg_gen_sub_i64(t0, al, bl);
2503 tcg_gen_setcond_i64(TCG_COND_LTU, t1, al, bl);
2504 tcg_gen_sub_i64(rh, ah, bh);
2505 tcg_gen_sub_i64(rh, rh, t1);
2506 tcg_gen_mov_i64(rl, t0);
2507 tcg_temp_free_i64(t0);
2508 tcg_temp_free_i64(t1);
2509 }
2510}
2511
Richard Henderson696a8be2013-02-19 23:51:55 -08002512static inline void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh,
2513 TCGv_i64 arg1, TCGv_i64 arg2)
2514{
2515 if (TCG_TARGET_HAS_mulu2_i64) {
2516 tcg_gen_op4_i64(INDEX_op_mulu2_i64, rl, rh, arg1, arg2);
2517 /* Allow the optimizer room to replace mulu2 with two moves. */
2518 tcg_gen_op0(INDEX_op_nop);
Richard Henderson03271522013-08-14 14:35:56 -07002519 } else if (TCG_TARGET_HAS_muluh_i64) {
2520 TCGv_i64 t = tcg_temp_new_i64();
2521 tcg_gen_op3_i64(INDEX_op_mul_i64, t, arg1, arg2);
2522 tcg_gen_op3_i64(INDEX_op_muluh_i64, rh, arg1, arg2);
2523 tcg_gen_mov_i64(rl, t);
2524 tcg_temp_free_i64(t);
Richard Hendersonf402f382013-02-19 23:52:01 -08002525 } else if (TCG_TARGET_HAS_mulu2_i64) {
2526 TCGv_i64 t0 = tcg_temp_new_i64();
2527 TCGv_i64 t1 = tcg_temp_new_i64();
2528 TCGv_i64 t2 = tcg_temp_new_i64();
2529 TCGv_i64 t3 = tcg_temp_new_i64();
2530 tcg_gen_op4_i64(INDEX_op_mulu2_i64, t0, t1, arg1, arg2);
2531 /* Allow the optimizer room to replace mulu2 with two moves. */
2532 tcg_gen_op0(INDEX_op_nop);
2533 /* Adjust for negative inputs. */
2534 tcg_gen_sari_i64(t2, arg1, 63);
2535 tcg_gen_sari_i64(t3, arg2, 63);
2536 tcg_gen_and_i64(t2, t2, arg2);
2537 tcg_gen_and_i64(t3, t3, arg1);
2538 tcg_gen_sub_i64(rh, t1, t2);
2539 tcg_gen_sub_i64(rh, rh, t3);
2540 tcg_gen_mov_i64(rl, t0);
2541 tcg_temp_free_i64(t0);
2542 tcg_temp_free_i64(t1);
2543 tcg_temp_free_i64(t2);
2544 tcg_temp_free_i64(t3);
Richard Henderson696a8be2013-02-19 23:51:55 -08002545 } else {
2546 TCGv_i64 t0 = tcg_temp_new_i64();
2547 int sizemask = 0;
2548 /* Return value and both arguments are 64-bit and unsigned. */
2549 sizemask |= tcg_gen_sizemask(0, 1, 0);
2550 sizemask |= tcg_gen_sizemask(1, 1, 0);
2551 sizemask |= tcg_gen_sizemask(2, 1, 0);
2552 tcg_gen_mul_i64(t0, arg1, arg2);
2553 tcg_gen_helper64(tcg_helper_muluh_i64, sizemask, rh, arg1, arg2);
2554 tcg_gen_mov_i64(rl, t0);
2555 tcg_temp_free_i64(t0);
2556 }
2557}
2558
2559static inline void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh,
2560 TCGv_i64 arg1, TCGv_i64 arg2)
2561{
2562 if (TCG_TARGET_HAS_muls2_i64) {
2563 tcg_gen_op4_i64(INDEX_op_muls2_i64, rl, rh, arg1, arg2);
2564 /* Allow the optimizer room to replace muls2 with two moves. */
2565 tcg_gen_op0(INDEX_op_nop);
Richard Henderson03271522013-08-14 14:35:56 -07002566 } else if (TCG_TARGET_HAS_mulsh_i64) {
2567 TCGv_i64 t = tcg_temp_new_i64();
2568 tcg_gen_op3_i64(INDEX_op_mul_i64, t, arg1, arg2);
2569 tcg_gen_op3_i64(INDEX_op_mulsh_i64, rh, arg1, arg2);
2570 tcg_gen_mov_i64(rl, t);
2571 tcg_temp_free_i64(t);
Richard Henderson696a8be2013-02-19 23:51:55 -08002572 } else {
2573 TCGv_i64 t0 = tcg_temp_new_i64();
2574 int sizemask = 0;
2575 /* Return value and both arguments are 64-bit and signed. */
2576 sizemask |= tcg_gen_sizemask(0, 1, 1);
2577 sizemask |= tcg_gen_sizemask(1, 1, 1);
2578 sizemask |= tcg_gen_sizemask(2, 1, 1);
2579 tcg_gen_mul_i64(t0, arg1, arg2);
2580 tcg_gen_helper64(tcg_helper_mulsh_i64, sizemask, rh, arg1, arg2);
2581 tcg_gen_mov_i64(rl, t0);
2582 tcg_temp_free_i64(t0);
2583 }
2584}
2585
bellardc896fe22008-02-01 10:05:41 +00002586/***************************************/
bellardc896fe22008-02-01 10:05:41 +00002587/* QEMU specific operations. Their type depend on the QEMU CPU
2588 type. */
2589#ifndef TARGET_LONG_BITS
2590#error must include QEMU headers
2591#endif
2592
pbrooka7812ae2008-11-17 14:43:54 +00002593#if TARGET_LONG_BITS == 32
2594#define TCGv TCGv_i32
2595#define tcg_temp_new() tcg_temp_new_i32()
2596#define tcg_global_reg_new tcg_global_reg_new_i32
2597#define tcg_global_mem_new tcg_global_mem_new_i32
aurel32df9247b2009-01-01 14:09:05 +00002598#define tcg_temp_local_new() tcg_temp_local_new_i32()
pbrooka7812ae2008-11-17 14:43:54 +00002599#define tcg_temp_free tcg_temp_free_i32
pbrooka7812ae2008-11-17 14:43:54 +00002600#define TCGV_UNUSED(x) TCGV_UNUSED_I32(x)
Richard Hendersonafcb92b2012-12-07 15:07:17 -06002601#define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I32(x)
aurel32fe75bcf2009-03-10 08:57:16 +00002602#define TCGV_EQUAL(a, b) TCGV_EQUAL_I32(a, b)
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002603#define tcg_add_param_tl tcg_add_param_i32
2604#define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i32
2605#define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i32
pbrooka7812ae2008-11-17 14:43:54 +00002606#else
2607#define TCGv TCGv_i64
2608#define tcg_temp_new() tcg_temp_new_i64()
2609#define tcg_global_reg_new tcg_global_reg_new_i64
2610#define tcg_global_mem_new tcg_global_mem_new_i64
aurel32df9247b2009-01-01 14:09:05 +00002611#define tcg_temp_local_new() tcg_temp_local_new_i64()
pbrooka7812ae2008-11-17 14:43:54 +00002612#define tcg_temp_free tcg_temp_free_i64
pbrooka7812ae2008-11-17 14:43:54 +00002613#define TCGV_UNUSED(x) TCGV_UNUSED_I64(x)
Richard Hendersonafcb92b2012-12-07 15:07:17 -06002614#define TCGV_IS_UNUSED(x) TCGV_IS_UNUSED_I64(x)
aurel32fe75bcf2009-03-10 08:57:16 +00002615#define TCGV_EQUAL(a, b) TCGV_EQUAL_I64(a, b)
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002616#define tcg_add_param_tl tcg_add_param_i64
2617#define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i64
2618#define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i64
pbrooka7812ae2008-11-17 14:43:54 +00002619#endif
2620
bellard7e4597d2008-05-22 16:56:05 +00002621/* debug info: write the PC of the corresponding QEMU CPU instruction */
2622static inline void tcg_gen_debug_insn_start(uint64_t pc)
2623{
2624 /* XXX: must really use a 32 bit size for TCGArg in all cases */
2625#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
pbrookbcb01262008-05-24 02:24:25 +00002626 tcg_gen_op2ii(INDEX_op_debug_insn_start,
2627 (uint32_t)(pc), (uint32_t)(pc >> 32));
bellard7e4597d2008-05-22 16:56:05 +00002628#else
2629 tcg_gen_op1i(INDEX_op_debug_insn_start, pc);
2630#endif
2631}
2632
Richard Henderson8cfd0492013-08-20 15:53:10 -07002633static inline void tcg_gen_exit_tb(uintptr_t val)
bellardc896fe22008-02-01 10:05:41 +00002634{
pbrookac56dd42008-02-03 19:56:33 +00002635 tcg_gen_op1i(INDEX_op_exit_tb, val);
bellardc896fe22008-02-01 10:05:41 +00002636}
2637
Richard Henderson0a209d42012-09-21 17:18:16 -07002638static inline void tcg_gen_goto_tb(unsigned idx)
bellardc896fe22008-02-01 10:05:41 +00002639{
Richard Henderson0a209d42012-09-21 17:18:16 -07002640 /* We only support two chained exits. */
2641 tcg_debug_assert(idx <= 1);
2642#ifdef CONFIG_DEBUG_TCG
2643 /* Verify that we havn't seen this numbered exit before. */
2644 tcg_debug_assert((tcg_ctx.goto_tb_issue_mask & (1 << idx)) == 0);
2645 tcg_ctx.goto_tb_issue_mask |= 1 << idx;
2646#endif
pbrookac56dd42008-02-03 19:56:33 +00002647 tcg_gen_op1i(INDEX_op_goto_tb, idx);
bellardc896fe22008-02-01 10:05:41 +00002648}
2649
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002650
2651void tcg_gen_qemu_ld_i32(TCGv_i32, TCGv, TCGArg, TCGMemOp);
2652void tcg_gen_qemu_st_i32(TCGv_i32, TCGv, TCGArg, TCGMemOp);
2653void tcg_gen_qemu_ld_i64(TCGv_i64, TCGv, TCGArg, TCGMemOp);
2654void tcg_gen_qemu_st_i64(TCGv_i64, TCGv, TCGArg, TCGMemOp);
2655
pbrookac56dd42008-02-03 19:56:33 +00002656static inline void tcg_gen_qemu_ld8u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002657{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002658 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_UB);
bellardc896fe22008-02-01 10:05:41 +00002659}
2660
pbrookac56dd42008-02-03 19:56:33 +00002661static inline void tcg_gen_qemu_ld8s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002662{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002663 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_SB);
bellardc896fe22008-02-01 10:05:41 +00002664}
2665
pbrookac56dd42008-02-03 19:56:33 +00002666static inline void tcg_gen_qemu_ld16u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002667{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002668 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TEUW);
bellardc896fe22008-02-01 10:05:41 +00002669}
2670
pbrookac56dd42008-02-03 19:56:33 +00002671static inline void tcg_gen_qemu_ld16s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002672{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002673 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TESW);
bellardc896fe22008-02-01 10:05:41 +00002674}
2675
pbrookac56dd42008-02-03 19:56:33 +00002676static inline void tcg_gen_qemu_ld32u(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002677{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002678 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TEUL);
bellardc896fe22008-02-01 10:05:41 +00002679}
2680
pbrookac56dd42008-02-03 19:56:33 +00002681static inline void tcg_gen_qemu_ld32s(TCGv ret, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002682{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002683 tcg_gen_qemu_ld_tl(ret, addr, mem_index, MO_TESL);
bellardc896fe22008-02-01 10:05:41 +00002684}
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{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002688 tcg_gen_qemu_ld_i64(ret, addr, mem_index, MO_TEQ);
bellardc896fe22008-02-01 10:05:41 +00002689}
2690
pbrookac56dd42008-02-03 19:56:33 +00002691static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002692{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002693 tcg_gen_qemu_st_tl(arg, addr, mem_index, MO_UB);
bellardc896fe22008-02-01 10:05:41 +00002694}
2695
pbrookac56dd42008-02-03 19:56:33 +00002696static inline void tcg_gen_qemu_st16(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002697{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002698 tcg_gen_qemu_st_tl(arg, addr, mem_index, MO_TEUW);
bellardc896fe22008-02-01 10:05:41 +00002699}
2700
pbrookac56dd42008-02-03 19:56:33 +00002701static inline void tcg_gen_qemu_st32(TCGv arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002702{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002703 tcg_gen_qemu_st_tl(arg, addr, mem_index, MO_TEUL);
bellardc896fe22008-02-01 10:05:41 +00002704}
2705
pbrooka7812ae2008-11-17 14:43:54 +00002706static inline void tcg_gen_qemu_st64(TCGv_i64 arg, TCGv addr, int mem_index)
bellardc896fe22008-02-01 10:05:41 +00002707{
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002708 tcg_gen_qemu_st_i64(arg, addr, mem_index, MO_TEQ);
bellardc896fe22008-02-01 10:05:41 +00002709}
2710
blueswir1f8422f52008-02-24 07:45:43 +00002711#if TARGET_LONG_BITS == 64
blueswir1f8422f52008-02-24 07:45:43 +00002712#define tcg_gen_movi_tl tcg_gen_movi_i64
2713#define tcg_gen_mov_tl tcg_gen_mov_i64
2714#define tcg_gen_ld8u_tl tcg_gen_ld8u_i64
2715#define tcg_gen_ld8s_tl tcg_gen_ld8s_i64
2716#define tcg_gen_ld16u_tl tcg_gen_ld16u_i64
2717#define tcg_gen_ld16s_tl tcg_gen_ld16s_i64
2718#define tcg_gen_ld32u_tl tcg_gen_ld32u_i64
2719#define tcg_gen_ld32s_tl tcg_gen_ld32s_i64
2720#define tcg_gen_ld_tl tcg_gen_ld_i64
2721#define tcg_gen_st8_tl tcg_gen_st8_i64
2722#define tcg_gen_st16_tl tcg_gen_st16_i64
2723#define tcg_gen_st32_tl tcg_gen_st32_i64
2724#define tcg_gen_st_tl tcg_gen_st_i64
2725#define tcg_gen_add_tl tcg_gen_add_i64
2726#define tcg_gen_addi_tl tcg_gen_addi_i64
2727#define tcg_gen_sub_tl tcg_gen_sub_i64
pbrook390efc52008-05-11 14:35:37 +00002728#define tcg_gen_neg_tl tcg_gen_neg_i64
pbrook10460c82008-11-02 13:26:16 +00002729#define tcg_gen_subfi_tl tcg_gen_subfi_i64
blueswir1f8422f52008-02-24 07:45:43 +00002730#define tcg_gen_subi_tl tcg_gen_subi_i64
2731#define tcg_gen_and_tl tcg_gen_and_i64
2732#define tcg_gen_andi_tl tcg_gen_andi_i64
2733#define tcg_gen_or_tl tcg_gen_or_i64
2734#define tcg_gen_ori_tl tcg_gen_ori_i64
2735#define tcg_gen_xor_tl tcg_gen_xor_i64
2736#define tcg_gen_xori_tl tcg_gen_xori_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002737#define tcg_gen_not_tl tcg_gen_not_i64
blueswir1f8422f52008-02-24 07:45:43 +00002738#define tcg_gen_shl_tl tcg_gen_shl_i64
2739#define tcg_gen_shli_tl tcg_gen_shli_i64
2740#define tcg_gen_shr_tl tcg_gen_shr_i64
2741#define tcg_gen_shri_tl tcg_gen_shri_i64
2742#define tcg_gen_sar_tl tcg_gen_sar_i64
2743#define tcg_gen_sari_tl tcg_gen_sari_i64
blueswir10cf767d2008-03-02 18:20:59 +00002744#define tcg_gen_brcond_tl tcg_gen_brcond_i64
pbrookcb636692008-05-24 02:22:00 +00002745#define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
Richard Hendersonbe210ac2010-01-07 10:13:31 -08002746#define tcg_gen_setcond_tl tcg_gen_setcond_i64
Aurelien Jarnoadd1e7e2010-02-08 12:06:05 +01002747#define tcg_gen_setcondi_tl tcg_gen_setcondi_i64
thsf730fd22008-05-04 08:14:08 +00002748#define tcg_gen_mul_tl tcg_gen_mul_i64
2749#define tcg_gen_muli_tl tcg_gen_muli_i64
aurel32ab364212009-03-29 01:19:22 +00002750#define tcg_gen_div_tl tcg_gen_div_i64
2751#define tcg_gen_rem_tl tcg_gen_rem_i64
aurel32864951a2009-03-29 14:08:54 +00002752#define tcg_gen_divu_tl tcg_gen_divu_i64
2753#define tcg_gen_remu_tl tcg_gen_remu_i64
blueswir1a768e4b2008-03-16 19:16:37 +00002754#define tcg_gen_discard_tl tcg_gen_discard_i64
blueswir1e4290732008-03-22 08:39:04 +00002755#define tcg_gen_trunc_tl_i32 tcg_gen_trunc_i64_i32
2756#define tcg_gen_trunc_i64_tl tcg_gen_mov_i64
2757#define tcg_gen_extu_i32_tl tcg_gen_extu_i32_i64
2758#define tcg_gen_ext_i32_tl tcg_gen_ext_i32_i64
2759#define tcg_gen_extu_tl_i64 tcg_gen_mov_i64
2760#define tcg_gen_ext_tl_i64 tcg_gen_mov_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002761#define tcg_gen_ext8u_tl tcg_gen_ext8u_i64
2762#define tcg_gen_ext8s_tl tcg_gen_ext8s_i64
2763#define tcg_gen_ext16u_tl tcg_gen_ext16u_i64
2764#define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
2765#define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
2766#define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
aurel32911d79b2009-03-13 09:35:19 +00002767#define tcg_gen_bswap16_tl tcg_gen_bswap16_i64
2768#define tcg_gen_bswap32_tl tcg_gen_bswap32_i64
2769#define tcg_gen_bswap64_tl tcg_gen_bswap64_i64
blueswir1945ca822008-09-21 18:32:28 +00002770#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
Richard Henderson3c51a982013-02-19 23:51:54 -08002771#define tcg_gen_extr_i64_tl tcg_gen_extr32_i64
aurel32f24cb332008-10-21 11:28:59 +00002772#define tcg_gen_andc_tl tcg_gen_andc_i64
2773#define tcg_gen_eqv_tl tcg_gen_eqv_i64
2774#define tcg_gen_nand_tl tcg_gen_nand_i64
2775#define tcg_gen_nor_tl tcg_gen_nor_i64
2776#define tcg_gen_orc_tl tcg_gen_orc_i64
aurel3215824572008-11-03 07:08:36 +00002777#define tcg_gen_rotl_tl tcg_gen_rotl_i64
2778#define tcg_gen_rotli_tl tcg_gen_rotli_i64
2779#define tcg_gen_rotr_tl tcg_gen_rotr_i64
2780#define tcg_gen_rotri_tl tcg_gen_rotri_i64
Richard Hendersonb7767f02011-01-10 19:23:42 -08002781#define tcg_gen_deposit_tl tcg_gen_deposit_i64
blueswir1a98824a2008-03-13 20:46:42 +00002782#define tcg_const_tl tcg_const_i64
aurel32bdffd4a2008-10-21 11:30:45 +00002783#define tcg_const_local_tl tcg_const_local_i64
Richard Hendersonffc5ea02012-09-21 10:13:34 -07002784#define tcg_gen_movcond_tl tcg_gen_movcond_i64
Richard Hendersonf6953a72013-02-19 23:51:56 -08002785#define tcg_gen_add2_tl tcg_gen_add2_i64
2786#define tcg_gen_sub2_tl tcg_gen_sub2_i64
Richard Henderson696a8be2013-02-19 23:51:55 -08002787#define tcg_gen_mulu2_tl tcg_gen_mulu2_i64
2788#define tcg_gen_muls2_tl tcg_gen_muls2_i64
blueswir1f8422f52008-02-24 07:45:43 +00002789#else
blueswir1f8422f52008-02-24 07:45:43 +00002790#define tcg_gen_movi_tl tcg_gen_movi_i32
2791#define tcg_gen_mov_tl tcg_gen_mov_i32
2792#define tcg_gen_ld8u_tl tcg_gen_ld8u_i32
2793#define tcg_gen_ld8s_tl tcg_gen_ld8s_i32
2794#define tcg_gen_ld16u_tl tcg_gen_ld16u_i32
2795#define tcg_gen_ld16s_tl tcg_gen_ld16s_i32
2796#define tcg_gen_ld32u_tl tcg_gen_ld_i32
2797#define tcg_gen_ld32s_tl tcg_gen_ld_i32
2798#define tcg_gen_ld_tl tcg_gen_ld_i32
2799#define tcg_gen_st8_tl tcg_gen_st8_i32
2800#define tcg_gen_st16_tl tcg_gen_st16_i32
2801#define tcg_gen_st32_tl tcg_gen_st_i32
2802#define tcg_gen_st_tl tcg_gen_st_i32
2803#define tcg_gen_add_tl tcg_gen_add_i32
2804#define tcg_gen_addi_tl tcg_gen_addi_i32
2805#define tcg_gen_sub_tl tcg_gen_sub_i32
pbrook390efc52008-05-11 14:35:37 +00002806#define tcg_gen_neg_tl tcg_gen_neg_i32
aurel3200457342008-11-02 08:23:04 +00002807#define tcg_gen_subfi_tl tcg_gen_subfi_i32
blueswir1f8422f52008-02-24 07:45:43 +00002808#define tcg_gen_subi_tl tcg_gen_subi_i32
2809#define tcg_gen_and_tl tcg_gen_and_i32
2810#define tcg_gen_andi_tl tcg_gen_andi_i32
2811#define tcg_gen_or_tl tcg_gen_or_i32
2812#define tcg_gen_ori_tl tcg_gen_ori_i32
2813#define tcg_gen_xor_tl tcg_gen_xor_i32
2814#define tcg_gen_xori_tl tcg_gen_xori_i32
bellard0b6ce4c2008-05-17 12:40:44 +00002815#define tcg_gen_not_tl tcg_gen_not_i32
blueswir1f8422f52008-02-24 07:45:43 +00002816#define tcg_gen_shl_tl tcg_gen_shl_i32
2817#define tcg_gen_shli_tl tcg_gen_shli_i32
2818#define tcg_gen_shr_tl tcg_gen_shr_i32
2819#define tcg_gen_shri_tl tcg_gen_shri_i32
2820#define tcg_gen_sar_tl tcg_gen_sar_i32
2821#define tcg_gen_sari_tl tcg_gen_sari_i32
blueswir10cf767d2008-03-02 18:20:59 +00002822#define tcg_gen_brcond_tl tcg_gen_brcond_i32
pbrookcb636692008-05-24 02:22:00 +00002823#define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
Richard Hendersonbe210ac2010-01-07 10:13:31 -08002824#define tcg_gen_setcond_tl tcg_gen_setcond_i32
Aurelien Jarnoadd1e7e2010-02-08 12:06:05 +01002825#define tcg_gen_setcondi_tl tcg_gen_setcondi_i32
thsf730fd22008-05-04 08:14:08 +00002826#define tcg_gen_mul_tl tcg_gen_mul_i32
2827#define tcg_gen_muli_tl tcg_gen_muli_i32
aurel32ab364212009-03-29 01:19:22 +00002828#define tcg_gen_div_tl tcg_gen_div_i32
2829#define tcg_gen_rem_tl tcg_gen_rem_i32
aurel32864951a2009-03-29 14:08:54 +00002830#define tcg_gen_divu_tl tcg_gen_divu_i32
2831#define tcg_gen_remu_tl tcg_gen_remu_i32
blueswir1a768e4b2008-03-16 19:16:37 +00002832#define tcg_gen_discard_tl tcg_gen_discard_i32
blueswir1e4290732008-03-22 08:39:04 +00002833#define tcg_gen_trunc_tl_i32 tcg_gen_mov_i32
2834#define tcg_gen_trunc_i64_tl tcg_gen_trunc_i64_i32
2835#define tcg_gen_extu_i32_tl tcg_gen_mov_i32
2836#define tcg_gen_ext_i32_tl tcg_gen_mov_i32
2837#define tcg_gen_extu_tl_i64 tcg_gen_extu_i32_i64
2838#define tcg_gen_ext_tl_i64 tcg_gen_ext_i32_i64
bellard0b6ce4c2008-05-17 12:40:44 +00002839#define tcg_gen_ext8u_tl tcg_gen_ext8u_i32
2840#define tcg_gen_ext8s_tl tcg_gen_ext8s_i32
2841#define tcg_gen_ext16u_tl tcg_gen_ext16u_i32
2842#define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
2843#define tcg_gen_ext32u_tl tcg_gen_mov_i32
2844#define tcg_gen_ext32s_tl tcg_gen_mov_i32
aurel32911d79b2009-03-13 09:35:19 +00002845#define tcg_gen_bswap16_tl tcg_gen_bswap16_i32
2846#define tcg_gen_bswap32_tl tcg_gen_bswap32_i32
blueswir1945ca822008-09-21 18:32:28 +00002847#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
Richard Henderson3c51a982013-02-19 23:51:54 -08002848#define tcg_gen_extr_tl_i64 tcg_gen_extr_i32_i64
aurel32f24cb332008-10-21 11:28:59 +00002849#define tcg_gen_andc_tl tcg_gen_andc_i32
2850#define tcg_gen_eqv_tl tcg_gen_eqv_i32
2851#define tcg_gen_nand_tl tcg_gen_nand_i32
2852#define tcg_gen_nor_tl tcg_gen_nor_i32
2853#define tcg_gen_orc_tl tcg_gen_orc_i32
aurel3215824572008-11-03 07:08:36 +00002854#define tcg_gen_rotl_tl tcg_gen_rotl_i32
2855#define tcg_gen_rotli_tl tcg_gen_rotli_i32
2856#define tcg_gen_rotr_tl tcg_gen_rotr_i32
2857#define tcg_gen_rotri_tl tcg_gen_rotri_i32
Richard Hendersonb7767f02011-01-10 19:23:42 -08002858#define tcg_gen_deposit_tl tcg_gen_deposit_i32
blueswir1a98824a2008-03-13 20:46:42 +00002859#define tcg_const_tl tcg_const_i32
aurel32bdffd4a2008-10-21 11:30:45 +00002860#define tcg_const_local_tl tcg_const_local_i32
Richard Hendersonffc5ea02012-09-21 10:13:34 -07002861#define tcg_gen_movcond_tl tcg_gen_movcond_i32
Richard Hendersonf6953a72013-02-19 23:51:56 -08002862#define tcg_gen_add2_tl tcg_gen_add2_i32
2863#define tcg_gen_sub2_tl tcg_gen_sub2_i32
Richard Henderson696a8be2013-02-19 23:51:55 -08002864#define tcg_gen_mulu2_tl tcg_gen_mulu2_i32
2865#define tcg_gen_muls2_tl tcg_gen_muls2_i32
blueswir1f8422f52008-02-24 07:45:43 +00002866#endif
pbrook6ddbc6e2008-03-31 03:46:33 +00002867
2868#if TCG_TARGET_REG_BITS == 32
Richard Hendersonf713d6a2013-09-04 08:11:05 -07002869# define tcg_gen_ld_ptr(R, A, O) \
2870 tcg_gen_ld_i32(TCGV_PTR_TO_NAT(R), (A), (O))
2871# define tcg_gen_discard_ptr(A) \
2872 tcg_gen_discard_i32(TCGV_PTR_TO_NAT(A))
2873# define tcg_gen_add_ptr(R, A, B) \
2874 tcg_gen_add_i32(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), TCGV_PTR_TO_NAT(B))
2875# define tcg_gen_addi_ptr(R, A, B) \
2876 tcg_gen_addi_i32(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), (B))
2877# define tcg_gen_ext_i32_ptr(R, A) \
2878 tcg_gen_mov_i32(TCGV_PTR_TO_NAT(R), (A))
2879#else
2880# define tcg_gen_ld_ptr(R, A, O) \
2881 tcg_gen_ld_i64(TCGV_PTR_TO_NAT(R), (A), (O))
2882# define tcg_gen_discard_ptr(A) \
2883 tcg_gen_discard_i64(TCGV_PTR_TO_NAT(A))
2884# define tcg_gen_add_ptr(R, A, B) \
2885 tcg_gen_add_i64(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), TCGV_PTR_TO_NAT(B))
2886# define tcg_gen_addi_ptr(R, A, B) \
2887 tcg_gen_addi_i64(TCGV_PTR_TO_NAT(R), TCGV_PTR_TO_NAT(A), (B))
2888# define tcg_gen_ext_i32_ptr(R, A) \
2889 tcg_gen_ext_i32_i64(TCGV_PTR_TO_NAT(R), (A))
2890#endif /* TCG_TARGET_REG_BITS == 32 */