1 // Helper functions used only in tests
7 // These functions are used in the unit tests for C ABI calls.
10 rust_dbg_extern_identity_u32(uint32_t u) {
15 rust_dbg_extern_identity_u64(uint64_t u) {
20 rust_dbg_extern_identity_double(double u) {
25 rust_dbg_extern_identity_u8(char u) {
29 typedef void *(*dbg_callback)(void*);
32 rust_dbg_call(dbg_callback cb, void *data) {
36 void rust_dbg_do_nothing() { }
44 rust_dbg_extern_return_TwoU8s() {
52 rust_dbg_extern_identity_TwoU8s(struct TwoU8s u) {
62 rust_dbg_extern_return_TwoU16s() {
70 rust_dbg_extern_identity_TwoU16s(struct TwoU16s u) {
80 rust_dbg_extern_return_TwoU32s() {
88 rust_dbg_extern_identity_TwoU32s(struct TwoU32s u) {
98 rust_dbg_extern_return_TwoU64s() {
106 rust_dbg_extern_identity_TwoU64s(struct TwoU64s u) {
116 rust_dbg_extern_identity_TwoDoubles(struct TwoDoubles u) {
129 // MSVC doesn't allow empty structs or unions
135 rust_dbg_extern_empty_struct(struct ManyInts v1, struct Empty e, struct ManyInts v2) {
136 assert(v1.arg1 == v2.arg1 + 1);
137 assert(v1.arg2 == v2.arg2 + 1);
138 assert(v1.arg3 == v2.arg3 + 1);
139 assert(v1.arg4 == v2.arg4 + 1);
140 assert(v1.arg5 == v2.arg5 + 1);
141 assert(v1.arg6.one == v2.arg6.one + 1);
142 assert(v1.arg6.two == v2.arg6.two + 1);
147 rust_get_test_int() {
152 rust_get_null_ptr() {
156 // Debug helpers strictly to verify ABI conformance.
172 rust_dbg_abi_1(struct quad q) {
173 struct quad qq = { q.c + 1,
181 rust_dbg_abi_2(struct floats f) {
182 struct floats ff = { f.c + 1.0,
189 rust_dbg_static_mut = 3;
192 rust_dbg_static_mut_check_four() {
193 assert(rust_dbg_static_mut == 4);
202 uint64_t get_x(struct S s) {
206 uint64_t get_y(struct S s) {
210 uint64_t get_z(struct S s) {
214 uint64_t get_c_many_params(void *a, void *b, void *c, void *d, struct quad f) {
225 float get_c_exhaust_sysv64_ints(
232 // `f` used the last integer register, so `g` goes on the stack.
233 // It also used to bring the "count of available integer registers" down to
234 // `-1` which broke the next SSE-only aggregate argument (`h`) - see #62350.
241 // Calculates the average of `(x + y) / n` where x: i64, y: f64. There must be exactly n pairs
242 // passed as variadic arguments. There are two versions of this function: the
243 // variadic one, and the one that takes a `va_list`.
244 double rust_valist_interesting_average(uint64_t n, va_list pairs) {
247 for(i = 0; i < n; i += 1) {
248 sum += (double)va_arg(pairs, int64_t);
249 sum += va_arg(pairs, double);
254 double rust_interesting_average(uint64_t n, ...) {
258 sum = rust_valist_interesting_average(n, pairs);
263 int32_t rust_int8_to_int32(int8_t x) {
267 typedef union LARGE_INTEGER {
279 LARGE_INTEGER increment_all_parts(LARGE_INTEGER li) {
288 #if __SIZEOF_INT128__ == 16
290 unsigned __int128 identity(unsigned __int128 a) {
294 __int128 square(__int128 a) {
298 __int128 sub(__int128 a, __int128 b) {