[erlang-questions] divrem eep?
ok@REDACTED
ok@REDACTED
Thu Aug 21 13:58:59 CEST 2014
Suppose you initially have instructions like
DIV src1, src2, dst1
REM src1, src2, dst2
-- made up, I have no idea what BEAM looks like here --
and you fuse them to
DIVREM src1, src2, dst1, dst2
Now a call to a tuple-returning function
erlang:divrem(X, Y)
can be compiled as
( Q = div(X, Y), R = rem(X, Y), {Q,R} )
which then does
( DIVREM X, Y, Q, R
{Q, R}
)
Why then is a DIVREMTUPLE X, Y, T instruction needed?
When it comes to integer quotient and remainder,
it would be really nice to have flooring remainder:
mod(X, Y) = if Y is zero then X else X - floor(X/Y)*Y
It would be OK to have it as erlang:mod/2 or some other
name, but the floor semantics would be so handy.
More information about the erlang-questions
mailing list