Systemnahe Programmierung in C: Parameterübergabe von Strukturen |
1typedef struct
2{
3 double re;
4 double im;
5}
6Complex;
7
8Complex
9times (Complex x, Complex y)
10{
11 Complex res;
12
13 res.re = x.re * y.re + x.im * y.im;
14 res.im = x.re * y.im + x.im * y.re;
15
16 return res;
17}
18
19void
20mult (Complex * x, Complex * y, Complex * res)
21{
22 res->re = x->re * y->re - x->im * y->im;
23 res->im = x->re * y->im + x->im * y->re;
24}
25
26Complex a = { 1.0, 1.0 };
27Complex b = { 2.0, 0.0 };
28
29void
30test1 (void)
31{
32 Complex r;
33
34 r = times (a, b);
35}
36
37void
38test2 (void)
39{
40 Complex r;
41
42 mult (&a, &b, &r);
43}
44
45void
46test3 (void)
47{
48 /* no comment */
49 mult (&a, &a, &a);
50}
|
1 times:
2 pushq %rbp
3 movq %rsp, %rbp
4 movapd %xmm1, %xmm4
5 movapd %xmm3, %xmm1
6 movsd %xmm0, -48(%rbp)
7 movsd %xmm4, -40(%rbp)
8 movsd %xmm2, -64(%rbp)
9 movsd %xmm1, -56(%rbp)
10 movsd -48(%rbp), %xmm1
11 movsd -64(%rbp), %xmm0
12 mulsd %xmm0, %xmm1
13 movsd -40(%rbp), %xmm2
14 movsd -56(%rbp), %xmm0
15 mulsd %xmm2, %xmm0
16 addsd %xmm1, %xmm0
17 movsd %xmm0, -32(%rbp)
18 movsd -48(%rbp), %xmm1
19 movsd -56(%rbp), %xmm0
20 mulsd %xmm0, %xmm1
21 movsd -40(%rbp), %xmm2
22 movsd -64(%rbp), %xmm0
23 mulsd %xmm2, %xmm0
24 addsd %xmm1, %xmm0
25 movsd %xmm0, -24(%rbp)
26 movq -32(%rbp), %rax
27 movq %rax, -16(%rbp)
28 movq -24(%rbp), %rax
29 movq %rax, -8(%rbp)
30 movq -16(%rbp), %rdx
31 movq -8(%rbp), %rax
32 movq %rdx, -88(%rbp)
33 movsd -88(%rbp), %xmm0
34 movq %rax, -88(%rbp)
35 movsd -88(%rbp), %xmm1
36 popq %rbp
37 ret
38 mult:
39 pushq %rbp
40 movq %rsp, %rbp
41 movq %rdi, -8(%rbp)
42 movq %rsi, -16(%rbp)
43 movq %rdx, -24(%rbp)
44 movq -8(%rbp), %rax
45 movsd (%rax), %xmm1
46 movq -16(%rbp), %rax
47 movsd (%rax), %xmm0
48 mulsd %xmm1, %xmm0
49 movq -8(%rbp), %rax
50 movsd 8(%rax), %xmm2
51 movq -16(%rbp), %rax
52 movsd 8(%rax), %xmm1
53 mulsd %xmm2, %xmm1
54 subsd %xmm1, %xmm0
55 movq -24(%rbp), %rax
56 movsd %xmm0, (%rax)
57 movq -8(%rbp), %rax
58 movsd (%rax), %xmm1
59 movq -16(%rbp), %rax
60 movsd 8(%rax), %xmm0
61 mulsd %xmm0, %xmm1
62 movq -8(%rbp), %rax
63 movsd 8(%rax), %xmm2
64 movq -16(%rbp), %rax
65 movsd (%rax), %xmm0
66 mulsd %xmm2, %xmm0
67 addsd %xmm1, %xmm0
68 movq -24(%rbp), %rax
69 movsd %xmm0, 8(%rax)
70 popq %rbp
71 ret
72 a:
73 b:
74 test1:
75 pushq %rbp
76 movq %rsp, %rbp
77 subq $32, %rsp
78 movsd b(%rip), %xmm2
79 movsd b+8(%rip), %xmm3
80 movsd a(%rip), %xmm0
81 movsd a+8(%rip), %xmm1
82 call times
83 movsd %xmm0, -32(%rbp)
84 movsd %xmm1, -24(%rbp)
85 movq -32(%rbp), %rax
86 movq %rax, -16(%rbp)
87 movq -24(%rbp), %rax
88 movq %rax, -8(%rbp)
89 leave
90 ret
91 test2:
92 pushq %rbp
93 movq %rsp, %rbp
94 subq $16, %rsp
95 leaq -16(%rbp), %rax
96 movq %rax, %rdx
97 movl $b, %esi
98 movl $a, %edi
99 call mult
100 leave
101 ret
102 test3:
103 pushq %rbp
104 movq %rsp, %rbp
105 movl $a, %edx
106 movl $a, %esi
107 movl $a, %edi
108 call mult
109 popq %rbp
110 ret
|
Letzte Änderung: 11.01.2007 | © Prof. Dr. Uwe Schmidt |