こんにちは。NoMaYです。ウェブで調べ物をしていて気付いたのですが、RenesasさんはLLVM(今はGCCと並ぶ著名なフリーコンパイラ)にRL78をPortingしようとしているのかも、、、[llvm-dev] New LLVM backend for Renesas RL78 MCUSebastian Perta via llvm-dev llvm-dev at lists.llvm.org Wed Apr 1 10:26:05 PDT 2020 lists.llvm.org/pipermail/llvm-dev/2020-April/140546.html
こんにちは。NoMaYです。以前に投稿したBlinkyサンプルプログラムのzipファイルにリストファイル(GNURL78)と逆アセンブルダンプファイル(LLVM-RL78とGNURL78)も入れておいたのですが、内蔵周辺レジスタアクセスのコードがLLVM-RL78はGNURL78より随分悪い件をちょっと調べていて気付いたことがありました。(1) LLVM向けiodefine.hではPIF0ビットは16ビットレジスタのビットの扱いになっていました(2) volatileが付いているので8ビットアクセスとなるビット操作命令を使うのはC言語規格とは整合しないですね(3) PIF0ビットが16ビットレジスタのビットの扱いなのはRL78/G14のGNURL78向けiodefine.hでも同じでしたsrc/smc_gen/r_bsp/mcu/rl78_g23/register_access/llvm/iodefine.h
#define PIF0 IF0_bit.no2#define IF0_bit (*(volatile union un_if0 *)0xFFFE0).BITunion un_if0 { unsigned short if0; __BITS16 BIT;};typedef struct { unsigned short no0 :1; unsigned short no1 :1; unsigned short no2 :1; unsigned short no3 :1; unsigned short no4 :1; unsigned short no5 :1; unsigned short no6 :1; unsigned short no7 :1; unsigned short no8 :1; unsigned short no9 :1; unsigned short no10 :1; unsigned short no11 :1; unsigned short no12 :1; unsigned short no13 :1; unsigned short no14 :1; unsigned short no15 :1;} __BITS16;
[追記]試しにiodefine.hを書き換えてみましたが、あまり変わらなかったですね。残念。現状の定義
#define PIF0 IF0_bit.no2#define PMK0 MK0_bit.no2
試しの定義
#define PIF0 IF0L_bit.no2#define PMK0 MK0L_bit.no2
現状での生成コード
0000332a _R_Config_INTC_INTP0_Start:; PIF0 = 0U; /* clear INTP0 interrupt flag */ 332a: 36 e0 ff movw hl, #65504 332d: ab movw ax, [hl] 332e: 5a f8 fb and 0xffef8, #251 3331: 36 e0 ff movw hl, #65504 3334: bb movw [hl], ax; PMK0 = 0U; /* enable INTP0 interrupt */ 3335: 36 e4 ff movw hl, #65508 3338: ab movw ax, [hl] 3339: 5a f8 fb and 0xffef8, #251 333c: 36 e4 ff movw hl, #65508 333f: bb movw [hl], ax; } 3340: d7 ret
試しでの生成コード
0000332a _R_Config_INTC_INTP0_Start:; PIF0 = 0U; /* clear INTP0 interrupt flag */ 332a: 36 e0 ff movw hl, #65504 332d: 8b mov a, [hl] 332e: 71 ab clr1 a.2 3330: 36 e0 ff movw hl, #65504 3333: 9b mov [hl], a; PMK0 = 0U; /* enable INTP0 interrupt */ 3334: 36 e4 ff movw hl, #65508 3337: 8b mov a, [hl] 3338: 71 ab clr1 a.2 333a: 36 e4 ff movw hl, #65508 333d: 9b mov [hl], a; } 333e: d7 ret