mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-17 17:20:29 +02:00
Add support for optimized unboxed abs and sqrt
Some components of this have been wired up for a while; this commit finishes the compiler, runtime, and JIT support. * libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): * libguile/intrinsics.c (scm_bootstrap_intrinsics): Declare the new intrinsics. * libguile/jit.c (compile_call_f64_from_f64): Define code generators for the new intrinsics. * libguile/vm-engine.c (call-f64<-f64): New instruction. * module/language/cps/effects-analysis.scm: * module/language/cps/reify-primitives.scm (compute-known-primitives): * module/language/cps/slot-allocation.scm (compute-var-representations): * module/language/cps/specialize-numbers.scm (specialize-operations): * module/language/tree-il/cps-primitives.scm (abs): * module/system/vm/assembler.scm (system, define-f64<-f64-intrinsic): (sqrt, abs, fsqrt, fabs): * module/language/cps/types.scm (fsqrt, fabs): Add new f64<-f64 primitives.
This commit is contained in:
parent
ef1869b723
commit
382cc5c246
11 changed files with 101 additions and 5 deletions
|
@ -21,6 +21,8 @@
|
|||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "alist.h"
|
||||
#include "atomics-internal.h"
|
||||
#include "boolean.h"
|
||||
|
@ -516,6 +518,10 @@ scm_bootstrap_intrinsics (void)
|
|||
scm_vm_intrinsics.current_module = current_module;
|
||||
scm_vm_intrinsics.push_prompt = push_prompt;
|
||||
scm_vm_intrinsics.allocate_words_with_freelist = allocate_words_with_freelist;
|
||||
scm_vm_intrinsics.abs = scm_abs;
|
||||
scm_vm_intrinsics.sqrt = scm_sqrt;
|
||||
scm_vm_intrinsics.fabs = fabs;
|
||||
scm_vm_intrinsics.fsqrt = sqrt;
|
||||
|
||||
scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
|
||||
"scm_init_intrinsics",
|
||||
|
|
|
@ -92,6 +92,7 @@ typedef SCM (*scm_t_scm_from_ptr_intrinsic) (SCM*);
|
|||
typedef void (*scm_t_ptr_scm_intrinsic) (SCM*, SCM);
|
||||
typedef SCM (*scm_t_scm_from_ptr_scm_intrinsic) (SCM*, SCM);
|
||||
typedef SCM (*scm_t_scm_from_ptr_scm_scm_intrinsic) (SCM*, SCM, SCM);
|
||||
typedef double (*scm_t_f64_from_f64_intrinsic) (double);
|
||||
typedef uint32_t* scm_t_vcode_intrinsic;
|
||||
|
||||
#define SCM_FOR_ALL_VM_INTRINSICS(M) \
|
||||
|
@ -162,6 +163,10 @@ typedef uint32_t* scm_t_vcode_intrinsic;
|
|||
M(thread_scm, unpack_values_object, "unpack-values-object", UNPACK_VALUES_OBJECT) \
|
||||
M(vcode, handle_interrupt_code, "%handle-interrupt-code", HANDLE_INTERRUPT_CODE) \
|
||||
M(scm_from_thread_sz, allocate_words_with_freelist, "allocate-words/freelist", ALLOCATE_WORDS_WITH_FREELIST) \
|
||||
M(scm_from_scm, abs, "abs", ABS) \
|
||||
M(scm_from_scm, sqrt, "sqrt", SQRT) \
|
||||
M(f64_from_f64, fabs, "fabs", FABS) \
|
||||
M(f64_from_f64, fsqrt, "fsqrt", FSQRT) \
|
||||
/* Add new intrinsics here; also update scm_bootstrap_intrinsics. */
|
||||
|
||||
enum scm_vm_intrinsic
|
||||
|
|
|
@ -516,6 +516,8 @@ DEFINE_CLOBBER_RECORDING_EMITTER_R_I(muli, gpr)
|
|||
DEFINE_CLOBBER_RECORDING_EMITTER_R_R(mulr, gpr)
|
||||
DEFINE_CLOBBER_RECORDING_EMITTER_R_R(mulr_d, fpr)
|
||||
DEFINE_CLOBBER_RECORDING_EMITTER_R_R(divr_d, fpr)
|
||||
DEFINE_CLOBBER_RECORDING_EMITTER_R(absr_d, fpr)
|
||||
DEFINE_CLOBBER_RECORDING_EMITTER_R(sqrtr_d, fpr)
|
||||
DEFINE_CLOBBER_RECORDING_EMITTER_R_I(andi, gpr)
|
||||
DEFINE_CLOBBER_RECORDING_EMITTER_R_R(andr, gpr)
|
||||
DEFINE_CLOBBER_RECORDING_EMITTER_R_R(orr, gpr)
|
||||
|
@ -2362,6 +2364,30 @@ compile_call_f64_from_scm (scm_jit_state *j, uint16_t dst, uint16_t a, uint32_t
|
|||
emit_sp_set_f64 (j, dst, JIT_F0);
|
||||
}
|
||||
|
||||
static void
|
||||
compile_call_f64_from_f64 (scm_jit_state *j, uint16_t dst, uint16_t src, uint32_t idx)
|
||||
{
|
||||
switch ((enum scm_vm_intrinsic) idx)
|
||||
{
|
||||
case SCM_VM_INTRINSIC_FABS:
|
||||
{
|
||||
emit_sp_ref_f64 (j, JIT_F0, src);
|
||||
emit_absr_d (j, JIT_F0, JIT_F0);
|
||||
emit_sp_set_f64 (j, dst, JIT_F0);
|
||||
break;
|
||||
}
|
||||
case SCM_VM_INTRINSIC_FSQRT:
|
||||
{
|
||||
emit_sp_ref_f64 (j, JIT_F0, src);
|
||||
emit_sqrtr_d (j, JIT_F0, JIT_F0);
|
||||
emit_sp_set_f64 (j, dst, JIT_F0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
DIE("unhandled f64<-f64");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
compile_call_u64_from_scm (scm_jit_state *j, uint16_t dst, uint16_t a, uint32_t idx)
|
||||
{
|
||||
|
|
|
@ -3242,7 +3242,25 @@ VM_NAME (scm_thread *thread)
|
|||
NEXT (1);
|
||||
}
|
||||
|
||||
VM_DEFINE_OP (155, unused_155, NULL, NOP)
|
||||
/* call-f64<-f64 dst:12 src:12 IDX:32
|
||||
*
|
||||
* Call the double-returning instrinsic with index IDX, passing SCM
|
||||
* local SRC as argument. Place the double result in DST.
|
||||
*/
|
||||
VM_DEFINE_OP (155, call_f64_from_f64, "call-f64<-f64", DOP2 (X8_S12_S12, C32))
|
||||
{
|
||||
uint16_t dst, src;
|
||||
scm_t_f64_from_f64_intrinsic intrinsic;
|
||||
|
||||
UNPACK_12_12 (op, dst, src);
|
||||
intrinsic = intrinsics[ip[1]];
|
||||
|
||||
/* We assume these instructions can't throw an exception. */
|
||||
SP_SET_F64 (dst, intrinsic (SP_REF_F64 (src)));
|
||||
|
||||
NEXT (2);
|
||||
}
|
||||
|
||||
VM_DEFINE_OP (156, unused_156, NULL, NOP)
|
||||
VM_DEFINE_OP (157, unused_157, NULL, NOP)
|
||||
VM_DEFINE_OP (158, unused_158, NULL, NOP)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue