64ãããARMã¢ãŒããã¯ãã£ã®äžçãžããããïŒ
çŸä»£ã®ã³ã³ãã¥ãŒãã£ã³ã°ç°å¢ã§ã¯ãã¹ããŒããã©ã³ãã¿ãã¬ãããã©ãããããïŒApple SiliconæèŒMacãªã©ïŒãããã«ã¯ãµãŒããŒãã¹ãŒããŒã³ã³ãã¥ãŒã¿ãŒã«è³ããŸã§ãARMã¢ãŒããã¯ãã£ãåºãæ¡çšãããŠããŸããç¹ã«ãã®64ãããçã§ããARM64ïŒAArch64ãšãåŒã°ããŸãïŒã¯ãé«ãããã©ãŒãã³ã¹ãšåªããé»åå¹çã«ããããã®ååšæãå¢ããŠããŸãã
æ®æ®µãç§ãã¡ãCèšèªãPythonãJavaãªã©ã®é«æ°Žæºèšèªã§ããã°ã©ãã³ã°ããéãCPUãçŽæ¥ç解ã§ãããæ©æ¢°èªããžã®ç¿»èš³ã¯ã³ã³ãã€ã©ãã€ã³ã¿ããªã¿ãèªåçã«è¡ã£ãŠãããŸãããããããœãããŠã§ã¢ãå®éã«ã©ã®ããã«åäœããŠããã®ããããã©ãŒãã³ã¹ã極éãŸã§è¿œæ±ãããããããã¯äœã¬ã€ã€ãŒã®ã»ãã¥ãªãã£ã«ã€ããŠåŠã³ãããšãã£ãå ŽåãCPUã®èšèªã§ããã¢ã»ã³ããªèšèªã®ç¥èã圹ç«ã¡ãŸãã
ãã®ããã°èšäºã§ã¯ãARM64ã¢ã»ã³ããªèšèªã®åºæ¬çãªæŠå¿µã解説ãããã®äžçãžã®ç¬¬äžæ©ãèžã¿åºããæäŒããããŸããäœã¬ã€ã€ãŒã®äžçã¯äžèŠé£è§£ã«æãããããããŸããããåºæ¬ãç解ããã°ãã³ã³ãã¥ãŒã¿ãŒã®åäœåçã«å¯Ÿããç解ãæ Œæ®µã«æ·±ãŸãã¯ãã§ã ðã
ARM64ã¢ãŒããã¯ãã£ã®æŠèŠ
ARM64ã¯ãArm Holdings瀟ã«ãã£ãŠèšèšãããARMã¢ãŒããã¯ãã£ã®64ãããçã§ãæ£åŒã«ã¯ARMv8-Aã¢ãŒããã¯ãã£ã®äžéšãšããŠ2011幎ã«çºè¡šãããŸããããããŸã§ã®32ãããã¢ãŒããã¯ãã£ïŒAArch32ïŒãšã®äºææ§ãä¿ã¡ã€ã€ã64ãããåŠçã«å¯Ÿå¿ããããšã§ããã倧ããªã¡ã¢ãªç©ºéïŒæ倧256TBã®ç©çã¢ãã¬ã¹ç©ºéã48ãããã®ä»®æ³ã¢ãã¬ã¹ç©ºéïŒãæ±ããããã«ãªããããã©ãŒãã³ã¹ãå€§å¹ ã«åäžããŸããã
äž»ãªç¹åŸŽ
- RISC (Reduced Instruction Set Computer) ããŒã¹ïŒ ã·ã³ãã«ã§åºå®é·ã®åœä»€ã»ãããæã¡ããã€ãã©ã€ã³åŠçã«é©ããŠããŸããããã«ãããé«éãªåŠçãšäœæ¶è²»é»åãäž¡ç«ããŠããŸãã
- å€æ°ã®æ±çšã¬ãžã¹ã¿ïŒ 31åã®64ãããæ±çšã¬ãžã¹ã¿ïŒX0ïœX30ïŒãæã¡ãããå€ãã®ããŒã¿ãCPUå éšã«ä¿æã§ãããããã¡ã¢ãªã¢ã¯ã»ã¹ãæžãããåŠçãé«éåã§ããŸãã
- åªããé»åå¹çïŒ ã¢ãã€ã«ããã€ã¹ã§ã®é·å¹Žã®çµéšãããé»åå¹çãéèŠããèšèšããããŠããŸããããã¯ãããããªãŒå¯¿åœãéèŠãªã©ãããããããéçšã³ã¹ãåæžãæ±ããããããŒã¿ã»ã³ã¿ãŒã«ãããŠã倧ããªå©ç¹ãšãªããŸãã
- ã¹ã±ãŒã©ããªãã£ïŒ äœæ¶è²»é»åã®çµã¿èŸŒã¿ã·ã¹ãã ããé«æ§èœãµãŒããŒãŸã§ãå¹ åºãçšéã«å¯Ÿå¿ã§ããã¹ã±ãŒã©ããªãã£ãæã£ãŠããŸãã
- ã»ãã¥ãªãã£æ©èœïŒ TrustZoneïŒã»ãã¥ã¢ãªå®è¡ç°å¢ãæäŸããæè¡ïŒããã€ã³ã¿èªèšŒïŒã¡ã¢ãªç Žå£æ»æãžã®å¯ŸçïŒãªã©ãããŒããŠã§ã¢ã¬ãã«ã§ã®ã»ãã¥ãªãã£æ©èœãçµã¿èŸŒãŸããŠããŸãã
- SIMD (Single Instruction, Multiple Data) åœä»€ïŒ NeonãšåŒã°ããæ¡åŒµåœä»€ã»ããã«ããããã«ãã¡ãã£ã¢åŠçãç§åŠæè¡èšç®ãªã©ã§å¿ èŠãšããããã¯ãã«æŒç®ãå¹ççã«å®è¡ã§ããŸãã32åã®128ãããã¬ãžã¹ã¿ïŒV0ïœV31ïŒã䜿çšããŸãã
ãããã®ç¹åŸŽã«ãããARM64ã¯ã¢ãã€ã«åéã ãã§ãªããAppleã2020幎ããMacã«æ¡çšãããApple SiliconãããAmazon Web Services (AWS) ã®ãGravitonãããã»ããµãªã©ããã¹ã¯ãããããµãŒããŒåžå Žã§ãæ¥éã«ã·ã§ã¢ãæ¡å€§ããŠããŸãã
ã¢ã»ã³ããªèšèªã®åºæ¬èŠçŽ ð§©
ã¬ãžã¹ã¿ïŒCPUå ã®é«éã¡ã¢ãª
ã¬ãžã¹ã¿ã¯ãCPUå éšã«ããéåžžã«é«éãªèšæ¶é åã§ããã¡ã¢ãªïŒRAMïŒããããŒã¿ãèªã¿æžããããããã¯ããã«é«éã«ã¢ã¯ã»ã¹ã§ãããããèšç®éäžã®äžæçãªå€ãé »ç¹ã«äœ¿ãããŒã¿ãä¿æããããã«äœ¿ãããŸããARM64ã«ã¯äž»ã«ä»¥äžã®ã¬ãžã¹ã¿ããããŸãã
ã¬ãžã¹ã¿ã®çš®é¡ | ååïŒäŸïŒ | ãããå¹ | äž»ãªçšé |
---|---|---|---|
æ±çšã¬ãžã¹ã¿ | X0 – X30 |
64ããã | ããŒã¿ã®äžæä¿åãæŒç®ãé¢æ°åŒæ°ã»æ»ãå€ã®åãæž¡ã |
æ±çšã¬ãžã¹ã¿ïŒ32ãããã¢ã¯ã»ã¹ïŒ | W0 – W30 |
32ããã | X0 –X30 ã®äžäœ32ããããžã®ã¢ã¯ã»ã¹ |
ã¹ã¿ãã¯ãã€ã³ã¿ | SP |
64ããã | çŸåšã®ã¹ã¿ãã¯ã®é äžïŒæ«å°ŸïŒãæãã¢ãã¬ã¹ |
ãŒãã¬ãžã¹ã¿ | XZR / WZR |
64/32ããã | åžžã«0ãè¿ããç¹å®ã®åœä»€ã§X31 /W31 ãšããŠæ±ããã |
ããã°ã©ã ã«ãŠã³ã¿ | PC |
64ããã | 次ã«å®è¡ããåœä»€ã®ã¢ãã¬ã¹ãä¿æïŒçŽæ¥ã¢ã¯ã»ã¹ã¯äžå¯ïŒ |
ãªã³ã¯ã¬ãžã¹ã¿ | LR (X30 ) |
64ããã | é¢æ°åŒã³åºãæã«ãåŒã³åºãå ã«æ»ãããã®ã¢ãã¬ã¹ãä¿æ |
æµ®åå°æ°ç¹/SIMDã¬ãžã¹ã¿ | V0 – V31 |
128ããã | æµ®åå°æ°ç¹æŒç®ããã¯ãã«æŒç®ïŒNeonåœä»€ïŒã«äœ¿çšïŒD0 –D31 : 64ããã, S0 –S31 : 32ããã, H0 –H31 : 16ããã, B0 –B31 : 8ããããšããŠãã¢ã¯ã»ã¹å¯èœïŒ |
ããã»ã¹ç¶æ ã¬ãžã¹ã¿ | PSTATE |
– | æŒç®çµæã®ç¶æ ïŒãŒããè² ããã£ãªãŒããªãŒããŒãããŒïŒã瀺ããã©ã°ïŒNZCVãã©ã°ïŒãªã©ãä¿æ |
æ±çšã¬ãžã¹ã¿X0
ããX30
ã¯ãæ§ã
ãªçšéã«äœ¿ãããŸããç¹ã«X0
ããX7
ã¯é¢æ°ã®åŒæ°ãæž¡ããããX0
ã¯é¢æ°ã®æ»ãå€ãè¿ãããã«äœ¿ãããããšãå€ãã§ãïŒåŸè¿°ã®åŒã³åºãèŠçŽã§è©³ãã説æããŸãïŒãX30
ã¯ãªã³ã¯ã¬ãžã¹ã¿LR
ãšããŠãæ©èœããŸãã
åœä»€ã®åºæ¬æ§é
ã¢ã»ã³ããªèšèªã®åè¡ã¯ãéåžžãäžã€ã®åœä»€ãè¡šããŸããåºæ¬çãªæ§é ã¯ä»¥äžã®ããã«ãªããŸãã
[ã©ãã«:] ããŒã¢ãã㯠[ãªãã©ã³ã1 [, ãªãã©ã³ã2 [, ...]]] [; ã³ã¡ã³ã]
- ã©ãã«ïŒãªãã·ã§ã³ïŒïŒ åœä»€ãããŒã¿ãé
眮ãããã¡ã¢ãªã¢ãã¬ã¹ã«ååãä»ããŸããåå²åœä»€ã®é£ã³å
ãªã©ã§äœ¿ãããŸããäŸïŒ
loop_start:
- ããŒã¢ããã¯ïŒ å®è¡ãããæäœãè¡šãçãè±åèªïŒèšæ¶è£å©èªïŒãCPUãå®è¡ããåœä»€ã®çš®é¡ã瀺ããŸããäŸïŒ
MOV
,ADD
,LDR
- ãªãã©ã³ãïŒåœä»€ã«ããïŒïŒ åœä»€ãæäœãã察象ïŒããŒã¿ãã¬ãžã¹ã¿ãã¡ã¢ãªã¢ãã¬ã¹ãªã©ïŒãæå®ããŸããæ°ã¯åœä»€ã«ãã£ãŠç°ãªããŸããäŸïŒ
X0
,#10
,[SP, #16]
- ã³ã¡ã³ãïŒãªãã·ã§ã³ïŒïŒ ã»ãã³ãã³ïŒ
;
ïŒãŸãã¯ã¹ã©ãã·ã¥2ã€ïŒ//
ïŒä»¥éã¯ã³ã¡ã³ããšããŠæ±ãããããã°ã©ã ã®èª¬æãªã©ãèšè¿°ããŸãã
äŸïŒ
start: ; ããã°ã©ã éå§ã©ãã«
MOV X0, #10 ; ã¬ãžã¹ã¿X0ã«å³å€10ãããŒããã (X0 = 10)
MOV X1, #20 ; ã¬ãžã¹ã¿X1ã«å³å€20ãããŒããã (X1 = 20)
ADD X0, X0, X1 ; X0 = X0 + X1 (X0 = 10 + 20 = 30)
ããŒã¿åãšãšã³ãã£ã¢ã³
ARM64ã¯ä»¥äžã®ããŒã¿ãµã€ãºãæ±ããŸãã
- Byte: 8ããã
- Halfword: 16ããã
- Word: 32ããã
- Doubleword: 64ããã
ãŸããARM64ã¯éåžžãªãã«ãšã³ãã£ã¢ã³ã§åäœããŸããããã¯ãè€æ°ãã€ãã§æ§æãããããŒã¿ãã¡ã¢ãªã«æ ŒçŽããéã«ãäžäœãã€ãïŒå°ããæ¡ã®å€ïŒãå°ããã¡ã¢ãªã¢ãã¬ã¹ã«æ ŒçŽããæ¹åŒã§ããïŒäžéšã®ARMããã»ããµã¯ããã°ãšã³ãã£ã¢ã³ããµããŒãããŸãããAArch64ã§ã¯ãªãã«ãšã³ãã£ã¢ã³ãäžè¬çã§ãïŒã
ãã䜿ãããARM64åœä»€ ð§
ARM64ã«ã¯å€ãã®åœä»€ããããŸãããããã§ã¯åºæ¬çãªããŒã¿æäœãç®è¡æŒç®ãã¡ã¢ãªæäœãåå²ã«é¢ãã代衚çãªåœä»€ã玹ä»ããŸãã
ããŒã¿è»¢éåœä»€
-
MOV <Xd>, <Xn|imm>
: ã¬ãžã¹ã¿éããŸãã¯å³å€ïŒããã°ã©ã äžã«çŽæ¥æžãããå€ã#
ã§å§ãŸãïŒãã¬ãžã¹ã¿ã«ç§»åïŒã³ããŒïŒããŸããMOV X0, X1 ; X0 = X1 MOV W2, #100 ; W2 = 100 (32ãããå³å€) MOV X3, #0xFF ; X3 = 255 (64ãããå³å€)
ã¡ã¢ãªã¢ã¯ã»ã¹åœä»€
-
LDR <Xt>, [<Xn|SP>, #offset]
: ã¡ã¢ãªããã¬ãžã¹ã¿ã«ããŒã¿ãããŒãïŒèªã¿èŸŒã¿ïŒããŸãã[]
å ã¯ã¡ã¢ãªã¢ãã¬ã¹ãæå®ããããŒã¹ã¬ãžã¹ã¿ïŒXn
ãŸãã¯SP
ïŒã«ãªãã»ãããå ããã¢ãã¬ã¹ããããŒã¿ãèªã¿èŸŒã¿ãŸããLDR X0, [X1] ; X0 = ã¡ã¢ãª[X1]ã®å 容 (ãªãã»ãã0) LDR W1, [SP, #16] ; W1 = ã¡ã¢ãª[SP + 16]ã®å 容 (32ããã) LDR X2, [X3, #8]! ; Pre-index: X3 = X3 + 8 ããŠãã X2 = ã¡ã¢ãª[X3] LDR X4, [X5], #16 ; Post-index: X4 = ã¡ã¢ãª[X5] ããŠãã X5 = X5 + 16
!
ãä»ã圢åŒïŒPre-indexïŒã¯ãã¢ãã¬ã¹èšç®åŸã«ããŒã¹ã¬ãžã¹ã¿ã®å€ãæŽæ°ããŸãã[]
ã®åŸã«ãªãã»ããããã圢åŒïŒPost-indexïŒã¯ãããŒãåŸã«ããŒã¹ã¬ãžã¹ã¿ãæŽæ°ããŸãã -
STR <Xt>, [<Xn|SP>, #offset]
: ã¬ãžã¹ã¿ã®ããŒã¿ãã¡ã¢ãªã«ã¹ãã¢ïŒæžã蟌ã¿ïŒããŸããã¢ãã¬ãã·ã³ã°ã¢ãŒãã¯LDR
ãšåæ§ã§ããSTR X0, [X1] ; ã¡ã¢ãª[X1] = X0 STR W1, [SP, #16] ; ã¡ã¢ãª[SP + 16] = W1 (32ããã) STR X2, [X3, #-8]! ; Pre-index: X3 = X3 - 8 ããŠãã ã¡ã¢ãª[X3] = X2
-
LDP <Xt1>, <Xt2>, [<Xn|SP>, #offset]
: ã¡ã¢ãªã®é£ç¶ããé åãã2ã€ã®ã¬ãžã¹ã¿ã«åæã«ããŒãããŸãïŒLoad PairïŒã -
STP <Xt1>, <Xt2>, [<Xn|SP>, #offset]
: 2ã€ã®ã¬ãžã¹ã¿ã®å€ãã¡ã¢ãªã®é£ç¶ããé åã«åæã«ã¹ãã¢ããŸãïŒStore PairïŒãã¹ã¿ãã¯ãžã®ã¬ãžã¹ã¿éé¿ãªã©ã§å¹ççã«å©çšãããŸãã
ããã¯é¢æ°ããããŒã°ã»ãšãããŒã°ã§ãã¬ãŒã ãã€ã³ã¿(X29)ãšãªã³ã¯ã¬ãžã¹ã¿(X30)ãã¹ã¿ãã¯ã«ä¿åã»åŸ©å ããå žåçãªäŸã§ããSTP X29, X30, [SP, #-16]! ; SP = SP - 16 ããŠãã ã¡ã¢ãª[SP] = X29, ã¡ã¢ãª[SP+8] = X30 LDP X29, X30, [SP], #16 ; ã¡ã¢ãª[SP]ãX29ã«, ã¡ã¢ãª[SP+8]ãX30ã«ããŒãåŸãSP = SP + 16
ç®è¡æŒç®åœä»€
ADD <Xd>, <Xn>, <Xm|imm>
: å ç®ãXd = Xn + Xm
ãŸãã¯Xd = Xn + imm
SUB <Xd>, <Xn>, <Xm|imm>
: æžç®ãXd = Xn - Xm
ãŸãã¯Xd = Xn - imm
MUL <Xd>, <Xn>, <Xm>
: ä¹ç®ãXd = Xn * Xm
SDIV <Xd>, <Xn>, <Xm>
: 笊å·ä»ãé€ç®ãXd = Xn / Xm
UDIV <Xd>, <Xn>, <Xm>
: 笊å·ç¡ãé€ç®ãXd = Xn / Xm
ADD X0, X1, X2 ; X0 = X1 + X2
SUB W3, W4, #10 ; W3 = W4 - 10
MUL X5, X6, X7 ; X5 = X6 * X7
è«çæŒç®ã»ã·ããåœä»€
AND <Xd>, <Xn>, <Xm|imm>
: è«çç© (AND)ORR <Xd>, <Xn>, <Xm|imm>
: è«çå (OR)EOR <Xd>, <Xn>, <Xm|imm>
: æä»çè«çå (XOR)LSL <Xd>, <Xn>, <#shift>
: è«çå·Šã·ããLSR <Xd>, <Xn>, <#shift>
: è«çå³ã·ããASR <Xd>, <Xn>, <#shift>
: ç®è¡å³ã·ããïŒç¬Šå·ããããç¶æïŒ
AND X0, X0, #0xFF ; X0ã®äžäœ8ããã以å€ã0ã«ãã
ORR W1, W1, #0x10 ; W1ã®ããã4ã1ã«ãã
LSL X2, X3, #3 ; X2 = X3 ã3ãããå·Šã·ãã (X3 * 8)
æ¯èŒåœä»€ãšåå²åœä»€
ããã°ã©ã ã®æµããå¶åŸ¡ããããã«ãæ¯èŒåœä»€ãšåå²åœä»€ã䜿ããŸãã
-
CMP <Xn>, <Xm|imm>
: 2ã€ã®å€ãæ¯èŒããŸãïŒå éšçã«ã¯Xn - Xm
ãŸãã¯Xn - imm
ãå®è¡ïŒãçµæã¯PSTATEã¬ãžã¹ã¿ã®ãã©ã°ïŒN, Z, C, VïŒã«åæ ãããåŸç¶ã®æ¡ä»¶åå²åœä»€ã§äœ¿ãããŸãã -
TST <Xn>, <Xm|imm>
: ãããåäœã®ãã¹ãïŒå éšçã«ã¯Xn AND Xm
ãŸãã¯Xn AND imm
ãå®è¡ïŒãçµæããŒããã©ãããªã©ããã©ã°ã«åæ ããŸãã -
B.<cond> <label>
: æ¡ä»¶ä»ãåå²ãæå®ããæ¡ä»¶ïŒ<cond>
ïŒãæºããããå Žåã<label>
ã«ãžã£ã³ãããŸããæ¡ä»¶ã³ãŒã (<cond>) 説æ ãã©ã° EQ
çãã (Equal) Z=1 NE
çãããªã (Not Equal) Z=0 CS
/HS
ãã£ãªãŒã»ãã / 笊å·ç¡ãã§ä»¥äž (Carry Set / Unsigned Higher or Same) C=1 CC
/LO
ãã£ãªãŒã¯ãªã¢ / 笊å·ç¡ãã§ããå°ãã (Carry Clear / Unsigned Lower) C=0 MI
è² (Minus / Negative) N=1 PL
æ£ãŸãã¯ãŒã (Plus / Positive or Zero) N=0 VS
ãªãŒããŒãã㌠(Overflow Set) V=1 VC
ãªãŒããŒãããŒãªã (Overflow Clear) V=0 HI
笊å·ç¡ãã§ãã倧ãã (Unsigned Higher) C=1 and Z=0 LS
笊å·ç¡ãã§ä»¥äž (Unsigned Lower or Same) C=0 or Z=1 GE
笊å·ä»ãã§ä»¥äž (Signed Greater than or Equal) N=V LT
笊å·ä»ãã§ããå°ãã (Signed Less Than) N!=V GT
笊å·ä»ãã§ãã倧ãã (Signed Greater Than) Z=0 and N=V LE
笊å·ä»ãã§ä»¥äž (Signed Less than or Equal) Z=1 or N!=V AL
åžžã« (Always) – ç¡æ¡ä»¶åå² B
ãšåã -
B <label>
: ç¡æ¡ä»¶åå²ãåžžã«<label>
ã«ãžã£ã³ãããŸãã -
BL <label>
: åå²ããŠãªã³ã¯ (Branch with Link)ã<label>
ã«ãžã£ã³ãããåã«ã次ã®åœä»€ã®ã¢ãã¬ã¹ããªã³ã¯ã¬ãžã¹ã¿ïŒLR
/X30
ïŒã«ä¿åããŸããé¢æ°åŒã³åºãã«äœ¿çšãããŸãã -
RET [<Xn>]
: ãµãã«ãŒãã³ããã®ãªã¿ãŒã³ãéåžžãLR
ã«ä¿åãããã¢ãã¬ã¹ã«ãžã£ã³ãããŠæ»ããŸãããªãã·ã§ã³ã§æå®ããã¬ãžã¹ã¿ã®ã¢ãã¬ã¹ã«æ»ãããšãå¯èœã§ãã
CMP W0, #10 ; W0 ãš 10 ãæ¯èŒ
B.EQ equal_label ; ãã W0 == 10 ãªã equal_label ãžãžã£ã³ã
; ... W0ã10ã§ãªãå Žåã®åŠç ...
B end_label ; åŠççµäºãžãžã£ã³ã
equal_label:
; ... W0ã10ã®å Žåã®åŠç ...
end_label:
; ... åŠççµäº ...
BL my_function ; my_function ãåŒã³åºãïŒæ»ãã¢ãã¬ã¹ã¯LRã«ä¿åïŒ
; ... my_function ããæ»ã£ãŠããåŸã®åŠç ...
my_function:
; ... é¢æ°ã®åŠç ...
RET ; LRã®ã¢ãã¬ã¹ïŒåŒã³åºãå
ã®æ¬¡ã®åœä»€ïŒãžæ»ã
é¢æ°åŒã³åºãèŠçŽ (AAPCS64) ð
è€æ°ã®é¢æ°ãé£æºããŠåäœããããã«ã¯ãåŒæ°ã®æž¡ãæ¹ãæ»ãå€ã®è¿ãæ¹ãã¬ãžã¹ã¿ã®äœ¿ãåããªã©ã«ã€ããŠå ±éã®ã«ãŒã«ãå¿ èŠã§ããARM64ã§ã¯ãProcedure Call Standard for the Arm 64-bit Architecture (AAPCS64) ãšããæšæºèŠçŽãå®ããããŠããŸããäž»èŠãªã«ãŒã«ã¯ä»¥äžã®éãã§ãã
- åŒæ°æž¡ãïŒ
- æåã®8åã®æŽæ°ã»ãã€ã³ã¿åŒæ°ã¯ãã¬ãžã¹ã¿
X0
ããX7
ïŒãŸãã¯W0
ããW7
ïŒã䜿ã£ãŠæž¡ãããŸãã - æåã®8åã®æµ®åå°æ°ç¹ã»SIMDåŒæ°ã¯ãã¬ãžã¹ã¿
V0
ããV7
ïŒãŸãã¯D0
–D7
,S0
–S7
ãªã©ïŒã䜿ã£ãŠæž¡ãããŸãã - 9åç®ä»¥éã®åŒæ°ãããµã€ãºã倧ããæ§é äœãªã©ã¯ã¹ã¿ãã¯ã䜿ã£ãŠæž¡ãããŸãã
- æåã®8åã®æŽæ°ã»ãã€ã³ã¿åŒæ°ã¯ãã¬ãžã¹ã¿
- æ»ãå€ïŒ
- æŽæ°ã»ãã€ã³ã¿ã®æ»ãå€ã¯
X0
ïŒãŸãã¯W0
ïŒã䜿ã£ãŠè¿ãããŸãã - æµ®åå°æ°ç¹ã»SIMDã®æ»ãå€ã¯
V0
ïŒãŸãã¯D0
,S0
ãªã©ïŒã䜿ã£ãŠè¿ãããŸãã - ãµã€ãºã倧ããæ§é äœãªã©ã¯ãåŒã³åºãå
ãçšæããã¡ã¢ãªé åãžã®ãã€ã³ã¿ã
X8
ã§æž¡ãããããžæ ŒçŽããŠè¿ããŸãã
- æŽæ°ã»ãã€ã³ã¿ã®æ»ãå€ã¯
- ã¬ãžã¹ã¿ã®åœ¹å²ïŒ
- åŒã³åºãå
ä¿å (Caller-Saved) / ã¹ã¯ã©ããã¬ãžã¹ã¿:
X0
–X18
(LR
=X30
ãé€ã),V0
–V7
,V16
–V31
ãé¢æ°ãåŒã³åºãåŽã¯ããããã®ã¬ãžã¹ã¿ã®å€ãå¿ èŠãªãåŒã³åºãåã«èªåã§éé¿ã»åŸ©å ããå¿ èŠããããŸããåŒã³åºãããé¢æ°ã¯ãããã®ã¬ãžã¹ã¿ãèªç±ã«æžãæããŠæ§ããŸãããX16
(IP0)ãšX17
(IP1)ã¯ããã·ãŒãžã£å åŒã³åºãã®äžæã¬ãžã¹ã¿ãšããŠãªã³ã«ã䜿çšããããšããããŸãã - åŒã³åºãå
ä¿å (Callee-Saved) / éé¿ã¬ãžã¹ã¿:
X19
–X29
,V8
–V15
ã®äžäœ64ããã(D8
–D15
)ãåŒã³åºãããé¢æ°ã¯ããããã®ã¬ãžã¹ã¿ã䜿çšããå Žåãé¢æ°ã®æåã§å€ãã¹ã¿ãã¯ãªã©ã«éé¿ããé¢æ°ã®æåŸã§å ã®å€ã«åŸ©å ããªããã°ãªããŸãããX29
ã¯ãã¬ãŒã ãã€ã³ã¿(FP)ãšããŠäœ¿ãããããšãå€ãã§ãã SP
,PC
,PSTATE
ã¯ç¹æ®ãªã¬ãžã¹ã¿ã§ããLR
(X30
)ã¯BL
åœä»€ã§èªåçã«æŽæ°ãããŸãã
- åŒã³åºãå
ä¿å (Caller-Saved) / ã¹ã¯ã©ããã¬ãžã¹ã¿:
- ã¹ã¿ãã¯ïŒ
- ã¹ã¿ãã¯ã¯ãã«ãã£ã¹ã¯ã»ã³ãã£ã³ã° (Full Descending) æ¹åŒã§ãã¹ã¿ãã¯ãã€ã³ã¿ïŒ
SP
ïŒã¯ã¹ã¿ãã¯ã®äžçªäžã®æå¹ãªããŒã¿ïŒæåŸã«ç©ãŸããããŒã¿ïŒãæããã¹ã¿ãã¯ã¯ã¢ãã¬ã¹ã®å€§ããæ¹ããå°ããæ¹ãžäŒžé·ããŸãã - ã¹ã¿ãã¯ãã€ã³ã¿ïŒ
SP
ïŒã¯åžžã«16ãã€ãå¢çã«ã¢ã©ã€ã³ãããŠããå¿ èŠããããŸãã - é¢æ°å
ã§ã¹ã¿ãã¯ã䜿çšããå Žåãéåžžãé¢æ°ã®æåïŒããããŒã°ïŒã§
SP
ãæžç®ããŠé åã確ä¿ããé¢æ°ã®æåŸïŒãšãããŒã°ïŒã§SP
ãå ç®ããŠé åã解æŸããŸãã
- ã¹ã¿ãã¯ã¯ãã«ãã£ã¹ã¯ã»ã³ãã£ã³ã° (Full Descending) æ¹åŒã§ãã¹ã¿ãã¯ãã€ã³ã¿ïŒ
ãããã®èŠçŽã«åŸãããšã§ãã¢ã»ã³ããªèšèªã§æžãããé¢æ°ãšãC/C++ãªã©ã®é«æ°Žæºèšèªã§ã³ã³ãã€ã«ãããé¢æ°ãäºãã«åŒã³åºããããããã«ãªããŸãã
ç°¡åãªäŸïŒCèšèªé¢æ°ãšã¢ã»ã³ã㪠ð»
ç°¡åãªCèšèªã®é¢æ°ããã©ã®ããã«ARM64ã¢ã»ã³ããªã«ã³ã³ãã€ã«ããããèŠãŠã¿ãŸããããïŒã³ã³ãã€ã©ã®æé©åã¬ãã«ã«ãã£ãŠåºåã¯ç°ãªããŸãïŒ
Cèšèªã®ã³ãŒã
long add_numbers(long a, long b) {
long result = a + b;
return result;
}
察å¿ããARM64ã¢ã»ã³ããªïŒæŠå¿µçãªäŸïŒ
add_numbers:
; AAPCS64ã«åºã¥ããåŒæ° 'a' 㯠X0 ã«ã'b' 㯠X1 ã«æž¡ããã
ADD X0, X0, X1 ; result = a + b. çµæã X0 ã«æ ŒçŽ
; æ»ãå€ã¯ X0 ã«æ ŒçŽãããŠããã®ã§ããã®ãŸãŸãªã¿ãŒã³
RET ; LRïŒåŒã³åºãå
ã®æ¬¡ã®ã¢ãã¬ã¹ïŒã«æ»ã
ãã®äŸã§ã¯ãCèšèªã®add_numbers
é¢æ°ãã¢ã»ã³ããªã®add_numbers
ã©ãã«ã«å¯Ÿå¿ããŸãã
- åŒã³åºãèŠçŽã«åŸããåŒæ°
a
ãã¬ãžã¹ã¿X0
ã«ãåŒæ°b
ãã¬ãžã¹ã¿X1
ã«å ¥ã£ãŠããŸãã ADD X0, X0, X1
åœä»€ã§ãX0
ãšX1
ãå ç®ããçµæãX0
ã«æ ŒçŽããŸããCèšèªã®result = a + b;
ã«çžåœããŸãã- åŒã³åºãèŠçŽã§ã¯ãæ»ãå€ã¯
X0
ã§è¿ãããšã«ãªã£ãŠãããããå ç®çµæãæ ŒçŽãããX0
ããã®ãŸãŸã«ããŠãããŸãã RET
åœä»€ã§ããªã³ã¯ã¬ãžã¹ã¿LR
ã«ä¿åãããŠããåŒã³åºãå ã®æ¬¡ã®åœä»€ã®ã¢ãã¬ã¹ã«åŠçãæ»ããŸãã
å®éã®ã³ã³ãã€ã©ã¯ãã¹ã¿ãã¯ãã¬ãŒã ã®èšå®ãªã©ãããå°ãè€éãªã³ãŒããçæããããšããããŸãããåºæ¬çãªåŠçã®æµãã¯ãã®ããã«ãªããŸãã
éçºããŒã« ð ïž
ARM64ã¢ã»ã³ããªèšèªã§ããã°ã©ãã³ã°ããã«ã¯ãããã€ãã®ããŒã«ãå¿ èŠã§ãã
- ã¢ã»ã³ãã©ïŒ ã¢ã»ã³ããªèšèªã®ã³ãŒãïŒ
.s
ãã¡ã€ã«ïŒããæ©æ¢°ãç解ã§ãããªããžã§ã¯ãã³ãŒãïŒ.o
ãã¡ã€ã«ïŒã«å€æããŸãã- GNU AS (gas): GCC (GNU Compiler Collection) ã«å«ãŸããã¢ã»ã³ãã©ãLinuxç°å¢ã§åºã䜿ãããŠããŸãã
- Clang/LLVM Assembler: LLVMããŒã«ãã§ã€ã³ã«å«ãŸããã¢ã»ã³ãã©ãmacOS (Xcode) ãä»ã®ç°å¢ã§æšæºçã«äœ¿ãããŠããŸããGNU ASãšäºææ§ã®ããæ§æããµããŒãããŠããŸãã
- ãªã³ã«ïŒ 1ã€ãŸãã¯è€æ°ã®ãªããžã§ã¯ããã¡ã€ã«ãšã©ã€ãã©ãªãã¡ã€ã«ãçµåããå®è¡å¯èœãªãã¡ã€ã«ãäœæããŸãã
- GNU ld: GCCã«å«ãŸãããªã³ã«ã
- LLVM lld: LLVMã®ãªã³ã«ã
- macOS Linker: Xcodeã«å«ãŸãããªã³ã«ã
- ãããã¬ïŒ ããã°ã©ã ãã¹ãããå®è¡ããããã¬ãžã¹ã¿ãã¡ã¢ãªã®å
容ã確èªãããããŠããã°ã®åå ãç¹å®ããã®ã«åœ¹ç«ã¡ãŸãã
- GDB (GNU Debugger): é«æ©èœãªã³ãã³ãã©ã€ã³ãããã¬ã
- LLDB: LLVMãããžã§ã¯ãã®ãããã¬ãmacOSã®æšæºãããã¬ã§ãã
- éã¢ã»ã³ãã©ïŒ å®è¡å¯èœãã¡ã€ã«ããªããžã§ã¯ããã¡ã€ã«ãããã¢ã»ã³ããªèšèªã®ã³ãŒãã埩å
ããŸããæ¢åã®ããã°ã©ã ã®åäœã解æããã®ã«äœ¿ãããŸãã
- objdump: GNU Binutilsã«å«ãŸããããŒã«ã
objdump -d <file>
ã§éã¢ã»ã³ãã«ã§ããŸãã - Ghidra: NSAã«ãã£ãŠéçºãããé«æ©èœãªãœãããŠã§ã¢ãªããŒã¹ãšã³ãžãã¢ãªã³ã°ããŒã«ïŒç¡åïŒã
- IDA Pro: åçšã®é«æ©èœéã¢ã»ã³ãã©ã»ãããã¬ã
- objdump: GNU Binutilsã«å«ãŸããããŒã«ã
- ããã¹ããšãã£ã¿/IDEïŒ ã³ãŒããæžãããã®ãšãã£ã¿ãVSCode, Vim, Emacs, Sublime Textãªã©ãã·ã³ã¿ãã¯ã¹ãã€ã©ã€ãæ©èœããããšäŸ¿å©ã§ãã
macOSã§éçºããå ŽåãXcode Command Line Tools ãã€ã³ã¹ããŒã«ããã°ãClang (ã¢ã»ã³ãã©ãã³ã³ãã€ã©)ããªã³ã«ãLLDBãªã©ãäžéãæããŸããLinuxã§ã¯ãGCC (build-essential
ããã±ãŒãžãªã©) ã LLVM ãã€ã³ã¹ããŒã«ããããšã§å¿
èŠãªããŒã«ãæããŸãã
# macOS ã§ã®ã³ã³ãã€ã«ãšãªã³ã¯ã®äŸ (Clangã䜿çš)
clang -c my_program.s -o my_program.o # ã¢ã»ã³ãã«
clang my_program.o -o my_program # ãªã³ã¯
./my_program # å®è¡
# Linux ã§ã®ã³ã³ãã€ã«ãšãªã³ã¯ã®äŸ (GCC/GNU ASã䜿çš)
as my_program.s -o my_program.o # ã¢ã»ã³ãã«
ld my_program.o -o my_program # ãªã³ã¯
./my_program # å®è¡
åŠç¿ãªãœãŒã¹ãšæ¬¡ã®ã¹ããã ð
ARM64ã¢ã»ã³ããªã«ã€ããŠããã«æ·±ãåŠã¶ããã®ãªãœãŒã¹ãããã€ã玹ä»ããŸãã
-
Arm Architecture Reference Manual (ARM ARM): Armv8-Aã¢ãŒããã¯ãã£ã®å
¬åŒãã€æã詳现ãªããã¥ã¡ã³ãã§ããArm Developerãµã€ãããå
¥æã§ããŸããïŒéåžžã«è©³çŽ°ã§ç¶²çŸ
çã§ãããåå¿è
ã«ã¯å°ãé£ãããããããŸããïŒ
Arm Architecture Reference Manual Armv8, for Armv8-A architecture profile -
Procedure Call Standard for the Arm 64-bit Architecture (AAPCS64): é¢æ°åŒã³åºãèŠçŽã®è©³çŽ°ãªä»æ§ã§ãã
AAPCS64 Specification on GitHub -
ãªã³ã©ã€ã³ãã¥ãŒããªã¢ã«ãããã°èšäºïŒ
- “ARM64ã¢ã»ã³ããª å ¥é” ã “AArch64 assembly tutorial” ãšãã£ãããŒã¯ãŒãã§æ€çŽ¢ãããšãå€ãã®è§£èª¬èšäºãèŠã€ãããŸãã
- ç¹å®ã®ãã©ãããã©ãŒã ïŒLinux, macOS/Apple SiliconïŒåãã®èšäºãåèã«ãªããŸããäŸãã°ãApple Siliconç¹æã®ç¹ã«ã€ããŠã¯Appleã®ããã¥ã¡ã³ãã圹ç«ã¡ãŸãã
Writing ARM64 Code for Apple Platforms - Jun Mizutaniæ°ã®ãŠã§ããµã€ãã«ã¯ãLinuxã«ãããARM64ã¢ã»ã³ããªããã°ã©ãã³ã°ã®è©³çŽ°ãªè§£èª¬ããããŸãã
Linux 㧠Arm64 ã¢ã»ã³ããªããã°ã©ãã³ã°
-
æžç±ïŒ
- ãARM 64-Bit Assembly Languageã (Larry D. Pyeatt, William Ughetta è): Raspberry Piãã¿ãŒã²ãããšããŠããŸãããARM64ã¢ã»ã³ããªã®åºç€ãåŠã¶ã®ã«åœ¹ç«ã¡ãŸãã
- Wikibooksã«ãARM64ã¢ã»ã³ããªèšèªã«é¢ããããŒãžããããŸãã
Wikibooks: ARM64ã¢ã»ã³ããªèšèª
-
å®è·µïŒ èªåã§ç°¡åãªããã°ã©ã ïŒHello Worldãç°¡åãªèšç®ãã«ãŒããªã©ïŒãæžããŠãã¢ã»ã³ãã«ããªã³ã¯ããããã°ããŠã¿ãããšãæãå¹æçãªåŠç¿æ¹æ³ã§ããCã³ã³ãã€ã©ãçæããã¢ã»ã³ããªã³ãŒãïŒ
gcc -S code.c
ãclang -S code.c
ïŒãèªãã§ã¿ãã®ãç解ãæ·±ããã®ã«åœ¹ç«ã¡ãŸãã
ãŸãšã âš
ãã®èšäºã§ã¯ãARM64ã¢ãŒããã¯ãã£ã®æŠèŠãããåºæ¬çãªã¢ã»ã³ããªèšèªã®èŠçŽ ïŒã¬ãžã¹ã¿ãåœä»€ãã¢ãã¬ãã·ã³ã°ã¢ãŒãïŒã代衚çãªåœä»€ãé¢æ°åŒã³åºãèŠçŽãéçºããŒã«ãåŠç¿ãªãœãŒã¹ãŸã§ã玹ä»ããŸããã
ã¢ã»ã³ããªèšèªã®åŠç¿ã¯ãã³ã³ãã¥ãŒã¿ãå éšã§ã©ã®ããã«åäœããŠããããç解ããããã®åŒ·åãªæ段ã§ããæåã¯é£ããæãããããããŸããããäžã€äžã€ã®åœä»€ãæŠå¿µãäžå¯§ã«åŠãã§ããã°ãå¿ ãç解ãæ·±ãŸããŸããããã©ãŒãã³ã¹ãã¥ãŒãã³ã°ãçµã¿èŸŒã¿ã·ã¹ãã éçºãã»ãã¥ãªãã£è§£æãªã©ãæ§ã ãªåéã§ãã®ç¥èã¯åœ¹ç«ã€ã§ãããã
ãã²ãå®éã«ã³ãŒããæžããŠåãããªãããARM64ã¢ã»ã³ããªã®äžçãæ¢æ±ããŠã¿ãŠãã ããïŒðð»
ã³ã¡ã³ã