[erlang-questions] divrem eep?

Björn-Egil Dahlberg wallentin.dahlberg@REDACTED
Wed Aug 20 20:04:28 CEST 2014


It should probably be an instruction instead.

The compiler should recognize if div and rem is used and combine them to
one instruction. You have no issue with multiple return values if you do it
in core for instance. I did some doodling with this on my previous summer
vacation .. along with sub-expr-elim .. I stopped after the doodling phase
=)

No eep necessary if you do it as an optimization pass, only light-eep.

// Björn-Egil


2014-08-20 19:41 GMT+02:00 Tony Rogvall <tony@REDACTED>:

> Hi list.
>
> I have been playing with a new BIF called divrem today. Calling
> erlang:divrem(A,B) has the the same result
> as calling {A div B, A rem B}. (possibly with some strange exceptional
> cases that remain to be found :-)
>
> Since the bignum div operation has always calculated the remainder as a
> "waste product" I thought it was
> about time to pick it up and make use if it.
>
> The speedup when comparing calculation of {Q,R} = erlang:divrem(A,B) and
> Q=A div B, R=A rem B,
> is about 70-80% already around 60 bit arguments (64bit platform) (max
> speedup is of course 100%),
> currently the downside is that divrem for small numbers are a bit slower,
> since a tuple {Q,R} is constructed
> and the emulator have instructions for div and rem.
>
> The above could probably be handle by regarding divrem as a builtin
> function with a multiple return value
> and have the compiler to generate an instruction for some instances of
> divrem.
>
> I remember some work for handling multiple return values?
>
> What about it ? eep?
>
> /Tony
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140820/220e507a/attachment.htm>


More information about the erlang-questions mailing list