blob: cd0e793a9d8c59cd2604671c27415fe955329a40 [file] [log] [blame]
Kirill Batuzov8f2e8c02011-07-07 16:37:12 +04001/*
2 * Optimizations for Tiny Code Generator for QEMU
3 *
4 * Copyright (c) 2010 Samsung Electronics.
5 * Contributed by Kirill Batuzov <batuzovk@ispras.ru>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26#include "config.h"
27
28#include <stdlib.h>
29#include <stdio.h>
30
31#include "qemu-common.h"
32#include "tcg-op.h"
33
Kirill Batuzov8f2e8c02011-07-07 16:37:12 +040034#define CASE_OP_32_64(x) \
35 glue(glue(case INDEX_op_, x), _i32): \
36 glue(glue(case INDEX_op_, x), _i64)
Kirill Batuzov8f2e8c02011-07-07 16:37:12 +040037
Kirill Batuzov22613af2011-07-07 16:37:13 +040038typedef enum {
39 TCG_TEMP_UNDEF = 0,
40 TCG_TEMP_CONST,
41 TCG_TEMP_COPY,
Kirill Batuzov22613af2011-07-07 16:37:13 +040042} tcg_temp_state;
43
44struct tcg_temp_info {
45 tcg_temp_state state;
46 uint16_t prev_copy;
47 uint16_t next_copy;
48 tcg_target_ulong val;
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -080049 tcg_target_ulong mask;
Kirill Batuzov22613af2011-07-07 16:37:13 +040050};
51
52static struct tcg_temp_info temps[TCG_MAX_TEMPS];
53
Aurelien Jarnoe590d4e2012-09-11 12:31:21 +020054/* Reset TEMP's state to TCG_TEMP_UNDEF. If TEMP only had one copy, remove
55 the copy flag from the left temp. */
56static void reset_temp(TCGArg temp)
Kirill Batuzov22613af2011-07-07 16:37:13 +040057{
Aurelien Jarnoe590d4e2012-09-11 12:31:21 +020058 if (temps[temp].state == TCG_TEMP_COPY) {
59 if (temps[temp].prev_copy == temps[temp].next_copy) {
60 temps[temps[temp].next_copy].state = TCG_TEMP_UNDEF;
61 } else {
62 temps[temps[temp].next_copy].prev_copy = temps[temp].prev_copy;
63 temps[temps[temp].prev_copy].next_copy = temps[temp].next_copy;
Kirill Batuzov22613af2011-07-07 16:37:13 +040064 }
Kirill Batuzov22613af2011-07-07 16:37:13 +040065 }
Aurelien Jarno48b56ce2012-09-10 23:51:42 +020066 temps[temp].state = TCG_TEMP_UNDEF;
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -080067 temps[temp].mask = -1;
Kirill Batuzov22613af2011-07-07 16:37:13 +040068}
69
Richard Hendersona4ce0992014-03-30 17:14:02 -070070static TCGOp *insert_op_before(TCGContext *s, TCGOp *old_op,
71 TCGOpcode opc, int nargs)
72{
73 int oi = s->gen_next_op_idx;
74 int pi = s->gen_next_parm_idx;
75 int prev = old_op->prev;
76 int next = old_op - s->gen_op_buf;
77 TCGOp *new_op;
78
79 tcg_debug_assert(oi < OPC_BUF_SIZE);
80 tcg_debug_assert(pi + nargs <= OPPARAM_BUF_SIZE);
81 s->gen_next_op_idx = oi + 1;
82 s->gen_next_parm_idx = pi + nargs;
83
84 new_op = &s->gen_op_buf[oi];
85 *new_op = (TCGOp){
86 .opc = opc,
87 .args = pi,
88 .prev = prev,
89 .next = next
90 };
91 if (prev >= 0) {
92 s->gen_op_buf[prev].next = oi;
93 } else {
94 s->gen_first_op_idx = oi;
95 }
96 old_op->prev = oi;
97
98 return new_op;
99}
100
Paolo Bonzinid193a142013-01-11 15:42:51 -0800101/* Reset all temporaries, given that there are NB_TEMPS of them. */
102static void reset_all_temps(int nb_temps)
103{
104 int i;
105 for (i = 0; i < nb_temps; i++) {
106 temps[i].state = TCG_TEMP_UNDEF;
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800107 temps[i].mask = -1;
Paolo Bonzinid193a142013-01-11 15:42:51 -0800108 }
109}
110
Blue Swirlfe0de7a2011-07-30 19:18:32 +0000111static int op_bits(TCGOpcode op)
Kirill Batuzov22613af2011-07-07 16:37:13 +0400112{
Richard Henderson8399ad52011-08-17 14:11:45 -0700113 const TCGOpDef *def = &tcg_op_defs[op];
114 return def->flags & TCG_OPF_64BIT ? 64 : 32;
Kirill Batuzov22613af2011-07-07 16:37:13 +0400115}
116
Richard Hendersona62f6f52014-05-22 10:59:12 -0700117static TCGOpcode op_to_mov(TCGOpcode op)
118{
119 switch (op_bits(op)) {
120 case 32:
121 return INDEX_op_mov_i32;
122 case 64:
123 return INDEX_op_mov_i64;
124 default:
125 fprintf(stderr, "op_to_mov: unexpected return value of "
126 "function op_bits.\n");
127 tcg_abort();
128 }
129}
130
Blue Swirlfe0de7a2011-07-30 19:18:32 +0000131static TCGOpcode op_to_movi(TCGOpcode op)
Kirill Batuzov22613af2011-07-07 16:37:13 +0400132{
133 switch (op_bits(op)) {
134 case 32:
135 return INDEX_op_movi_i32;
Kirill Batuzov22613af2011-07-07 16:37:13 +0400136 case 64:
137 return INDEX_op_movi_i64;
Kirill Batuzov22613af2011-07-07 16:37:13 +0400138 default:
139 fprintf(stderr, "op_to_movi: unexpected return value of "
140 "function op_bits.\n");
141 tcg_abort();
142 }
143}
144
Aurelien Jarnoe590d4e2012-09-11 12:31:21 +0200145static TCGArg find_better_copy(TCGContext *s, TCGArg temp)
146{
147 TCGArg i;
148
149 /* If this is already a global, we can't do better. */
150 if (temp < s->nb_globals) {
151 return temp;
152 }
153
154 /* Search for a global first. */
155 for (i = temps[temp].next_copy ; i != temp ; i = temps[i].next_copy) {
156 if (i < s->nb_globals) {
157 return i;
158 }
159 }
160
161 /* If it is a temp, search for a temp local. */
162 if (!s->temps[temp].temp_local) {
163 for (i = temps[temp].next_copy ; i != temp ; i = temps[i].next_copy) {
164 if (s->temps[i].temp_local) {
165 return i;
166 }
167 }
168 }
169
170 /* Failure to find a better representation, return the same temp. */
171 return temp;
172}
173
174static bool temps_are_copies(TCGArg arg1, TCGArg arg2)
175{
176 TCGArg i;
177
178 if (arg1 == arg2) {
179 return true;
180 }
181
182 if (temps[arg1].state != TCG_TEMP_COPY
183 || temps[arg2].state != TCG_TEMP_COPY) {
184 return false;
185 }
186
187 for (i = temps[arg1].next_copy ; i != arg1 ; i = temps[i].next_copy) {
188 if (i == arg2) {
189 return true;
190 }
191 }
192
193 return false;
194}
195
Aurelien Jarno97a79eb2015-06-05 11:19:18 +0200196static void tcg_opt_gen_movi(TCGContext *s, TCGOp *op, TCGArg *args,
197 TCGArg dst, TCGArg val)
198{
199 TCGOpcode new_op = op_to_movi(op->opc);
200 tcg_target_ulong mask;
201
202 op->opc = new_op;
203
204 reset_temp(dst);
205 temps[dst].state = TCG_TEMP_CONST;
206 temps[dst].val = val;
207 mask = val;
Aurelien Jarno96152122015-07-10 18:03:30 +0200208 if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_movi_i32) {
Aurelien Jarno97a79eb2015-06-05 11:19:18 +0200209 /* High bits of the destination are now garbage. */
210 mask |= ~0xffffffffull;
211 }
212 temps[dst].mask = mask;
213
214 args[0] = dst;
215 args[1] = val;
216}
217
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700218static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg *args,
Aurelien Jarno8d6a9162015-06-04 21:53:24 +0200219 TCGArg dst, TCGArg src)
Kirill Batuzov22613af2011-07-07 16:37:13 +0400220{
Aurelien Jarno53657182015-06-04 21:53:25 +0200221 if (temps_are_copies(dst, src)) {
222 tcg_op_remove(s, op);
223 return;
224 }
225
Aurelien Jarno97a79eb2015-06-05 11:19:18 +0200226 if (temps[src].state == TCG_TEMP_CONST) {
227 tcg_opt_gen_movi(s, op, args, dst, temps[src].val);
228 return;
229 }
230
Aurelien Jarno8d6a9162015-06-04 21:53:24 +0200231 TCGOpcode new_op = op_to_mov(op->opc);
Richard Henderson24666ba2014-05-22 11:14:10 -0700232 tcg_target_ulong mask;
Richard Hendersona62f6f52014-05-22 10:59:12 -0700233
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700234 op->opc = new_op;
Richard Hendersona62f6f52014-05-22 10:59:12 -0700235
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800236 reset_temp(dst);
Richard Henderson24666ba2014-05-22 11:14:10 -0700237 mask = temps[src].mask;
238 if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_mov_i32) {
239 /* High bits of the destination are now garbage. */
240 mask |= ~0xffffffffull;
241 }
242 temps[dst].mask = mask;
243
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800244 assert(temps[src].state != TCG_TEMP_CONST);
Aurelien Jarnoe590d4e2012-09-11 12:31:21 +0200245
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800246 if (s->temps[src].type == s->temps[dst].type) {
247 if (temps[src].state != TCG_TEMP_COPY) {
248 temps[src].state = TCG_TEMP_COPY;
249 temps[src].next_copy = src;
250 temps[src].prev_copy = src;
Kirill Batuzov22613af2011-07-07 16:37:13 +0400251 }
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800252 temps[dst].state = TCG_TEMP_COPY;
253 temps[dst].next_copy = temps[src].next_copy;
254 temps[dst].prev_copy = src;
255 temps[temps[dst].next_copy].prev_copy = dst;
256 temps[src].next_copy = dst;
257 }
Aurelien Jarnoe590d4e2012-09-11 12:31:21 +0200258
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700259 args[0] = dst;
260 args[1] = src;
Kirill Batuzov22613af2011-07-07 16:37:13 +0400261}
262
Blue Swirlfe0de7a2011-07-30 19:18:32 +0000263static TCGArg do_constant_folding_2(TCGOpcode op, TCGArg x, TCGArg y)
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400264{
Richard Henderson03271522013-08-14 14:35:56 -0700265 uint64_t l64, h64;
266
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400267 switch (op) {
268 CASE_OP_32_64(add):
269 return x + y;
270
271 CASE_OP_32_64(sub):
272 return x - y;
273
274 CASE_OP_32_64(mul):
275 return x * y;
276
Kirill Batuzov9a810902011-07-07 16:37:15 +0400277 CASE_OP_32_64(and):
278 return x & y;
279
280 CASE_OP_32_64(or):
281 return x | y;
282
283 CASE_OP_32_64(xor):
284 return x ^ y;
285
Kirill Batuzov55c09752011-07-07 16:37:16 +0400286 case INDEX_op_shl_i32:
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700287 return (uint32_t)x << (y & 31);
Kirill Batuzov55c09752011-07-07 16:37:16 +0400288
Kirill Batuzov55c09752011-07-07 16:37:16 +0400289 case INDEX_op_shl_i64:
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700290 return (uint64_t)x << (y & 63);
Kirill Batuzov55c09752011-07-07 16:37:16 +0400291
292 case INDEX_op_shr_i32:
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700293 return (uint32_t)x >> (y & 31);
Kirill Batuzov55c09752011-07-07 16:37:16 +0400294
Richard Henderson4bb7a412013-09-09 17:03:24 -0700295 case INDEX_op_trunc_shr_i32:
Kirill Batuzov55c09752011-07-07 16:37:16 +0400296 case INDEX_op_shr_i64:
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700297 return (uint64_t)x >> (y & 63);
Kirill Batuzov55c09752011-07-07 16:37:16 +0400298
299 case INDEX_op_sar_i32:
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700300 return (int32_t)x >> (y & 31);
Kirill Batuzov55c09752011-07-07 16:37:16 +0400301
Kirill Batuzov55c09752011-07-07 16:37:16 +0400302 case INDEX_op_sar_i64:
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700303 return (int64_t)x >> (y & 63);
Kirill Batuzov55c09752011-07-07 16:37:16 +0400304
305 case INDEX_op_rotr_i32:
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700306 return ror32(x, y & 31);
Kirill Batuzov55c09752011-07-07 16:37:16 +0400307
Kirill Batuzov55c09752011-07-07 16:37:16 +0400308 case INDEX_op_rotr_i64:
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700309 return ror64(x, y & 63);
Kirill Batuzov55c09752011-07-07 16:37:16 +0400310
311 case INDEX_op_rotl_i32:
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700312 return rol32(x, y & 31);
Kirill Batuzov55c09752011-07-07 16:37:16 +0400313
Kirill Batuzov55c09752011-07-07 16:37:16 +0400314 case INDEX_op_rotl_i64:
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700315 return rol64(x, y & 63);
Kirill Batuzov55c09752011-07-07 16:37:16 +0400316
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700317 CASE_OP_32_64(not):
Kirill Batuzova640f032011-07-07 16:37:17 +0400318 return ~x;
319
Richard Hendersoncb25c802011-08-17 14:11:47 -0700320 CASE_OP_32_64(neg):
321 return -x;
322
323 CASE_OP_32_64(andc):
324 return x & ~y;
325
326 CASE_OP_32_64(orc):
327 return x | ~y;
328
329 CASE_OP_32_64(eqv):
330 return ~(x ^ y);
331
332 CASE_OP_32_64(nand):
333 return ~(x & y);
334
335 CASE_OP_32_64(nor):
336 return ~(x | y);
337
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700338 CASE_OP_32_64(ext8s):
Kirill Batuzova640f032011-07-07 16:37:17 +0400339 return (int8_t)x;
340
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700341 CASE_OP_32_64(ext16s):
Kirill Batuzova640f032011-07-07 16:37:17 +0400342 return (int16_t)x;
343
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700344 CASE_OP_32_64(ext8u):
Kirill Batuzova640f032011-07-07 16:37:17 +0400345 return (uint8_t)x;
346
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700347 CASE_OP_32_64(ext16u):
Kirill Batuzova640f032011-07-07 16:37:17 +0400348 return (uint16_t)x;
349
Kirill Batuzova640f032011-07-07 16:37:17 +0400350 case INDEX_op_ext32s_i64:
351 return (int32_t)x;
352
353 case INDEX_op_ext32u_i64:
354 return (uint32_t)x;
Kirill Batuzova640f032011-07-07 16:37:17 +0400355
Richard Henderson03271522013-08-14 14:35:56 -0700356 case INDEX_op_muluh_i32:
357 return ((uint64_t)(uint32_t)x * (uint32_t)y) >> 32;
358 case INDEX_op_mulsh_i32:
359 return ((int64_t)(int32_t)x * (int32_t)y) >> 32;
360
361 case INDEX_op_muluh_i64:
362 mulu64(&l64, &h64, x, y);
363 return h64;
364 case INDEX_op_mulsh_i64:
365 muls64(&l64, &h64, x, y);
366 return h64;
367
Richard Henderson01547f72013-08-14 15:22:46 -0700368 case INDEX_op_div_i32:
369 /* Avoid crashing on divide by zero, otherwise undefined. */
370 return (int32_t)x / ((int32_t)y ? : 1);
371 case INDEX_op_divu_i32:
372 return (uint32_t)x / ((uint32_t)y ? : 1);
373 case INDEX_op_div_i64:
374 return (int64_t)x / ((int64_t)y ? : 1);
375 case INDEX_op_divu_i64:
376 return (uint64_t)x / ((uint64_t)y ? : 1);
377
378 case INDEX_op_rem_i32:
379 return (int32_t)x % ((int32_t)y ? : 1);
380 case INDEX_op_remu_i32:
381 return (uint32_t)x % ((uint32_t)y ? : 1);
382 case INDEX_op_rem_i64:
383 return (int64_t)x % ((int64_t)y ? : 1);
384 case INDEX_op_remu_i64:
385 return (uint64_t)x % ((uint64_t)y ? : 1);
386
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400387 default:
388 fprintf(stderr,
389 "Unrecognized operation %d in do_constant_folding.\n", op);
390 tcg_abort();
391 }
392}
393
Blue Swirlfe0de7a2011-07-30 19:18:32 +0000394static TCGArg do_constant_folding(TCGOpcode op, TCGArg x, TCGArg y)
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400395{
396 TCGArg res = do_constant_folding_2(op, x, y);
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400397 if (op_bits(op) == 32) {
Aurelien Jarno29f3ff82015-07-10 18:03:31 +0200398 res = (int32_t)res;
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400399 }
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400400 return res;
401}
402
Richard Henderson9519da72012-10-02 11:32:26 -0700403static bool do_constant_folding_cond_32(uint32_t x, uint32_t y, TCGCond c)
404{
405 switch (c) {
406 case TCG_COND_EQ:
407 return x == y;
408 case TCG_COND_NE:
409 return x != y;
410 case TCG_COND_LT:
411 return (int32_t)x < (int32_t)y;
412 case TCG_COND_GE:
413 return (int32_t)x >= (int32_t)y;
414 case TCG_COND_LE:
415 return (int32_t)x <= (int32_t)y;
416 case TCG_COND_GT:
417 return (int32_t)x > (int32_t)y;
418 case TCG_COND_LTU:
419 return x < y;
420 case TCG_COND_GEU:
421 return x >= y;
422 case TCG_COND_LEU:
423 return x <= y;
424 case TCG_COND_GTU:
425 return x > y;
426 default:
427 tcg_abort();
428 }
429}
430
431static bool do_constant_folding_cond_64(uint64_t x, uint64_t y, TCGCond c)
432{
433 switch (c) {
434 case TCG_COND_EQ:
435 return x == y;
436 case TCG_COND_NE:
437 return x != y;
438 case TCG_COND_LT:
439 return (int64_t)x < (int64_t)y;
440 case TCG_COND_GE:
441 return (int64_t)x >= (int64_t)y;
442 case TCG_COND_LE:
443 return (int64_t)x <= (int64_t)y;
444 case TCG_COND_GT:
445 return (int64_t)x > (int64_t)y;
446 case TCG_COND_LTU:
447 return x < y;
448 case TCG_COND_GEU:
449 return x >= y;
450 case TCG_COND_LEU:
451 return x <= y;
452 case TCG_COND_GTU:
453 return x > y;
454 default:
455 tcg_abort();
456 }
457}
458
459static bool do_constant_folding_cond_eq(TCGCond c)
460{
461 switch (c) {
462 case TCG_COND_GT:
463 case TCG_COND_LTU:
464 case TCG_COND_LT:
465 case TCG_COND_GTU:
466 case TCG_COND_NE:
467 return 0;
468 case TCG_COND_GE:
469 case TCG_COND_GEU:
470 case TCG_COND_LE:
471 case TCG_COND_LEU:
472 case TCG_COND_EQ:
473 return 1;
474 default:
475 tcg_abort();
476 }
477}
478
Aurelien Jarnob336ceb2012-09-18 19:37:00 +0200479/* Return 2 if the condition can't be simplified, and the result
480 of the condition (0 or 1) if it can */
Aurelien Jarnof8dd19e2012-09-06 16:47:14 +0200481static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,
482 TCGArg y, TCGCond c)
483{
Aurelien Jarnob336ceb2012-09-18 19:37:00 +0200484 if (temps[x].state == TCG_TEMP_CONST && temps[y].state == TCG_TEMP_CONST) {
485 switch (op_bits(op)) {
486 case 32:
Richard Henderson9519da72012-10-02 11:32:26 -0700487 return do_constant_folding_cond_32(temps[x].val, temps[y].val, c);
Aurelien Jarnob336ceb2012-09-18 19:37:00 +0200488 case 64:
Richard Henderson9519da72012-10-02 11:32:26 -0700489 return do_constant_folding_cond_64(temps[x].val, temps[y].val, c);
490 default:
491 tcg_abort();
Aurelien Jarnof8dd19e2012-09-06 16:47:14 +0200492 }
Aurelien Jarnob336ceb2012-09-18 19:37:00 +0200493 } else if (temps_are_copies(x, y)) {
Richard Henderson9519da72012-10-02 11:32:26 -0700494 return do_constant_folding_cond_eq(c);
Aurelien Jarnob336ceb2012-09-18 19:37:00 +0200495 } else if (temps[y].state == TCG_TEMP_CONST && temps[y].val == 0) {
496 switch (c) {
497 case TCG_COND_LTU:
498 return 0;
499 case TCG_COND_GEU:
500 return 1;
501 default:
502 return 2;
503 }
504 } else {
505 return 2;
Aurelien Jarnof8dd19e2012-09-06 16:47:14 +0200506 }
Aurelien Jarnof8dd19e2012-09-06 16:47:14 +0200507}
508
Richard Henderson6c4382f2012-10-02 11:32:27 -0700509/* Return 2 if the condition can't be simplified, and the result
510 of the condition (0 or 1) if it can */
511static TCGArg do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c)
512{
513 TCGArg al = p1[0], ah = p1[1];
514 TCGArg bl = p2[0], bh = p2[1];
515
516 if (temps[bl].state == TCG_TEMP_CONST
517 && temps[bh].state == TCG_TEMP_CONST) {
518 uint64_t b = ((uint64_t)temps[bh].val << 32) | (uint32_t)temps[bl].val;
519
520 if (temps[al].state == TCG_TEMP_CONST
521 && temps[ah].state == TCG_TEMP_CONST) {
522 uint64_t a;
523 a = ((uint64_t)temps[ah].val << 32) | (uint32_t)temps[al].val;
524 return do_constant_folding_cond_64(a, b, c);
525 }
526 if (b == 0) {
527 switch (c) {
528 case TCG_COND_LTU:
529 return 0;
530 case TCG_COND_GEU:
531 return 1;
532 default:
533 break;
534 }
535 }
536 }
537 if (temps_are_copies(al, bl) && temps_are_copies(ah, bh)) {
538 return do_constant_folding_cond_eq(c);
539 }
540 return 2;
541}
542
Richard Henderson24c9ae42012-10-02 11:32:21 -0700543static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2)
544{
545 TCGArg a1 = *p1, a2 = *p2;
546 int sum = 0;
547 sum += temps[a1].state == TCG_TEMP_CONST;
548 sum -= temps[a2].state == TCG_TEMP_CONST;
549
550 /* Prefer the constant in second argument, and then the form
551 op a, a, b, which is better handled on non-RISC hosts. */
552 if (sum > 0 || (sum == 0 && dest == a2)) {
553 *p1 = a2;
554 *p2 = a1;
555 return true;
556 }
557 return false;
558}
559
Richard Henderson0bfcb862012-10-02 11:32:23 -0700560static bool swap_commutative2(TCGArg *p1, TCGArg *p2)
561{
562 int sum = 0;
563 sum += temps[p1[0]].state == TCG_TEMP_CONST;
564 sum += temps[p1[1]].state == TCG_TEMP_CONST;
565 sum -= temps[p2[0]].state == TCG_TEMP_CONST;
566 sum -= temps[p2[1]].state == TCG_TEMP_CONST;
567 if (sum > 0) {
568 TCGArg t;
569 t = p1[0], p1[0] = p2[0], p2[0] = t;
570 t = p1[1], p1[1] = p2[1], p2[1] = t;
571 return true;
572 }
573 return false;
574}
575
Kirill Batuzov22613af2011-07-07 16:37:13 +0400576/* Propagate constants and copies, fold constant expressions. */
Aurelien Jarno36e60ef2015-06-04 21:53:27 +0200577void tcg_optimize(TCGContext *s)
Kirill Batuzov8f2e8c02011-07-07 16:37:12 +0400578{
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700579 int oi, oi_next, nb_temps, nb_globals;
Richard Henderson5d8f5362012-09-21 10:13:38 -0700580
Kirill Batuzov22613af2011-07-07 16:37:13 +0400581 /* Array VALS has an element for each temp.
582 If this temp holds a constant then its value is kept in VALS' element.
Aurelien Jarnoe590d4e2012-09-11 12:31:21 +0200583 If this temp is a copy of other ones then the other copies are
584 available through the doubly linked circular list. */
Kirill Batuzov8f2e8c02011-07-07 16:37:12 +0400585
586 nb_temps = s->nb_temps;
587 nb_globals = s->nb_globals;
Paolo Bonzinid193a142013-01-11 15:42:51 -0800588 reset_all_temps(nb_temps);
Kirill Batuzov8f2e8c02011-07-07 16:37:12 +0400589
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700590 for (oi = s->gen_first_op_idx; oi >= 0; oi = oi_next) {
Richard Henderson24666ba2014-05-22 11:14:10 -0700591 tcg_target_ulong mask, partmask, affected;
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700592 int nb_oargs, nb_iargs, i;
Richard Hendersoncf066672014-03-22 20:06:52 -0700593 TCGArg tmp;
594
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700595 TCGOp * const op = &s->gen_op_buf[oi];
596 TCGArg * const args = &s->gen_opparam_buf[op->args];
597 TCGOpcode opc = op->opc;
598 const TCGOpDef *def = &tcg_op_defs[opc];
599
600 oi_next = op->next;
601 if (opc == INDEX_op_call) {
602 nb_oargs = op->callo;
603 nb_iargs = op->calli;
Aurelien Jarno1ff8c542012-09-11 16:18:49 +0200604 } else {
Richard Hendersoncf066672014-03-22 20:06:52 -0700605 nb_oargs = def->nb_oargs;
606 nb_iargs = def->nb_iargs;
Richard Hendersoncf066672014-03-22 20:06:52 -0700607 }
608
609 /* Do copy propagation */
610 for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) {
611 if (temps[args[i]].state == TCG_TEMP_COPY) {
612 args[i] = find_better_copy(s, args[i]);
Kirill Batuzov22613af2011-07-07 16:37:13 +0400613 }
614 }
615
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400616 /* For commutative operations make constant second argument */
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700617 switch (opc) {
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400618 CASE_OP_32_64(add):
619 CASE_OP_32_64(mul):
Kirill Batuzov9a810902011-07-07 16:37:15 +0400620 CASE_OP_32_64(and):
621 CASE_OP_32_64(or):
622 CASE_OP_32_64(xor):
Richard Hendersoncb25c802011-08-17 14:11:47 -0700623 CASE_OP_32_64(eqv):
624 CASE_OP_32_64(nand):
625 CASE_OP_32_64(nor):
Richard Henderson03271522013-08-14 14:35:56 -0700626 CASE_OP_32_64(muluh):
627 CASE_OP_32_64(mulsh):
Richard Henderson24c9ae42012-10-02 11:32:21 -0700628 swap_commutative(args[0], &args[1], &args[2]);
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400629 break;
Aurelien Jarno65a7cce2012-09-06 16:47:14 +0200630 CASE_OP_32_64(brcond):
Richard Henderson24c9ae42012-10-02 11:32:21 -0700631 if (swap_commutative(-1, &args[0], &args[1])) {
Aurelien Jarno65a7cce2012-09-06 16:47:14 +0200632 args[2] = tcg_swap_cond(args[2]);
633 }
634 break;
635 CASE_OP_32_64(setcond):
Richard Henderson24c9ae42012-10-02 11:32:21 -0700636 if (swap_commutative(args[0], &args[1], &args[2])) {
Aurelien Jarno65a7cce2012-09-06 16:47:14 +0200637 args[3] = tcg_swap_cond(args[3]);
638 }
639 break;
Richard Hendersonfa01a202012-09-21 10:13:37 -0700640 CASE_OP_32_64(movcond):
Richard Henderson24c9ae42012-10-02 11:32:21 -0700641 if (swap_commutative(-1, &args[1], &args[2])) {
642 args[5] = tcg_swap_cond(args[5]);
Richard Hendersonfa01a202012-09-21 10:13:37 -0700643 }
Richard Henderson5d8f5362012-09-21 10:13:38 -0700644 /* For movcond, we canonicalize the "false" input reg to match
645 the destination reg so that the tcg backend can implement
646 a "move if true" operation. */
Richard Henderson24c9ae42012-10-02 11:32:21 -0700647 if (swap_commutative(args[0], &args[4], &args[3])) {
648 args[5] = tcg_invert_cond(args[5]);
Richard Henderson5d8f5362012-09-21 10:13:38 -0700649 }
Richard Henderson1e484e62012-10-02 11:32:22 -0700650 break;
Richard Hendersond7156f72013-02-19 23:51:52 -0800651 CASE_OP_32_64(add2):
Richard Henderson1e484e62012-10-02 11:32:22 -0700652 swap_commutative(args[0], &args[2], &args[4]);
653 swap_commutative(args[1], &args[3], &args[5]);
654 break;
Richard Hendersond7156f72013-02-19 23:51:52 -0800655 CASE_OP_32_64(mulu2):
Richard Henderson4d3203f2013-02-19 23:51:53 -0800656 CASE_OP_32_64(muls2):
Richard Henderson14149682012-10-02 11:32:30 -0700657 swap_commutative(args[0], &args[2], &args[3]);
658 break;
Richard Henderson0bfcb862012-10-02 11:32:23 -0700659 case INDEX_op_brcond2_i32:
660 if (swap_commutative2(&args[0], &args[2])) {
661 args[4] = tcg_swap_cond(args[4]);
662 }
663 break;
664 case INDEX_op_setcond2_i32:
665 if (swap_commutative2(&args[1], &args[3])) {
666 args[5] = tcg_swap_cond(args[5]);
667 }
668 break;
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400669 default:
670 break;
671 }
672
Richard Henderson2d497542013-03-21 09:13:33 -0700673 /* Simplify expressions for "shift/rot r, 0, a => movi r, 0",
674 and "sub r, 0, a => neg r, a" case. */
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700675 switch (opc) {
Aurelien Jarno01ee5282012-09-06 16:47:14 +0200676 CASE_OP_32_64(shl):
677 CASE_OP_32_64(shr):
678 CASE_OP_32_64(sar):
679 CASE_OP_32_64(rotl):
680 CASE_OP_32_64(rotr):
681 if (temps[args[1]].state == TCG_TEMP_CONST
682 && temps[args[1]].val == 0) {
Aurelien Jarnoebd27392015-06-04 21:53:23 +0200683 tcg_opt_gen_movi(s, op, args, args[0], 0);
Aurelien Jarno01ee5282012-09-06 16:47:14 +0200684 continue;
685 }
686 break;
Richard Henderson2d497542013-03-21 09:13:33 -0700687 CASE_OP_32_64(sub):
688 {
689 TCGOpcode neg_op;
690 bool have_neg;
691
692 if (temps[args[2]].state == TCG_TEMP_CONST) {
693 /* Proceed with possible constant folding. */
694 break;
695 }
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700696 if (opc == INDEX_op_sub_i32) {
Richard Henderson2d497542013-03-21 09:13:33 -0700697 neg_op = INDEX_op_neg_i32;
698 have_neg = TCG_TARGET_HAS_neg_i32;
699 } else {
700 neg_op = INDEX_op_neg_i64;
701 have_neg = TCG_TARGET_HAS_neg_i64;
702 }
703 if (!have_neg) {
704 break;
705 }
706 if (temps[args[1]].state == TCG_TEMP_CONST
707 && temps[args[1]].val == 0) {
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700708 op->opc = neg_op;
Richard Henderson2d497542013-03-21 09:13:33 -0700709 reset_temp(args[0]);
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700710 args[1] = args[2];
Richard Henderson2d497542013-03-21 09:13:33 -0700711 continue;
712 }
713 }
714 break;
Richard Hendersone201b562014-01-28 13:15:38 -0800715 CASE_OP_32_64(xor):
716 CASE_OP_32_64(nand):
717 if (temps[args[1]].state != TCG_TEMP_CONST
718 && temps[args[2]].state == TCG_TEMP_CONST
719 && temps[args[2]].val == -1) {
720 i = 1;
721 goto try_not;
722 }
723 break;
724 CASE_OP_32_64(nor):
725 if (temps[args[1]].state != TCG_TEMP_CONST
726 && temps[args[2]].state == TCG_TEMP_CONST
727 && temps[args[2]].val == 0) {
728 i = 1;
729 goto try_not;
730 }
731 break;
732 CASE_OP_32_64(andc):
733 if (temps[args[2]].state != TCG_TEMP_CONST
734 && temps[args[1]].state == TCG_TEMP_CONST
735 && temps[args[1]].val == -1) {
736 i = 2;
737 goto try_not;
738 }
739 break;
740 CASE_OP_32_64(orc):
741 CASE_OP_32_64(eqv):
742 if (temps[args[2]].state != TCG_TEMP_CONST
743 && temps[args[1]].state == TCG_TEMP_CONST
744 && temps[args[1]].val == 0) {
745 i = 2;
746 goto try_not;
747 }
748 break;
749 try_not:
750 {
751 TCGOpcode not_op;
752 bool have_not;
753
754 if (def->flags & TCG_OPF_64BIT) {
755 not_op = INDEX_op_not_i64;
756 have_not = TCG_TARGET_HAS_not_i64;
757 } else {
758 not_op = INDEX_op_not_i32;
759 have_not = TCG_TARGET_HAS_not_i32;
760 }
761 if (!have_not) {
762 break;
763 }
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700764 op->opc = not_op;
Richard Hendersone201b562014-01-28 13:15:38 -0800765 reset_temp(args[0]);
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700766 args[1] = args[i];
Richard Hendersone201b562014-01-28 13:15:38 -0800767 continue;
768 }
Aurelien Jarno01ee5282012-09-06 16:47:14 +0200769 default:
770 break;
771 }
772
Richard Henderson464a1442014-01-31 07:42:11 -0600773 /* Simplify expression for "op r, a, const => mov r, a" cases */
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700774 switch (opc) {
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400775 CASE_OP_32_64(add):
776 CASE_OP_32_64(sub):
Kirill Batuzov55c09752011-07-07 16:37:16 +0400777 CASE_OP_32_64(shl):
778 CASE_OP_32_64(shr):
779 CASE_OP_32_64(sar):
Richard Henderson25c4d9c2011-08-17 14:11:46 -0700780 CASE_OP_32_64(rotl):
781 CASE_OP_32_64(rotr):
Aurelien Jarno38ee1882012-09-06 16:47:14 +0200782 CASE_OP_32_64(or):
783 CASE_OP_32_64(xor):
Richard Henderson464a1442014-01-31 07:42:11 -0600784 CASE_OP_32_64(andc):
785 if (temps[args[1]].state != TCG_TEMP_CONST
786 && temps[args[2]].state == TCG_TEMP_CONST
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400787 && temps[args[2]].val == 0) {
Aurelien Jarno97a79eb2015-06-05 11:19:18 +0200788 tcg_opt_gen_mov(s, op, args, args[0], args[1]);
789 continue;
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400790 }
791 break;
Richard Henderson464a1442014-01-31 07:42:11 -0600792 CASE_OP_32_64(and):
793 CASE_OP_32_64(orc):
794 CASE_OP_32_64(eqv):
795 if (temps[args[1]].state != TCG_TEMP_CONST
796 && temps[args[2]].state == TCG_TEMP_CONST
797 && temps[args[2]].val == -1) {
Aurelien Jarno97a79eb2015-06-05 11:19:18 +0200798 tcg_opt_gen_mov(s, op, args, args[0], args[1]);
799 continue;
Richard Henderson464a1442014-01-31 07:42:11 -0600800 }
801 break;
Aurelien Jarno56e49432012-09-06 16:47:13 +0200802 default:
803 break;
804 }
805
Aurelien Jarno30312442013-09-03 08:27:38 +0200806 /* Simplify using known-zero bits. Currently only ops with a single
807 output argument is supported. */
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800808 mask = -1;
Paolo Bonzini633f6502013-01-11 15:42:53 -0800809 affected = -1;
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700810 switch (opc) {
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800811 CASE_OP_32_64(ext8s):
812 if ((temps[args[1]].mask & 0x80) != 0) {
813 break;
814 }
815 CASE_OP_32_64(ext8u):
816 mask = 0xff;
817 goto and_const;
818 CASE_OP_32_64(ext16s):
819 if ((temps[args[1]].mask & 0x8000) != 0) {
820 break;
821 }
822 CASE_OP_32_64(ext16u):
823 mask = 0xffff;
824 goto and_const;
825 case INDEX_op_ext32s_i64:
826 if ((temps[args[1]].mask & 0x80000000) != 0) {
827 break;
828 }
829 case INDEX_op_ext32u_i64:
830 mask = 0xffffffffU;
831 goto and_const;
832
833 CASE_OP_32_64(and):
834 mask = temps[args[2]].mask;
835 if (temps[args[2]].state == TCG_TEMP_CONST) {
836 and_const:
Paolo Bonzini633f6502013-01-11 15:42:53 -0800837 affected = temps[args[1]].mask & ~mask;
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800838 }
839 mask = temps[args[1]].mask & mask;
840 break;
841
Richard Henderson23ec69ed2014-01-28 12:03:24 -0800842 CASE_OP_32_64(andc):
843 /* Known-zeros does not imply known-ones. Therefore unless
844 args[2] is constant, we can't infer anything from it. */
845 if (temps[args[2]].state == TCG_TEMP_CONST) {
846 mask = ~temps[args[2]].mask;
847 goto and_const;
848 }
849 /* But we certainly know nothing outside args[1] may be set. */
850 mask = temps[args[1]].mask;
851 break;
852
Aurelien Jarnoe46b2252013-09-03 08:27:38 +0200853 case INDEX_op_sar_i32:
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800854 if (temps[args[2]].state == TCG_TEMP_CONST) {
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700855 tmp = temps[args[2]].val & 31;
856 mask = (int32_t)temps[args[1]].mask >> tmp;
Aurelien Jarnoe46b2252013-09-03 08:27:38 +0200857 }
858 break;
859 case INDEX_op_sar_i64:
860 if (temps[args[2]].state == TCG_TEMP_CONST) {
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700861 tmp = temps[args[2]].val & 63;
862 mask = (int64_t)temps[args[1]].mask >> tmp;
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800863 }
864 break;
865
Aurelien Jarnoe46b2252013-09-03 08:27:38 +0200866 case INDEX_op_shr_i32:
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800867 if (temps[args[2]].state == TCG_TEMP_CONST) {
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700868 tmp = temps[args[2]].val & 31;
869 mask = (uint32_t)temps[args[1]].mask >> tmp;
Aurelien Jarnoe46b2252013-09-03 08:27:38 +0200870 }
871 break;
872 case INDEX_op_shr_i64:
873 if (temps[args[2]].state == TCG_TEMP_CONST) {
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700874 tmp = temps[args[2]].val & 63;
875 mask = (uint64_t)temps[args[1]].mask >> tmp;
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800876 }
877 break;
878
Richard Henderson4bb7a412013-09-09 17:03:24 -0700879 case INDEX_op_trunc_shr_i32:
880 mask = (uint64_t)temps[args[1]].mask >> args[2];
881 break;
882
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800883 CASE_OP_32_64(shl):
884 if (temps[args[2]].state == TCG_TEMP_CONST) {
Richard Henderson50c5c4d2014-03-18 07:45:39 -0700885 tmp = temps[args[2]].val & (TCG_TARGET_REG_BITS - 1);
886 mask = temps[args[1]].mask << tmp;
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800887 }
888 break;
889
890 CASE_OP_32_64(neg):
891 /* Set to 1 all bits to the left of the rightmost. */
892 mask = -(temps[args[1]].mask & -temps[args[1]].mask);
893 break;
894
895 CASE_OP_32_64(deposit):
Richard Hendersond998e552014-03-18 14:23:52 -0700896 mask = deposit64(temps[args[1]].mask, args[3], args[4],
897 temps[args[2]].mask);
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800898 break;
899
900 CASE_OP_32_64(or):
901 CASE_OP_32_64(xor):
902 mask = temps[args[1]].mask | temps[args[2]].mask;
903 break;
904
905 CASE_OP_32_64(setcond):
Richard Hendersona7635512014-04-23 22:18:30 -0700906 case INDEX_op_setcond2_i32:
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800907 mask = 1;
908 break;
909
910 CASE_OP_32_64(movcond):
911 mask = temps[args[3]].mask | temps[args[4]].mask;
912 break;
913
Aurelien Jarnoc8d70272013-09-03 08:27:39 +0200914 CASE_OP_32_64(ld8u):
Aurelien Jarnoc8d70272013-09-03 08:27:39 +0200915 mask = 0xff;
916 break;
917 CASE_OP_32_64(ld16u):
Aurelien Jarnoc8d70272013-09-03 08:27:39 +0200918 mask = 0xffff;
919 break;
920 case INDEX_op_ld32u_i64:
Aurelien Jarnoc8d70272013-09-03 08:27:39 +0200921 mask = 0xffffffffu;
922 break;
923
924 CASE_OP_32_64(qemu_ld):
925 {
Richard Henderson59227d52015-05-12 11:51:44 -0700926 TCGMemOpIdx oi = args[nb_oargs + nb_iargs];
927 TCGMemOp mop = get_memop(oi);
Aurelien Jarnoc8d70272013-09-03 08:27:39 +0200928 if (!(mop & MO_SIGN)) {
929 mask = (2ULL << ((8 << (mop & MO_SIZE)) - 1)) - 1;
930 }
931 }
932 break;
933
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -0800934 default:
935 break;
936 }
937
Richard Hendersonbc8d6882014-06-08 18:24:14 -0700938 /* 32-bit ops generate 32-bit results. For the result is zero test
939 below, we can ignore high bits, but for further optimizations we
940 need to record that the high bits contain garbage. */
Richard Henderson24666ba2014-05-22 11:14:10 -0700941 partmask = mask;
Richard Hendersonbc8d6882014-06-08 18:24:14 -0700942 if (!(def->flags & TCG_OPF_64BIT)) {
Richard Henderson24666ba2014-05-22 11:14:10 -0700943 mask |= ~(tcg_target_ulong)0xffffffffu;
944 partmask &= 0xffffffffu;
945 affected &= 0xffffffffu;
Aurelien Jarnof096dc92013-09-03 08:27:38 +0200946 }
947
Richard Henderson24666ba2014-05-22 11:14:10 -0700948 if (partmask == 0) {
Richard Hendersoncf066672014-03-22 20:06:52 -0700949 assert(nb_oargs == 1);
Aurelien Jarnoebd27392015-06-04 21:53:23 +0200950 tcg_opt_gen_movi(s, op, args, args[0], 0);
Paolo Bonzini633f6502013-01-11 15:42:53 -0800951 continue;
952 }
953 if (affected == 0) {
Richard Hendersoncf066672014-03-22 20:06:52 -0700954 assert(nb_oargs == 1);
Aurelien Jarno97a79eb2015-06-05 11:19:18 +0200955 tcg_opt_gen_mov(s, op, args, args[0], args[1]);
Paolo Bonzini633f6502013-01-11 15:42:53 -0800956 continue;
957 }
958
Aurelien Jarno56e49432012-09-06 16:47:13 +0200959 /* Simplify expression for "op r, a, 0 => movi r, 0" cases */
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700960 switch (opc) {
Aurelien Jarno61251c02012-09-06 16:47:14 +0200961 CASE_OP_32_64(and):
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400962 CASE_OP_32_64(mul):
Richard Henderson03271522013-08-14 14:35:56 -0700963 CASE_OP_32_64(muluh):
964 CASE_OP_32_64(mulsh):
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400965 if ((temps[args[2]].state == TCG_TEMP_CONST
966 && temps[args[2]].val == 0)) {
Aurelien Jarnoebd27392015-06-04 21:53:23 +0200967 tcg_opt_gen_movi(s, op, args, args[0], 0);
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400968 continue;
969 }
970 break;
Aurelien Jarno56e49432012-09-06 16:47:13 +0200971 default:
972 break;
973 }
974
975 /* Simplify expression for "op r, a, a => mov r, a" cases */
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700976 switch (opc) {
Kirill Batuzov9a810902011-07-07 16:37:15 +0400977 CASE_OP_32_64(or):
978 CASE_OP_32_64(and):
Aurelien Jarno0aba1c72012-09-18 19:11:32 +0200979 if (temps_are_copies(args[1], args[2])) {
Aurelien Jarno97a79eb2015-06-05 11:19:18 +0200980 tcg_opt_gen_mov(s, op, args, args[0], args[1]);
Kirill Batuzov9a810902011-07-07 16:37:15 +0400981 continue;
982 }
983 break;
Blue Swirlfe0de7a2011-07-30 19:18:32 +0000984 default:
985 break;
Kirill Batuzov53108fb2011-07-07 16:37:14 +0400986 }
987
Aurelien Jarno3c941932012-09-18 19:12:36 +0200988 /* Simplify expression for "op r, a, a => movi r, 0" cases */
Richard Hendersonc45cb8b2014-09-19 13:49:15 -0700989 switch (opc) {
Richard Hendersone64e9582014-01-28 13:26:17 -0800990 CASE_OP_32_64(andc):
Aurelien Jarno3c941932012-09-18 19:12:36 +0200991 CASE_OP_32_64(sub):
992 CASE_OP_32_64(xor):
993 if (temps_are_copies(args[1], args[2])) {
Aurelien Jarnoebd27392015-06-04 21:53:23 +0200994 tcg_opt_gen_movi(s, op, args, args[0], 0);
Aurelien Jarno3c941932012-09-18 19:12:36 +0200995 continue;
996 }
997 break;
998 default:
999 break;
1000 }
1001
Kirill Batuzov22613af2011-07-07 16:37:13 +04001002 /* Propagate constants through copy operations and do constant
1003 folding. Constants will be substituted to arguments by register
1004 allocator where needed and possible. Also detect copies. */
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001005 switch (opc) {
Kirill Batuzov22613af2011-07-07 16:37:13 +04001006 CASE_OP_32_64(mov):
Aurelien Jarno97a79eb2015-06-05 11:19:18 +02001007 tcg_opt_gen_mov(s, op, args, args[0], args[1]);
1008 break;
Kirill Batuzov22613af2011-07-07 16:37:13 +04001009 CASE_OP_32_64(movi):
Aurelien Jarnoebd27392015-06-04 21:53:23 +02001010 tcg_opt_gen_movi(s, op, args, args[0], args[1]);
Kirill Batuzov22613af2011-07-07 16:37:13 +04001011 break;
Richard Henderson6e14e912012-10-02 11:32:24 -07001012
Kirill Batuzova640f032011-07-07 16:37:17 +04001013 CASE_OP_32_64(not):
Richard Hendersoncb25c802011-08-17 14:11:47 -07001014 CASE_OP_32_64(neg):
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001015 CASE_OP_32_64(ext8s):
1016 CASE_OP_32_64(ext8u):
1017 CASE_OP_32_64(ext16s):
1018 CASE_OP_32_64(ext16u):
Kirill Batuzova640f032011-07-07 16:37:17 +04001019 case INDEX_op_ext32s_i64:
1020 case INDEX_op_ext32u_i64:
Kirill Batuzova640f032011-07-07 16:37:17 +04001021 if (temps[args[1]].state == TCG_TEMP_CONST) {
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001022 tmp = do_constant_folding(opc, temps[args[1]].val, 0);
Aurelien Jarnoebd27392015-06-04 21:53:23 +02001023 tcg_opt_gen_movi(s, op, args, args[0], tmp);
Richard Henderson6e14e912012-10-02 11:32:24 -07001024 break;
Kirill Batuzova640f032011-07-07 16:37:17 +04001025 }
Richard Henderson6e14e912012-10-02 11:32:24 -07001026 goto do_default;
1027
Richard Henderson4bb7a412013-09-09 17:03:24 -07001028 case INDEX_op_trunc_shr_i32:
1029 if (temps[args[1]].state == TCG_TEMP_CONST) {
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001030 tmp = do_constant_folding(opc, temps[args[1]].val, args[2]);
Aurelien Jarnoebd27392015-06-04 21:53:23 +02001031 tcg_opt_gen_movi(s, op, args, args[0], tmp);
Richard Henderson4bb7a412013-09-09 17:03:24 -07001032 break;
1033 }
1034 goto do_default;
1035
Kirill Batuzov53108fb2011-07-07 16:37:14 +04001036 CASE_OP_32_64(add):
1037 CASE_OP_32_64(sub):
1038 CASE_OP_32_64(mul):
Kirill Batuzov9a810902011-07-07 16:37:15 +04001039 CASE_OP_32_64(or):
1040 CASE_OP_32_64(and):
1041 CASE_OP_32_64(xor):
Kirill Batuzov55c09752011-07-07 16:37:16 +04001042 CASE_OP_32_64(shl):
1043 CASE_OP_32_64(shr):
1044 CASE_OP_32_64(sar):
Richard Henderson25c4d9c2011-08-17 14:11:46 -07001045 CASE_OP_32_64(rotl):
1046 CASE_OP_32_64(rotr):
Richard Hendersoncb25c802011-08-17 14:11:47 -07001047 CASE_OP_32_64(andc):
1048 CASE_OP_32_64(orc):
1049 CASE_OP_32_64(eqv):
1050 CASE_OP_32_64(nand):
1051 CASE_OP_32_64(nor):
Richard Henderson03271522013-08-14 14:35:56 -07001052 CASE_OP_32_64(muluh):
1053 CASE_OP_32_64(mulsh):
Richard Henderson01547f72013-08-14 15:22:46 -07001054 CASE_OP_32_64(div):
1055 CASE_OP_32_64(divu):
1056 CASE_OP_32_64(rem):
1057 CASE_OP_32_64(remu):
Kirill Batuzov53108fb2011-07-07 16:37:14 +04001058 if (temps[args[1]].state == TCG_TEMP_CONST
1059 && temps[args[2]].state == TCG_TEMP_CONST) {
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001060 tmp = do_constant_folding(opc, temps[args[1]].val,
Kirill Batuzov53108fb2011-07-07 16:37:14 +04001061 temps[args[2]].val);
Aurelien Jarnoebd27392015-06-04 21:53:23 +02001062 tcg_opt_gen_movi(s, op, args, args[0], tmp);
Richard Henderson6e14e912012-10-02 11:32:24 -07001063 break;
Kirill Batuzov53108fb2011-07-07 16:37:14 +04001064 }
Richard Henderson6e14e912012-10-02 11:32:24 -07001065 goto do_default;
1066
Aurelien Jarno7ef55fc2012-09-21 11:07:29 +02001067 CASE_OP_32_64(deposit):
1068 if (temps[args[1]].state == TCG_TEMP_CONST
1069 && temps[args[2]].state == TCG_TEMP_CONST) {
Richard Hendersond998e552014-03-18 14:23:52 -07001070 tmp = deposit64(temps[args[1]].val, args[3], args[4],
1071 temps[args[2]].val);
Aurelien Jarnoebd27392015-06-04 21:53:23 +02001072 tcg_opt_gen_movi(s, op, args, args[0], tmp);
Richard Henderson6e14e912012-10-02 11:32:24 -07001073 break;
Aurelien Jarno7ef55fc2012-09-21 11:07:29 +02001074 }
Richard Henderson6e14e912012-10-02 11:32:24 -07001075 goto do_default;
1076
Aurelien Jarnof8dd19e2012-09-06 16:47:14 +02001077 CASE_OP_32_64(setcond):
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001078 tmp = do_constant_folding_cond(opc, args[1], args[2], args[3]);
Aurelien Jarnob336ceb2012-09-18 19:37:00 +02001079 if (tmp != 2) {
Aurelien Jarnoebd27392015-06-04 21:53:23 +02001080 tcg_opt_gen_movi(s, op, args, args[0], tmp);
Richard Henderson6e14e912012-10-02 11:32:24 -07001081 break;
Aurelien Jarnof8dd19e2012-09-06 16:47:14 +02001082 }
Richard Henderson6e14e912012-10-02 11:32:24 -07001083 goto do_default;
1084
Aurelien Jarnofbeaa262012-09-06 16:47:14 +02001085 CASE_OP_32_64(brcond):
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001086 tmp = do_constant_folding_cond(opc, args[0], args[1], args[2]);
Aurelien Jarnob336ceb2012-09-18 19:37:00 +02001087 if (tmp != 2) {
1088 if (tmp) {
Paolo Bonzinid193a142013-01-11 15:42:51 -08001089 reset_all_temps(nb_temps);
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001090 op->opc = INDEX_op_br;
1091 args[0] = args[3];
Aurelien Jarnofbeaa262012-09-06 16:47:14 +02001092 } else {
Richard Henderson0c627cd2014-03-30 16:51:54 -07001093 tcg_op_remove(s, op);
Aurelien Jarnofbeaa262012-09-06 16:47:14 +02001094 }
Richard Henderson6e14e912012-10-02 11:32:24 -07001095 break;
Aurelien Jarnofbeaa262012-09-06 16:47:14 +02001096 }
Richard Henderson6e14e912012-10-02 11:32:24 -07001097 goto do_default;
1098
Richard Hendersonfa01a202012-09-21 10:13:37 -07001099 CASE_OP_32_64(movcond):
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001100 tmp = do_constant_folding_cond(opc, args[1], args[2], args[5]);
Aurelien Jarnob336ceb2012-09-18 19:37:00 +02001101 if (tmp != 2) {
Aurelien Jarno97a79eb2015-06-05 11:19:18 +02001102 tcg_opt_gen_mov(s, op, args, args[0], args[4-tmp]);
Richard Henderson6e14e912012-10-02 11:32:24 -07001103 break;
Richard Hendersonfa01a202012-09-21 10:13:37 -07001104 }
Richard Henderson6e14e912012-10-02 11:32:24 -07001105 goto do_default;
1106
Richard Henderson212c3282012-10-02 11:32:28 -07001107 case INDEX_op_add2_i32:
1108 case INDEX_op_sub2_i32:
1109 if (temps[args[2]].state == TCG_TEMP_CONST
1110 && temps[args[3]].state == TCG_TEMP_CONST
1111 && temps[args[4]].state == TCG_TEMP_CONST
1112 && temps[args[5]].state == TCG_TEMP_CONST) {
1113 uint32_t al = temps[args[2]].val;
1114 uint32_t ah = temps[args[3]].val;
1115 uint32_t bl = temps[args[4]].val;
1116 uint32_t bh = temps[args[5]].val;
1117 uint64_t a = ((uint64_t)ah << 32) | al;
1118 uint64_t b = ((uint64_t)bh << 32) | bl;
1119 TCGArg rl, rh;
Richard Hendersona4ce0992014-03-30 17:14:02 -07001120 TCGOp *op2 = insert_op_before(s, op, INDEX_op_movi_i32, 2);
1121 TCGArg *args2 = &s->gen_opparam_buf[op2->args];
Richard Henderson212c3282012-10-02 11:32:28 -07001122
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001123 if (opc == INDEX_op_add2_i32) {
Richard Henderson212c3282012-10-02 11:32:28 -07001124 a += b;
1125 } else {
1126 a -= b;
1127 }
1128
Richard Henderson212c3282012-10-02 11:32:28 -07001129 rl = args[0];
1130 rh = args[1];
Aurelien Jarno29f3ff82015-07-10 18:03:31 +02001131 tcg_opt_gen_movi(s, op, args, rl, (int32_t)a);
1132 tcg_opt_gen_movi(s, op2, args2, rh, (int32_t)(a >> 32));
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001133
1134 /* We've done all we need to do with the movi. Skip it. */
1135 oi_next = op2->next;
Richard Henderson212c3282012-10-02 11:32:28 -07001136 break;
1137 }
1138 goto do_default;
1139
Richard Henderson14149682012-10-02 11:32:30 -07001140 case INDEX_op_mulu2_i32:
1141 if (temps[args[2]].state == TCG_TEMP_CONST
1142 && temps[args[3]].state == TCG_TEMP_CONST) {
1143 uint32_t a = temps[args[2]].val;
1144 uint32_t b = temps[args[3]].val;
1145 uint64_t r = (uint64_t)a * b;
1146 TCGArg rl, rh;
Richard Hendersona4ce0992014-03-30 17:14:02 -07001147 TCGOp *op2 = insert_op_before(s, op, INDEX_op_movi_i32, 2);
1148 TCGArg *args2 = &s->gen_opparam_buf[op2->args];
Richard Henderson14149682012-10-02 11:32:30 -07001149
1150 rl = args[0];
1151 rh = args[1];
Aurelien Jarno29f3ff82015-07-10 18:03:31 +02001152 tcg_opt_gen_movi(s, op, args, rl, (int32_t)r);
1153 tcg_opt_gen_movi(s, op2, args2, rh, (int32_t)(r >> 32));
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001154
1155 /* We've done all we need to do with the movi. Skip it. */
1156 oi_next = op2->next;
Richard Henderson14149682012-10-02 11:32:30 -07001157 break;
1158 }
1159 goto do_default;
1160
Richard Hendersonbc1473e2012-10-02 11:32:25 -07001161 case INDEX_op_brcond2_i32:
Richard Henderson6c4382f2012-10-02 11:32:27 -07001162 tmp = do_constant_folding_cond2(&args[0], &args[2], args[4]);
1163 if (tmp != 2) {
1164 if (tmp) {
Richard Hendersona7635512014-04-23 22:18:30 -07001165 do_brcond_true:
Paolo Bonzinid193a142013-01-11 15:42:51 -08001166 reset_all_temps(nb_temps);
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001167 op->opc = INDEX_op_br;
1168 args[0] = args[5];
Richard Henderson6c4382f2012-10-02 11:32:27 -07001169 } else {
Richard Hendersona7635512014-04-23 22:18:30 -07001170 do_brcond_false:
Richard Henderson0c627cd2014-03-30 16:51:54 -07001171 tcg_op_remove(s, op);
Richard Henderson6c4382f2012-10-02 11:32:27 -07001172 }
1173 } else if ((args[4] == TCG_COND_LT || args[4] == TCG_COND_GE)
1174 && temps[args[2]].state == TCG_TEMP_CONST
1175 && temps[args[3]].state == TCG_TEMP_CONST
1176 && temps[args[2]].val == 0
1177 && temps[args[3]].val == 0) {
1178 /* Simplify LT/GE comparisons vs zero to a single compare
1179 vs the high word of the input. */
Richard Hendersona7635512014-04-23 22:18:30 -07001180 do_brcond_high:
Paolo Bonzinid193a142013-01-11 15:42:51 -08001181 reset_all_temps(nb_temps);
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001182 op->opc = INDEX_op_brcond_i32;
1183 args[0] = args[1];
1184 args[1] = args[3];
1185 args[2] = args[4];
1186 args[3] = args[5];
Richard Hendersona7635512014-04-23 22:18:30 -07001187 } else if (args[4] == TCG_COND_EQ) {
1188 /* Simplify EQ comparisons where one of the pairs
1189 can be simplified. */
1190 tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
1191 args[0], args[2], TCG_COND_EQ);
1192 if (tmp == 0) {
1193 goto do_brcond_false;
1194 } else if (tmp == 1) {
1195 goto do_brcond_high;
1196 }
1197 tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
1198 args[1], args[3], TCG_COND_EQ);
1199 if (tmp == 0) {
1200 goto do_brcond_false;
1201 } else if (tmp != 1) {
1202 goto do_default;
1203 }
1204 do_brcond_low:
1205 reset_all_temps(nb_temps);
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001206 op->opc = INDEX_op_brcond_i32;
1207 args[1] = args[2];
1208 args[2] = args[4];
1209 args[3] = args[5];
Richard Hendersona7635512014-04-23 22:18:30 -07001210 } else if (args[4] == TCG_COND_NE) {
1211 /* Simplify NE comparisons where one of the pairs
1212 can be simplified. */
1213 tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
1214 args[0], args[2], TCG_COND_NE);
1215 if (tmp == 0) {
1216 goto do_brcond_high;
1217 } else if (tmp == 1) {
1218 goto do_brcond_true;
1219 }
1220 tmp = do_constant_folding_cond(INDEX_op_brcond_i32,
1221 args[1], args[3], TCG_COND_NE);
1222 if (tmp == 0) {
1223 goto do_brcond_low;
1224 } else if (tmp == 1) {
1225 goto do_brcond_true;
1226 }
1227 goto do_default;
Richard Henderson6c4382f2012-10-02 11:32:27 -07001228 } else {
1229 goto do_default;
Richard Hendersonbc1473e2012-10-02 11:32:25 -07001230 }
Richard Henderson6c4382f2012-10-02 11:32:27 -07001231 break;
Richard Hendersonbc1473e2012-10-02 11:32:25 -07001232
1233 case INDEX_op_setcond2_i32:
Richard Henderson6c4382f2012-10-02 11:32:27 -07001234 tmp = do_constant_folding_cond2(&args[1], &args[3], args[5]);
1235 if (tmp != 2) {
Richard Hendersona7635512014-04-23 22:18:30 -07001236 do_setcond_const:
Aurelien Jarnoebd27392015-06-04 21:53:23 +02001237 tcg_opt_gen_movi(s, op, args, args[0], tmp);
Richard Henderson6c4382f2012-10-02 11:32:27 -07001238 } else if ((args[5] == TCG_COND_LT || args[5] == TCG_COND_GE)
1239 && temps[args[3]].state == TCG_TEMP_CONST
1240 && temps[args[4]].state == TCG_TEMP_CONST
1241 && temps[args[3]].val == 0
1242 && temps[args[4]].val == 0) {
1243 /* Simplify LT/GE comparisons vs zero to a single compare
1244 vs the high word of the input. */
Richard Hendersona7635512014-04-23 22:18:30 -07001245 do_setcond_high:
Aurelien Jarno66e61b52013-05-08 22:36:39 +02001246 reset_temp(args[0]);
Richard Hendersona7635512014-04-23 22:18:30 -07001247 temps[args[0]].mask = 1;
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001248 op->opc = INDEX_op_setcond_i32;
1249 args[1] = args[2];
1250 args[2] = args[4];
1251 args[3] = args[5];
Richard Hendersona7635512014-04-23 22:18:30 -07001252 } else if (args[5] == TCG_COND_EQ) {
1253 /* Simplify EQ comparisons where one of the pairs
1254 can be simplified. */
1255 tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
1256 args[1], args[3], TCG_COND_EQ);
1257 if (tmp == 0) {
1258 goto do_setcond_const;
1259 } else if (tmp == 1) {
1260 goto do_setcond_high;
1261 }
1262 tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
1263 args[2], args[4], TCG_COND_EQ);
1264 if (tmp == 0) {
1265 goto do_setcond_high;
1266 } else if (tmp != 1) {
1267 goto do_default;
1268 }
1269 do_setcond_low:
1270 reset_temp(args[0]);
1271 temps[args[0]].mask = 1;
Richard Hendersonc45cb8b2014-09-19 13:49:15 -07001272 op->opc = INDEX_op_setcond_i32;
1273 args[2] = args[3];
1274 args[3] = args[5];
Richard Hendersona7635512014-04-23 22:18:30 -07001275 } else if (args[5] == TCG_COND_NE) {
1276 /* Simplify NE comparisons where one of the pairs
1277 can be simplified. */
1278 tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
1279 args[1], args[3], TCG_COND_NE);
1280 if (tmp == 0) {
1281 goto do_setcond_high;
1282 } else if (tmp == 1) {
1283 goto do_setcond_const;
1284 }
1285 tmp = do_constant_folding_cond(INDEX_op_setcond_i32,
1286 args[2], args[4], TCG_COND_NE);
1287 if (tmp == 0) {
1288 goto do_setcond_low;
1289 } else if (tmp == 1) {
1290 goto do_setcond_const;
1291 }
1292 goto do_default;
Richard Henderson6c4382f2012-10-02 11:32:27 -07001293 } else {
1294 goto do_default;
Richard Hendersonbc1473e2012-10-02 11:32:25 -07001295 }
Richard Henderson6c4382f2012-10-02 11:32:27 -07001296 break;
Richard Hendersonbc1473e2012-10-02 11:32:25 -07001297
Kirill Batuzov8f2e8c02011-07-07 16:37:12 +04001298 case INDEX_op_call:
Richard Hendersoncf066672014-03-22 20:06:52 -07001299 if (!(args[nb_oargs + nb_iargs + 1]
1300 & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS))) {
Kirill Batuzov22613af2011-07-07 16:37:13 +04001301 for (i = 0; i < nb_globals; i++) {
Aurelien Jarnoe590d4e2012-09-11 12:31:21 +02001302 reset_temp(i);
Kirill Batuzov22613af2011-07-07 16:37:13 +04001303 }
1304 }
Richard Hendersoncf066672014-03-22 20:06:52 -07001305 goto do_reset_output;
Richard Henderson6e14e912012-10-02 11:32:24 -07001306
Kirill Batuzov8f2e8c02011-07-07 16:37:12 +04001307 default:
Richard Henderson6e14e912012-10-02 11:32:24 -07001308 do_default:
1309 /* Default case: we know nothing about operation (or were unable
1310 to compute the operation result) so no propagation is done.
1311 We trash everything if the operation is the end of a basic
Paolo Bonzini3a9d8b12013-01-11 15:42:52 -08001312 block, otherwise we only trash the output args. "mask" is
1313 the non-zero bits mask for the first output arg. */
Aurelien Jarnoa2550662012-09-19 21:40:30 +02001314 if (def->flags & TCG_OPF_BB_END) {
Paolo Bonzinid193a142013-01-11 15:42:51 -08001315 reset_all_temps(nb_temps);
Aurelien Jarnoa2550662012-09-19 21:40:30 +02001316 } else {
Richard Hendersoncf066672014-03-22 20:06:52 -07001317 do_reset_output:
1318 for (i = 0; i < nb_oargs; i++) {
Aurelien Jarnoe590d4e2012-09-11 12:31:21 +02001319 reset_temp(args[i]);
Aurelien Jarno30312442013-09-03 08:27:38 +02001320 /* Save the corresponding known-zero bits mask for the
1321 first output argument (only one supported so far). */
1322 if (i == 0) {
1323 temps[args[i]].mask = mask;
1324 }
Aurelien Jarnoa2550662012-09-19 21:40:30 +02001325 }
Kirill Batuzov22613af2011-07-07 16:37:13 +04001326 }
Kirill Batuzov8f2e8c02011-07-07 16:37:12 +04001327 break;
1328 }
1329 }
Kirill Batuzov8f2e8c02011-07-07 16:37:12 +04001330}