14

gcc.godbolt.orgでGCC逆アセンブラをいじっていたところ、バージョン4.6以降のGCCは乗算のコンパイル方法が異なることに気付きました。私には次の2つの機能があります。

unsigned m126(unsigned i)
{
    return i * 126;
}

unsigned m131(unsigned i)
{
    return i * 131;
}

m126コンパイル:

mov eax, edi
mov edx, 126
imul eax, edx
ret

そして、m131コンパイルします:

imul eax, edi, 131
ret

なぜ違いがあるのですか?GCC 4.5は、どちらの場合も同じオペコードを生成します。

GCCExplorerの実際の例へのリンク

4

1 に答える 1

10

これを見つけましたgcc/config/i386/i386.md(上部のコメントを参照):

;; imul $8/16bit_imm, regmem, reg is vector decoded.
;; Convert it into imul reg, reg
;; It would be better to force assembler to encode instruction using long
;; immediate, but there is apparently no way to do so.
(define_peephole2
  [(parallel [(set (match_operand:SWI248 0 "register_operand")
           (mult:SWI248
            (match_operand:SWI248 1 "nonimmediate_operand")
            (match_operand:SWI248 2 "const_int_operand")))
          (clobber (reg:CC FLAGS_REG))])
   (match_scratch:SWI248 3 "r")]
  "TARGET_SLOW_IMUL_IMM8 && optimize_insn_for_speed_p ()
   && satisfies_constraint_K (operands[2])"
  [(set (match_dup 3) (match_dup 2))
   (parallel [(set (match_dup 0) (mult:SWI248 (match_dup 0) (match_dup 3)))
          (clobber (reg:CC FLAGS_REG))])]
{
  if (!rtx_equal_p (operands[0], operands[1]))
    emit_move_insn (operands[0], operands[1]);
})

命令のデコードと関係があるようです(申し訳ありませんが、私は専門家ではありません)

于 2012-12-20T19:28:58.887 に答える