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
27 27
28// Declare initializers for built-in modules.28// Declare initializers for built-in modules.
29extern void Sysmodinit(void);29extern void Sysmodinit(void);
30extern void Mathmodinit(void);
30 31
31void disvm::runtime::builtin::initialize_builtin_modules()32void disvm::runtime::builtin::initialize_builtin_modules()
32{33{
@@ -38,6 +39,7 @@ void disvm::runtime::builtin::initialize_builtin_modules() · 5 unmodified lines
38 // e.g. Sysmodinit()39 // e.g. Sysmodinit()
39 40
40 Sysmodinit();41 Sysmodinit();
42 Mathmodinit();
41}43}
42 44
43void disvm::runtime::builtin::register_module_exports(const char *name, word_t table_length, const vm_runtab_t *module_runtime_table)45void 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
23 'vm.cpp',23 'vm.cpp',
24 'vm_memory.cpp',24 'vm_memory.cpp',
25 'vm_exception_handler.cpp',25 'vm_exception_handler.cpp',
26 'math/Mathmod.cpp',
26 'sys/print.cpp',27 'sys/print.cpp',
27 'sys/Sysmod.cpp',28 'sys/Sysmod.cpp',
28 'sys/file_system.cpp',29 '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
9using namespace disvm;
10using namespace disvm::runtime;
11
12namespace
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
89void
90Mathmodinit(void)
91{
92 builtin::register_module_exports(Math_PATH, Mathmodlen, Mathmodtab);
93}
94
95void
96Math_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
104void
105Math_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
111void
112Math_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
118void
119Math_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
125void
126Math_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
132void
133Math_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
139void
140Math_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
146void
147Math_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
153void
154Math_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
160void
161Math_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
167void
168Math_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
174void
175Math_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
181void
182Math_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
188void
189Math_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
195void
196Math_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
202void
203Math_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
209void
210Math_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
216void
217Math_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
223void
224Math_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
230void
231Math_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
237void
238Math_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
244void
245Math_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
251void
252Math_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
258void
259Math_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
265void
266Math_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
272void
273Math_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
279void
280Math_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
286void
287Math_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
293void
294Math_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
300void
301Math_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
307void
308Math_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
314void
315Math_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
321void
322Math_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
328void
329Math_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
335void
336Math_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
342void
343Math_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
349void
350Math_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
356void
357Math_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
363void
364Math_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
393void
394Math_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
400void
401Math_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
407void
408Math_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
414void
415Math_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
421void
422Math_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
428void
429Math_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
435void
436Math_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
442void
443Math_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
449void
450Math_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
456void
457Math_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
463void
464Math_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
470void
471Math_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
477void
478Math_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
484void
485Math_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
491void
492Math_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
498void
499Math_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
505void
506Math_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
512void
513Math_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
519void
520Math_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
526void
527Math_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
533void
534Math_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
540void
541Math_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
547void
548Math_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
554void
555Math_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
561void
562Math_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
568void
569Math_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
575void
576Math_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
582void
583Math_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
589void
590Math_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
14using namespace disvm;
15using namespace disvm::runtime;
16
17void Math_FPcontrol(vm_registers_t &r, vm_t &vm);
18struct 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};
25void Math_FPstatus(vm_registers_t &r, vm_t &vm);
26struct 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};
33void Math_acos(vm_registers_t &r, vm_t &vm);
34struct F_Math_acos : public vm_frame_base_alloc_t
35{
36 real_t* ret;
37 byte_t temps[12];
38 real_t x;
39};
40void Math_acosh(vm_registers_t &r, vm_t &vm);
41struct F_Math_acosh : public vm_frame_base_alloc_t
42{
43 real_t* ret;
44 byte_t temps[12];
45 real_t x;
46};
47void Math_asin(vm_registers_t &r, vm_t &vm);
48struct F_Math_asin : public vm_frame_base_alloc_t
49{
50 real_t* ret;
51 byte_t temps[12];
52 real_t x;
53};
54void Math_asinh(vm_registers_t &r, vm_t &vm);
55struct F_Math_asinh : public vm_frame_base_alloc_t
56{
57 real_t* ret;
58 byte_t temps[12];
59 real_t x;
60};
61void Math_atan(vm_registers_t &r, vm_t &vm);
62struct F_Math_atan : public vm_frame_base_alloc_t
63{
64 real_t* ret;
65 byte_t temps[12];
66 real_t x;
67};
68void Math_atan2(vm_registers_t &r, vm_t &vm);
69struct 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};
76void Math_atanh(vm_registers_t &r, vm_t &vm);
77struct F_Math_atanh : public vm_frame_base_alloc_t
78{
79 real_t* ret;
80 byte_t temps[12];
81 real_t x;
82};
83void Math_bits32real(vm_registers_t &r, vm_t &vm);
84struct F_Math_bits32real : public vm_frame_base_alloc_t
85{
86 real_t* ret;
87 byte_t temps[12];
88 word_t b;
89};
90void Math_bits64real(vm_registers_t &r, vm_t &vm);
91struct F_Math_bits64real : public vm_frame_base_alloc_t
92{
93 real_t* ret;
94 byte_t temps[12];
95 big_t b;
96};
97void Math_cbrt(vm_registers_t &r, vm_t &vm);
98struct F_Math_cbrt : public vm_frame_base_alloc_t
99{
100 real_t* ret;
101 byte_t temps[12];
102 real_t x;
103};
104void Math_ceil(vm_registers_t &r, vm_t &vm);
105struct F_Math_ceil : public vm_frame_base_alloc_t
106{
107 real_t* ret;
108 byte_t temps[12];
109 real_t x;
110};
111void Math_copysign(vm_registers_t &r, vm_t &vm);
112struct 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};
119void Math_cos(vm_registers_t &r, vm_t &vm);
120struct F_Math_cos : public vm_frame_base_alloc_t
121{
122 real_t* ret;
123 byte_t temps[12];
124 real_t x;
125};
126void Math_cosh(vm_registers_t &r, vm_t &vm);
127struct F_Math_cosh : public vm_frame_base_alloc_t
128{
129 real_t* ret;
130 byte_t temps[12];
131 real_t x;
132};
133void Math_dot(vm_registers_t &r, vm_t &vm);
134struct 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};
141void Math_erf(vm_registers_t &r, vm_t &vm);
142struct F_Math_erf : public vm_frame_base_alloc_t
143{
144 real_t* ret;
145 byte_t temps[12];
146 real_t x;
147};
148void Math_erfc(vm_registers_t &r, vm_t &vm);
149struct F_Math_erfc : public vm_frame_base_alloc_t
150{
151 real_t* ret;
152 byte_t temps[12];
153 real_t x;
154};
155void Math_exp(vm_registers_t &r, vm_t &vm);
156struct F_Math_exp : public vm_frame_base_alloc_t
157{
158 real_t* ret;
159 byte_t temps[12];
160 real_t x;
161};
162void Math_expm1(vm_registers_t &r, vm_t &vm);
163struct F_Math_expm1 : public vm_frame_base_alloc_t
164{
165 real_t* ret;
166 byte_t temps[12];
167 real_t x;
168};
169void Math_export_int(vm_registers_t &r, vm_t &vm);
170struct 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};
177void Math_export_real(vm_registers_t &r, vm_t &vm);
178struct 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};
185void Math_export_real32(vm_registers_t &r, vm_t &vm);
186struct 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};
193void Math_fabs(vm_registers_t &r, vm_t &vm);
194struct F_Math_fabs : public vm_frame_base_alloc_t
195{
196 real_t* ret;
197 byte_t temps[12];
198 real_t x;
199};
200void Math_fdim(vm_registers_t &r, vm_t &vm);
201struct 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};
208void Math_finite(vm_registers_t &r, vm_t &vm);
209struct F_Math_finite : public vm_frame_base_alloc_t
210{
211 word_t* ret;
212 byte_t temps[12];
213 real_t x;
214};
215void Math_floor(vm_registers_t &r, vm_t &vm);
216struct F_Math_floor : public vm_frame_base_alloc_t
217{
218 real_t* ret;
219 byte_t temps[12];
220 real_t x;
221};
222void Math_fmax(vm_registers_t &r, vm_t &vm);
223struct 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};
230void Math_fmin(vm_registers_t &r, vm_t &vm);
231struct 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};
238void Math_fmod(vm_registers_t &r, vm_t &vm);
239struct 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};
246void Math_gemm(vm_registers_t &r, vm_t &vm);
247struct 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};
266void Math_getFPcontrol(vm_registers_t &r, vm_t &vm);
267struct F_Math_getFPcontrol : public vm_frame_base_alloc_t
268{
269 word_t* ret;
270 byte_t temps[12];
271};
272void Math_getFPstatus(vm_registers_t &r, vm_t &vm);
273struct F_Math_getFPstatus : public vm_frame_base_alloc_t
274{
275 word_t* ret;
276 byte_t temps[12];
277};
278void Math_hypot(vm_registers_t &r, vm_t &vm);
279struct 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};
286void Math_iamax(vm_registers_t &r, vm_t &vm);
287struct 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};
293void Math_ilogb(vm_registers_t &r, vm_t &vm);
294struct F_Math_ilogb : public vm_frame_base_alloc_t
295{
296 word_t* ret;
297 byte_t temps[12];
298 real_t x;
299};
300void Math_import_int(vm_registers_t &r, vm_t &vm);
301struct 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};
308void Math_import_real(vm_registers_t &r, vm_t &vm);
309struct 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};
316void Math_import_real32(vm_registers_t &r, vm_t &vm);
317struct 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};
324void Math_isnan(vm_registers_t &r, vm_t &vm);
325struct F_Math_isnan : public vm_frame_base_alloc_t
326{
327 word_t* ret;
328 byte_t temps[12];
329 real_t x;
330};
331void Math_j0(vm_registers_t &r, vm_t &vm);
332struct F_Math_j0 : public vm_frame_base_alloc_t
333{
334 real_t* ret;
335 byte_t temps[12];
336 real_t x;
337};
338void Math_j1(vm_registers_t &r, vm_t &vm);
339struct F_Math_j1 : public vm_frame_base_alloc_t
340{
341 real_t* ret;
342 byte_t temps[12];
343 real_t x;
344};
345void Math_jn(vm_registers_t &r, vm_t &vm);
346struct 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};
354void Math_lgamma(vm_registers_t &r, vm_t &vm);
355struct 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};
361void Math_log(vm_registers_t &r, vm_t &vm);
362struct F_Math_log : public vm_frame_base_alloc_t
363{
364 real_t* ret;
365 byte_t temps[12];
366 real_t x;
367};
368void Math_log10(vm_registers_t &r, vm_t &vm);
369struct F_Math_log10 : public vm_frame_base_alloc_t
370{
371 real_t* ret;
372 byte_t temps[12];
373 real_t x;
374};
375void Math_log1p(vm_registers_t &r, vm_t &vm);
376struct F_Math_log1p : public vm_frame_base_alloc_t
377{
378 real_t* ret;
379 byte_t temps[12];
380 real_t x;
381};
382void Math_modf(vm_registers_t &r, vm_t &vm);
383struct 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};
389void Math_nextafter(vm_registers_t &r, vm_t &vm);
390struct 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};
397void Math_norm1(vm_registers_t &r, vm_t &vm);
398struct 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};
404void Math_norm2(vm_registers_t &r, vm_t &vm);
405struct 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};
411void Math_pow(vm_registers_t &r, vm_t &vm);
412struct 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};
419void Math_pow10(vm_registers_t &r, vm_t &vm);
420struct F_Math_pow10 : public vm_frame_base_alloc_t
421{
422 real_t* ret;
423 byte_t temps[12];
424 word_t p;
425};
426void Math_realbits32(vm_registers_t &r, vm_t &vm);
427struct F_Math_realbits32 : public vm_frame_base_alloc_t
428{
429 word_t* ret;
430 byte_t temps[12];
431 real_t x;
432};
433void Math_realbits64(vm_registers_t &r, vm_t &vm);
434struct F_Math_realbits64 : public vm_frame_base_alloc_t
435{
436 big_t* ret;
437 byte_t temps[12];
438 real_t x;
439};
440void Math_remainder(vm_registers_t &r, vm_t &vm);
441struct 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};
448void Math_rint(vm_registers_t &r, vm_t &vm);
449struct F_Math_rint : public vm_frame_base_alloc_t
450{
451 real_t* ret;
452 byte_t temps[12];
453 real_t x;
454};
455void Math_scalbn(vm_registers_t &r, vm_t &vm);
456struct 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};
463void Math_sin(vm_registers_t &r, vm_t &vm);
464struct F_Math_sin : public vm_frame_base_alloc_t
465{
466 real_t* ret;
467 byte_t temps[12];
468 real_t x;
469};
470void Math_sinh(vm_registers_t &r, vm_t &vm);
471struct F_Math_sinh : public vm_frame_base_alloc_t
472{
473 real_t* ret;
474 byte_t temps[12];
475 real_t x;
476};
477void Math_sort(vm_registers_t &r, vm_t &vm);
478struct 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};
485void Math_sqrt(vm_registers_t &r, vm_t &vm);
486struct F_Math_sqrt : public vm_frame_base_alloc_t
487{
488 real_t* ret;
489 byte_t temps[12];
490 real_t x;
491};
492void Math_tan(vm_registers_t &r, vm_t &vm);
493struct F_Math_tan : public vm_frame_base_alloc_t
494{
495 real_t* ret;
496 byte_t temps[12];
497 real_t x;
498};
499void Math_tanh(vm_registers_t &r, vm_t &vm);
500struct F_Math_tanh : public vm_frame_base_alloc_t
501{
502 real_t* ret;
503 byte_t temps[12];
504 real_t x;
505};
506void Math_y0(vm_registers_t &r, vm_t &vm);
507struct F_Math_y0 : public vm_frame_base_alloc_t
508{
509 real_t* ret;
510 byte_t temps[12];
511 real_t x;
512};
513void Math_y1(vm_registers_t &r, vm_t &vm);
514struct F_Math_y1 : public vm_frame_base_alloc_t
515{
516 real_t* ret;
517 byte_t temps[12];
518 real_t x;
519};
520void Math_yn(vm_registers_t &r, vm_t &vm);
521struct 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};
529const char *Math_PATH = "$Math";
530const real_t Math_Infinity = INFINITY;
531const real_t Math_NaN = NAN;
532
533static_assert(sizeof(real_t) == 8, "Recalculate EPS if size of real_t is changing");
534const real_t Math_MachEps = 2.220446049250313e-16; // 64-bit double
535const real_t Math_Pi = 3.141592653589793;
536const real_t Math_Degree = .017453292519943295;
537const word_t Math_INVAL = 0x1;
538const word_t Math_ZDIV = 0x2;
539const word_t Math_OVFL = 0x4;
540const word_t Math_UNFL = 0x8;
541const word_t Math_INEX = 0x10;
542const word_t Math_RND_NR = 0x0;
543const word_t Math_RND_NINF = 0x100;
544const word_t Math_RND_PINF = 0x200;
545const word_t Math_RND_Z = 0x300;
546const word_t Math_RND_MASK = 0x300;
547
548#endif // _DISVM_SRC_VM_MATH_MATHMOD_H_