Any relationship to CLJ-701, other than similar symptoms? http://dev.clojure.org/jira/browse/CLJ-701
Andy On Nov 20, 2012, at 9:15 AM, Christophe Grand wrote: > Hi, > > It looks like, because of the recur, the compiler fails to notice that if > returns a primitive. > As far as I understand in Compiler.java, RecurExpr does not implement > MaybePrimitiveExpr and thus causes on canEmitPrimitive the surrounding IfExpr > to return false. > > Someone to confirm this analysis? > > > On Tue, Nov 20, 2012 at 4:34 PM, Gunnar Völkel > <gunnar.voel...@googlemail.com> wrote: > I have written a primitive function for exponentiation with integers as power > using the multiply-and-square algorithm. > For performance reasons I used primitive type hints for the arguments and the > return value. > Profiling the whole application I noticed that there are a lot of > java.lang.Double/valueOf calls. > Looking at the bytecode I see that in Clojure 1.3 as well as in Clojure 1.4 > the result value gets boxed and unboxed like > Double.valueOf(result).doubleValue(). > > Am I doing something wrong? Is there a serious bug related to the support of > primitive functions? > > The source code: > > (defn first-bit? > {:inline (fn [n] `(== 1 (clojure.lang.Numbers/and ~n, 1)) )} > [^long n] > (== 1 (clojure.lang.Numbers/and n, 1))) > > (defn exp-int > ^double [^double x, ^long c] > (loop [result 1.0, factor x, c c] > (if (> c 0) > (recur > (if (first-bit? c) > (* result factor) > result), > (* factor factor), > (bit-shift-right c 1)) > result))) > > Last lines of the Java bytecode of `exp-int`: > 59 dload 5; /* result */ > 61 invokestatic 40; /* java.lang.Double java.lang.Double.valueOf(double > c) */ > 64 checkcast 85; /* java.lang.Number */ > 67 invokevirtual 89; /* double doubleValue() */ > 70 dreturn; -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en