RISCã¢ãŒããã¯ãã£ã®ä»£è¡šæ ŒãSPARCã®äžçãžããããïŒ
ð ã¯ããã«
ã³ã³ãã¥ãŒã¿ã®å¿èéšã§ããCPUã¯ããã·ã³èªãšåŒã°ããäœæ°Žæºãªåœä»€ã解éããŠåäœããŸãããããã人éããã·ã³èªãçŽæ¥èªã¿æžãããã®ã¯éåžžã«å°é£ã§ããããã§ç»å Žããã®ãã¢ã»ã³ããªèšèªã§ããã¢ã»ã³ããªèšèªã¯ããã·ã³èªã®åœä»€ãšã»ãŒäžå¯Ÿäžã«å¯Ÿå¿ããããŒã¢ããã¯ïŒèŠããããèšå·ïŒã䜿ã£ãŠããã°ã©ã ãèšè¿°ããèšèªã§ãã
ãã®èšäºã§ã¯ãæ°ããCPUã¢ãŒããã¯ãã£ã®äžã§ããç¹ã«RISCïŒReduced Instruction Set ComputerïŒèšèšææ³ã®å é§ããšããŠç¥ãããSPARC (Scalable Processor ARChitecture) ã®ã¢ã»ã³ããªèšèªã«ã€ããŠãåºç€ãã解説ããŠãããŸããSPARCã¯ããã€ãŠSun Microsystems瀟ïŒåŸã«Oracle瀟ãè²·åïŒã®ã¯ãŒã¯ã¹ããŒã·ã§ã³ããµãŒããŒã§åºã䜿ããããã®åŸã®ããã»ããµèšèšã«å€§ããªåœ±é¿ãäžããŸãããçŸåšã§ã¯ãå¯å£«éæ ªåŒäŒç€Ÿãªã©ãéçºãç¶ç¶ããŠããã¹ãŒããŒã³ã³ãã¥ãŒã¿ãå¯å²³ãã®CPU (A64FX) ã®æºæµã®äžã€ãšãèšããŸãïŒãã ãA64FXã¯ARMã¢ãŒããã¯ãã£ããŒã¹ã§ãããéçºçµéšã¯æŽ»ããããŠããŸãïŒã
äœã¬ã€ã€ãŒã®åäœãç解ãããæ¹ãç¹å®ã®SPARCããŒã¹ã·ã¹ãã ãæ±ãå¿ èŠãããæ¹ããããã¯åã«ã³ã³ãã¥ãŒã¿ã¢ãŒããã¯ãã£ã®å€æ§æ§ã«èå³ãããæ¹ã«ãšã£ãŠããã®èšäºãSPARCã¢ã»ã³ããªãžã®ç¬¬äžæ©ãšãªãããšãé¡ã£ãŠããŸããð
ð¡ SPARCã¢ãŒããã¯ãã£ãšã¯ïŒ
SPARCã¯ã1980幎代åã°ã«Sun Microsystems瀟ã«ãã£ãŠéçºãéå§ããããã€ã¯ãããã»ããµã¢ãŒããã¯ãã£ã§ããã«ãªãã©ã«ãã¢å€§åŠããŒã¯ã¬ãŒæ ¡ã®RISC I/IIãããžã§ã¯ãã®åœ±é¿ã匷ãåããŠããã以äžã®ãããªããã€ãã®éèŠãªç¹åŸŽãæã£ãŠããŸãã
äž»ãªç¹åŸŽ:
- RISCèšèš: åœä»€ã»ãããåçŽåããååœä»€ãåºæ¬çã«1ã¯ããã¯ãµã€ã¯ã«ã§å®è¡ã§ããããã«èšèšãããŠããŸããããã«ããããã€ãã©ã€ã³åŠçå¹çãé«ããé«éåãå³ã£ãŠããŸãã
- ã¬ãžã¹ã¿ã»ãŠã£ã³ã㊠(Register Windows): é¢æ°åŒã³åºãæã®ã¬ãžã¹ã¿éé¿ã»åŸ©å ã®ãªãŒããŒããããåæžããããã®ç¬åµçãªä»çµã¿ã§ããåŸã»ã©è©³ãã解説ããŸãã
- é 延åå² (Delayed Branch): åå²åœä»€ã®çŽåŸã®åœä»€ïŒé 延ã¹ãããïŒã¯ãåå²ãããã©ããã«é¢ãããå®è¡ããããšããç¹åŸŽããããŸããããã«ããããã€ãã©ã€ã³ã®ä¹±ããæå°éã«æããããšããŸãããïŒè¿å¹Žã®é«æ§èœããã»ããµã§ã¯åå²äºæž¬æè¡ãé«åºŠåããããããã®æ¹åŒã®ã¡ãªããã¯çžå¯Ÿçã«èããŠããŸããïŒ
- 32ããã / 64ããã: åœåã¯32ãããã¢ãŒããã¯ã㣠(SPARC V7, V8) ã§ããããåŸã«64ãããã«æ¡åŒµãããŸãã (SPARC V9)ã
- ãªãŒãã³ã¢ãŒããã¯ãã£: SPARCä»æ§ã¯å ¬éãããŠãããè€æ°ã®ãã³ããŒãSPARCããã»ããµã補é ã»è²©å£²ããŠããŸããã
SPARCã¯ãSunã®ã¯ãŒã¯ã¹ããŒã·ã§ã³ (SPARCstationã·ãªãŒãºãªã©) ããµãŒã㌠(Sun Enterpriseã·ãªãŒãºãªã©) ã§é·å¹Žã«ãããæ¡çšãããç§åŠæè¡èšç®ããšã³ã¿ãŒãã©ã€ãºã·ã¹ãã ãéä¿¡æ©åšãªã©å¹ åºãåéã§å©çšãããŸãããOracle瀟ã«ããSunè²·åïŒ2010幎å®äºïŒåŸãéçºã¯ç¶ããããŸãããã2017幎é ã«çºè¡šãããSPARC M8äžä»£ãæåŸã«ãOracle瀟ã«ããæ°èŠéçºã¯çµäºãããšãããŠããŸããäžæ¹ã§ãå¯å£«éã¯SPARC64ã·ãªãŒãºãšããŠç¬èªã«éçºãç¶ããé«æ§èœãµãŒããŒãã¹ãŒããŒã³ã³ãã¥ãŒã¿åãã«æäŸããŠããŸããã
âïž SPARCã®ã¬ãžã¹ã¿
ã¢ã»ã³ããªããã°ã©ãã³ã°ã«ãããŠãã¬ãžã¹ã¿ã®ç解ã¯äžå¯æ¬ ã§ããã¬ãžã¹ã¿ã¯CPUå éšã«ããé«éãªèšæ¶é åã§ãèšç®å¯Ÿè±¡ã®ããŒã¿ãã¡ã¢ãªã¢ãã¬ã¹ãªã©ãäžæçã«ä¿æããŸããSPARCã¢ãŒããã¯ãã£ïŒç¹ã«SPARC V8/V9ïŒã«ã¯ãããã€ãã®çš®é¡ã®ã¬ãžã¹ã¿ããããŸãã
æ±çšã¬ãžã¹ã¿
SPARCã¯å€æ°ã®æ±çšã¬ãžã¹ã¿ãæã£ãŠããŸãããäžåºŠã«èŠããã®ã¯32åã§ãããããã®ã¬ãžã¹ã¿ã¯ããã®åœ¹å²ã«å¿ããŠè«ççã«ã°ã«ãŒãåããããŠããŸãã
ã¬ãžã¹ã¿å | åæ° | 説æ |
---|---|---|
%g0 – %g7 |
8å | ã°ããŒãã«ã¬ãžã¹ã¿ (Global Registers)ãé¢æ°åŒã³åºããéããŠåžžã«åãå
容ãä¿æããŸãã%g0 ã¯åžžã«0ãä¿æããæžã蟌ã¿ã¯ç¡èŠãããŸãïŒãŒãã¬ãžã¹ã¿ïŒã |
%o0 – %o7 |
8å | åºåã¬ãžã¹ã¿ (Output Registers)ãé¢æ°åŒã³åºãæã«åŒæ°ãæž¡ããããæ»ãå€ãè¿ãããããã®ã«äœ¿ãããŸããåŒã³åºãããé¢æ°ããèŠããšããããã¯å
¥åã¬ãžã¹ã¿ (%i ) ã«ãªããŸãã%o6 ã¯ã¹ã¿ãã¯ãã€ã³ã¿ (%sp ) ãšããŠäœ¿ãããŸãã%o7 ã¯call åœä»€å®è¡æã®æ»ãã¢ãã¬ã¹ãæ ŒçŽããŸãã |
%l0 – %l7 |
8å | ããŒã«ã«ã¬ãžã¹ã¿ (Local Registers)ãçŸåšã®é¢æ°å ã§ã®ã¿äœ¿çšãããäžæçãªå€ãæ ŒçŽããŸããé¢æ°åŒã³åºãæã«ã¯å 容ã¯ä¿èšŒãããŸããã |
%i0 – %i7 |
8å | å
¥åã¬ãžã¹ã¿ (Input Registers)ãåŒã³åºãå
ã®é¢æ°ã %o ã¬ãžã¹ã¿ã«èšå®ããåŒæ°ãåãåããŸãã%i6 ã¯ãã¬ãŒã ãã€ã³ã¿ (%fp ) ãšããŠäœ¿ãããŸãã%i7 ã¯åŒã³åºãå
ãžã®æ»ãã¢ãã¬ã¹ãä¿æããŸãã |
ã¬ãžã¹ã¿ã»ãŠã£ã³ã㊠ð
SPARCã®æãç¹åŸŽçãªæ©èœã®äžã€ãã¬ãžã¹ã¿ã»ãŠã£ã³ããŠã§ããCPUå éšã«ã¯å®éã«ã¯32åãããå€ãã®æ±çšã¬ãžã¹ã¿ãååšãïŒäŸãã°64åãã520åãªã©å®è£ ã«ããïŒãããããããŠã£ã³ããŠããšããŠåãæ¿ããããŠäœ¿çšãããŸãã
é¢æ°ãåŒã³åºãéãsave
åœä»€ãå®è¡ããããšãçŸåšã®ã¬ãžã¹ã¿ãŠã£ã³ããŠãäžã€ãå転ãããŸãã
- çŸåšã®ãŠã£ã³ããŠã®
%o
ã¬ãžã¹ã¿ããæ°ãããŠã£ã³ããŠã®%i
ã¬ãžã¹ã¿ã«ãªããŸãã - çŸåšã®ãŠã£ã³ããŠã®
%l
ã¬ãžã¹ã¿ã¯éé¿ãããæ°ãããŠã£ã³ããŠã§ã¯æ°ãã%l
ã¬ãžã¹ã¿ã䜿ããŸãã - çŸåšã®ãŠã£ã³ããŠã®
%i
ã¬ãžã¹ã¿ã¯ã¢ã¯ã»ã¹ã§ããªããªããŸãïŒéé¿ãããŠããç¶æ ïŒã %g
ã¬ãžã¹ã¿ã¯ãŠã£ã³ããŠã®åœ±é¿ãåãããåžžã«åããã®ã䜿ãããŸãã
é¢æ°ããæ»ãéã«ã¯ restore
åœä»€ã䜿ããããŠã£ã³ããŠãéæ¹åã«å転ããå
ã®ã¬ãžã¹ã¿ã»ããã埩å
ãããŸããããã«ãããé¢æ°åŒã³åºãæã®ã¬ãžã¹ã¿ã®éé¿ã»åŸ©å
ã«å¿
èŠãªã¡ã¢ãªã¢ã¯ã»ã¹ã倧å¹
ã«åæžã§ããŸãããã ãããŠã£ã³ããŠã®æ°ãéãããŠãããããæ·±ãé¢æ°åŒã³åºããçºçãããšãŠã£ã³ããŠã溢ãïŒãªãŒããŒãããŒïŒãOSãä»å
¥ããŠã¬ãžã¹ã¿å
容ãã¡ã¢ãªã«éé¿ãããå¿
èŠããããŸããéã«é¢æ°ã次ã
ã«æ»ã£ãŠãããšãŠã£ã³ããŠã空ã«ãªãïŒã¢ã³ããŒãããŒïŒãOSãã¡ã¢ãªããå
容ã埩å
ããŸãã
+-------------------+ save +-------------------+
| Global (%g0-%g7) | <------------> | Global (%g0-%g7) |
+-------------------+ +-------------------+
| Out (%o0-%o7) | ------------> | In (%i0-%i7) | \
+-------------------+ +-------------------+ | æ°ãããŠã£ã³ããŠ
| Local (%l0-%l7) | --(éé¿)--> | Local (%l0-%l7) | | (New Window)
+-------------------+ +-------------------+ /
| In (%i0-%i7) | --(ã¢ã¯ã»ã¹äžå¯)-> | Out (%o0-%o7) | /
+-------------------+ +-------------------+
å€ããŠã£ã³ã㊠(New %o regs)
(Old Window) restore ã¯éæ¹å
ç¹æ®ã¬ãžã¹ã¿
æ±çšã¬ãžã¹ã¿ä»¥å€ã«ããããã»ããµã®ç¶æ ãå¶åŸ¡ã«äœ¿ãããç¹æ®ãªã¬ãžã¹ã¿ããããŸãã
%psr
(Processor State Register): ããã»ããµã®çŸåšã®ç¶æ ïŒå²ã蟌ã¿èš±å¯/çŠæ¢ãçŸåšã®ãŠã£ã³ããŠçªå·(CWP)ãæ¡ä»¶ã³ãŒããªã©ïŒãä¿æããŸãã%pc
(Program Counter): 次ã«å®è¡ãããåœä»€ã®ã¢ãã¬ã¹ãæããŸãã%npc
(Next Program Counter): 次ã®æ¬¡ã«å®è¡ãããåœä»€ã®ã¢ãã¬ã¹ãæããŸããé 延åå²ã®ããã«éèŠã§ããåå²åœä»€èªäœãå®è¡ãããåŸã%npc
ã®å€ã%pc
ã«ã³ããŒãããŸãã%y
: ä¹ç®ã»é€ç®åœä»€ã§äœ¿çšãããã¬ãžã¹ã¿ã%wim
(Window Invalid Mask): ã¬ãžã¹ã¿ãŠã£ã³ããŠã®ãªãŒããŒãããŒ/ã¢ã³ããŒãããŒæ€åºã«äœ¿ãããŸãã%tbr
(Trap Base Register): ãã©ããïŒäŸå€ãå²ã蟌ã¿ïŒçºçæã«ãžã£ã³ãããå ã®ãã³ãã©ã¢ãã¬ã¹ã®åºç¹ãä¿æããŸãã
ð§ åºæ¬çãªSPARCã¢ã»ã³ããªåœä»€
SPARCã¢ã»ã³ããªã®åœä»€ã¯ãæ¯èŒçã·ã³ãã«ã§èŠåçãªåœ¢åŒãæã£ãŠããŸããããã§ã¯ä»£è¡šçãªåœä»€ã®çš®é¡ãšäŸãããã€ã玹ä»ããŸããåœä»€ã®ãªãã©ã³ãã¯éåžžãåœä»€ å
, å
, å
ãŸã㯠åœä»€ å
, å³å€, å
ã®ããã«ããœãŒã¹ãªãã©ã³ããå
ã«æ¥ãŠããã¹ãã£ããŒã·ã§ã³ãªãã©ã³ããæåŸã«æ¥ãŸãã
ããŒã¿è»¢éåœä»€ (Load/Store)
ã¡ã¢ãªãšã¬ãžã¹ã¿éã§ããŒã¿ãããåãããåœä»€ã§ããSPARCã¯å žåçãªLoad/Storeã¢ãŒããã¯ãã£ã§ãããã¡ã¢ãªæäœã¯ãããã®åœä»€ã§ã®ã¿è¡ããç®è¡æŒç®ãªã©ã¯ã¬ãžã¹ã¿éã§è¡ããŸãã
ld [ã¢ãã¬ã¹], %ã¬ãžã¹ã¿
: ã¡ã¢ãªããã¬ãžã¹ã¿ãžããŒã (Load Word: 4ãã€ã)ãã¢ãã¬ã¹ã¯[%ã¬ãžã¹ã¿ + %ã¬ãžã¹ã¿]
ã[%ã¬ãžã¹ã¿ + å³å€]
ã®åœ¢åŒã§æå®ããŸããld [%o0 + %o1], %l1
:%o0
+%o1
ã®ã¢ãã¬ã¹ãã4ãã€ãèªã¿èŸŒã¿%l1
ãžæ ŒçŽãld [%fp + 68], %l2
: ãã¬ãŒã ãã€ã³ã¿+68ãã€ãã®ã¢ãã¬ã¹ãã4ãã€ãèªã¿èŸŒã¿%l2
ãžæ ŒçŽã- ä»ã«ã
ldub
(Load Unsigned Byte),ldsh
(Load Signed Halfword) ãªã©ããµã€ãºã笊å·æ¡åŒµãæå®ããããªãšãŒã·ã§ã³ããããŸãã
st %ã¬ãžã¹ã¿, [ã¢ãã¬ã¹]
: ã¬ãžã¹ã¿ããã¡ã¢ãªãžã¹ã㢠(Store Word: 4ãã€ã)ãst %l1, [%o0 + %o1]
:%l1
ã®å 容ã%o0
+%o1
ã®ã¢ãã¬ã¹ãž4ãã€ãæžã蟌ã¿ãst %l2, [%fp + 68]
:%l2
ã®å 容ã ãã¬ãŒã ãã€ã³ã¿+68ãã€ãã®ã¢ãã¬ã¹ãž4ãã€ãæžã蟌ã¿ã- åæ§ã«
stb
(Store Byte),sth
(Store Halfword) ãªã©ããããŸãã
ç®è¡æŒç®åœä»€
å ç®ãæžç®ãªã©ã®èšç®ãè¡ããŸãã
add %src1, src2, %dst
:%dst = %src1 + src2
ãsrc2
ã¯ã¬ãžã¹ã¿ (%reg
) ãŸãã¯å³å€ (imm
)ãadd %l0, %l1, %l2
:%l2 = %l0 + %l1
add %o0, 10, %o0
:%o0 = %o0 + 10
sub %src1, src2, %dst
:%dst = %src1 - src2
ãsub %l0, %l1, %l2
:%l2 = %l0 - %l1
addcc
,subcc
: æŒç®çµæã«å¿ããŠæ¡ä»¶ã³ãŒã (%psr
å ã®ãã©ã°) ãã»ããããããŒãžã§ã³ãæ¡ä»¶åå²ã§äœ¿ãããŸãã- ä¹ç® (
mulscc
) ãé€ç® (udiv
,sdiv
) åœä»€ããããŸãããå°ãè€éã§ãã
è«çæŒç®åœä»€
AND, OR, XOR ãªã©ã®ãããåäœã®è«çæŒç®ãè¡ããŸãã
and %src1, src2, %dst
:%dst = %src1 & src2
or %src1, src2, %dst
:%dst = %src1 | src2
xor %src1, src2, %dst
:%dst = %src1 ^ src2
andcc
,orcc
,xorcc
: æ¡ä»¶ã³ãŒããã»ããããããŒãžã§ã³ãorcc %g0, %reg, %g0
ã¯ã¬ãžã¹ã¿ã®å 容ã0ãã©ããã®ãã¹ãã«ãã䜿ãããŸãïŒçµæããŒããªãZãã©ã°ãç«ã€ïŒã
ã·ããåœä»€
ããããå·Šå³ã«ã·ããããŸãã
sll %src1, amount, %dst
: è«çå·Šã·ãã (Shift Left Logical)ãamount
ã¯ã¬ãžã¹ã¿ãŸãã¯å³å€ãsrl %src1, amount, %dst
: è«çå³ã·ãã (Shift Right Logical)ãsra %src1, amount, %dst
: ç®è¡å³ã·ãã (Shift Right Arithmetic)ã笊å·ããããç¶æããŸãã
å¶åŸ¡è»¢éåœä»€ (åå²ã»ãžã£ã³ãã»åŒã³åºã)
ããã°ã©ã ã®å®è¡ãããŒãå€æŽããŸãã
sethi å®æ°, %ã¬ãžã¹ã¿
: å®æ°ã®äžäœ22ããããã¬ãžã¹ã¿ã®äžäœ22ãããã«ã»ããããäžäœ10ãããã0ã«ãã (Set High)ã32ãããå®æ°ãã¬ãžã¹ã¿ã«ããŒãããããã«or
åœä»€ãšçµã¿åãããŠäœ¿ãããŸãã- äŸ:
0x12345678
ã%l0
ã«ããŒãããå Žåsethi %hi(0x12345678), %l0 ! %l0 = 0x12345400 or %l0, %lo(0x12345678), %l0 ! %l0 = 0x12345400 | 0x278 = 0x12345678
- äŸ:
b
: æ¡ä»¶ä»ãåå² (Branch on Condition)ãçŽåã®ã©ãã« cc
ä»ãåœä»€ã®çµæïŒæ¡ä»¶ã³ãŒãïŒã«åºã¥ããŠåå²ããŸãã
ã«ã¯a
(Always),e
(Equal/Zero),ne
(Not Equal/Non-Zero),g
(Greater),le
(Less or Equal) ãªã©ãå ¥ããŸããcmp %l0, %l1
(ããã¯subcc %l0, %l1, %g0
ã®ç䌌åœä»€)be equal_label
: çãããã°equal_label
ãžåå²bne not_equal_label
: çãããªããã°not_equal_label
ãžåå²ba always_label
: ç¡æ¡ä»¶åå²- 泚æ: SPARCã®åå²åœä»€ã«ã¯éåžžãé
延ã¹ããã (Delay Slot) ããããŸããåå²åœä»€ã®çŽåŸã«ããåœä»€ã¯ãåå²ãçºçãããã©ããã«é¢ãããå®è¡ãããŸãããã®ã¹ããããæå¹æŽ»çšïŒäŸãã°ãåå²å
ã§å¿
èŠãªåŠçã®äžéšãããã«å
¥ããïŒããããäœããããããªãå Žåã¯
nop
(No Operation) åœä»€ãå ¥ããŸããã¢ã»ã³ãã©ãèªåã§nop
ãè£å®ããŠãããå ŽåããããŸã (-xO
ãªãã·ã§ã³ãªã©ã§æé©åããå Žåãªã©)ã b
: Annul (ç¡å¹å) ãããä»ãåå²ãæ¡ä»¶ãæºããããªãå Žåãé 延ã¹ãããã®åœä»€ãå®è¡ããŸããã,a ã©ãã«
call ã©ãã«
: é¢æ°ïŒãµãã«ãŒãã³ïŒãåŒã³åºããŸããæ»ãã¢ãã¬ã¹ã%o7
ã«æ ŒçŽãããŸãããããé 延ã¹ããããæã¡ãŸããjmpl %ã¢ãã¬ã¹ã¬ãžã¹ã¿ + ãªãã»ãã, %æ»ãå ã¬ãžã¹ã¿
: ã¬ãžã¹ã¿ã®å 容ã«åºã¥ããŠãžã£ã³ã (Jump and Link)ãé¢æ°ããã®ãªã¿ãŒã³ã«ãã䜿ãããŸããret
:jmpl %i7 + 8, %g0
ã®ç䌌åœä»€ãåŒã³åºãå ã«æ»ããretl
:jmpl %o7 + 8, %g0
ã®ç䌌åœä»€ããªãŒãé¢æ°ïŒèªèº«ã¯ä»ã®é¢æ°ãåŒã°ãªãé¢æ°ïŒããã®ãªã¿ãŒã³ã
save %sp, -ãµã€ãº, %sp
: æ°ããã¹ã¿ãã¯ãã¬ãŒã ãäœæããã¬ãžã¹ã¿ãŠã£ã³ããŠãå転ãããŸããé¢æ°ããããŒã°ã§äœ¿ãããŸããrestore
: ã¹ã¿ãã¯ãã¬ãŒã ãç Žæ£ããã¬ãžã¹ã¿ãŠã£ã³ããŠãå ã«æ»ããŸããé¢æ°ãšãããŒã°ã§äœ¿ãããŸããrestore %g0, %g0, %g0
ã®ããã«æžãããããšãå€ãã§ããnop
: äœãããªãåœä»€ (No Operation)ãé 延ã¹ããããåãããããªã©ã«äœ¿ãããŸããå®éã«ã¯sethi 0, %g0
ãªã©ã§å®è£ ãããŸãã
ð ç°¡åãªãµã³ãã«ã³ãŒã
èšèã ãã§ã¯åããã«ããã®ã§ãç°¡åãªäŸãèŠãŠã¿ãŸããããããã§ã¯ã2ã€ã®åŒæ°ãåãåãããã®åèšãè¿ãåçŽãªé¢æ° add_func
ãSPARCã¢ã»ã³ããªã§æžããŠã¿ãŸãã
Cèšèªã§ã®ã€ã¡ãŒãž:
int add_func(int a, int b) {
int sum = a + b;
return sum;
}
SPARCã¢ã»ã³ã㪠(SPARC V8/V9 ABI):
.section ".text" ! ã³ãŒãã»ã¯ã·ã§ã³
.global add_func ! ã°ããŒãã«ã·ã³ãã«ãšããŠå
Ž
.align 4 ! 4ãã€ãå¢çã«é
眮
add_func:
! é¢æ°ããããŒã° (ãã®åçŽãªäŸã§ã¯äžèŠã ããäžè¬çã«ã¯saveã䜿ã)
! save %sp, -96, %sp ! äŸ: 96ãã€ãã®ã¹ã¿ãã¯ãã¬ãŒã 確ä¿ãšãŠã£ã³ããŠå転
! åŒæ°ã¯ %o0 (a) ãš %o1 (b) ã«å
¥ã£ãŠãã
! åŒã³åºãããåŽãã㯠%i0, %i1 ãšããŠèŠãã
! (save ã䜿ã£ãå Žå㯠%i0, %i1 ã«ãªããããã®äŸã§ã¯ save ããªãã®ã§ %o0, %o1 ã®ãŸãŸäœ¿ã)
add %o0, %o1, %o0 ! %o0 = %o0 + %o1 (çµæã %o0 ã«æ ŒçŽ)
! é¢æ°ãšãããŒã°
retl ! ãªãŒãé¢æ°ããã®ãªã¿ãŒã³ (jmpl %o7 + 8, %g0)
nop ! é
延ã¹ããã (retl ã®å Žåã¯å¿
é ã§ã¯ãªãããšãå€ãã念ã®ãã)
! (save ã䜿ã£ãå Žå㯠ret; restore ãšãªã)
! ret ! éåžžã®ãªã¿ãŒã³ (jmpl %i7 + 8, %g0)
! restore ! ãŠã£ã³ããŠãæ»ããã¹ã¿ãã¯ãã¬ãŒã ãè§£æŸ (é
延ã¹ãããå
)
解説:
.section ".text"
: ãã以éãå®è¡ã³ãŒãã§ããããšã瀺ããŸãã.global add_func
:add_func
ãšããååãä»ã®ãã¡ã€ã«ããåç §ã§ããããã«ããŸãã.align 4
: åœä»€ã¯éåžž4ãã€ãå¢çã«é 眮ãããã¹ãã§ããadd_func:
: ã©ãã«ãé¢æ°ã®éå§ç¹ã瀺ããŸããadd %o0, %o1, %o0
: SPARC ABI (Application Binary Interface) ã«åŸããæåã®åŒæ°(a)ã¯%o0
ã2çªç®ã®åŒæ°(b)ã¯%o1
ã«æ ŒçŽãããŠæž¡ãããŸãããã®åœä»€ã§ããããå ç®ããçµæãæ»ãå€çšã®ã¬ãžã¹ã¿ã§ãã%o0
ã«æ ŒçŽããŠããŸããretl
: ãªãŒãé¢æ° (Leaf function: èªèº«ãä»ã®é¢æ°ãåŒã³åºããªãé¢æ°) ããã®æ»ãåœä»€ã§ããcall
åœä»€ã§%o7
ã«æ ŒçŽãããæ»ãã¢ãã¬ã¹ã«ãžã£ã³ãããŸããnop
:retl
ã®é 延ã¹ããããåããŸãã- ã³ã¡ã³ãã¯
!
以éã«èšè¿°ããŸãã - ãã®äŸã§ã¯éåžžã«åçŽãªãããã¹ã¿ãã¯ãã¬ãŒã ã®ç¢ºä¿ (
save
) ãã¬ãžã¹ã¿ãŠã£ã³ããŠã®å転ãè¡ã£ãŠããŸããããããè€éãªé¢æ°ã§ã¯éåžžããããå¿ èŠã«ãªããŸãã
ð€ åŒã³åºãèŠçŽ (Calling Convention)
è€æ°ã®é¢æ°ãæ£ããé£æºããããã«ã¯ãåŒæ°ã®æž¡ãæ¹ãæ»ãå€ã®è¿ãæ¹ãã¬ãžã¹ã¿ã®å©çšã«ãŒã«ãªã©ãå®ããåŒã³åºãèŠçŽ (Calling Convention) ã«åŸãå¿ èŠããããŸããSPARCã§ã¯ãSystem V ABI (Application Binary Interface) ã®äžéšãšããŠæšæºçãªèŠçŽãå®ããããŠããŸãã
SPARC V8/V9 ABIã®äž»ãªã«ãŒã«:
- åŒæ°æž¡ã:
- æåã®6ã€ã®æŽæ°/ãã€ã³ã¿åŒæ°ã¯ãã¬ãžã¹ã¿
%o0
ãã%o5
ã«é çªã«æ ŒçŽãããŸãã - 7ã€ç®ä»¥éã®åŒæ°ã¯ãã¹ã¿ãã¯ã«ç©ãŸããŸãïŒéåžžã
[%sp + 92]
ããé ã«ç©ãŸããŸãïŒã - æµ®åå°æ°ç¹åŒæ°ã¯ãæµ®åå°æ°ç¹ã¬ãžã¹ã¿ (
%f0
,%f1
, …) ã䜿ããŸã (ããã§ã¯è©³çŽ°ç¥)ã
- æåã®6ã€ã®æŽæ°/ãã€ã³ã¿åŒæ°ã¯ãã¬ãžã¹ã¿
- æ»ãå€:
- æŽæ°ããã€ã³ã¿ã®æ»ãå€ã¯ã
%o0
ã«æ ŒçŽãããŸãã64ãããã¢ãŒããã¯ã㣠(V9) ã§64ããããã倧ããªæ§é äœãè¿ãå Žåãªã©ã¯ãå¥ã®æ¹æ³ãåãããŸãã - æµ®åå°æ°ç¹æ°ã®æ»ãå€ã¯ã
%f0
ãªã©ã䜿ããŸãã
- æŽæ°ããã€ã³ã¿ã®æ»ãå€ã¯ã
- ã¬ãžã¹ã¿ã®ä¿å:
%g
ã¬ãžã¹ã¿ (%g0
é€ã) ãš%o
ã¬ãžã¹ã¿ (%o6=%sp
,%o7
é€ã) ã¯ãé¢æ°åŒã³åºãã«ãã£ãŠå 容ãç Žå£ãããå¯èœæ§ããããŸã (Caller-saved ãŸã㯠Scratch registers)ãåŒã³åºãåŽãå¿ èŠãªããåŒã³åºãåã«éé¿ããå¿ èŠããããŸãã%l
ã¬ãžã¹ã¿ãš%i
ã¬ãžã¹ã¿ (%i6=%fp
,%i7
é€ã) ã¯ãé¢æ°å ã§èªç±ã«äœ¿ããŸããããã®é¢æ°ãä»ã®é¢æ°ãåŒã³åºãå Žåã«ã¯éé¿ãå¿ èŠã«ãªããããããŸãããé¢æ°ããæ»ãéã«ã¯ãåŒã³åºãããæç¹ã§ã®å 容ã埩å ãããŠããå¿ èŠããããŸã (Callee-saved)ããã ããã¬ãžã¹ã¿ãŠã£ã³ããŠæ©æ§ã«ãããsave
/restore
ã§èªåçã«éé¿ã»åŸ©å ããããããéåžžã¯åå¥ã«ã¡ã¢ãªã«éé¿ããå¿ èŠã¯ãããŸããã%sp
(%o6
) ãš%fp
(%i6
) ã¯ç¹å®ã®åœ¹å²ãæã€ãããèŠçŽã«åŸã£ãŠç®¡çããå¿ èŠããããŸãã
- ã¹ã¿ãã¯ãã¬ãŒã :
- é¢æ°ã¯éåžžã
save
åœä»€ã§èªèº«ã®ã¹ã¿ãã¯ãã¬ãŒã ã確ä¿ããŸããã¹ã¿ãã¯ã¯é«äœã¢ãã¬ã¹ããäœäœã¢ãã¬ã¹ã«åãã£ãŠäŒžé·ããŸãã - ã¹ã¿ãã¯ãã¬ãŒã ã«ã¯ãããŒã«ã«å€æ°ãéé¿ããã¬ãžã¹ã¿ã7ã€ç®ä»¥éã®åŒæ°ãªã©ãæ ŒçŽãããŸãã
%fp
(%i6
) ã¯ãåã®ãã¬ãŒã ãæããã¬ãŒã ãã€ã³ã¿ãšããŠæ©èœãããããã°ãªã©ã«åœ¹ç«ã¡ãŸããsave
åœä»€ã¯ãå€ã%sp
ãæ°ãã%fp
ã«èªåçã«ã³ããŒããŸãã- æå°ã¹ã¿ãã¯ãã¬ãŒã ãµã€ãº (SPARC V9 ABIã§ã¯éåžž96ãã€ããªã©) ãå®ããããŠããŸããããã«ã¯åŒæ°éé¿é åãã¬ãžã¹ã¿éé¿é åãªã©ãå«ãŸããŸãã
é«äœã¢ãã¬ã¹ +-------------------+ <-- [%fp + ãªãã»ãã] (åã®ãã¬ãŒã ã®åŒæ°ãªã©) | ... | +-------------------+ <-- %fp (åã® %sp) | ããŒã«ã«å€æ° | | ã¬ãžã¹ã¿éé¿é å | | ... | +-------------------+ <-- %sp + 92 (7çªç®ã®åŒæ°) | åŒæ°éé¿é å(6åå)| +-------------------+ <-- %sp + 68 (æ§é äœæ»ãå€ãã€ã³ã¿çš) | ... (Hidden param)| +-------------------+ <-- %sp (çŸåšã®ã¹ã¿ãã¯ããã) äœäœã¢ãã¬ã¹
- é¢æ°ã¯éåžžã
ãããã®èŠçŽãç解ããéµå®ããããšã§ãã¢ã»ã³ããªèšèªã§æžãããã³ãŒããšãCèšèªãªã©ã®é«æ°Žæºèšèªã§æžãããã³ãŒããšãçžäºã«åŒã³åºãããšãå¯èœã«ãªããŸãã
ð°ïž SPARCã®çŸåšãšæŽå²çæ矩
SPARCã¢ãŒããã¯ãã£ã¯ã1980幎代åŸåãã2000幎代ã«ãããŠãç¹ã«UNIXã¯ãŒã¯ã¹ããŒã·ã§ã³ããµãŒããŒåžå Žã§å€§ããªæåãåããŸãããSun Microsystemsã®äž»å補åã©ã€ã³ãæ¯ããSolaris OSãšå ±ã«ãå€ãã®äŒæ¥ãç 究æ©é¢ã§å©çšãããŸãããð
ããããx86ã¢ãŒããã¯ãã£ïŒIntelãAMDïŒã®æ§èœåäžãšäœäŸ¡æ ŒåããããŠè¿å¹Žã§ã¯ARMã¢ãŒããã¯ãã£ã®å°é ã«ãããSPARCã®åžå Žã·ã§ã¢ã¯åŸã ã«çž®å°ããŠãããŸãããOracleã«ããSunè²·ååŸãSPARC/Solarisã®éçºã¯ç¶ç¶ãããŸããããåè¿°ã®éããOracleã«ããæ°èŠSPARCããã»ããµéçºã¯2017幎é ã«çµäºããŸããã
äžæ¹ã§ãå¯å£«éã¯SPARC64ã¢ãŒããã¯ãã£ã®éçºãç¶ããã¡ããŒã³ã¢åãé«æ§èœåãé²ããŠããŸãããç¹ã«ãã¹ãŒããŒã³ã³ãã¥ãŒã¿åéã§ã¯ãçååŠç 究æã®ã京ãã³ã³ãã¥ãŒã¿ïŒSPARC64 VIIIfxæèŒã2011幎皌åéå§ïŒãããã®åŸç¶æ©ã§ãããå¯å²³ãïŒARMããŒã¹ã®A64FXæèŒã2020幎é ãã皌åïŒã®éçºã«ãããŠãSPARCã§å¹ãããæè¡ãçµéšã掻ããããŠããŸãããã ãããå¯å²³ãã®CPUã³ã¢èªäœã¯ARMã¢ãŒããã¯ãã£ãæ¡çšããŠãããSPARCããã®çŽæ¥çãªç§»è¡ã§ã¯ãããŸãããå¯å£«éã®SPARCãµãŒããŒè£œåããçŸåšã§ã¯ã¡ã€ã³ãã¬ãŒã ããã®ç§»è¡å ãªã©ãç¹å®ã®éèŠã«å¿ãã圢ã§ã®æäŸãäžå¿ãšãªã£ãŠããŸãã
SPARCã®æŽå²çæ矩ã¯å€§ããã§ããRISCèšèšææ³ãæ©æã«æ¡çšããåçšçã«æåãããããšãã¬ãžã¹ã¿ã»ãŠã£ã³ããŠã®ãããªãŠããŒã¯ãªæ©æ§ãå°å ¥ããããšããªãŒãã³ã¢ãŒããã¯ãã£ãšããŠè€æ°ã®ãã³ããŒã«ãã競äºãä¿ããããšãªã©ãæããããŸããçŸä»£ã®ããã»ããµèšèšã«ãããŠããSPARCã®è©Šã¿ããåŸãããæèšïŒäŸãã°ãé 延åå²ã®æå¹æ§ãã¬ãžã¹ã¿ã»ãŠã£ã³ããŠã®éçãªã©ïŒã¯åèã«ãããŠããŸãã
çŸåšãSPARCã¢ã»ã³ããªãç©æ¥µçã«åŠã¶å¿ èŠæ§ã¯éå®çãããããŸããããã³ã³ãã¥ãŒã¿ã¢ãŒããã¯ãã£ã®é²åãç解ããäžã§ããŸãç¹å®ã®ã¬ã¬ã·ãŒã·ã¹ãã ãçµã¿èŸŒã¿ã·ã¹ãã ãæ±ãäžã§ããã®ç¥èã¯äŸç¶ãšããŠäŸ¡å€ãæã¡ãŸããâš
ð ãŸãšã
ãã®èšäºã§ã¯ãSPARCã¢ã»ã³ããªèšèªã®å ¥éãšããŠã以äžã®å 容ã解説ããŸããã
- SPARCã¢ãŒããã¯ãã£ã®æŠèŠãšç¹åŸŽïŒRISC, ã¬ãžã¹ã¿ã»ãŠã£ã³ããŠïŒ
- æ±çšã¬ãžã¹ã¿ãç¹æ®ã¬ãžã¹ã¿ãã¬ãžã¹ã¿ã»ãŠã£ã³ããŠã®ä»çµã¿
- åºæ¬çãªSPARCåœä»€ïŒLoad/Store, æŒç®, è«ç, ã·ãã, å¶åŸ¡è»¢éïŒ
- ç°¡åãªã³ãŒãäŸïŒåŒæ°ãåãåãåèšãè¿ãé¢æ°ïŒ
- åŒã³åºãèŠçŽã®æŠèŠïŒåŒæ°ãæ»ãå€ãã¬ãžã¹ã¿ä¿åãã¹ã¿ãã¯ãã¬ãŒã ïŒ
- SPARCã®æŽå²ãšçŸåšã®ç¶æ³
SPARCã¢ã»ã³ããªã¯ãã¬ãžã¹ã¿ã»ãŠã£ã³ããŠãé 延åå²ãšãã£ãç¹åŸŽçãªèŠçŽ ãæã¡ãäœã¬ã€ã€ãŒã§ã®ããã»ããµåäœãæ·±ãç解ããããã®è¯ãé¡æãšãªããŸãããã®èšäºããSPARCãã³ã³ãã¥ãŒã¿ã¢ãŒããã¯ãã£ãžã®èå³ãæ·±ããäžå©ãšãªãã°å¹žãã§ããð
ããã«æ·±ãåŠã¶ããã«ã¯ãSPARCã¢ãŒããã¯ãã£ã®ããã¥ã¢ã«ããSolaris/Linuxäžã§ã®ã¢ã»ã³ããªããã°ã©ãã³ã°ã«é¢ããããã¥ã¡ã³ããåç §ããããšããå§ãããŸãã
ð åèæ å ±
ãã詳现ãªæ å ±ã«ã€ããŠã¯ã以äžã®è³æãªã©ãåèã«ãªããŸãã
- The SPARC Architecture Manual, Version 8: SPARC V8ã¢ãŒããã¯ãã£ã®å ¬åŒä»æ§æžã (泚: çŸåšãå ¬åŒã®é åžå ããã®å ¥æãå°é£ãªå ŽåããããŸããWebæ€çŽ¢ãªã©ã§èŠã€ããå¿ èŠããããããããŸããã)
- SPARC V9 Architecture Manual: SPARC V9 (64ããã) ã¢ãŒããã¯ãã£ã®ä»æ§æžã (泚: åäž)
- System V Application Binary Interface – SPARC Processor Supplement: SPARCã«ãããåŒã³åºãèŠçŽãªã©ã®ABIä»æ§ã (泚: åäžãæ€çŽ¢ãšã³ãžã³ã§ “SPARC System V ABI” ãªã©ã§æ€çŽ¢ãããšãé¢é£ããã¥ã¡ã³ããèŠã€ããããšããããŸãã)
ã³ã¡ã³ã