[erlang-questions] divrem eep?

Tony Rogvall <>
Wed Aug 20 19:41:37 CEST 2014


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140820/2aaca74c/attachment.htm>


More information about the erlang-questions mailing list