ObjFW  Diff

Differences From Artifact [567ef57186]:

To Artifact [036198eaf0]:


33
34
35
36
37
38
39

40
41
42
43
44
45
46
#define NUM_SSE_IN 8
#define NUM_X87_OUT 2

enum {
	RETURN_TYPE_NORMAL,
	RETURN_TYPE_STRUCT,
	RETURN_TYPE_X87,

	RETURN_TYPE_JMP,
	RETURN_TYPE_JMP_STRET
};

struct call_context {
	uint64_t gpr[NUM_GPR_IN + NUM_GPR_OUT];
	__m128 sse[NUM_SSE_IN];







>







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#define NUM_SSE_IN 8
#define NUM_X87_OUT 2

enum {
	RETURN_TYPE_NORMAL,
	RETURN_TYPE_STRUCT,
	RETURN_TYPE_X87,
	RETURN_TYPE_COMPLEX_X87,
	RETURN_TYPE_JMP,
	RETURN_TYPE_JMP_STRET
};

struct call_context {
	uint64_t gpr[NUM_GPR_IN + NUM_GPR_OUT];
	__m128 sse[NUM_SSE_IN];
142
143
144
145
146
147
148






















149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
		    sizeof(**context) + ((*context)->stack_size + 2) * 8];
	}

	memcpy(&newContext->stack[newContext->stack_size], &value, 16);
	newContext->stack_size += 2;
	*context = newContext;
}























#if defined(__SIZEOF_INT128__) && !defined(__clang__)
static void
pushInt128(struct call_context **context, uint_fast8_t *currentGPR,
    uint64_t low, uint64_t high)
{
	size_t stackSize;
	struct call_context *newContext;

	if (*currentGPR + 1 < NUM_GPR_IN) {
		(*context)->gpr[(*currentGPR)++] = low;
		(*context)->gpr[(*currentGPR)++] = high;
		return;
	}

	stackSize = OF_ROUND_UP_POW2(2, (*context)->stack_size) + 2;

	if ((newContext = realloc(*context,
	    sizeof(**context) + stackSize * 8)) == NULL) {
		free(*context);
		@throw [OFOutOfMemoryException exceptionWithRequestedSize:
		    sizeof(**context) + stackSize * 8];
	}

	memset(&newContext->stack[newContext->stack_size], '\0',
	    (stackSize - newContext->stack_size) * 8);
	newContext->stack[stackSize - 2] = low;
	newContext->stack[stackSize - 1] = high;
	newContext->stack_size = stackSize;
	*context = newContext;
}
#endif

void
of_invocation_invoke(OFInvocation *invocation)







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




|





|
|














|
<







143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
		    sizeof(**context) + ((*context)->stack_size + 2) * 8];
	}

	memcpy(&newContext->stack[newContext->stack_size], &value, 16);
	newContext->stack_size += 2;
	*context = newContext;
}

static void
pushLongDoublePair(struct call_context **context, long double value[2])
{
	size_t stackSize;
	struct call_context *newContext;

	stackSize = OF_ROUND_UP_POW2(2, (*context)->stack_size) + 4;

	if ((newContext = realloc(*context,
	    sizeof(**context) + stackSize * 8)) == NULL) {
		free(*context);
		@throw [OFOutOfMemoryException exceptionWithRequestedSize:
		    sizeof(**context) + stackSize * 8];
	}

	memset(&newContext->stack[newContext->stack_size], '\0',
	    (stackSize - newContext->stack_size) * 8);
	memcpy(&newContext->stack[stackSize - 4], value, 32);
	newContext->stack_size = stackSize;
	*context = newContext;
}

#if defined(__SIZEOF_INT128__) && !defined(__clang__)
static void
pushInt128(struct call_context **context, uint_fast8_t *currentGPR,
    uint64_t value[2])
{
	size_t stackSize;
	struct call_context *newContext;

	if (*currentGPR + 1 < NUM_GPR_IN) {
		(*context)->gpr[(*currentGPR)++] = value[0];
		(*context)->gpr[(*currentGPR)++] = value[1];
		return;
	}

	stackSize = OF_ROUND_UP_POW2(2, (*context)->stack_size) + 2;

	if ((newContext = realloc(*context,
	    sizeof(**context) + stackSize * 8)) == NULL) {
		free(*context);
		@throw [OFOutOfMemoryException exceptionWithRequestedSize:
		    sizeof(**context) + stackSize * 8];
	}

	memset(&newContext->stack[newContext->stack_size], '\0',
	    (stackSize - newContext->stack_size) * 8);
	memcpy(&newContext->stack[stackSize - 2], value, 16);

	newContext->stack_size = stackSize;
	*context = newContext;
}
#endif

void
of_invocation_invoke(OFInvocation *invocation)
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
		CASE_GPR('@', uintptr_t)
		CASE_GPR('#', uintptr_t)
		CASE_GPR(':', uintptr_t)
		CASE_GPR('^', uintptr_t)
#ifdef __SIZEOF_INT128__
		case 't':
		case 'T':;
			struct {
				uint64_t low, high;
			} int128Tmp;
			[invocation getArgument: &int128Tmp
					atIndex: i];
# ifndef __clang__
			pushInt128(&context, &currentGPR,
			    int128Tmp.low, int128Tmp.high);
# else
			/* See https://bugs.llvm.org/show_bug.cgi?id=34646 */
			pushGPR(&context, &currentGPR, int128Tmp.low);
			pushGPR(&context, &currentGPR, int128Tmp.high);
# endif
			break;
#endif
		case 'f':;
			float floatTmp;
			[invocation getArgument: &floatTmp
					atIndex: i];







<
<
|



|
<


|
|







244
245
246
247
248
249
250


251
252
253
254
255

256
257
258
259
260
261
262
263
264
265
266
		CASE_GPR('@', uintptr_t)
		CASE_GPR('#', uintptr_t)
		CASE_GPR(':', uintptr_t)
		CASE_GPR('^', uintptr_t)
#ifdef __SIZEOF_INT128__
		case 't':
		case 'T':;


			uint64_t int128Tmp[2];
			[invocation getArgument: &int128Tmp
					atIndex: i];
# ifndef __clang__
			pushInt128(&context, &currentGPR, int128Tmp);

# else
			/* See https://bugs.llvm.org/show_bug.cgi?id=34646 */
			pushGPR(&context, &currentGPR, int128Tmp[0]);
			pushGPR(&context, &currentGPR, int128Tmp[1]);
# endif
			break;
#endif
		case 'f':;
			float floatTmp;
			[invocation getArgument: &floatTmp
					atIndex: i];
272
273
274
275
276
277
278
279






280
281
282
283
284
285
286
			case 'd':;
				double complexDoubleTmp[2];
				[invocation getArgument: &complexDoubleTmp
						atIndex: i];
				pushQuad(&context, &currentSSE,
				    complexDoubleTmp[0], complexDoubleTmp[1]);
				break;
			/* TODO: 'D' */






			default:
				free(context);
				@throw [OFInvalidFormatException exception];
			}

			break;
#endif







|
>
>
>
>
>
>







291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
			case 'd':;
				double complexDoubleTmp[2];
				[invocation getArgument: &complexDoubleTmp
						atIndex: i];
				pushQuad(&context, &currentSSE,
				    complexDoubleTmp[0], complexDoubleTmp[1]);
				break;
			case 'D':;
				long double complexLongDoubleTmp[2];
				[invocation getArgument: &complexLongDoubleTmp
						atIndex: i];
				pushLongDoublePair(&context,
				    complexLongDoubleTmp);
				break;
			default:
				free(context);
				@throw [OFInvalidFormatException exception];
			}

			break;
#endif
330
331
332
333
334
335
336
337


338
339
340
341
342
343
344
#ifndef __STDC_NO_COMPLEX__
	case 'j':
		switch (typeEncoding[1]) {
		case 'f':
		case 'd':
			context->return_type = RETURN_TYPE_NORMAL;
			break;
		/* TODO: 'D' */


		default:
			free(context);
			@throw [OFInvalidFormatException exception];
		}

		break;
#endif







|
>
>







355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#ifndef __STDC_NO_COMPLEX__
	case 'j':
		switch (typeEncoding[1]) {
		case 'f':
		case 'd':
			context->return_type = RETURN_TYPE_NORMAL;
			break;
		case 'D':
			context->return_type = RETURN_TYPE_COMPLEX_X87;
			break;
		default:
			free(context);
			@throw [OFInvalidFormatException exception];
		}

		break;
#endif
408
409
410
411
412
413
414
415


416
417
418
419
420
421
422
				double complexDoubleTmp[2];
				_mm_store_sd(&complexDoubleTmp[0],
				    (__m128d)context->sse[0]);
				_mm_store_sd(&complexDoubleTmp[1],
				    (__m128d)context->sse[1]);
				[invocation setReturnValue: &complexDoubleTmp];
				break;
			/* TODO: 'D' */


			default:
				free(context);
				@throw [OFInvalidFormatException exception];
			}

			break;
#endif







|
>
>







435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
				double complexDoubleTmp[2];
				_mm_store_sd(&complexDoubleTmp[0],
				    (__m128d)context->sse[0]);
				_mm_store_sd(&complexDoubleTmp[1],
				    (__m128d)context->sse[1]);
				[invocation setReturnValue: &complexDoubleTmp];
				break;
			case 'D':
				[invocation setReturnValue: context->x87];
				break;
			default:
				free(context);
				@throw [OFInvalidFormatException exception];
			}

			break;
#endif