ultrasparc. ultrasparc data types byte halfword word doubleword quadword

38
UltraSPARC

Upload: jakayla-corell

Post on 14-Dec-2015

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

UltraSPARC

Page 2: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

UltraSPARC data types

• byte• halfword• word• doubleword• quadword

Page 3: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

UltraSPARC

• big endian• fixed length instructions (1 word / 4 bytes

each)• label:opcode src, dst !comment

Page 4: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

UltraSPARC registers

• 32 “general” purpose registers (%r0..%r31)

• 4 groups of 8 each:– %g0..%g7– %o0..%o7– %l0..%l7– %i0..%i7

Page 5: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

UltraSPARC registers

• 32 “general” purpose registers (%r0..%r31)

• %g0..%g7– same as %r0..%r7– globals– %g0 is always 0. It cannot be changed.– There is only one set of (shared) global registers.

Page 6: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

UltraSPARC registers

• 32 “general” purpose registers (%r0..%r31)

• %o0..%o7 (note: letter oh)– same as %r8..%r15– outs

• for arguments passed to functions called by the current function

• %o0 is the first arg, %o1 is the second, …

– %o6 = %sp– %o7 is used for return address (do not use)

Page 7: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

UltraSPARC registers

• 32 “general” purpose registers (%r0..%r31)

• %l0..%l7 (note: letter ell)– same as %r16..%r23– locals (for function local variables)– %i6 = %fp– %i7 used for return address (do not use)

Page 8: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

UltraSPARC registers

• 32 “general” purpose registers (%r0..%r31)

• %i0..%i7– same as %r24..%r31– ins• arguments coming into this function• %i0 is the first arg, %i1 is the second, …

– %i0 is also used to return value to caller

Page 9: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

More registers

• Actually, there are many more than 32 register.– There is only one set of global registers, shared by all.– There are 2..32 other sets of 16 registers (32..512

registers).– At any time, you have a “window” into these sets.– %l0..%l7 and %i0..%i7 (%r16..%r31) are the current set.– %o0..%o7 (%r8..%r15) are the in registers from the next

set.– SAVE/RESTORE instructions switch to the next/previous

set.

Page 10: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword
Page 11: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword
Page 12: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Special purpose registers

• %psr - processor status register• %pc - holds the address of the instruction

which is currently being executed• %npc - holds the address of the instruction

which is currently being fetched and which will be executed next

• And many others.

Page 13: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Comments!======================================================================/*file: simple.sdate: 6-dec-2008author: george j. grevera, ph.d.description: example "hello world" program in sparc assembler.build: gcc -mcpu=ultrasparc -o simple.exe simple.s

Note: Add -v to above to see separate assemble/link steps.run: ./simple.exedebug: mdb ./simple.exe*/!======================================================================

Page 14: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Defining symbols and data.file "simple.s"

!symbol definitionsSSIZE = 112 !minimum stack allocation size!read-only data definitions

.section ".rodata"

.align 8msg: .asciz "\nhello, world!\n\n"!read-write data definitions

.section ".data"

.align 8val:.word 12

Page 15: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Code

!code.section ".text".align 4.global main

main:save %sp, -SSIZE, %sp !allocate _required_ temp storage on! stack. 96 is the minimum amount to allocate.

set msg, %o0 !load address of message.! actually a "synthetic" instruction which! translates into two instructions below:! sethi %hi(msg), %o0! or %o0, %lo(msg), %o0call printf !call function to output the message.! 1 out reg used as an arg.! (in general, args may be in %o0..%o5)nop !delay instruction (actually done before call!)! (comment this out and see what happens)

ret !return from mainrestore !restore old set of registers (delay slot)

Page 16: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Basic instructions

Loads:• ldsb [addr], rd !load signed byte• ldsh [addr], rd !ld signed halfword• ldub [addr], rd !ld unsigned byte• lduh [addr], rd !ld unsigned halfword• ld [addr], rd !ld word• ldd [addr], rd !ld doubleword

! rd must be even

Page 17: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Basic instructions

Stores:• stb rs, [addr] !store byte• sth rs, [addr] !st halfword• st rs, [addr] !st word• std rs, [addr] !st doubleword

! rs must be even

Page 18: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Basic instructions

• add rs, reg_or_imm, rd• addcc rs, reg_or_imm, rd !add w/ mod

cc

• sub rs, reg_or_imm, rd• subcc rs, reg_or_imm, rd !sub w/ mod

cc

Page 19: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Basic instructions

• and rs, reg_or_imm, rd• andcc rs, reg_or_imm, rd !and w/ mod cc

• or rs, reg_or_imm, rd• orcc rs, reg_or_imm, rd !or w/ mod cc

• xor rs, reg_or_imm, rd• xorccrs, reg_or_imm, rd !xor w/ mod cc

Page 20: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Basic instructions

• sdiv rs, reg_or_imm, rd !signed• smul rs, reg_or_imm, rd

• udiv rs, reg_or_imm, rd !unsigned• umul rs, reg_or_imm, rd

Page 21: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Basic instructions

Page 22: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Basic instruction

• nop• ret

Page 23: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Synthetic instructions

• call reg_or_imm• cmp reg, reg_or_imm• dec rd• deccc rd !dec w/ mod cc• inc rd• inccc rd !inc w/ mod cc• mov reg_or_imm, rd• neg rd !2’s complement• not rd !1’s complement

Page 24: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Synthetic instructions

• restore• save rs, reg_or_imm, rd• set value, rd• tst rd

Page 25: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Operand addressing modes

Page 26: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

• Consider the following sequence of instructions:call fmov 52, %0

• Before the first instruction of printf can be executed, the mov instruction is already in the pipeline and execution of it has started.

Page 27: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

• Consider the following sequence of instructions:beq someLabelmov 52, %0

• If the branch is not taken, then the instruction after beq should be executed.

• If the branch is taken, then the instruction after beq should NOT be executed.

• Regardless, the mov instruction is already in the pipeline and execution of it has started.

Page 28: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

What should we do?

Options:1. Invalidate the next instruction in the pipeline

(and everything in the pipeline after the branch, or course).

2. Go ahead and execute the next instruction in the pipeline (the delay slot).

What’s the most efficient?

Page 29: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

What should we do?

Options:1. Invalidate the next instruction in the pipeline

(and everything in the pipeline after the branch, or course).

2. Go ahead and execute the next instruction in the pipeline (the delay slot).

What’s the most efficient?

Page 30: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

#1 rule: You must ALWAYS fill the delay slot!#2 rule: Only fill the delay slot w/ 1 instruction.• Consider the following sequence of

instructions:call fcall g

• What must be done? (See rule #1.)

Page 31: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

#1 rule: You must ALWAYS fill the delay slot!#2 rule: Only fill the delay slot w/ 1 instruction!• Consider the following sequence of instructions:

call fnopcall gnop

• Should we always fill the delay slot w/ NOP?

Page 32: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

• Should we always fill the delay slot w/ NOP?• What happens if we don’t? Recall our example:

save %sp, -SSIZE, %sp !allocate _required_ temp storage on! stack. 96 is the minimum amount to allocate.

set msg, %o0 !load address of message.! actually a "synthetic" instruction which! translates into two instructions below:! sethi %hi(msg), %o0! or %o0, %lo(msg), %o0

call printf !call function to output the message.! 1 out reg used as an arg.! (in general, args may be in %o0..%o5)

nop !delay instruction (actually done before call!)! (comment this out and see what happens)

ret !return from mainrestore !restore old set of registers (delay slot)

What happens if we remove this nop?

Page 33: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

• Should we always fill the delay slot w/ NOP?• What happens if we don’t? Recall our example:

save %sp, -SSIZE, %sp !allocate _required_ temp storage on! stack. 96 is the minimum amount to allocate.

set msg, %o0 !load address of message.! actually a "synthetic" instruction which! translates into two instructions below:! sethi %hi(msg), %o0! or %o0, %lo(msg), %o0

call printf !call function to output the message.! 1 out reg used as an arg.! (in general, args may be in %o0..%o5)

!nop !delay instruction (actually done before call!)! (comment this out and see what happens)

ret !return from mainrestore !restore old set of registers (delay slot)

ret fills the delay slot and is executed before printf so NOTHING is printed!

Page 34: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

• Let’s try to fill the delay slot with something useful.

save %sp, -SSIZE, %sp !allocate _required_ temp storage on! stack. 96 is the minimum amount to allocate.

call printf !call function to output the message.! 1 out reg used as an arg.! (in general, args may be in %o0..%o5)

set msg, %o0 !load address of message.! actually a "synthetic" instruction which! translates into two instructions below:! sethi %hi(msg), %o0! or %o0, %lo(msg), %o0

ret !return from mainrestore !restore old set of registers (delay slot)

This is something useful. What happens now?

Page 35: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

• Let’s try to fill the delay slot with something useful.

save %sp, -SSIZE, %sp !allocate _required_ temp storage on! stack. 96 is the minimum amount to allocate.

call printf !call function to output the message.! 1 out reg used as an arg.! (in general, args may be in %o0..%o5)

set msg, %o0 !load address of message.! actually a "synthetic" instruction which! translates into two instructions below:! sethi %hi(msg), %o0! or %o0, %lo(msg), %o0

ret !return from mainrestore !restore old set of registers (delay slot)

bash-3.00$ gcc simple3.s

/usr/ccs/bin/as: "simple3.s", line 38: warning: 2-word "set" pseudo-instruction in delay slot (follows CTI)

Page 36: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

• Let’s try to fill the delay slot with something useful.

save %sp, -SSIZE, %sp !allocate _required_ temp storage on! stack. 96 is the minimum amount to allocate.

call printf !call function to output the message.! 1 out reg used as an arg.! (in general, args may be in %o0..%o5)

set msg, %o0 !load address of message.! actually a "synthetic" instruction which! translates into two instructions below:! sethi %hi(msg), %o0! or %o0, %lo(msg), %o0

ret !return from mainrestore !restore old set of registers (delay slot)

So what should we do – back to nop?

Page 37: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

• Let’s try to fill the delay slot with something useful.

save %sp, -SSIZE, %sp !allocate _required_ temp storage on! stack. 96 is the minimum amount to allocate.

call printf !call function to output the message.! 1 out reg used as an arg.! (in general, args may be in %o0..%o5)

set msg, %o0 !load address of message.! actually a "synthetic" instruction which! translates into two instructions below:! sethi %hi(msg), %o0! or %o0, %lo(msg), %o0

ret !return from mainrestore !restore old set of registers (delay slot)

So what should we do – back to nop?

Page 38: UltraSPARC. UltraSPARC data types byte halfword word doubleword quadword

Pipeline and delay slot

• Let’s try to fill the delay slot with something useful.

save %sp, -SSIZE, %sp !allocate _required_ temp storage on! stack. 96 is the minimum amount to allocate.

sethi %hi(msg), %o0 !load addr of messagecall printf !call function to output the message.

! 1 out reg used as an arg.! (in general, args may be in %o0..%o5)

or %o0, %lo(msg), %o0 !delay slot – finish loading addr of message

ret !return from mainrestore !restore old set of registers (delay slot)

This works well!