2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
25 #define cg_upcall_vector name(cg_upcall_vector)
26 #define hacked_upcall_map name(hacked_upcall_map)
28 /*#define DEBUG_UPCALL*/
30 #ifdef POINTER_COMPRESSION
31 #define pointer_t_upcall uintptr_t
32 #define int_default_t_upcall intptr_t
34 #define pointer_t_upcall pointer_t
35 #define int_default_t_upcall int_default_t
38 void attr_fastcall
run(frame_s
*, ip_t
);
40 extern uint32_t hacked_upcall_map
;
42 struct cg_upcall_vector_s
{
43 atomic_type tick_stamp_t ts
;
45 void (*mem_copy
)(void *dest
, const void *src
, size_t size
);
46 void (*mem_clear
)(void *ptr
, size_t size
);
47 void (*cg_upcall_pointer_dereference
)(pointer_t_upcall ptr
);
48 void (*cg_upcall_pointer_reference_owned
)(pointer_t_upcall ptr
);
49 pointer_t (*cg_upcall_ipret_copy_variable_to_pointer_noderef
)(frame_s
*src_fp
, uintptr_t src_slot
);
50 pointer_t (*cg_upcall_ipret_copy_variable_to_pointer_deref
)(frame_s
*src_fp
, uintptr_t src_slot
);
51 pointer_t (*cg_upcall_flat_to_data
)(frame_s
*fp
, uintptr_t slot
);
52 unsigned char *(*cg_upcall_data_alloc_function_reference_mayfail
)(uintptr_t n_curried_arguments
);
53 unsigned char *(*cg_upcall_data_alloc_record_mayfail
)(frame_s
*fp
, uintptr_t slot
);
54 unsigned char *(*cg_upcall_data_alloc_option_mayfail
)(void);
55 unsigned char *(*cg_upcall_data_alloc_array_flat_tag_mayfail
)(uintptr_t t
, int_default_t_upcall n_entries
);
56 unsigned char *(*cg_upcall_data_alloc_array_flat_slot_mayfail
)(frame_s
*fp
, uintptr_t slot
, int_default_t_upcall n_entries
);
57 unsigned char *(*cg_upcall_data_alloc_array_flat_types_ptr_mayfail
)(frame_s
*fp
, uintptr_t local_type
, int_default_t_upcall n_allocated
, int_default_t_upcall n_used
);
58 unsigned char *(*cg_upcall_data_alloc_array_pointers_mayfail
)(int_default_t_upcall n_allocated
, int_default_t_upcall n_used
);
59 pointer_t (*cg_upcall_array_create_flat
)(frame_s
*fp
, int_default_t_upcall length
, uintptr_t content_slot
);
60 pointer_t (*cg_upcall_array_create_pointers
)(frame_s
*fp
, uintptr_t ip_offset
, uintptr_t length_slot
, pointer_t_upcall ptr
);
61 pointer_t (*cg_upcall_array_create_sparse
)(int_default_t_upcall length
, pointer_t_upcall ptr
);
62 pointer_t (*cg_upcall_array_sub
)(pointer_t_upcall array
, int_default_t_upcall start
, int_default_t_upcall end
, bool deref
);
63 pointer_t (*cg_upcall_array_skip
)(pointer_t_upcall array
, int_default_t_upcall start
, bool deref
);
64 pointer_t (*cg_upcall_array_join
)(pointer_t_upcall ptr1
, pointer_t_upcall ptr2
);
65 void *(*cg_upcall_ipret_io
)(frame_s
*fp
, uintptr_t ip_offset
, uintptr_t code_params
);
66 int_default_t (*cg_upcall_ipret_system_property
)(int_default_t_upcall idx
);
67 #define f(n, s, u, sz, bits) \
68 bool (*cat(INT_binary_const_,s))(const s *v1, int_default_t_upcall v2, s *r, bool (*op)(const void *, const void *, void *));
69 for_all_int(f
, for_all_empty
)
71 bool (*cat(FIXED_binary_add_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, uintbig_t
*r
);
72 bool (*cat(FIXED_binary_subtract_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, uintbig_t
*r
);
73 #define f(n, s, u, sz, bits) \
74 bool (*cat(FIXED_binary_multiply_,s))(const u *v1, const u *v2, u *r);
77 #define f(n, s, u, sz, bits) \
78 bool (*cat(FIXED_binary_divide_,s))(const u *v1, const u *v2, u *r);
81 #define f(n, s, u, sz, bits) \
82 bool (*cat(FIXED_binary_udivide_,s))(const u *v1, const u *v2, u *r);
85 #define f(n, s, u, sz, bits) \
86 bool (*cat(FIXED_binary_modulo_,s))(const u *v1, const u *v2, u *r);
89 #define f(n, s, u, sz, bits) \
90 bool (*cat(FIXED_binary_umodulo_,s))(const u *v1, const u *v2, u *r);
93 #define f(n, s, u, sz, bits) \
94 bool (*cat(FIXED_binary_power_,s))(const u *v1, const u *v2, u *r);
97 bool (*cat(FIXED_binary_shl_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, uintbig_t
*r
);
98 bool (*cat(FIXED_binary_shr_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, uintbig_t
*r
);
99 bool (*cat(FIXED_binary_ushr_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, uintbig_t
*r
);
100 bool (*cat(FIXED_binary_rol_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, uintbig_t
*r
);
101 bool (*cat(FIXED_binary_ror_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, uintbig_t
*r
);
102 bool (*cat(FIXED_binary_bts_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, uintbig_t
*r
);
103 bool (*cat(FIXED_binary_btr_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, uintbig_t
*r
);
104 bool (*cat(FIXED_binary_btc_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, uintbig_t
*r
);
105 bool (*cat(FIXED_binary_less_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, ajla_flat_option_t
*r
);
106 bool (*cat(FIXED_binary_less_equal_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, ajla_flat_option_t
*r
);
107 bool (*cat(FIXED_binary_greater_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, ajla_flat_option_t
*r
);
108 bool (*cat(FIXED_binary_greater_equal_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, ajla_flat_option_t
*r
);
109 bool (*cat(FIXED_binary_uless_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, ajla_flat_option_t
*r
);
110 bool (*cat(FIXED_binary_uless_equal_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, ajla_flat_option_t
*r
);
111 bool (*cat(FIXED_binary_ugreater_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, ajla_flat_option_t
*r
);
112 bool (*cat(FIXED_binary_ugreater_equal_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, ajla_flat_option_t
*r
);
113 bool (*cat(FIXED_binary_bt_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, const uintbig_t
*v2
, ajla_flat_option_t
*r
);
114 void (*cat(FIXED_unary_neg_
,TYPE_INT_MAX
))(const uintbig_t
*v1
, uintbig_t
*r
);
115 #define f(n, s, u, sz, bits) \
116 void (*cat(FIXED_unary_bswap_,s))(const u *v1, u *r);
119 #define f(n, s, u, sz, bits) \
120 void (*cat(FIXED_unary_brev_,s))(const u *v1, u *r);
123 #define f(n, s, u, sz, bits) \
124 void (*cat(FIXED_unary_bsf_,s))(const u *v1, u *r);
127 #define f(n, s, u, sz, bits) \
128 void (*cat(FIXED_unary_bsr_,s))(const u *v1, u *r);
131 #define f(n, s, u, sz, bits) \
132 void (*cat(FIXED_unary_popcnt_,s))(const u *v1, u *r);
135 #define f(n, s, u, sz, bits) \
136 bool (*cat(FIXED_uto_int_,s))(const u *v1, int_default_t *r);
139 #define f(n, s, u, sz, bits) \
140 bool (*cat(FIXED_ufrom_int_,s))(const int_default_t *v1, u *r);
143 bool (*cat(INT_binary_add_
,TYPE_INT_MAX
))(const intbig_t
*v1
, const intbig_t
*v2
, intbig_t
*r
);
144 bool (*cat(INT_binary_subtract_
,TYPE_INT_MAX
))(const intbig_t
*v1
, const intbig_t
*v2
, intbig_t
*r
);
145 #define f(n, s, u, sz, bits) \
146 bool (*cat(INT_binary_multiply_,s))(const s *v1, const s *v2, s *r);
147 for_all_int(f
, for_all_empty
)
149 #define f(n, s, u, sz, bits) \
150 bool (*cat(INT_binary_divide_,s))(const s *v1, const s *v2, s *r);
151 for_all_int(f
, for_all_empty
)
153 #define f(n, s, u, sz, bits) \
154 bool (*cat(INT_binary_modulo_,s))(const s *v1, const s *v2, s *r);
155 for_all_int(f
, for_all_empty
)
157 #define f(n, s, u, sz, bits) \
158 bool (*cat(INT_binary_power_,s))(const s *v1, const s *v2, s *r);
159 for_all_int(f
, for_all_empty
)
161 bool (*cat(INT_binary_shl_
,TYPE_INT_MAX
))(const intbig_t
*v1
, const intbig_t
*v2
, intbig_t
*r
);
162 bool (*cat(INT_binary_shr_
,TYPE_INT_MAX
))(const intbig_t
*v1
, const intbig_t
*v2
, intbig_t
*r
);
163 bool (*cat(INT_binary_bts_
,TYPE_INT_MAX
))(const intbig_t
*v1
, const intbig_t
*v2
, intbig_t
*r
);
164 bool (*cat(INT_binary_btr_
,TYPE_INT_MAX
))(const intbig_t
*v1
, const intbig_t
*v2
, intbig_t
*r
);
165 bool (*cat(INT_binary_btc_
,TYPE_INT_MAX
))(const intbig_t
*v1
, const intbig_t
*v2
, intbig_t
*r
);
166 bool (*cat(INT_binary_bt_
,TYPE_INT_MAX
))(const intbig_t
*v1
, const intbig_t
*v2
, ajla_flat_option_t
*r
);
167 bool (*cat(INT_unary_neg_
,TYPE_INT_MAX
))(const intbig_t
*v1
, intbig_t
*r
);
168 #define f(n, s, u, sz, bits) \
169 bool (*cat(INT_unary_bsf_,s))(const s *v1, s *r);
170 for_all_int(f
, for_all_empty
)
172 #define f(n, s, u, sz, bits) \
173 bool (*cat(INT_unary_bsr_,s))(const s *v1, s *r);
174 for_all_int(f
, for_all_empty
)
176 #define f(n, s, u, sz, bits) \
177 bool (*cat(INT_unary_popcnt_,s))(const s *v1, s *r);
178 for_all_int(f
, for_all_empty
)
180 #define f(n, t, nt, pack, unpack) \
181 bool (*cat(REAL_binary_add_,t))(const t *v1, const t *v2, t *r);
183 void (*cat(REAL_binary_add_,t))(void);
187 #define f(n, t, nt, pack, unpack) \
188 bool (*cat(REAL_binary_subtract_,t))(const t *v1, const t *v2, t *r);
190 void (*cat(REAL_binary_subtract_,t))(void);
194 #define f(n, t, nt, pack, unpack) \
195 bool (*cat(REAL_binary_multiply_,t))(const t *v1, const t *v2, t *r);
197 void (*cat(REAL_binary_multiply_,t))(void);
201 #define f(n, t, nt, pack, unpack) \
202 bool (*cat(REAL_binary_divide_,t))(const t *v1, const t *v2, t *r);
204 void (*cat(REAL_binary_divide_,t))(void);
208 #define f(n, t, nt, pack, unpack) \
209 bool (*cat(REAL_binary_modulo_,t))(const t *v1, const t *v2, t *r);
211 void (*cat(REAL_binary_modulo_,t))(void);
215 #define f(n, t, nt, pack, unpack) \
216 bool (*cat(REAL_binary_power_,t))(const t *v1, const t *v2, t *r);
218 void (*cat(REAL_binary_power_,t))(void);
222 #define f(n, t, nt, pack, unpack) \
223 bool (*cat(REAL_binary_ldexp_,t))(const t *v1, const t *v2, t *r);
225 void (*cat(REAL_binary_ldexp_,t))(void);
229 #define f(n, t, nt, pack, unpack) \
230 bool (*cat(REAL_binary_atan2_,t))(const t *v1, const t *v2, t *r);
232 void (*cat(REAL_binary_atan2_,t))(void);
236 #define f(n, t, nt, pack, unpack) \
237 bool (*cat(REAL_binary_equal_,t))(const t *v1, const t *v2, ajla_flat_option_t *r);
239 void (*cat(REAL_binary_equal_,t))(void);
243 #define f(n, t, nt, pack, unpack) \
244 bool (*cat(REAL_binary_not_equal_,t))(const t *v1, const t *v2, ajla_flat_option_t *r);
246 void (*cat(REAL_binary_not_equal_,t))(void);
250 #define f(n, t, nt, pack, unpack) \
251 bool (*cat(REAL_binary_less_,t))(const t *v1, const t *v2, ajla_flat_option_t *r);
253 void (*cat(REAL_binary_less_,t))(void);
257 #define f(n, t, nt, pack, unpack) \
258 bool (*cat(REAL_binary_less_equal_,t))(const t *v1, const t *v2, ajla_flat_option_t *r);
260 void (*cat(REAL_binary_less_equal_,t))(void);
264 #define f(n, t, nt, pack, unpack) \
265 bool (*cat(REAL_binary_greater_,t))(const t *v1, const t *v2, ajla_flat_option_t *r);
267 void (*cat(REAL_binary_greater_,t))(void);
271 #define f(n, t, nt, pack, unpack) \
272 bool (*cat(REAL_binary_greater_equal_,t))(const t *v1, const t *v2, ajla_flat_option_t *r);
274 void (*cat(REAL_binary_greater_equal_,t))(void);
278 #define f(n, t, nt, pack, unpack) \
279 void (*cat(REAL_unary_neg_,t))(const t *v1, t *r);
281 void (*cat(REAL_unary_neg_,t))(void);
285 #define f(n, t, nt, pack, unpack) \
286 void (*cat(REAL_unary_sqrt_,t))(const t *v1, t *r);
288 void (*cat(REAL_unary_sqrt_,t))(void);
292 #define f(n, t, nt, pack, unpack) \
293 void (*cat(REAL_unary_cbrt_,t))(const t *v1, t *r);
295 void (*cat(REAL_unary_cbrt_,t))(void);
299 #define f(n, t, nt, pack, unpack) \
300 void (*cat(REAL_unary_sin_,t))(const t *v1, t *r);
302 void (*cat(REAL_unary_sin_,t))(void);
306 #define f(n, t, nt, pack, unpack) \
307 void (*cat(REAL_unary_cos_,t))(const t *v1, t *r);
309 void (*cat(REAL_unary_cos_,t))(void);
313 #define f(n, t, nt, pack, unpack) \
314 void (*cat(REAL_unary_tan_,t))(const t *v1, t *r);
316 void (*cat(REAL_unary_tan_,t))(void);
320 #define f(n, t, nt, pack, unpack) \
321 void (*cat(REAL_unary_asin_,t))(const t *v1, t *r);
323 void (*cat(REAL_unary_asin_,t))(void);
327 #define f(n, t, nt, pack, unpack) \
328 void (*cat(REAL_unary_acos_,t))(const t *v1, t *r);
330 void (*cat(REAL_unary_acos_,t))(void);
334 #define f(n, t, nt, pack, unpack) \
335 void (*cat(REAL_unary_atan_,t))(const t *v1, t *r);
337 void (*cat(REAL_unary_atan_,t))(void);
341 #define f(n, t, nt, pack, unpack) \
342 void (*cat(REAL_unary_sinh_,t))(const t *v1, t *r);
344 void (*cat(REAL_unary_sinh_,t))(void);
348 #define f(n, t, nt, pack, unpack) \
349 void (*cat(REAL_unary_cosh_,t))(const t *v1, t *r);
351 void (*cat(REAL_unary_cosh_,t))(void);
355 #define f(n, t, nt, pack, unpack) \
356 void (*cat(REAL_unary_tanh_,t))(const t *v1, t *r);
358 void (*cat(REAL_unary_tanh_,t))(void);
362 #define f(n, t, nt, pack, unpack) \
363 void (*cat(REAL_unary_asinh_,t))(const t *v1, t *r);
365 void (*cat(REAL_unary_asinh_,t))(void);
369 #define f(n, t, nt, pack, unpack) \
370 void (*cat(REAL_unary_acosh_,t))(const t *v1, t *r);
372 void (*cat(REAL_unary_acosh_,t))(void);
376 #define f(n, t, nt, pack, unpack) \
377 void (*cat(REAL_unary_atanh_,t))(const t *v1, t *r);
379 void (*cat(REAL_unary_atanh_,t))(void);
383 #define f(n, t, nt, pack, unpack) \
384 void (*cat(REAL_unary_exp2_,t))(const t *v1, t *r);
386 void (*cat(REAL_unary_exp2_,t))(void);
390 #define f(n, t, nt, pack, unpack) \
391 void (*cat(REAL_unary_exp_,t))(const t *v1, t *r);
393 void (*cat(REAL_unary_exp_,t))(void);
397 #define f(n, t, nt, pack, unpack) \
398 void (*cat(REAL_unary_exp10_,t))(const t *v1, t *r);
400 void (*cat(REAL_unary_exp10_,t))(void);
404 #define f(n, t, nt, pack, unpack) \
405 void (*cat(REAL_unary_log2_,t))(const t *v1, t *r);
407 void (*cat(REAL_unary_log2_,t))(void);
411 #define f(n, t, nt, pack, unpack) \
412 void (*cat(REAL_unary_log_,t))(const t *v1, t *r);
414 void (*cat(REAL_unary_log_,t))(void);
418 #define f(n, t, nt, pack, unpack) \
419 void (*cat(REAL_unary_log10_,t))(const t *v1, t *r);
421 void (*cat(REAL_unary_log10_,t))(void);
425 #define f(n, t, nt, pack, unpack) \
426 void (*cat(REAL_unary_round_,t))(const t *v1, t *r);
428 void (*cat(REAL_unary_round_,t))(void);
432 #define f(n, t, nt, pack, unpack) \
433 void (*cat(REAL_unary_ceil_,t))(const t *v1, t *r);
435 void (*cat(REAL_unary_ceil_,t))(void);
439 #define f(n, t, nt, pack, unpack) \
440 void (*cat(REAL_unary_floor_,t))(const t *v1, t *r);
442 void (*cat(REAL_unary_floor_,t))(void);
446 #define f(n, t, nt, pack, unpack) \
447 void (*cat(REAL_unary_trunc_,t))(const t *v1, t *r);
449 void (*cat(REAL_unary_trunc_,t))(void);
453 #define f(n, t, nt, pack, unpack) \
454 void (*cat(REAL_unary_fract_,t))(const t *v1, t *r);
456 void (*cat(REAL_unary_fract_,t))(void);
460 #define f(n, t, nt, pack, unpack) \
461 void (*cat(REAL_unary_mantissa_,t))(const t *v1, t *r);
463 void (*cat(REAL_unary_mantissa_,t))(void);
467 #define f(n, t, nt, pack, unpack) \
468 void (*cat(REAL_unary_exponent_,t))(const t *v1, t *r);
470 void (*cat(REAL_unary_exponent_,t))(void);
474 #define f(n, t, nt, pack, unpack) \
475 void (*cat(REAL_unary_next_number_,t))(const t *v1, t *r);
477 void (*cat(REAL_unary_next_number_,t))(void);
481 #define f(n, t, nt, pack, unpack) \
482 void (*cat(REAL_unary_prev_number_,t))(const t *v1, t *r);
484 void (*cat(REAL_unary_prev_number_,t))(void);
488 #define f(n, t, nt, pack, unpack) \
489 bool (*cat(REAL_unary_to_int_,t))(const t *val, int_default_t *r);
491 void (*cat(REAL_unary_to_int_,t))(void);
495 #define f(n, t, nt, pack, unpack) \
496 void (*cat(REAL_unary_from_int_,t))(const int_default_t *val, t *r);
498 void (*cat(REAL_unary_from_int_,t))(void);
502 #define f(n, t, nt, pack, unpack) \
503 void (*cat(REAL_unary_is_exception_,t))(const t *v1, ajla_flat_option_t *r);
505 void (*cat(REAL_unary_is_exception_,t))(void);
511 void (*cg_upcall_debug
)(unsigned long x1
, unsigned long x2
, unsigned long x3
, unsigned long x4
);
517 extern struct cg_upcall_vector_s cg_upcall_vector
;
519 #define tick_stamp (cg_upcall_vector.ts)