- /* if one is already the TOS, we need two fxch */
- if (op1_idx == 0) {
- /* first one is TOS, move to st(1) */
- x87_create_fxch(state, n, 1);
- assert(op2_idx != 1);
- op1_idx = 1;
- x87_create_fxch(state, n, op2_idx);
- op2_idx = 0;
- /* res = op X tos, pop, pop */
- pops = 2;
- permuted = !permuted;
- xchg = true;
- } else if (op2_idx == 0) {
- /* second one is TOS, move to st(1) */
- x87_create_fxch(state, n, 1);
- assert(op1_idx != 1);
- op2_idx = 1;
- x87_create_fxch(state, n, op1_idx);
- op1_idx = 0;
- /* res = tos X op, pop, pop */
- pops = 2;
- } else {
- /* none of them is either TOS or st(1), 3 fxch needed */
- x87_create_fxch(state, n, op2_idx);
- assert(op1_idx != 0);
- x87_create_fxch(state, n, 1);
- op2_idx = 1;
- x87_create_fxch(state, n, op1_idx);
- op1_idx = 0;
- /* res = tos X op, pop, pop */
- pops = 2;
+ if (op1_idx != 0 && op2_idx != 0) {
+ /* Both not at tos: Move one operand to tos. Move the one not at
+ * pos 1, so we get a chance to use fucompp. */
+ if (op1_idx != 1) {
+ x87_create_fxch(state, n, op1_idx);
+ op1_idx = 0;
+ } else {
+ x87_create_fxch(state, n, op2_idx);
+ op2_idx = 0;
+ }