orashi
cippus_sss
#include<stdio.h>
int main()
{
printf("hello, world\n");
}hello.c
main:
subq $8, %rsp
movl $.LCO, %edi
call puts
movl $0, %eax
addq $8, %rsp
retcharacter stream
token stream
token stream
syntax tree
syntax tree
syntax tree
int foo(unsigned int u) {
return (u > -1) ? 1 : 0;
}syntax tree
intermediate representation
intermediate representation
intermediate representation
intermediate representation
machine code
一个典型的系统硬件构成
Main memory Allocation
Single Contiguous Allocation
fixed-sized Allocation
dynamic storage allocation
Divide physical memory into fixed-sized blocks called frames
Divide logical memory into blocks of same size called pages
CPU Scheduling
Is x2 ≥ 0?
Float’s: Yes!
Int’s:
40000 * 40000 ➙ 1600000000
50000 * 50000 ➙ ??
typedef struct {
int a[2];
double d;
} struct_t;
double fun(int i) {
struct_t s;
s.d = 3.14;
s.a[i] = 1073741824; /* Possibly out of bounds */
return s.d;
}fun(0) ➙ 3.14
fun(1) ➙ 3.14
fun(2) ➙ 3.1399998664856
fun(3) ➙ 2.00000061035156
fun(4) ➙ 3.14
fun(6) ➙ Segmentation fault
§Result is system specific
typedef struct {
int a[2];
double d;
} struct_t;
double fun(int i) {
struct_t s;
s.d = 3.14;
s.a[i] = 1073741824; /* Possibly out of bounds */
return s.d;
}fun(0) ➙ 3.14
fun(1) ➙ 3.14
fun(2) ➙ 3.1399998664856
fun(3) ➙ 2.00000061035156
fun(4) ➙ 3.14
fun(6) ➙ Segmentation fault
Explanation:
void copyij(int src[2048][2048],
int dst[2048][2048])
{
int i,j;
for (i = 0; i < 2048; i++)
for (j = 0; j < 2048; j++)
dst[i][j] = src[i][j];
}void copyji(int src[2048][2048],
int dst[2048][2048])
{
int i,j;
for (j = 0; j < 2048; j++)
for (i = 0; i < 2048; i++)
dst[i][j] = src[i][j];
}4.3ms
81.8ms
2.1 GHz Intel Core i7 Haswell
Core i7 Haswell
2.1 GHz
32 KB L1 SRAM
256 KB L2 SRAM
8 MB L3 SRAM
終わり
By orashi