I know nothing about the JVM, but I do know that on x86 you can handle fixnum -> bignum promotion fairly cheaply. You compile two versions of the code: one for bignums and one for fixnums. After an arithmetic instruction in the fixnum code you check if it overflowed, and if it did you switch to the bignum code.
while(n < 10) { n = n + 1; } => while(n #< 10) { a = n #+ 1; if(overflow){ n = ToBignum(n); goto foo; } n = a; } while(n.lessthan(10)) { foo: n = n.add(1); } where #< and #+ are the fixnum versions of < and +, and lessthan and add are the bignum versions. Yeah it's slower than ignoring the overflow, but faster than tagged 31-bit fixnums and a whole lot faster than bignums. Can you convince the JVM to produce similar code? Jules On Jun 19, 4:22 am, Rich Hickey <richhic...@gmail.com> wrote: > On Jun 18, 2010, at 10:18 PM, Mark Fredrickson wrote: > > > So far most of the action has concerned arithmetic ops (+, -, *, /). > > Will these new semantics include the bit-shift operators? I vote yes. > > My use cases for bit ops would benefit from primitive ops. > > > On a related note, my use cases call for silent overflow of bit shifts > > (pseudo random number generators). Will there be a way to disable > > overflow exceptions (either via a binding or through unchecked-* > > functions)? > > Yes, bit-ops will be made to align with whatever is done here. > > Rich > > > > > > > On Jun 18, 8:33 pm, Rich Hickey <richhic...@gmail.com> wrote: > >> Turnabout is fair play, so I've produced a version that swaps the > >> defaults, still in the 'equal' branch: > > >> Docs: > > >>https://www.assembla.com/wiki/show/b4-TTcvBSr3RAZeJe5aVNr/ > >> Enhanced_Pr... > > >> Code: > > >>http://github.com/richhickey/clojure/commit/ > >> 310534b8e7e7f28c75bb122b4... > > >> You can get the older arbitrary-precision default with this commit: > > >>http://github.com/richhickey/clojure/commit/ > >> 7652f7e935684d3c7851fbcad... > > >> I've also temporarily enabled a diagnostic (in both) that tells you > >> when you have a mismatch between a loop initializer and its recur > >> form. It goes off over a hundred times in Clojure itself, when using > >> the arbitrary precision default. In each case, the recur value is > >> needlessly being boxed, every iteration of a loop, for loops that > >> will > >> never be bigints; indexes, counters etc. I expect this will be very > >> typical of most code. But removing that useless overhead would be a > >> lot of tedious work. > > >> With the defaults swapped, only 2 warnings. > > >> Pay for what you use ... > > >> Rich > > >> On Jun 18, 4:52 pm, Rich Hickey <richhic...@gmail.com> wrote: > > >>> I've revised and enhanced the strategy, based upon the feedback > >>> here. > >>> I think it is a nice compromise. > > >>> Docs (see update section at the top) > > >>>https://www.assembla.com/wiki/show/b4-TTcvBSr3RAZeJe5aVNr/Enhanced_Pr > >>> ... > > >>> Code: > > >>>http://github.com/richhickey/clojure/commit/c79d28775e06b196ae1426f6c > >>> ... > > >>> Thanks to all for the feedback, keep it coming! > > >>> Rich > > >>> On Jun 17, 2010, at 4:13 PM, Rich Hickey wrote: > > >>>> I've been doing some work to enhance the performance, and unify the > >>>> semantics, of primitives, in three branches. I've started to > >>>> document > >>>> this work here: > > >>>>https://www.assembla.com/wiki/show/clojure/Enhanced_Primitive_Support > > >>>> Feedback welcome, > > >>>> Rich > > > -- > > 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 -- 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