annotate dyncallback/dyncall_args_x64.c @ 537:804df3409b51

- callback fix for non-trivial aggregate return values: allowing access to caller-reserved space user is supposed to copy non-triv object into
author Tassilo Philipp
date Sat, 23 Apr 2022 16:28:47 +0200
parents c0df40c888ac
children 111236b31c75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: dyncallback
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: dyncallback/dyncall_args_x64.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description: Callback's Arguments VM - Implementation for x64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 #include "dyncall_args_x64.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
30 #include <assert.h>
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
31 #include <string.h>
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
32
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 static int64* arg_i64(DCArgs* args)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 {
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
36 args->reg_count.i += (args->reg_count.i == args->aggr_return_register);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
37
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 if (args->reg_count.i < numIntRegs)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 return &args->reg_data.i[args->reg_count.i++];
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 else
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 return args->stack_ptr++;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 static double* arg_f64(DCArgs* args)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 {
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
47 #if defined(DC_WINDOWS)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
48 args->reg_count.f += (args->reg_count.f == args->aggr_return_register);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
49 #endif
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 if (args->reg_count.f < numFloatRegs)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 return &args->reg_data.f[args->reg_count.f++];
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 else
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 return (double*)args->stack_ptr++;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 DClonglong dcbArgLongLong (DCArgs* p) { return *arg_i64(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 DCint dcbArgInt (DCArgs* p) { return (int) dcbArgLongLong(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 DClong dcbArgLong (DCArgs* p) { return (long) dcbArgLongLong(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 DCchar dcbArgChar (DCArgs* p) { return (char) dcbArgLongLong(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 DCshort dcbArgShort (DCArgs* p) { return (short) dcbArgLongLong(p); }
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
63 DCbool dcbArgBool (DCArgs* p) { return dcbArgInt(p) != 0; }
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 DCuint dcbArgUInt (DCArgs* p) { return (DCuint) dcbArgInt(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 DCuchar dcbArgUChar (DCArgs* p) { return (DCuchar) dcbArgChar(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 DCushort dcbArgUShort (DCArgs* p) { return (DCushort) dcbArgShort(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 DCulong dcbArgULong (DCArgs* p) { return (DCulong) dcbArgLong(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 DCulonglong dcbArgULongLong(DCArgs* p) { return (DCulonglong) dcbArgLongLong(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 DCpointer dcbArgPointer (DCArgs* p) { return (DCpointer) dcbArgLongLong(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 DCdouble dcbArgDouble (DCArgs* p) { return *arg_f64(p); }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 DCfloat dcbArgFloat (DCArgs* p) { return *(float*)arg_f64(p); }
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
76
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
77 void dcbArgAggr (DCArgs* p, DCpointer target)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
78 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
79 int i;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
80 DCaggr *ag = *(p->aggrs++);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
81
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
82 if(!ag) {
536
c0df40c888ac - dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents: 533
diff changeset
83 /* non-trivial aggr: retrieve as ptr, user is supposed to make copy */
c0df40c888ac - dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents: 533
diff changeset
84 target = dcbArgPointer(p);
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
85 return;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
86 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
87
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
88 #if defined(DC_UNIX)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
89 DCRegCount_x64 n_regs = { p->reg_count.i, p->reg_count.f };
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
90
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
91 if(ag->sysv_classes[0] != SYSVC_MEMORY) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
92 /* reclassify aggr w/ respect to remaining regs, might have been passed entirely via the stack */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
93 for(i=0; ag->sysv_classes[i] && i<DC_SYSV_MAX_NUM_CLASSES; ++i) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
94 DCuchar clz = ag->sysv_classes[i];
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
95 n_regs.i += (clz == SYSVC_INTEGER);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
96 n_regs.f += (clz == SYSVC_SSE);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
97 /* @@@AGGR implement when implementing x87 types */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
98 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
99 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
100
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
101 if(ag->sysv_classes[0] == SYSVC_MEMORY || (n_regs.i > numIntRegs) || (n_regs.f > numFloatRegs))
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
102 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
103 memcpy(target, p->stack_ptr, ag->size);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
104 p->stack_ptr = p->stack_ptr + ((ag->size + (sizeof(DClonglong)-1)) >> 3); // advance to next full stack slot
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
105 return;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
106 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
107
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
108
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
109 for(i=0; ag->sysv_classes[i] && i<DC_SYSV_MAX_NUM_CLASSES; ++i)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
110 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
111 switch (ag->sysv_classes[i])
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
112 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
113 case SYSVC_INTEGER: ((DClonglong*)target)[i] = dcbArgLongLong(p); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
114 case SYSVC_SSE: ((DCdouble *)target)[i] = dcbArgDouble (p); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
115 /* @@@AGGR implement when implementing x87 types */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
116 default:
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
117 assert(DC_FALSE && "Should never be reached because we check for unupported classes earlier");
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
118 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
119 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
120
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
121 #else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
122
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
123 switch (ag->size) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
124 case 1: *(DCchar *)target = dcbArgChar (p); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
125 case 2: *(DCshort *)target = dcbArgShort (p); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
126 case 4: *(DClong *)target = dcbArgLong (p); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
127 case 8: *(DClonglong*)target = dcbArgLongLong(p); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
128 default: memcpy(target, dcbArgPointer(p), ag->size); break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
129 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
130 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
131 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
132
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
133
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
134 /* A 16 byte struct would be sufficient for System V (because at most two of the four registers can be full). */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
135 /* But then it's much more complicated to copy the result to the correct registers in assembly. */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
136 typedef struct {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
137 DClonglong r[2]; /* rax, rdx */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
138 DCdouble x[2]; /* xmm0, xmm1 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
139 } DCRetRegs_SysV;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
140
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
141 void dcbReturnAggr(DCArgs *args, DCValue *result, DCpointer ret)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
142 {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
143 int i;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
144 DCaggr *ag = *(args->aggrs++);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
145
536
c0df40c888ac - dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents: 533
diff changeset
146 if(!ag) {
537
804df3409b51 - callback fix for non-trivial aggregate return values: allowing access to caller-reserved space user is supposed to copy non-triv object into
Tassilo Philipp
parents: 536
diff changeset
147 /* non-trivial aggr: all we can do is to provide the ptr to the output space, user has to make copy */
804df3409b51 - callback fix for non-trivial aggregate return values: allowing access to caller-reserved space user is supposed to copy non-triv object into
Tassilo Philipp
parents: 536
diff changeset
148 result->p = args->reg_data.i[0];
536
c0df40c888ac - dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents: 533
diff changeset
149 return;
c0df40c888ac - dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents: 533
diff changeset
150 }
c0df40c888ac - dyncallback fixes related to C++ non-trivial aggregates (not final, but fixing most obvious things I missed)
Tassilo Philipp
parents: 533
diff changeset
151
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
152 if (args->aggr_return_register >= 0) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
153 DCpointer dest = (DCpointer) args->reg_data.i[args->aggr_return_register];
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
154 memcpy(dest, ret, ag->size);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
155 result->p = dest;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
156 } else {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
157 #if defined(DC_UNIX)
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
158 /* a max of 2 regs are used in this case, out of rax, rdx, xmm0 and xmm1 */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
159 /* space for 4 qwords is pointed to by (DCRetRegs_SysV*)result */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
160 DClonglong *intRegs = ((DCRetRegs_SysV*)result)->r;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
161 DCdouble *sseRegs = ((DCRetRegs_SysV*)result)->x;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
162 for(i=0; ag->sysv_classes[i] && i<2/*guaranteed*/; ++i) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
163 switch (ag->sysv_classes[i]) {
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
164 case SYSVC_INTEGER: *(intRegs++) = ((DClonglong*)ret)[i]; break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
165 case SYSVC_SSE: *(sseRegs++) = ((DCdouble *)ret)[i]; break;
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
166 /* @@@AGGR implement when implementing x87 types, might lead to more than 2 regs (e.g. _m512) */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
167 default: assert(DC_FALSE && "Should never be reached because we check for unupported classes earlier");
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
168 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
169 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
170 #else
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
171 /* copy aggregate (guaranteed to be <= 8b by call conv, as no hidden ptr) into result */
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
172 assert(ag->size <= 8 && "aggregate info mismatch for return type");
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
173 memcpy(result, ret, ag->size);
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
174 #endif
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
175 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
176 }
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 281
diff changeset
177