ObjFW  Check-in [1b96a21136]

Overview
Comment:invoke-x86_64.m: Add support for __int128
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1b96a2113633b477a9ee16b280e0d170bb03ae104134c113049a46ee85a53b4d
User & Date: js on 2017-09-15 00:03:02
Other Links: manifest | tags
Context
2017-09-16
19:11
OFInvocation: Support for invoking on x86_64/ELF check-in: 6d2f81aea9 user: js tags: trunk
2017-09-15
00:03
invoke-x86_64.m: Add support for __int128 check-in: 1b96a21136 user: js tags: trunk
2017-09-14
21:51
apple-call-x86_64.S: Add support for stret and jmp check-in: d6e5e6beb3 user: js tags: trunk
Changes

Modified src/invocation/invoke-x86_64.m from [8ed55a5c76] to [75aba7c79f].

147
148
149
150
151
152
153










154
155
156
157
158
159
160
		CASE_GPR('I', unsigned int)
		CASE_GPR('s', short)
		CASE_GPR('S', unsigned short)
		CASE_GPR('l', long)
		CASE_GPR('L', unsigned long)
		CASE_GPR('q', long long)
		CASE_GPR('Q', unsigned long long)










		case 'f':;
			float floatTmp;
			[invocation getArgument: &floatTmp
					atIndex: i];
			pushDouble(&context, &currentSSE, floatTmp);
			break;
		case 'd':;







>
>
>
>
>
>
>
>
>
>







147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
		CASE_GPR('I', unsigned int)
		CASE_GPR('s', short)
		CASE_GPR('S', unsigned short)
		CASE_GPR('l', long)
		CASE_GPR('L', unsigned long)
		CASE_GPR('q', long long)
		CASE_GPR('Q', unsigned long long)
#ifdef __SIZEOF_INT128__
		case 't':
		case 'T':;
			uint64_t int128Tmp[2];
			[invocation getArgument: int128Tmp
					atIndex: i];
			pushGPR(&context, &currentGPR, int128Tmp[0]);
			pushGPR(&context, &currentGPR, int128Tmp[1]);
			break;
#endif
		case 'f':;
			float floatTmp;
			[invocation getArgument: &floatTmp
					atIndex: i];
			pushDouble(&context, &currentSSE, floatTmp);
			break;
		case 'd':;
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
		/* TODO: '[' */
		/* TODO: '{' */
		/* TODO: '(' */
		CASE_GPR('^', uintptr_t)
#ifndef __STDC_NO_COMPLEX__
		/* TODO: 'j' */
#endif
#ifdef __SIZEOF_INT128__
		/* TODO: 't' */
		/* TODO: 'T' */
#endif
		default:
			free(context);
			@throw [OFInvalidFormatException exception];
#undef CASE_GPR
		}
	}








<
<
<
<







187
188
189
190
191
192
193




194
195
196
197
198
199
200
		/* TODO: '[' */
		/* TODO: '{' */
		/* TODO: '(' */
		CASE_GPR('^', uintptr_t)
#ifndef __STDC_NO_COMPLEX__
		/* TODO: 'j' */
#endif




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

204
205
206
207
208
209
210




211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
	case 'I':
	case 's':
	case 'S':
	case 'l':
	case 'L':
	case 'q':
	case 'Q':




	case 'f':
	case 'd':
	case 'B':
	case '*':
	case '@':
	case '#':
	case ':':
	case '^':
		context->return_type = RETURN_TYPE_NORMAL;
		break;
	case 'D':
		context->return_type = RETURN_TYPE_X87;
		break;
	/* TODO: '[' */
	/* TODO: '{' */
	/* TODO: '(' */
#ifndef __STDC_NO_COMPLEX__
	/* TODO: 'j' */
#endif
#ifdef __SIZEOF_INT128__
	/* TODO: 't' */
	/* TODO: 'T' */
#endif
	default:
		free(context);
		@throw [OFInvalidFormatException exception];
	}

	of_invocation_call(context);








>
>
>
>



















<
<
<
<







210
211
212
213
214
215
216
217
218
219
220
221
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
	case 'I':
	case 's':
	case 'S':
	case 'l':
	case 'L':
	case 'q':
	case 'Q':
#ifdef __SIZEOF_INT128__
	case 't':
	case 'T':
#endif
	case 'f':
	case 'd':
	case 'B':
	case '*':
	case '@':
	case '#':
	case ':':
	case '^':
		context->return_type = RETURN_TYPE_NORMAL;
		break;
	case 'D':
		context->return_type = RETURN_TYPE_X87;
		break;
	/* TODO: '[' */
	/* TODO: '{' */
	/* TODO: '(' */
#ifndef __STDC_NO_COMPLEX__
	/* TODO: 'j' */
#endif




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

	of_invocation_call(context);

252
253
254
255
256
257
258






259
260
261
262
263
264
265
		CASE_GPR('I', unsigned int)
		CASE_GPR('s', short)
		CASE_GPR('S', unsigned short)
		CASE_GPR('l', long)
		CASE_GPR('L', unsigned long)
		CASE_GPR('q', long long)
		CASE_GPR('Q', unsigned long long)






		case 'f':;
			float floatTmp;
			_mm_store_ss(&floatTmp, context->sse[0]);
			[invocation setReturnValue: &floatTmp];
			break;
		case 'd':;
			double doubleTmp;







>
>
>
>
>
>







258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
		CASE_GPR('I', unsigned int)
		CASE_GPR('s', short)
		CASE_GPR('S', unsigned short)
		CASE_GPR('l', long)
		CASE_GPR('L', unsigned long)
		CASE_GPR('q', long long)
		CASE_GPR('Q', unsigned long long)
#ifdef __SIZEOF_INT128__
		case 't':
		case 'T':;
			[invocation setReturnValue: &context->gpr[NUM_GPR_IN]];
			break;
#endif
		case 'f':;
			float floatTmp;
			_mm_store_ss(&floatTmp, context->sse[0]);
			[invocation setReturnValue: &floatTmp];
			break;
		case 'd':;
			double doubleTmp;
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
		/* TODO: '[' */
		/* TODO: '{' */
		/* TODO: '(' */
		CASE_GPR('^', uintptr_t)
#ifndef __STDC_NO_COMPLEX__
		/* TODO: 'j' */
#endif
#ifdef __SIZEOF_INT128__
		/* TODO: 't' */
		/* TODO: 'T' */
#endif
		default:
			free(context);
			@throw [OFInvalidFormatException exception];
#undef CASE_GPR
	}

	free(context);
}







<
<
<
<








289
290
291
292
293
294
295




296
297
298
299
300
301
302
303
		/* TODO: '[' */
		/* TODO: '{' */
		/* TODO: '(' */
		CASE_GPR('^', uintptr_t)
#ifndef __STDC_NO_COMPLEX__
		/* TODO: 'j' */
#endif




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

	free(context);
}

Modified tests/OFInvocationTests.m from [d5cabd9696] to [943b8e059c].

98
99
100
101
102
103
104











































105
106
107
108
109
110
111
				    : (long double)d14
				    : (long double)d15
				    : (long double)d16
{
	return (d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10 + d11 +
	    d12 + d13 + d14 + d15 + d16) / 16;
}












































- (void)invocationTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	SEL selector = @selector(invocationTestMethod1::::);
	OFMethodSignature *sig = [self methodSignatureForSelector: selector];
	OFInvocation *invocation;







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







98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
				    : (long double)d14
				    : (long double)d15
				    : (long double)d16
{
	return (d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 + d10 + d11 +
	    d12 + d13 + d14 + d15 + d16) / 16;
}

#ifdef __SIZEOF_INT128__
- (__int128)invocationTestMethod5: (__int128)i1
				 : (__int128)i2
				 : (int)i3	 /* to check alignment */
				 : (__int128)i4
				 : (__int128)i5
				 : (__int128)i6
				 : (__int128)i7
				 : (__int128)i8
				 : (__int128)i9
				 : (__int128)i10
				 : (__int128)i11
				 : (__int128)i12
				 : (__int128)i13
				 : (__int128)i14
				 : (__int128)i15
				 : (__int128)i16
{
	__int128 mask = (__int128)0xFFFFFFFFFFFFFFFF << 64;

	OF_ENSURE(i1 == mask + 1);
	OF_ENSURE(i2 == mask + 2);
	OF_ENSURE(i3 == 3);
	OF_ENSURE(i4 == mask + 4);
	OF_ENSURE(i5 == mask + 5);
	OF_ENSURE(i6 == mask + 6);
	OF_ENSURE(i7 == mask + 7);
	OF_ENSURE(i8 == mask + 8);
	OF_ENSURE(i9 == mask + 9);
	OF_ENSURE(i10 == mask + 10);
	OF_ENSURE(i11 == mask + 11);
	OF_ENSURE(i12 == mask + 12);
	OF_ENSURE(i13 == mask + 13);
	OF_ENSURE(i14 == mask + 14);
	OF_ENSURE(i15 == mask + 15);
	OF_ENSURE(i16 == mask + 16);

	return (((int)i1 + (int)i2 + (int)i3 + (int)i4 + (int)i5 + (int)i6 +
	    (int)i7 + (int)i8 + (int)i9 + (int)i10 + (int)i11 + (int)i12 +
	    (int)i13 + (int)i14 + (int)i15 + (int)i16) / 16) + mask;
}
#endif

- (void)invocationTests
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	SEL selector = @selector(invocationTestMethod1::::);
	OFMethodSignature *sig = [self methodSignatureForSelector: selector];
	OFInvocation *invocation;
216
217
218
219
220
221
222






























223
224
225
226
227
		}

		long double longDoubleResult;
		TEST(@"-[invoke] #3", R([invocation invoke]) &&
		    R([invocation getReturnValue: &longDoubleResult]) &&
		    longDoubleResult == 8.5)
	}






























#endif

	[pool drain];
}
@end







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





259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
		}

		long double longDoubleResult;
		TEST(@"-[invoke] #3", R([invocation invoke]) &&
		    R([invocation getReturnValue: &longDoubleResult]) &&
		    longDoubleResult == 8.5)
	}

# ifdef __SIZEOF_INT128__
	/* -[invoke] #4 */
	selector = @selector(invocationTestMethod5::::::::::::::::);
	invocation = [OFInvocation invocationWithMethodSignature:
	    [self methodSignatureForSelector: selector]];

	[invocation setArgument: &self
			atIndex: 0];
	[invocation setArgument: &selector
			atIndex: 1];

	for (int i = 1; i <= 16; i++) {
		__int128 i128 = 0xFFFFFFFFFFFFFFFF;
		i128 <<= 64;
		i128 |= i;

		if (i == 3)
			[invocation setArgument: &i
					atIndex: i + 1];
		else
			[invocation setArgument: &i128
					atIndex: i + 1];
	}

	__int128 int128Result;
	TEST(@"-[invoke] #4", R([invocation invoke]) &&
	    R([invocation getReturnValue: &int128Result]) &&
	    int128Result == ((__int128)0xFFFFFFFFFFFFFFFF << 64) + 8)
# endif
#endif

	[pool drain];
}
@end