History

Skeleton of the built-in Math module. - Only functions needed for the limbo compiler are implemented.

arr committed 9 years ago

Commit 99a0b811 parent 7838bae4 files · +1145 −0Browse files

Unified · Split

4 files
  1. src/vm/builtin_module.cpp +2 −0
  2. src/vm/disvm.gyp +1 −0
  3. src/vm/math/Mathmod.cpp +594 −0
  4. src/vm/math/Mathmod.h +548 −0
src/vm/builtin_module.cpp+2−0
@@ -27,6 +27,7 @@ namespace · 26 unmodified lines
2727
2828 // Declare initializers for built-in modules.
2929 extern void Sysmodinit(void);
30+extern void Mathmodinit(void);
3031
3132 void disvm::runtime::builtin::initialize_builtin_modules()
3233 {
@@ -38,6 +39,7 @@ void disvm::runtime::builtin::initialize_builtin_modules() · 5 unmodified lines
3839 // e.g. Sysmodinit()
3940
4041 Sysmodinit();
42+ Mathmodinit();
4143 }
4244
4345 void disvm::runtime::builtin::register_module_exports(const char *name, word_t table_length, const vm_runtab_t *module_runtime_table)
src/vm/disvm.gyp+1−0
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 'vm.cpp',
2424 'vm_memory.cpp',
2525 'vm_exception_handler.cpp',
26+ 'math/Mathmod.cpp',
2627 'sys/print.cpp',
2728 'sys/Sysmod.cpp',
2829 'sys/file_system.cpp',
src/vm/math/Mathmod.cpp+594−0
@@ -0,0 +1,594 @@
1+//
2+// Dis VM
3+// File: Mathmod.cpp
4+// Author: arr
5+//
6+
7+#include "Mathmod.h"
8+
9+using namespace disvm;
10+using namespace disvm::runtime;
11+
12+namespace
13+{
14+ disvm::runtime::builtin::vm_runtab_t Mathmodtab[] = {
15+ "FPcontrol",0x6584767b,Math_FPcontrol,40,0,{0},
16+ "FPstatus",0x6584767b,Math_FPstatus,40,0,{0},
17+ "acos",0xa1d1fe48,Math_acos,40,0,{0},
18+ "acosh",0xa1d1fe48,Math_acosh,40,0,{0},
19+ "asin",0xa1d1fe48,Math_asin,40,0,{0},
20+ "asinh",0xa1d1fe48,Math_asinh,40,0,{0},
21+ "atan",0xa1d1fe48,Math_atan,40,0,{0},
22+ "atan2",0xf293f6cf,Math_atan2,48,0,{0},
23+ "atanh",0xa1d1fe48,Math_atanh,40,0,{0},
24+ "bits32real",0x40a58596,Math_bits32real,40,0,{0},
25+ "bits64real",0x5463c72c,Math_bits64real,40,0,{0},
26+ "cbrt",0xa1d1fe48,Math_cbrt,40,0,{0},
27+ "ceil",0xa1d1fe48,Math_ceil,40,0,{0},
28+ "copysign",0xf293f6cf,Math_copysign,48,0,{0},
29+ "cos",0xa1d1fe48,Math_cos,40,0,{0},
30+ "cosh",0xa1d1fe48,Math_cosh,40,0,{0},
31+ "dot",0xfeca4db6,Math_dot,40,2,{0x0,0xc0,},
32+ "erf",0xa1d1fe48,Math_erf,40,0,{0},
33+ "erfc",0xa1d1fe48,Math_erfc,40,0,{0},
34+ "exp",0xa1d1fe48,Math_exp,40,0,{0},
35+ "expm1",0xa1d1fe48,Math_expm1,40,0,{0},
36+ "export_int",0x3f1d94ee,Math_export_int,40,2,{0x0,0xc0,},
37+ "export_real",0xd1fb0c8c,Math_export_real,40,2,{0x0,0xc0,},
38+ "export_real32",0xd1fb0c8c,Math_export_real32,40,2,{0x0,0xc0,},
39+ "fabs",0xa1d1fe48,Math_fabs,40,0,{0},
40+ "fdim",0xf293f6cf,Math_fdim,48,0,{0},
41+ "finite",0x7b2e5f52,Math_finite,40,0,{0},
42+ "floor",0xa1d1fe48,Math_floor,40,0,{0},
43+ "fmax",0xf293f6cf,Math_fmax,48,0,{0},
44+ "fmin",0xf293f6cf,Math_fmin,48,0,{0},
45+ "fmod",0xf293f6cf,Math_fmod,48,0,{0},
46+ "gemm",0x53b8cd34,Math_gemm,96,3,{0x0,0x0,0xa2,},
47+ "getFPcontrol",0x616977e8,Math_getFPcontrol,32,0,{0},
48+ "getFPstatus",0x616977e8,Math_getFPstatus,32,0,{0},
49+ "hypot",0xf293f6cf,Math_hypot,48,0,{0},
50+ "iamax",0xa5fc2e4d,Math_iamax,40,2,{0x0,0x80,},
51+ "ilogb",0x7b2e5f52,Math_ilogb,40,0,{0},
52+ "import_int",0x3f1d94ee,Math_import_int,40,2,{0x0,0xc0,},
53+ "import_real",0xd1fb0c8c,Math_import_real,40,2,{0x0,0xc0,},
54+ "import_real32",0xd1fb0c8c,Math_import_real32,40,2,{0x0,0xc0,},
55+ "isnan",0x7b2e5f52,Math_isnan,40,0,{0},
56+ "j0",0xa1d1fe48,Math_j0,40,0,{0},
57+ "j1",0xa1d1fe48,Math_j1,40,0,{0},
58+ "jn",0xb61ffc5b,Math_jn,48,0,{0},
59+ "lgamma",0x6e97c646,Math_lgamma,40,0,{0},
60+ "log",0xa1d1fe48,Math_log,40,0,{0},
61+ "log10",0xa1d1fe48,Math_log10,40,0,{0},
62+ "log1p",0xa1d1fe48,Math_log1p,40,0,{0},
63+ "modf",0x6e97c646,Math_modf,40,0,{0},
64+ "nextafter",0xf293f6cf,Math_nextafter,48,0,{0},
65+ "norm1",0x1629207e,Math_norm1,40,2,{0x0,0x80,},
66+ "norm2",0x1629207e,Math_norm2,40,2,{0x0,0x80,},
67+ "pow",0xf293f6cf,Math_pow,48,0,{0},
68+ "pow10",0x40a58596,Math_pow10,40,0,{0},
69+ "realbits32",0x7b2e5f52,Math_realbits32,40,0,{0},
70+ "realbits64",0x9589d476,Math_realbits64,40,0,{0},
71+ "remainder",0xf293f6cf,Math_remainder,48,0,{0},
72+ "rint",0xa1d1fe48,Math_rint,40,0,{0},
73+ "scalbn",0x64fa84ba,Math_scalbn,48,0,{0},
74+ "sin",0xa1d1fe48,Math_sin,40,0,{0},
75+ "sinh",0xa1d1fe48,Math_sinh,40,0,{0},
76+ "sort",0xfc7c7b8,Math_sort,40,2,{0x0,0xc0,},
77+ "sqrt",0xa1d1fe48,Math_sqrt,40,0,{0},
78+ "tan",0xa1d1fe48,Math_tan,40,0,{0},
79+ "tanh",0xa1d1fe48,Math_tanh,40,0,{0},
80+ "y0",0xa1d1fe48,Math_y0,40,0,{0},
81+ "y1",0xa1d1fe48,Math_y1,40,0,{0},
82+ "yn",0xb61ffc5b,Math_yn,48,0,{0},
83+ 0
84+ };
85+
86+ const word_t Mathmodlen = 68;
87+}
88+
89+void
90+Mathmodinit(void)
91+{
92+ builtin::register_module_exports(Math_PATH, Mathmodlen, Mathmodtab);
93+}
94+
95+void
96+Math_FPcontrol(vm_registers_t &r, vm_t &vm)
97+{
98+ auto &fp = r.stack.peek_frame()->base<F_Math_FPcontrol>();
99+
100+ // [TODO] Properly implment floating point control
101+ *fp.ret = fp.mask;
102+}
103+
104+void
105+Math_FPstatus(vm_registers_t &r, vm_t &vm)
106+{
107+ auto &fp = r.stack.peek_frame()->base<F_Math_FPstatus>();
108+ throw vm_system_exception{ "Instruction not implemented" };
109+}
110+
111+void
112+Math_acos(vm_registers_t &r, vm_t &vm)
113+{
114+ auto &fp = r.stack.peek_frame()->base<F_Math_acos>();
115+ throw vm_system_exception{ "Instruction not implemented" };
116+}
117+
118+void
119+Math_acosh(vm_registers_t &r, vm_t &vm)
120+{
121+ auto &fp = r.stack.peek_frame()->base<F_Math_acosh>();
122+ throw vm_system_exception{ "Instruction not implemented" };
123+}
124+
125+void
126+Math_asin(vm_registers_t &r, vm_t &vm)
127+{
128+ auto &fp = r.stack.peek_frame()->base<F_Math_asin>();
129+ throw vm_system_exception{ "Instruction not implemented" };
130+}
131+
132+void
133+Math_asinh(vm_registers_t &r, vm_t &vm)
134+{
135+ auto &fp = r.stack.peek_frame()->base<F_Math_asinh>();
136+ throw vm_system_exception{ "Instruction not implemented" };
137+}
138+
139+void
140+Math_atan(vm_registers_t &r, vm_t &vm)
141+{
142+ auto &fp = r.stack.peek_frame()->base<F_Math_atan>();
143+ throw vm_system_exception{ "Instruction not implemented" };
144+}
145+
146+void
147+Math_atan2(vm_registers_t &r, vm_t &vm)
148+{
149+ auto &fp = r.stack.peek_frame()->base<F_Math_atan2>();
150+ throw vm_system_exception{ "Instruction not implemented" };
151+}
152+
153+void
154+Math_atanh(vm_registers_t &r, vm_t &vm)
155+{
156+ auto &fp = r.stack.peek_frame()->base<F_Math_atanh>();
157+ throw vm_system_exception{ "Instruction not implemented" };
158+}
159+
160+void
161+Math_bits32real(vm_registers_t &r, vm_t &vm)
162+{
163+ auto &fp = r.stack.peek_frame()->base<F_Math_bits32real>();
164+ throw vm_system_exception{ "Instruction not implemented" };
165+}
166+
167+void
168+Math_bits64real(vm_registers_t &r, vm_t &vm)
169+{
170+ auto &fp = r.stack.peek_frame()->base<F_Math_bits64real>();
171+ throw vm_system_exception{ "Instruction not implemented" };
172+}
173+
174+void
175+Math_cbrt(vm_registers_t &r, vm_t &vm)
176+{
177+ auto &fp = r.stack.peek_frame()->base<F_Math_cbrt>();
178+ throw vm_system_exception{ "Instruction not implemented" };
179+}
180+
181+void
182+Math_ceil(vm_registers_t &r, vm_t &vm)
183+{
184+ auto &fp = r.stack.peek_frame()->base<F_Math_ceil>();
185+ throw vm_system_exception{ "Instruction not implemented" };
186+}
187+
188+void
189+Math_copysign(vm_registers_t &r, vm_t &vm)
190+{
191+ auto &fp = r.stack.peek_frame()->base<F_Math_copysign>();
192+ throw vm_system_exception{ "Instruction not implemented" };
193+}
194+
195+void
196+Math_cos(vm_registers_t &r, vm_t &vm)
197+{
198+ auto &fp = r.stack.peek_frame()->base<F_Math_cos>();
199+ throw vm_system_exception{ "Instruction not implemented" };
200+}
201+
202+void
203+Math_cosh(vm_registers_t &r, vm_t &vm)
204+{
205+ auto &fp = r.stack.peek_frame()->base<F_Math_cosh>();
206+ throw vm_system_exception{ "Instruction not implemented" };
207+}
208+
209+void
210+Math_dot(vm_registers_t &r, vm_t &vm)
211+{
212+ auto &fp = r.stack.peek_frame()->base<F_Math_dot>();
213+ throw vm_system_exception{ "Instruction not implemented" };
214+}
215+
216+void
217+Math_erf(vm_registers_t &r, vm_t &vm)
218+{
219+ auto &fp = r.stack.peek_frame()->base<F_Math_erf>();
220+ throw vm_system_exception{ "Instruction not implemented" };
221+}
222+
223+void
224+Math_erfc(vm_registers_t &r, vm_t &vm)
225+{
226+ auto &fp = r.stack.peek_frame()->base<F_Math_erfc>();
227+ throw vm_system_exception{ "Instruction not implemented" };
228+}
229+
230+void
231+Math_exp(vm_registers_t &r, vm_t &vm)
232+{
233+ auto &fp = r.stack.peek_frame()->base<F_Math_exp>();
234+ throw vm_system_exception{ "Instruction not implemented" };
235+}
236+
237+void
238+Math_expm1(vm_registers_t &r, vm_t &vm)
239+{
240+ auto &fp = r.stack.peek_frame()->base<F_Math_expm1>();
241+ throw vm_system_exception{ "Instruction not implemented" };
242+}
243+
244+void
245+Math_export_int(vm_registers_t &r, vm_t &vm)
246+{
247+ auto &fp = r.stack.peek_frame()->base<F_Math_export_int>();
248+ throw vm_system_exception{ "Instruction not implemented" };
249+}
250+
251+void
252+Math_export_real(vm_registers_t &r, vm_t &vm)
253+{
254+ auto &fp = r.stack.peek_frame()->base<F_Math_export_real>();
255+ throw vm_system_exception{ "Instruction not implemented" };
256+}
257+
258+void
259+Math_export_real32(vm_registers_t &r, vm_t &vm)
260+{
261+ auto &fp = r.stack.peek_frame()->base<F_Math_export_real32>();
262+ throw vm_system_exception{ "Instruction not implemented" };
263+}
264+
265+void
266+Math_fabs(vm_registers_t &r, vm_t &vm)
267+{
268+ auto &fp = r.stack.peek_frame()->base<F_Math_fabs>();
269+ throw vm_system_exception{ "Instruction not implemented" };
270+}
271+
272+void
273+Math_fdim(vm_registers_t &r, vm_t &vm)
274+{
275+ auto &fp = r.stack.peek_frame()->base<F_Math_fdim>();
276+ throw vm_system_exception{ "Instruction not implemented" };
277+}
278+
279+void
280+Math_finite(vm_registers_t &r, vm_t &vm)
281+{
282+ auto &fp = r.stack.peek_frame()->base<F_Math_finite>();
283+ throw vm_system_exception{ "Instruction not implemented" };
284+}
285+
286+void
287+Math_floor(vm_registers_t &r, vm_t &vm)
288+{
289+ auto &fp = r.stack.peek_frame()->base<F_Math_floor>();
290+ throw vm_system_exception{ "Instruction not implemented" };
291+}
292+
293+void
294+Math_fmax(vm_registers_t &r, vm_t &vm)
295+{
296+ auto &fp = r.stack.peek_frame()->base<F_Math_fmax>();
297+ throw vm_system_exception{ "Instruction not implemented" };
298+}
299+
300+void
301+Math_fmin(vm_registers_t &r, vm_t &vm)
302+{
303+ auto &fp = r.stack.peek_frame()->base<F_Math_fmin>();
304+ throw vm_system_exception{ "Instruction not implemented" };
305+}
306+
307+void
308+Math_fmod(vm_registers_t &r, vm_t &vm)
309+{
310+ auto &fp = r.stack.peek_frame()->base<F_Math_fmod>();
311+ throw vm_system_exception{ "Instruction not implemented" };
312+}
313+
314+void
315+Math_gemm(vm_registers_t &r, vm_t &vm)
316+{
317+ auto &fp = r.stack.peek_frame()->base<F_Math_gemm>();
318+ throw vm_system_exception{ "Instruction not implemented" };
319+}
320+
321+void
322+Math_getFPcontrol(vm_registers_t &r, vm_t &vm)
323+{
324+ auto &fp = r.stack.peek_frame()->base<F_Math_getFPcontrol>();
325+ throw vm_system_exception{ "Instruction not implemented" };
326+}
327+
328+void
329+Math_getFPstatus(vm_registers_t &r, vm_t &vm)
330+{
331+ auto &fp = r.stack.peek_frame()->base<F_Math_getFPstatus>();
332+ throw vm_system_exception{ "Instruction not implemented" };
333+}
334+
335+void
336+Math_hypot(vm_registers_t &r, vm_t &vm)
337+{
338+ auto &fp = r.stack.peek_frame()->base<F_Math_hypot>();
339+ throw vm_system_exception{ "Instruction not implemented" };
340+}
341+
342+void
343+Math_iamax(vm_registers_t &r, vm_t &vm)
344+{
345+ auto &fp = r.stack.peek_frame()->base<F_Math_iamax>();
346+ throw vm_system_exception{ "Instruction not implemented" };
347+}
348+
349+void
350+Math_ilogb(vm_registers_t &r, vm_t &vm)
351+{
352+ auto &fp = r.stack.peek_frame()->base<F_Math_ilogb>();
353+ throw vm_system_exception{ "Instruction not implemented" };
354+}
355+
356+void
357+Math_import_int(vm_registers_t &r, vm_t &vm)
358+{
359+ auto &fp = r.stack.peek_frame()->base<F_Math_import_int>();
360+ throw vm_system_exception{ "Instruction not implemented" };
361+}
362+
363+void
364+Math_import_real(vm_registers_t &r, vm_t &vm)
365+{
366+ auto &fp = r.stack.peek_frame()->base<F_Math_import_real>();
367+
368+ auto buffer = vm_alloc_t::from_allocation<vm_array_t>(fp.b);
369+ assert(buffer->get_element_type()->size_in_bytes == intrinsic_type_desc::type<byte_t>()->size_in_bytes);
370+
371+ auto result = vm_alloc_t::from_allocation<vm_array_t>(fp.x);
372+ assert(result->get_element_type()->size_in_bytes == intrinsic_type_desc::type<real_t>()->size_in_bytes);
373+ const auto result_len = result->get_length();
374+
375+ if (buffer->get_length() != (8 * result_len))
376+ throw vm_user_exception{ "Invalid buffer size based on conversion" };
377+
378+ // Process as big endian
379+ for (int i = 0; i < result_len; ++i)
380+ {
381+ uint64_t t = buffer->at<byte_t>(0);
382+ for (int j = 1; j < 8; ++j)
383+ t = (t << 8) | buffer->at<byte_t>(j);
384+
385+ auto r = real_t{};
386+ std::memcpy(&r, &t, sizeof(t));
387+ static_assert(sizeof(t) == sizeof(r), "Real should be 64-bits");
388+
389+ result->at<real_t>(i) = r;
390+ }
391+}
392+
393+void
394+Math_import_real32(vm_registers_t &r, vm_t &vm)
395+{
396+ auto &fp = r.stack.peek_frame()->base<F_Math_import_real32>();
397+ throw vm_system_exception{ "Instruction not implemented" };
398+}
399+
400+void
401+Math_isnan(vm_registers_t &r, vm_t &vm)
402+{
403+ auto &fp = r.stack.peek_frame()->base<F_Math_isnan>();
404+ *fp.ret = std::isnan(fp.x) ? 1 : 0;
405+}
406+
407+void
408+Math_j0(vm_registers_t &r, vm_t &vm)
409+{
410+ auto &fp = r.stack.peek_frame()->base<F_Math_j0>();
411+ throw vm_system_exception{ "Instruction not implemented" };
412+}
413+
414+void
415+Math_j1(vm_registers_t &r, vm_t &vm)
416+{
417+ auto &fp = r.stack.peek_frame()->base<F_Math_j1>();
418+ throw vm_system_exception{ "Instruction not implemented" };
419+}
420+
421+void
422+Math_jn(vm_registers_t &r, vm_t &vm)
423+{
424+ auto &fp = r.stack.peek_frame()->base<F_Math_jn>();
425+ throw vm_system_exception{ "Instruction not implemented" };
426+}
427+
428+void
429+Math_lgamma(vm_registers_t &r, vm_t &vm)
430+{
431+ auto &fp = r.stack.peek_frame()->base<F_Math_lgamma>();
432+ throw vm_system_exception{ "Instruction not implemented" };
433+}
434+
435+void
436+Math_log(vm_registers_t &r, vm_t &vm)
437+{
438+ auto &fp = r.stack.peek_frame()->base<F_Math_log>();
439+ throw vm_system_exception{ "Instruction not implemented" };
440+}
441+
442+void
443+Math_log10(vm_registers_t &r, vm_t &vm)
444+{
445+ auto &fp = r.stack.peek_frame()->base<F_Math_log10>();
446+ throw vm_system_exception{ "Instruction not implemented" };
447+}
448+
449+void
450+Math_log1p(vm_registers_t &r, vm_t &vm)
451+{
452+ auto &fp = r.stack.peek_frame()->base<F_Math_log1p>();
453+ throw vm_system_exception{ "Instruction not implemented" };
454+}
455+
456+void
457+Math_modf(vm_registers_t &r, vm_t &vm)
458+{
459+ auto &fp = r.stack.peek_frame()->base<F_Math_modf>();
460+ throw vm_system_exception{ "Instruction not implemented" };
461+}
462+
463+void
464+Math_nextafter(vm_registers_t &r, vm_t &vm)
465+{
466+ auto &fp = r.stack.peek_frame()->base<F_Math_nextafter>();
467+ throw vm_system_exception{ "Instruction not implemented" };
468+}
469+
470+void
471+Math_norm1(vm_registers_t &r, vm_t &vm)
472+{
473+ auto &fp = r.stack.peek_frame()->base<F_Math_norm1>();
474+ throw vm_system_exception{ "Instruction not implemented" };
475+}
476+
477+void
478+Math_norm2(vm_registers_t &r, vm_t &vm)
479+{
480+ auto &fp = r.stack.peek_frame()->base<F_Math_norm2>();
481+ throw vm_system_exception{ "Instruction not implemented" };
482+}
483+
484+void
485+Math_pow(vm_registers_t &r, vm_t &vm)
486+{
487+ auto &fp = r.stack.peek_frame()->base<F_Math_pow>();
488+ throw vm_system_exception{ "Instruction not implemented" };
489+}
490+
491+void
492+Math_pow10(vm_registers_t &r, vm_t &vm)
493+{
494+ auto &fp = r.stack.peek_frame()->base<F_Math_pow10>();
495+ throw vm_system_exception{ "Instruction not implemented" };
496+}
497+
498+void
499+Math_realbits32(vm_registers_t &r, vm_t &vm)
500+{
501+ auto &fp = r.stack.peek_frame()->base<F_Math_realbits32>();
502+ throw vm_system_exception{ "Instruction not implemented" };
503+}
504+
505+void
506+Math_realbits64(vm_registers_t &r, vm_t &vm)
507+{
508+ auto &fp = r.stack.peek_frame()->base<F_Math_realbits64>();
509+ throw vm_system_exception{ "Instruction not implemented" };
510+}
511+
512+void
513+Math_remainder(vm_registers_t &r, vm_t &vm)
514+{
515+ auto &fp = r.stack.peek_frame()->base<F_Math_remainder>();
516+ throw vm_system_exception{ "Instruction not implemented" };
517+}
518+
519+void
520+Math_rint(vm_registers_t &r, vm_t &vm)
521+{
522+ auto &fp = r.stack.peek_frame()->base<F_Math_rint>();
523+ throw vm_system_exception{ "Instruction not implemented" };
524+}
525+
526+void
527+Math_scalbn(vm_registers_t &r, vm_t &vm)
528+{
529+ auto &fp = r.stack.peek_frame()->base<F_Math_scalbn>();
530+ throw vm_system_exception{ "Instruction not implemented" };
531+}
532+
533+void
534+Math_sin(vm_registers_t &r, vm_t &vm)
535+{
536+ auto &fp = r.stack.peek_frame()->base<F_Math_sin>();
537+ throw vm_system_exception{ "Instruction not implemented" };
538+}
539+
540+void
541+Math_sinh(vm_registers_t &r, vm_t &vm)
542+{
543+ auto &fp = r.stack.peek_frame()->base<F_Math_sinh>();
544+ throw vm_system_exception{ "Instruction not implemented" };
545+}
546+
547+void
548+Math_sort(vm_registers_t &r, vm_t &vm)
549+{
550+ auto &fp = r.stack.peek_frame()->base<F_Math_sort>();
551+ throw vm_system_exception{ "Instruction not implemented" };
552+}
553+
554+void
555+Math_sqrt(vm_registers_t &r, vm_t &vm)
556+{
557+ auto &fp = r.stack.peek_frame()->base<F_Math_sqrt>();
558+ throw vm_system_exception{ "Instruction not implemented" };
559+}
560+
561+void
562+Math_tan(vm_registers_t &r, vm_t &vm)
563+{
564+ auto &fp = r.stack.peek_frame()->base<F_Math_tan>();
565+ throw vm_system_exception{ "Instruction not implemented" };
566+}
567+
568+void
569+Math_tanh(vm_registers_t &r, vm_t &vm)
570+{
571+ auto &fp = r.stack.peek_frame()->base<F_Math_tanh>();
572+ throw vm_system_exception{ "Instruction not implemented" };
573+}
574+
575+void
576+Math_y0(vm_registers_t &r, vm_t &vm)
577+{
578+ auto &fp = r.stack.peek_frame()->base<F_Math_y0>();
579+ throw vm_system_exception{ "Instruction not implemented" };
580+}
581+
582+void
583+Math_y1(vm_registers_t &r, vm_t &vm)
584+{
585+ auto &fp = r.stack.peek_frame()->base<F_Math_y1>();
586+ throw vm_system_exception{ "Instruction not implemented" };
587+}
588+
589+void
590+Math_yn(vm_registers_t &r, vm_t &vm)
591+{
592+ auto &fp = r.stack.peek_frame()->base<F_Math_yn>();
593+ throw vm_system_exception{ "Instruction not implemented" };
594+}
src/vm/math/Mathmod.h+548−0
@@ -0,0 +1,548 @@
1+//
2+// Dis VM
3+// File: Mathmod.h
4+// Author: arr
5+//
6+
7+#ifndef _DISVM_SRC_VM_MATH_MATHMOD_H_
8+#define _DISVM_SRC_VM_MATH_MATHMOD_H_
9+
10+#include <cmath>
11+#include <disvm.h>
12+#include <builtin_module.h>
13+
14+using namespace disvm;
15+using namespace disvm::runtime;
16+
17+void Math_FPcontrol(vm_registers_t &r, vm_t &vm);
18+struct F_Math_FPcontrol : public vm_frame_base_alloc_t
19+{
20+ word_t* ret;
21+ byte_t temps[12];
22+ word_t r;
23+ word_t mask;
24+};
25+void Math_FPstatus(vm_registers_t &r, vm_t &vm);
26+struct F_Math_FPstatus : public vm_frame_base_alloc_t
27+{
28+ word_t* ret;
29+ byte_t temps[12];
30+ word_t r;
31+ word_t mask;
32+};
33+void Math_acos(vm_registers_t &r, vm_t &vm);
34+struct F_Math_acos : public vm_frame_base_alloc_t
35+{
36+ real_t* ret;
37+ byte_t temps[12];
38+ real_t x;
39+};
40+void Math_acosh(vm_registers_t &r, vm_t &vm);
41+struct F_Math_acosh : public vm_frame_base_alloc_t
42+{
43+ real_t* ret;
44+ byte_t temps[12];
45+ real_t x;
46+};
47+void Math_asin(vm_registers_t &r, vm_t &vm);
48+struct F_Math_asin : public vm_frame_base_alloc_t
49+{
50+ real_t* ret;
51+ byte_t temps[12];
52+ real_t x;
53+};
54+void Math_asinh(vm_registers_t &r, vm_t &vm);
55+struct F_Math_asinh : public vm_frame_base_alloc_t
56+{
57+ real_t* ret;
58+ byte_t temps[12];
59+ real_t x;
60+};
61+void Math_atan(vm_registers_t &r, vm_t &vm);
62+struct F_Math_atan : public vm_frame_base_alloc_t
63+{
64+ real_t* ret;
65+ byte_t temps[12];
66+ real_t x;
67+};
68+void Math_atan2(vm_registers_t &r, vm_t &vm);
69+struct F_Math_atan2 : public vm_frame_base_alloc_t
70+{
71+ real_t* ret;
72+ byte_t temps[12];
73+ real_t y;
74+ real_t x;
75+};
76+void Math_atanh(vm_registers_t &r, vm_t &vm);
77+struct F_Math_atanh : public vm_frame_base_alloc_t
78+{
79+ real_t* ret;
80+ byte_t temps[12];
81+ real_t x;
82+};
83+void Math_bits32real(vm_registers_t &r, vm_t &vm);
84+struct F_Math_bits32real : public vm_frame_base_alloc_t
85+{
86+ real_t* ret;
87+ byte_t temps[12];
88+ word_t b;
89+};
90+void Math_bits64real(vm_registers_t &r, vm_t &vm);
91+struct F_Math_bits64real : public vm_frame_base_alloc_t
92+{
93+ real_t* ret;
94+ byte_t temps[12];
95+ big_t b;
96+};
97+void Math_cbrt(vm_registers_t &r, vm_t &vm);
98+struct F_Math_cbrt : public vm_frame_base_alloc_t
99+{
100+ real_t* ret;
101+ byte_t temps[12];
102+ real_t x;
103+};
104+void Math_ceil(vm_registers_t &r, vm_t &vm);
105+struct F_Math_ceil : public vm_frame_base_alloc_t
106+{
107+ real_t* ret;
108+ byte_t temps[12];
109+ real_t x;
110+};
111+void Math_copysign(vm_registers_t &r, vm_t &vm);
112+struct F_Math_copysign : public vm_frame_base_alloc_t
113+{
114+ real_t* ret;
115+ byte_t temps[12];
116+ real_t x;
117+ real_t s;
118+};
119+void Math_cos(vm_registers_t &r, vm_t &vm);
120+struct F_Math_cos : public vm_frame_base_alloc_t
121+{
122+ real_t* ret;
123+ byte_t temps[12];
124+ real_t x;
125+};
126+void Math_cosh(vm_registers_t &r, vm_t &vm);
127+struct F_Math_cosh : public vm_frame_base_alloc_t
128+{
129+ real_t* ret;
130+ byte_t temps[12];
131+ real_t x;
132+};
133+void Math_dot(vm_registers_t &r, vm_t &vm);
134+struct F_Math_dot : public vm_frame_base_alloc_t
135+{
136+ real_t* ret;
137+ byte_t temps[12];
138+ /* vm_array_t */ pointer_t x;
139+ /* vm_array_t */ pointer_t y;
140+};
141+void Math_erf(vm_registers_t &r, vm_t &vm);
142+struct F_Math_erf : public vm_frame_base_alloc_t
143+{
144+ real_t* ret;
145+ byte_t temps[12];
146+ real_t x;
147+};
148+void Math_erfc(vm_registers_t &r, vm_t &vm);
149+struct F_Math_erfc : public vm_frame_base_alloc_t
150+{
151+ real_t* ret;
152+ byte_t temps[12];
153+ real_t x;
154+};
155+void Math_exp(vm_registers_t &r, vm_t &vm);
156+struct F_Math_exp : public vm_frame_base_alloc_t
157+{
158+ real_t* ret;
159+ byte_t temps[12];
160+ real_t x;
161+};
162+void Math_expm1(vm_registers_t &r, vm_t &vm);
163+struct F_Math_expm1 : public vm_frame_base_alloc_t
164+{
165+ real_t* ret;
166+ byte_t temps[12];
167+ real_t x;
168+};
169+void Math_export_int(vm_registers_t &r, vm_t &vm);
170+struct F_Math_export_int : public vm_frame_base_alloc_t
171+{
172+ word_t noret;
173+ byte_t temps[12];
174+ /* vm_array_t */ pointer_t b;
175+ /* vm_array_t */ pointer_t x;
176+};
177+void Math_export_real(vm_registers_t &r, vm_t &vm);
178+struct F_Math_export_real : public vm_frame_base_alloc_t
179+{
180+ word_t noret;
181+ byte_t temps[12];
182+ /* vm_array_t */ pointer_t b;
183+ /* vm_array_t */ pointer_t x;
184+};
185+void Math_export_real32(vm_registers_t &r, vm_t &vm);
186+struct F_Math_export_real32 : public vm_frame_base_alloc_t
187+{
188+ word_t noret;
189+ byte_t temps[12];
190+ /* vm_array_t */ pointer_t b;
191+ /* vm_array_t */ pointer_t x;
192+};
193+void Math_fabs(vm_registers_t &r, vm_t &vm);
194+struct F_Math_fabs : public vm_frame_base_alloc_t
195+{
196+ real_t* ret;
197+ byte_t temps[12];
198+ real_t x;
199+};
200+void Math_fdim(vm_registers_t &r, vm_t &vm);
201+struct F_Math_fdim : public vm_frame_base_alloc_t
202+{
203+ real_t* ret;
204+ byte_t temps[12];
205+ real_t x;
206+ real_t y;
207+};
208+void Math_finite(vm_registers_t &r, vm_t &vm);
209+struct F_Math_finite : public vm_frame_base_alloc_t
210+{
211+ word_t* ret;
212+ byte_t temps[12];
213+ real_t x;
214+};
215+void Math_floor(vm_registers_t &r, vm_t &vm);
216+struct F_Math_floor : public vm_frame_base_alloc_t
217+{
218+ real_t* ret;
219+ byte_t temps[12];
220+ real_t x;
221+};
222+void Math_fmax(vm_registers_t &r, vm_t &vm);
223+struct F_Math_fmax : public vm_frame_base_alloc_t
224+{
225+ real_t* ret;
226+ byte_t temps[12];
227+ real_t x;
228+ real_t y;
229+};
230+void Math_fmin(vm_registers_t &r, vm_t &vm);
231+struct F_Math_fmin : public vm_frame_base_alloc_t
232+{
233+ real_t* ret;
234+ byte_t temps[12];
235+ real_t x;
236+ real_t y;
237+};
238+void Math_fmod(vm_registers_t &r, vm_t &vm);
239+struct F_Math_fmod : public vm_frame_base_alloc_t
240+{
241+ real_t* ret;
242+ byte_t temps[12];
243+ real_t x;
244+ real_t y;
245+};
246+void Math_gemm(vm_registers_t &r, vm_t &vm);
247+struct F_Math_gemm : public vm_frame_base_alloc_t
248+{
249+ word_t noret;
250+ byte_t temps[12];
251+ word_t transa;
252+ word_t transb;
253+ word_t m;
254+ word_t n;
255+ word_t k;
256+ byte_t _pad52[4];
257+ real_t alpha;
258+ /* vm_array_t */ pointer_t a;
259+ word_t lda;
260+ /* vm_array_t */ pointer_t b;
261+ word_t ldb;
262+ real_t beta;
263+ /* vm_array_t */ pointer_t c;
264+ word_t ldc;
265+};
266+void Math_getFPcontrol(vm_registers_t &r, vm_t &vm);
267+struct F_Math_getFPcontrol : public vm_frame_base_alloc_t
268+{
269+ word_t* ret;
270+ byte_t temps[12];
271+};
272+void Math_getFPstatus(vm_registers_t &r, vm_t &vm);
273+struct F_Math_getFPstatus : public vm_frame_base_alloc_t
274+{
275+ word_t* ret;
276+ byte_t temps[12];
277+};
278+void Math_hypot(vm_registers_t &r, vm_t &vm);
279+struct F_Math_hypot : public vm_frame_base_alloc_t
280+{
281+ real_t* ret;
282+ byte_t temps[12];
283+ real_t x;
284+ real_t y;
285+};
286+void Math_iamax(vm_registers_t &r, vm_t &vm);
287+struct F_Math_iamax : public vm_frame_base_alloc_t
288+{
289+ word_t* ret;
290+ byte_t temps[12];
291+ /* vm_array_t */ pointer_t x;
292+};
293+void Math_ilogb(vm_registers_t &r, vm_t &vm);
294+struct F_Math_ilogb : public vm_frame_base_alloc_t
295+{
296+ word_t* ret;
297+ byte_t temps[12];
298+ real_t x;
299+};
300+void Math_import_int(vm_registers_t &r, vm_t &vm);
301+struct F_Math_import_int : public vm_frame_base_alloc_t
302+{
303+ word_t noret;
304+ byte_t temps[12];
305+ /* vm_array_t */ pointer_t b;
306+ /* vm_array_t */ pointer_t x;
307+};
308+void Math_import_real(vm_registers_t &r, vm_t &vm);
309+struct F_Math_import_real : public vm_frame_base_alloc_t
310+{
311+ word_t noret;
312+ byte_t temps[12];
313+ /* vm_array_t */ pointer_t b;
314+ /* vm_array_t */ pointer_t x;
315+};
316+void Math_import_real32(vm_registers_t &r, vm_t &vm);
317+struct F_Math_import_real32 : public vm_frame_base_alloc_t
318+{
319+ word_t noret;
320+ byte_t temps[12];
321+ /* vm_array_t */ pointer_t b;
322+ /* vm_array_t */ pointer_t x;
323+};
324+void Math_isnan(vm_registers_t &r, vm_t &vm);
325+struct F_Math_isnan : public vm_frame_base_alloc_t
326+{
327+ word_t* ret;
328+ byte_t temps[12];
329+ real_t x;
330+};
331+void Math_j0(vm_registers_t &r, vm_t &vm);
332+struct F_Math_j0 : public vm_frame_base_alloc_t
333+{
334+ real_t* ret;
335+ byte_t temps[12];
336+ real_t x;
337+};
338+void Math_j1(vm_registers_t &r, vm_t &vm);
339+struct F_Math_j1 : public vm_frame_base_alloc_t
340+{
341+ real_t* ret;
342+ byte_t temps[12];
343+ real_t x;
344+};
345+void Math_jn(vm_registers_t &r, vm_t &vm);
346+struct F_Math_jn : public vm_frame_base_alloc_t
347+{
348+ real_t* ret;
349+ byte_t temps[12];
350+ word_t n;
351+ byte_t _pad36[4];
352+ real_t x;
353+};
354+void Math_lgamma(vm_registers_t &r, vm_t &vm);
355+struct F_Math_lgamma : public vm_frame_base_alloc_t
356+{
357+ struct { word_t t0; byte_t _pad4[4]; real_t t1; }*ret;
358+ byte_t temps[12];
359+ real_t x;
360+};
361+void Math_log(vm_registers_t &r, vm_t &vm);
362+struct F_Math_log : public vm_frame_base_alloc_t
363+{
364+ real_t* ret;
365+ byte_t temps[12];
366+ real_t x;
367+};
368+void Math_log10(vm_registers_t &r, vm_t &vm);
369+struct F_Math_log10 : public vm_frame_base_alloc_t
370+{
371+ real_t* ret;
372+ byte_t temps[12];
373+ real_t x;
374+};
375+void Math_log1p(vm_registers_t &r, vm_t &vm);
376+struct F_Math_log1p : public vm_frame_base_alloc_t
377+{
378+ real_t* ret;
379+ byte_t temps[12];
380+ real_t x;
381+};
382+void Math_modf(vm_registers_t &r, vm_t &vm);
383+struct F_Math_modf : public vm_frame_base_alloc_t
384+{
385+ struct { word_t t0; byte_t _pad4[4]; real_t t1; }*ret;
386+ byte_t temps[12];
387+ real_t x;
388+};
389+void Math_nextafter(vm_registers_t &r, vm_t &vm);
390+struct F_Math_nextafter : public vm_frame_base_alloc_t
391+{
392+ real_t* ret;
393+ byte_t temps[12];
394+ real_t x;
395+ real_t y;
396+};
397+void Math_norm1(vm_registers_t &r, vm_t &vm);
398+struct F_Math_norm1 : public vm_frame_base_alloc_t
399+{
400+ real_t* ret;
401+ byte_t temps[12];
402+ /* vm_array_t */ pointer_t x;
403+};
404+void Math_norm2(vm_registers_t &r, vm_t &vm);
405+struct F_Math_norm2 : public vm_frame_base_alloc_t
406+{
407+ real_t* ret;
408+ byte_t temps[12];
409+ /* vm_array_t */ pointer_t x;
410+};
411+void Math_pow(vm_registers_t &r, vm_t &vm);
412+struct F_Math_pow : public vm_frame_base_alloc_t
413+{
414+ real_t* ret;
415+ byte_t temps[12];
416+ real_t x;
417+ real_t y;
418+};
419+void Math_pow10(vm_registers_t &r, vm_t &vm);
420+struct F_Math_pow10 : public vm_frame_base_alloc_t
421+{
422+ real_t* ret;
423+ byte_t temps[12];
424+ word_t p;
425+};
426+void Math_realbits32(vm_registers_t &r, vm_t &vm);
427+struct F_Math_realbits32 : public vm_frame_base_alloc_t
428+{
429+ word_t* ret;
430+ byte_t temps[12];
431+ real_t x;
432+};
433+void Math_realbits64(vm_registers_t &r, vm_t &vm);
434+struct F_Math_realbits64 : public vm_frame_base_alloc_t
435+{
436+ big_t* ret;
437+ byte_t temps[12];
438+ real_t x;
439+};
440+void Math_remainder(vm_registers_t &r, vm_t &vm);
441+struct F_Math_remainder : public vm_frame_base_alloc_t
442+{
443+ real_t* ret;
444+ byte_t temps[12];
445+ real_t x;
446+ real_t p;
447+};
448+void Math_rint(vm_registers_t &r, vm_t &vm);
449+struct F_Math_rint : public vm_frame_base_alloc_t
450+{
451+ real_t* ret;
452+ byte_t temps[12];
453+ real_t x;
454+};
455+void Math_scalbn(vm_registers_t &r, vm_t &vm);
456+struct F_Math_scalbn : public vm_frame_base_alloc_t
457+{
458+ real_t* ret;
459+ byte_t temps[12];
460+ real_t x;
461+ word_t n;
462+};
463+void Math_sin(vm_registers_t &r, vm_t &vm);
464+struct F_Math_sin : public vm_frame_base_alloc_t
465+{
466+ real_t* ret;
467+ byte_t temps[12];
468+ real_t x;
469+};
470+void Math_sinh(vm_registers_t &r, vm_t &vm);
471+struct F_Math_sinh : public vm_frame_base_alloc_t
472+{
473+ real_t* ret;
474+ byte_t temps[12];
475+ real_t x;
476+};
477+void Math_sort(vm_registers_t &r, vm_t &vm);
478+struct F_Math_sort : public vm_frame_base_alloc_t
479+{
480+ word_t noret;
481+ byte_t temps[12];
482+ /* vm_array_t */ pointer_t x;
483+ /* vm_array_t */ pointer_t pi;
484+};
485+void Math_sqrt(vm_registers_t &r, vm_t &vm);
486+struct F_Math_sqrt : public vm_frame_base_alloc_t
487+{
488+ real_t* ret;
489+ byte_t temps[12];
490+ real_t x;
491+};
492+void Math_tan(vm_registers_t &r, vm_t &vm);
493+struct F_Math_tan : public vm_frame_base_alloc_t
494+{
495+ real_t* ret;
496+ byte_t temps[12];
497+ real_t x;
498+};
499+void Math_tanh(vm_registers_t &r, vm_t &vm);
500+struct F_Math_tanh : public vm_frame_base_alloc_t
501+{
502+ real_t* ret;
503+ byte_t temps[12];
504+ real_t x;
505+};
506+void Math_y0(vm_registers_t &r, vm_t &vm);
507+struct F_Math_y0 : public vm_frame_base_alloc_t
508+{
509+ real_t* ret;
510+ byte_t temps[12];
511+ real_t x;
512+};
513+void Math_y1(vm_registers_t &r, vm_t &vm);
514+struct F_Math_y1 : public vm_frame_base_alloc_t
515+{
516+ real_t* ret;
517+ byte_t temps[12];
518+ real_t x;
519+};
520+void Math_yn(vm_registers_t &r, vm_t &vm);
521+struct F_Math_yn : public vm_frame_base_alloc_t
522+{
523+ real_t* ret;
524+ byte_t temps[12];
525+ word_t n;
526+ byte_t _pad36[4];
527+ real_t x;
528+};
529+const char *Math_PATH = "$Math";
530+const real_t Math_Infinity = INFINITY;
531+const real_t Math_NaN = NAN;
532+
533+static_assert(sizeof(real_t) == 8, "Recalculate EPS if size of real_t is changing");
534+const real_t Math_MachEps = 2.220446049250313e-16; // 64-bit double
535+const real_t Math_Pi = 3.141592653589793;
536+const real_t Math_Degree = .017453292519943295;
537+const word_t Math_INVAL = 0x1;
538+const word_t Math_ZDIV = 0x2;
539+const word_t Math_OVFL = 0x4;
540+const word_t Math_UNFL = 0x8;
541+const word_t Math_INEX = 0x10;
542+const word_t Math_RND_NR = 0x0;
543+const word_t Math_RND_NINF = 0x100;
544+const word_t Math_RND_PINF = 0x200;
545+const word_t Math_RND_Z = 0x300;
546+const word_t Math_RND_MASK = 0x300;
547+
548+#endif // _DISVM_SRC_VM_MATH_MATHMOD_H_