<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="color: rgb(0, 0, 0); font-family: Helvetica;"><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; ">Hi list.</span></div><div style="color: rgb(0, 0, 0); font-family: Helvetica;"><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; "><br></span></div><div style="color: rgb(0, 0, 0); font-family: Helvetica;"><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; ">I have been playing with a new BIF called divrem today. Calling erlang:divrem(A,B) has the the same result</span></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">as calling {A div B, A rem B}. (possibly with some strange exceptional cases that remain to be found :-)</font></div><div><br></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">Since the bignum div operation has always calculated the remainder as a "waste product" I thought it was</font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">about time to pick it up and make use if it.</font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><br></font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">The speedup when comparing calculation of {Q,R} = erlang:divrem(A,B) and Q=A div B, R=A rem B,</font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">is about 70-80% already around 60 bit arguments (64bit platform) (max speedup is of course 100%), </font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">currently the downside </font><span style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; text-align: -webkit-auto;">is that divrem for small numbers are a bit slower, since a tuple {Q,R} is constructed </span></div><div><span style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; text-align: -webkit-auto;">and the emulator have instructions for div and rem.</span></div><div><span style="color: rgb(51, 51, 51); font-family: Geneva, Arial, Helvetica, sans-serif; text-align: -webkit-auto;"><br></span></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">The above could probably be handle by regarding divrem as a builtin function with a multiple return value</font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">and have the compiler to generate an instruction for some instances of divrem.</font></div><div><br></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">I remember some work for handling multiple return values?</font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><br></font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">What about it ? eep?</font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><br></font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif">/Tony</font></div><div><font color="#333333" face="Geneva, Arial, Helvetica, sans-serif"><br></font></div></span></div></body></html>