aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrea Corallo2019-08-15 17:43:58 +0200
committerAndrea Corallo2020-01-01 11:34:00 +0100
commitaf51e6556daaa4e847209f79ac9dbc1a3ecc8836 (patch)
tree37b7679c7fef98a9975f723dac02804a138b5941 /src
parent757a95906805b1d7fcbe4b536841a7b53ce0c047 (diff)
downloademacs-af51e6556daaa4e847209f79ac9dbc1a3ecc8836.tar.gz
emacs-af51e6556daaa4e847209f79ac9dbc1a3ecc8836.zip
inline add1
Diffstat (limited to 'src')
-rw-r--r--src/comp.c283
1 files changed, 187 insertions, 96 deletions
diff --git a/src/comp.c b/src/comp.c
index 8a9d98fde51..95390c52638 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -136,6 +136,8 @@ typedef struct {
136 gcc_jit_rvalue *lisp_int0; 136 gcc_jit_rvalue *lisp_int0;
137 gcc_jit_function *pseudovectorp; 137 gcc_jit_function *pseudovectorp;
138 gcc_jit_function *bool_to_lisp_obj; 138 gcc_jit_function *bool_to_lisp_obj;
139 gcc_jit_function *add1;
140 gcc_jit_function *sub1;
139 gcc_jit_function *car; 141 gcc_jit_function *car;
140 gcc_jit_function *cdr; 142 gcc_jit_function *cdr;
141 gcc_jit_function *setcar; 143 gcc_jit_function *setcar;
@@ -615,67 +617,67 @@ emit_CONSP (gcc_jit_rvalue *obj)
615/* args); */ 617/* args); */
616/* } */ 618/* } */
617 619
618/* static gcc_jit_rvalue * */ 620static gcc_jit_rvalue *
619/* emit_FIXNUMP (gcc_jit_rvalue *obj) */ 621emit_FIXNUMP (gcc_jit_rvalue *obj)
620/* { */ 622{
621/* /\* (! (((unsigned) (XLI (x) >> (USE_LSB_TAG ? 0 : FIXNUM_BITS)) */ 623 /* (! (((unsigned) (XLI (x) >> (USE_LSB_TAG ? 0 : FIXNUM_BITS))
622/* - (unsigned) (Lisp_Int0 >> !USE_LSB_TAG)) */ 624 - (unsigned) (Lisp_Int0 >> !USE_LSB_TAG))
623/* & ((1 << INTTYPEBITS) - 1))) *\/ */ 625 & ((1 << INTTYPEBITS) - 1))) */
624/* emit_comment ("FIXNUMP"); */ 626 emit_comment ("FIXNUMP");
625
626/* gcc_jit_rvalue *sh_res = */
627/* gcc_jit_context_new_binary_op ( */
628/* comp.ctxt, */
629/* NULL, */
630/* GCC_JIT_BINARY_OP_RSHIFT, */
631/* comp.emacs_int_type, */
632/* emit_XLI (obj), */
633/* gcc_jit_context_new_rvalue_from_int (comp.ctxt, */
634/* comp.emacs_int_type, */
635/* (USE_LSB_TAG ? 0 : FIXNUM_BITS))); */
636
637/* gcc_jit_rvalue *minus_res = */
638/* gcc_jit_context_new_binary_op (comp.ctxt, */
639/* NULL, */
640/* GCC_JIT_BINARY_OP_MINUS, */
641/* comp.unsigned_type, */
642/* emit_cast (comp.unsigned_type, sh_res), */
643/* gcc_jit_context_new_rvalue_from_int ( */
644/* comp.ctxt, */
645/* comp.unsigned_type, */
646/* (Lisp_Int0 >> !USE_LSB_TAG))); */
647
648/* gcc_jit_rvalue *res = */
649/* gcc_jit_context_new_unary_op ( */
650/* comp.ctxt, */
651/* NULL, */
652/* GCC_JIT_UNARY_OP_LOGICAL_NEGATE, */
653/* comp.int_type, */
654/* gcc_jit_context_new_binary_op (comp.ctxt, */
655/* NULL, */
656/* GCC_JIT_BINARY_OP_BITWISE_AND, */
657/* comp.unsigned_type, */
658/* minus_res, */
659/* gcc_jit_context_new_rvalue_from_int ( */
660/* comp.ctxt, */
661/* comp.unsigned_type, */
662/* ((1 << INTTYPEBITS) - 1)))); */
663
664/* return res; */
665/* } */
666 627
667/* static gcc_jit_rvalue * */ 628 gcc_jit_rvalue *sh_res =
668/* emit_XFIXNUM (gcc_jit_rvalue *obj) */ 629 gcc_jit_context_new_binary_op (
669/* { */ 630 comp.ctxt,
670/* emit_comment ("XFIXNUM"); */ 631 NULL,
632 GCC_JIT_BINARY_OP_RSHIFT,
633 comp.emacs_int_type,
634 emit_XLI (obj),
635 gcc_jit_context_new_rvalue_from_int (comp.ctxt,
636 comp.emacs_int_type,
637 (USE_LSB_TAG ? 0 : FIXNUM_BITS)));
671 638
672/* return gcc_jit_context_new_binary_op (comp.ctxt, */ 639 gcc_jit_rvalue *minus_res =
673/* NULL, */ 640 gcc_jit_context_new_binary_op (comp.ctxt,
674/* GCC_JIT_BINARY_OP_RSHIFT, */ 641 NULL,
675/* comp.emacs_int_type, */ 642 GCC_JIT_BINARY_OP_MINUS,
676/* emit_XLI (obj), */ 643 comp.unsigned_type,
677/* comp.inttypebits); */ 644 emit_cast (comp.unsigned_type, sh_res),
678/* } */ 645 gcc_jit_context_new_rvalue_from_int (
646 comp.ctxt,
647 comp.unsigned_type,
648 (Lisp_Int0 >> !USE_LSB_TAG)));
649
650 gcc_jit_rvalue *res =
651 gcc_jit_context_new_unary_op (
652 comp.ctxt,
653 NULL,
654 GCC_JIT_UNARY_OP_LOGICAL_NEGATE,
655 comp.int_type,
656 gcc_jit_context_new_binary_op (comp.ctxt,
657 NULL,
658 GCC_JIT_BINARY_OP_BITWISE_AND,
659 comp.unsigned_type,
660 minus_res,
661 gcc_jit_context_new_rvalue_from_int (
662 comp.ctxt,
663 comp.unsigned_type,
664 ((1 << INTTYPEBITS) - 1))));
665
666 return res;
667}
668
669static gcc_jit_rvalue *
670emit_XFIXNUM (gcc_jit_rvalue *obj)
671{
672 emit_comment ("XFIXNUM");
673
674 return gcc_jit_context_new_binary_op (comp.ctxt,
675 NULL,
676 GCC_JIT_BINARY_OP_RSHIFT,
677 comp.emacs_int_type,
678 emit_XLI (obj),
679 comp.inttypebits);
680}
679 681
680/* static gcc_jit_rvalue * */ 682/* static gcc_jit_rvalue * */
681/* emit_INTEGERP (gcc_jit_rvalue *obj) */ 683/* emit_INTEGERP (gcc_jit_rvalue *obj) */
@@ -705,38 +707,38 @@ emit_CONSP (gcc_jit_rvalue *obj)
705/* emit_FLOATP (obj))); */ 707/* emit_FLOATP (obj))); */
706/* } */ 708/* } */
707 709
708/* static gcc_jit_rvalue * */ 710static gcc_jit_rvalue *
709/* emit_make_fixnum (gcc_jit_rvalue *obj) */ 711emit_make_fixnum (gcc_jit_rvalue *obj)
710/* { */ 712{
711/* emit_comment ("make_fixnum"); */ 713 emit_comment ("make_fixnum");
712 714
713/* gcc_jit_rvalue *tmp = */ 715 gcc_jit_rvalue *tmp =
714/* gcc_jit_context_new_binary_op (comp.ctxt, */ 716 gcc_jit_context_new_binary_op (comp.ctxt,
715/* NULL, */ 717 NULL,
716/* GCC_JIT_BINARY_OP_LSHIFT, */ 718 GCC_JIT_BINARY_OP_LSHIFT,
717/* comp.emacs_int_type, */ 719 comp.emacs_int_type,
718/* obj, */ 720 obj,
719/* comp.inttypebits); */ 721 comp.inttypebits);
720 722
721/* tmp = gcc_jit_context_new_binary_op (comp.ctxt, */ 723 tmp = gcc_jit_context_new_binary_op (comp.ctxt,
722/* NULL, */ 724 NULL,
723/* GCC_JIT_BINARY_OP_PLUS, */ 725 GCC_JIT_BINARY_OP_PLUS,
724/* comp.emacs_int_type, */ 726 comp.emacs_int_type,
725/* tmp, */ 727 tmp,
726/* comp.lisp_int0); */ 728 comp.lisp_int0);
727 729
728/* gcc_jit_lvalue *res = gcc_jit_function_new_local (comp.func, */ 730 gcc_jit_lvalue *res = gcc_jit_function_new_local (comp.func,
729/* NULL, */ 731 NULL,
730/* comp.lisp_obj_type, */ 732 comp.lisp_obj_type,
731/* "lisp_obj_fixnum"); */ 733 "lisp_obj_fixnum");
732 734
733/* gcc_jit_block_add_assignment (comp.block, */ 735 gcc_jit_block_add_assignment (comp.block,
734/* NULL, */ 736 NULL,
735/* emit_lval_XLI (res), */ 737 emit_lval_XLI (res),
736/* tmp); */ 738 tmp);
737 739
738/* return gcc_jit_lvalue_as_rvalue (res); */ 740 return gcc_jit_lvalue_as_rvalue (res);
739/* } */ 741}
740 742
741/* Construct fill and return a lisp object form a raw pointer. */ 743/* Construct fill and return a lisp object form a raw pointer. */
742static gcc_jit_rvalue * 744static gcc_jit_rvalue *
@@ -1377,6 +1379,18 @@ emit_limple_insn (Lisp_Object insn)
1377} 1379}
1378 1380
1379 1381
1382/*******************************/
1383/* Code emitters for inlines. */
1384/*******************************/
1385
1386static gcc_jit_rvalue *
1387emit_add1 (Lisp_Object insn)
1388{
1389 gcc_jit_rvalue *n = emit_mvar_val (SECOND (insn));
1390 return gcc_jit_context_new_call (comp.ctxt, NULL, comp.add1, 1, &n);
1391}
1392
1393
1380/****************************************************************/ 1394/****************************************************************/
1381/* Inline function definition and lisp data structure follows. */ 1395/* Inline function definition and lisp data structure follows. */
1382/****************************************************************/ 1396/****************************************************************/
@@ -1774,8 +1788,7 @@ define_CHECK_TYPE (void)
1774 gcc_jit_block_end_with_void_return (not_ok_block, NULL); 1788 gcc_jit_block_end_with_void_return (not_ok_block, NULL);
1775} 1789}
1776 1790
1777 1791/* Define a substitute for CAR as always inlined function. */
1778/* Declare a substitute for CAR as always inlined function. */
1779 1792
1780static void 1793static void
1781define_CAR_CDR (void) 1794define_CAR_CDR (void)
@@ -1926,7 +1939,82 @@ define_setcar_setcdr (void)
1926 } 1939 }
1927} 1940}
1928 1941
1929/* Declare a substitute for PSEUDOVECTORP as always inlined function. */ 1942/*
1943 Define a substitute for Fadd1 Fsub1.
1944 Currently expose just fixnum arithmetic.
1945*/
1946
1947static void
1948define_add1_sub1 (void)
1949{
1950 gcc_jit_block *bb_orig = comp.block;
1951
1952 gcc_jit_param *param[] =
1953 { gcc_jit_context_new_param (comp.ctxt,
1954 NULL,
1955 comp.lisp_obj_type,
1956 "n") };
1957
1958 comp.func = comp.add1 =
1959 gcc_jit_context_new_function (comp.ctxt, NULL,
1960 GCC_JIT_FUNCTION_ALWAYS_INLINE,
1961 comp.lisp_obj_type,
1962 "add1",
1963 1,
1964 param,
1965 0);
1966
1967 DECL_BLOCK (init_block, comp.add1);
1968 DECL_BLOCK (add1_inline_block, comp.add1);
1969 DECL_BLOCK (add1_fcall_block, comp.add1);
1970
1971 comp.block = init_block;
1972
1973 /* (FIXNUMP (n) && XFIXNUM (n) != MOST_POSITIVE_FIXNUM
1974 ? (XFIXNUM (n) + 1)
1975 : Fadd1 (n)) */
1976
1977 gcc_jit_rvalue *n = gcc_jit_param_as_rvalue (param[0]);
1978 gcc_jit_rvalue *n_fixnum = emit_XFIXNUM (n);
1979
1980 emit_cond_jump (
1981 gcc_jit_context_new_binary_op (
1982 comp.ctxt,
1983 NULL,
1984 GCC_JIT_BINARY_OP_LOGICAL_AND,
1985 comp.bool_type,
1986 emit_cast (comp.bool_type,
1987 emit_FIXNUMP (n)),
1988 gcc_jit_context_new_comparison (comp.ctxt,
1989 NULL,
1990 GCC_JIT_COMPARISON_NE,
1991 n_fixnum,
1992 comp.most_positive_fixnum)),
1993 add1_inline_block,
1994 add1_fcall_block);
1995
1996 comp.block = add1_inline_block;
1997 gcc_jit_rvalue *inline_res =
1998 gcc_jit_context_new_binary_op (comp.ctxt,
1999 NULL,
2000 GCC_JIT_BINARY_OP_PLUS,
2001 comp.emacs_int_type,
2002 n_fixnum,
2003 comp.one);
2004
2005 gcc_jit_block_end_with_return (add1_inline_block,
2006 NULL,
2007 emit_make_fixnum (inline_res));
2008
2009 comp.block = add1_fcall_block;
2010 gcc_jit_rvalue *call_res = emit_call ("Fadd1", comp.lisp_obj_type, 1, &n);
2011 gcc_jit_block_end_with_return (add1_fcall_block,
2012 NULL,
2013 call_res);
2014 comp.block = bb_orig;
2015}
2016
2017/* Define a substitute for PSEUDOVECTORP as always inlined function. */
1930 2018
1931static void 2019static void
1932define_PSEUDOVECTORP (void) 2020define_PSEUDOVECTORP (void)
@@ -2029,7 +2117,7 @@ define_CHECK_IMPURE (void)
2029 gcc_jit_block_end_with_void_return (err_block, NULL); 2117 gcc_jit_block_end_with_void_return (err_block, NULL);
2030} 2118}
2031 2119
2032/* Declare a function to convert boolean into t or nil */ 2120/* Define a function to convert boolean into t or nil */
2033 2121
2034static void 2122static void
2035define_bool_to_lisp_obj (void) 2123define_bool_to_lisp_obj (void)
@@ -2099,6 +2187,7 @@ DEFUN ("comp-init-ctxt", Fcomp_init_ctxt, Scomp_init_ctxt,
2099 emit_simple_limple_call_void_ret); 2187 emit_simple_limple_call_void_ret);
2100 register_emitter (Qhelper_save_restriction, 2188 register_emitter (Qhelper_save_restriction,
2101 emit_simple_limple_call_void_ret); 2189 emit_simple_limple_call_void_ret);
2190 register_emitter (QFadd1, emit_add1);
2102 } 2191 }
2103 2192
2104 comp.ctxt = gcc_jit_context_acquire(); 2193 comp.ctxt = gcc_jit_context_acquire();
@@ -2239,7 +2328,8 @@ DEFUN ("comp-init-ctxt", Fcomp_init_ctxt, Scomp_init_ctxt,
2239 define_CHECK_TYPE (); 2328 define_CHECK_TYPE ();
2240 define_CHECK_IMPURE (); 2329 define_CHECK_IMPURE ();
2241 define_bool_to_lisp_obj (); 2330 define_bool_to_lisp_obj ();
2242 define_setcar_setcdr(); 2331 define_setcar_setcdr ();
2332 define_add1_sub1 ();
2243 2333
2244 return Qt; 2334 return Qt;
2245} 2335}
@@ -2497,7 +2587,8 @@ syms_of_comp (void)
2497 DEFSYM (Qrecord_unwind_protect_excursion, "record_unwind_protect_excursion"); 2587 DEFSYM (Qrecord_unwind_protect_excursion, "record_unwind_protect_excursion");
2498 DEFSYM (Qhelper_unbind_n, "helper_unbind_n"); 2588 DEFSYM (Qhelper_unbind_n, "helper_unbind_n");
2499 DEFSYM (Qhelper_unwind_protect, "helper_unwind_protect"); 2589 DEFSYM (Qhelper_unwind_protect, "helper_unwind_protect");
2500 DEFSYM (Qhelper_save_restriction, "helper_save_restriction") 2590 DEFSYM (Qhelper_save_restriction, "helper_save_restriction");
2591 DEFSYM (QFadd1, "Fadd1")
2501 2592
2502 defsubr (&Scomp_init_ctxt); 2593 defsubr (&Scomp_init_ctxt);
2503 defsubr (&Scomp_release_ctxt); 2594 defsubr (&Scomp_release_ctxt);