compile_math.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. int compile_sin(int retreg, Cell* args, int requires) {
  2. if (!car(args)) return argnum_error("(sin rad*10000)");
  3. Cell* arg = car(args);
  4. compile_arg(JIT_R0, arg, TAG_PURE_INT);
  5. jit_extr_d(JIT_F0, JIT_R0); // F0 = (float)R0
  6. jit_divi_d(JIT_F0, JIT_F0, 10000.0); // F0 = R0/10000
  7. jit_prepare();
  8. jit_pushargr_d(JIT_F0);
  9. jit_finishi(sin);
  10. jit_retval_d(JIT_F0);
  11. jit_muli_d(JIT_F0, JIT_F0, 10000.0); // F0 = 10000*F0
  12. jit_truncr_d_i(retreg, JIT_F0); // retreg = (float)F0
  13. return box_int(retreg, requires);
  14. }
  15. int compile_cos(int retreg, Cell* args, int requires) {
  16. if (!car(args)) return argnum_error("(cos rad*10000)");
  17. Cell* arg = car(args);
  18. compile_arg(JIT_R0, arg, TAG_PURE_INT);
  19. jit_extr_d(JIT_F0, JIT_R0); // F0 = (float)R0
  20. jit_divi_d(JIT_F0, JIT_F0, 10000.0); // F0 = R0/10000
  21. jit_prepare();
  22. jit_pushargr_d(JIT_F0);
  23. jit_finishi(cos);
  24. jit_retval_d(JIT_F0);
  25. jit_muli_d(JIT_F0, JIT_F0, 10000.0); // F0 = 10000*F0
  26. jit_truncr_d_i(retreg, JIT_F0); // retreg = (float)F0
  27. return box_int(retreg, requires);
  28. }
  29. int compile_sqrt(int retreg, Cell* args, int requires) {
  30. if (!car(args)) return argnum_error("(sqrt 36)");
  31. Cell* arg = car(args);
  32. compile_arg(JIT_R0, arg, TAG_PURE_INT);
  33. jit_extr_d(JIT_F0, JIT_R0); // F0 = (float)R0
  34. /*jit_prepare();
  35. jit_pushargr_d(JIT_F0);
  36. jit_finishi(sqrt);
  37. jit_retval_d(JIT_F0);*/
  38. jit_truncr_d_i(retreg, JIT_F0); // retreg = (float)F0
  39. return box_int(retreg, requires);
  40. }