chicken-janitors
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-janitors] #1624: Flonum unboxing too agressive


From: Chicken Trac
Subject: Re: [Chicken-janitors] #1624: Flonum unboxing too agressive
Date: Mon, 24 Jun 2019 09:21:49 -0000

#1624: Flonum unboxing too agressive
---------------------------------+-------------------
            Reporter:  sjamaan   |      Owner:
                Type:  defect    |     Status:  new
            Priority:  critical  |  Milestone:  5.2
           Component:  compiler  |    Version:  5.1.0
          Resolution:            |   Keywords:  lfa2
Estimated difficulty:  medium    |
---------------------------------+-------------------
Description changed by sjamaan:

Old description:

> Found by Sven Hartrumpf. The following program will segfault:
>
> {{{
> (define (test-it)
>   (let loop ((done #f))
>     (if done
>         '()
>         (cons  (or (read) 0.0) (loop #t)))))
>
> (print (test-it))
> }}}
>
> When run with a {{{DEBUGBUILD}}} CHICKEN, you'll see it fails with a nice
> panic due to a low-level assertion error triggered by a
> {{{C_flonum_magnitude}}} call when you enter a fixnum:
>
> {{{
> [panic] Low-level type assertion
> C_blockp((C_word)C_VAL1(C__PREV_TMPST.n1))=#t failed at test.c:176 -
> execution terminated
> }}}
>
> Generated code failing:
>
> {{{
> /* k150 in loop in test-it in k131 in k128 in k125 */
> static void C_ccall f_152(C_word c,C_word *av){
> C_word tmp;
> C_word t0=av[0];
> C_word t1=av[1];
> C_word t2;
> C_word t3;
> C_word t4;
> double f0;
> C_word *a;
> C_check_for_interrupt;
> if(C_unlikely(!C_demand(C_calculate_demand(8,c,2)))){
> C_save_and_reclaim((void *)f_152,2,av);}
> a=C_alloc(8);
> f0=C_flonum_magnitude((C_truep(t1)?t1:lf[1])); /// <--- offending code
> t2=C_flonum(&a,f0);
> t3=(*a=C_CLOSURE_TYPE|3,a[1]=(C_word)f_159,a[2]=((C_word*)t0)[2],a[3]=t2,tmp=(C_word)a,a+=4,tmp);
> C_trace(C_text("test.scm:5: loop"));
> t4=((C_word*)((C_word*)t0)[3])[1];
> f_141(t4,t3,C_SCHEME_TRUE);}
> }}}
>
> Most likely introduced by 79cf7427638eebf695f2be54731bb6bbf4d0fff2.

New description:

 Found by Sven Hartrumpf. The following program will segfault:

 {{{
 (define (test-it)
   (let loop ((done #f))
     (if done
         '()
         (cons  (or (read) 0.0) (loop #t)))))

 (print (test-it))
 }}}

 When run with a {{{DEBUGBUILD}}} CHICKEN, you'll see it fails with a nice
 panic due to a low-level assertion error triggered by a
 {{{C_flonum_magnitude}}} call when you enter a fixnum:

 {{{
 [panic] Low-level type assertion
 C_blockp((C_word)C_VAL1(C__PREV_TMPST.n1))=#t failed at test.c:176 -
 execution terminated
 }}}

 Generated code failing:

 {{{
 /* k150 in loop in test-it in k131 in k128 in k125 */
 static void C_ccall f_152(C_word c,C_word *av){
 C_word tmp;
 C_word t0=av[0];
 C_word t1=av[1];
 C_word t2;
 C_word t3;
 C_word t4;
 double f0;
 C_word *a;
 C_check_for_interrupt;
 if(C_unlikely(!C_demand(C_calculate_demand(8,c,2)))){
 C_save_and_reclaim((void *)f_152,2,av);}
 a=C_alloc(8);
 f0=C_flonum_magnitude((C_truep(t1)?t1:lf[1])); /// <--- offending code
 t2=C_flonum(&a,f0);
 
t3=(*a=C_CLOSURE_TYPE|3,a[1]=(C_word)f_159,a[2]=((C_word*)t0)[2],a[3]=t2,tmp=(C_word)a,a+=4,tmp);
 C_trace(C_text("test.scm:5: loop"));
 t4=((C_word*)((C_word*)t0)[3])[1];
 f_141(t4,t3,C_SCHEME_TRUE);}
 }}}

 Most likely introduced by 79cf7427638eebf695f2be54731bb6bbf4d0fff2.

 ALSO: In the generated code in this case, it unboxes and immediately boxes
 the flonum. There's no operation in between, so that's wasteful.

 It only makes sense with >1 operations (though with exactly 1 it should be
 okay too but adds no perf improvement)

--

--
Ticket URL: <https://bugs.call-cc.org/ticket/1624#comment:2>
CHICKEN Scheme <https://www.call-cc.org/>
CHICKEN Scheme is a compiler for the Scheme programming language.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]