忍者ブログ

なんだか

知らないほうが幸せかもしれない

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

rx-elf-gcc(4.7.2)でbtst命令を使うようにしてみようという試み、その2

試したのはこれです。今回はbit1です。

/*volatile*/
unsigned
char bar1;

/*volatile*/
unsigned
char bar;

void
tst_bar_bit1(void)
{
  if(bar1&2)
    bar &= ~2;
  else
    bar |= 2;
}


rx-elf-gccで-O2 -fomitframe-pointerでコンパイルすると

0000 FB E2 00 00 00 00    mov.L   #_bar1, r14
0006 CC EE                mov.B   [r14], r14
0008 64 2E                and     #2, r14
000a 5B EE                movu.B  r14, r14
000c 61 0E                cmp     #0, r14
000e FB E2 00 00 00 00    mov.L   #_bar, r14
0014 1C                   bne     .L5
0015 F0 E1                bset    #1, [r14].B
0017 02                   rts
                      .L5:
0018 F0 E9                bclr    #1, [r14].B
001a 02                   rts


こうなります。(注:改造したrx-elf-gccを使っているので出力コードが違うことがあります)
色の付いたところをbtst命令を使うようにしてみます。

Failed to match this instruction:
(set (pc)
    (if_then_else (eq (if_then_else:SI (zero_extract:SI (subreg:SI (reg:QI 31 [ bar1 ]) 0)
                    (const_int 1 [0x1])
                    (const_int 1 [0x1]))
                (const_int 2 [0x2])
                (const_int 0 [0]))
            (const_int 0 [0]))
        (label_ref 21)
        (pc)))


コンバインパターンを成功するように

(define_insn_and_split "*cbranchqi4_tst_ext"
  [(set (pc)
    (if_then_else
      (match_operator 4 "rx_z_comparison_operator"
        [ (if_then_else:SI
               (zero_extract:SI
           (subreg:SI
                  (match_operand:QI 0 "register_operand" "r")
                   0)
           (match_operand    1 "rx_constshift_operand" "")
           (match_operand    2 "rx_constshift_operand" ""))
               (match_operand 5 "const_int_operand" "")
               (const_int 0))
         (const_int 0)])
      (match_operand 3 "label_ref_operand" "")
      (pc)))]
  "INTVAL (operands[1]) == 1"
  "#"
  "reload_completed"
  [(const_int 0)]
{
  HOST_WIDE_INT mask;
  rtx x;

  mask = 1;
  mask <<= INTVAL (operands[1]);
  mask -= 1;
  mask <<= INTVAL (operands[2]);

  operands[0] = gen_rtx_REG (SImode, REGNO (operands[0]));

  x = gen_rtx_AND (SImode, operands[0], gen_int_mode (mask, SImode));

  rx_split_cbranch (CC_ZSmode, GET_CODE (operands[4]),
            x, const0_rtx, operands[3]);
  DONE;
})

これをrx.mdのその1の前あたりに追加します。

この変更を使ったgccでコンパイルすると

0000 FB E2 00 00 00 00    mov.L   #_bar1, r14
0006 CC EE                mov.B   [r14], r14
0008 7C 1E                btst    #1, r14
000a FB E2 00 00 00 00    mov.L   #_bar, r14
0010 1C                   bne     .L5
0011 F0 E1                bset    #1, [r14].B
0013 02                   rts
                      .L5:
0014 F0 E9                bclr    #1, [r14].B
0016 02                   rts

btstを使うようになります。



拍手[0回]

PR

コメント

お名前
タイトル
文字色
メールアドレス
URL
コメント
パスワード Vodafone絵文字 i-mode絵文字 Ezweb絵文字

カレンダー

03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

フリーエリア

最新CM

最新記事

(07/27)
(03/27)
(03/26)
(03/23)
(03/22)
(03/19)
(03/18)
(03/18)
(03/15)
(03/14)
(03/13)
(03/12)
(03/11)
(03/11)
(03/08)
(03/08)
(03/06)
(03/05)
(03/02)
(03/01)
(02/28)
(02/27)
(02/24)
(02/23)
(02/22)

プロフィール

HN:
kenrou
性別:
非公開

バーコード

ブログ内検索

最古記事

(12/15)
(12/16)
(12/17)
(12/18)
(12/19)
(12/20)
(12/21)
(12/22)
(12/23)
(12/24)
(12/25)
(12/26)
(12/27)
(12/28)
(12/29)
(12/30)
(12/31)
(01/01)
(01/02)
(01/21)
(01/22)
(01/23)
(01/24)
(01/24)
(01/28)

P R

忍者アナライズ

コガネモチ

忍者カウンター

カレンダー

03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30