64-Bit Architectures

Download Report

Transcript 64-Bit Architectures

CS 105
“Tour of the Black Holes of Computing!”
64-Bit Architectures
Topics



64-bit data
New registers and instructions
Calling conventions
Data Representations: IA32 +
x86-64
Sizes of C Objects (in Bytes)
C Data Type
Typical 32-bit
 unsigned
 int
 long int
 char
 short
 float
 double
 long double
 char *
4
4
4
1
2
4
8
8
4
Intel IA32
x86-64
4
4
4
1
2
4
8
10/12
4
4
4
8
1
2
4
8
16
8
Or any other pointer
–2–
CS 105
x86-64 Integer Registers
%rax
%eax
ah
%axal
%r8
%r8d
r8b
%r8w
%rbx
%ebx
bh
%bxbl
%r9
%r9d
r9b
%r9w
%rcx
%ecx
ch
%cxcl
%r10
r10b
%r10d
%r10w
%rdx
%edx
dh
%dxdl
%r11
r11b
%r11d
%r11w
%rsi
%esi%sisil
%r12
r12b
%r12d
%r12w
%rdi
%edi%didil
%r13
r13b
%r13d
%r13w
%rsp
%esp%sp
spl
%r14
r14b
%r14d
%r14w
%rbp
%ebp%bp
bpl
%r15
r15b
%r15d
%r15w

–3– 
Extend existing registers. Add 8 new ones.
Make %ebp/%rbp general purpose
CS 105
x86-64 Integer Registers
%rax
%eax
%r8
%r8d
%rbx
%ebx
%r9
%r9d
%rcx
%ecx
%r10
%r10d
%rdx
%edx
%r11
%r11d
%rsi
%esi
%r12
%r12d
%rdi
%edi
%r13
%r13d
%rsp
%esp
%r14
%r14d
%rbp
%ebp
%r15
%r15d

–4– 
Extend existing registers. Add 8 new ones.
Make %ebp/%rbp general purpose
CS 105
Instructions
Long word l (4 Bytes) ↔ Quad word q (8 Bytes)
New instructions:

movl → movq
addl → addq
sall → salq
movzbq, movslq

etc.



32-bit instructions that generate 32-bit results


–5–
Set higher order bits of destination register to 0
Example: addl, movl (thus no movzlq)
CS 105
Swap in 32-bit Mode
void swap(int *xp, int *yp)
{
int t0 = *xp;
int t1 = *yp;
*xp = t1;
*yp = t0;
}
swap:
pushl %ebp
movl %esp,%ebp
pushl %ebx
movl
movl
movl
movl
movl
movl
12(%ebp),%ecx
8(%ebp),%edx
(%ecx),%eax
(%edx),%ebx
%eax,(%edx)
%ebx,(%ecx)
movl -4(%ebp),%ebx
movl %ebp,%esp
popl %ebp
ret
–6–
Setup
Body
Finish
CS 105
Swap in 64-bit Mode
void swap(int *xp, int *yp)
{
int t0 = *xp;
int t1 = *yp;
*xp = t1;
*yp = t0;
}
swap:
movl
movl
movl
movl
retq
(%rdi), %edx
(%rsi), %eax
%eax, (%rdi)
%edx, (%rsi)
Operands passed in registers (why useful?)

First (xp) in %rdi, second (yp) in %rsi

64-bit pointers
No stack operations required
32-bit data

–7–

Data held in registers %eax and %edx
movl operation
CS 105
Swap Long Ints in 64-bit Mode
void swap_l
(long int *xp, long int *yp)
{
long int t0 = *xp;
long int t1 = *yp;
*xp = t1;
*yp = t0;
}
swap_l:
movq
movq
movq
movq
retq
(%rdi), %rdx
(%rsi), %rax
%rax, (%rdi)
%rdx, (%rsi)
64-bit data

Data held in registers %rax and %rdx
movq operation

Otherwise same

–8–
CS 105
New Calling Conventions
Most procedures no longer need stack frame
First six arguments passed in registers
Register %rbp available for general use
Stack frame accessed via %rsp
128 bytes below %rsp usable by function (“red zone”)
–9–
CS 105