2010-07-21 16:03:44 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* PURPOSE: Implementation of ceil
|
|
|
|
* FILE: lib/sdk/crt/math/amd64/ceil.S
|
|
|
|
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2010-11-27 22:12:15 +00:00
|
|
|
#include <asm.inc>
|
|
|
|
#include <ksamd64.inc>
|
2010-07-21 16:03:44 +00:00
|
|
|
|
2011-02-10 10:30:43 +00:00
|
|
|
/* CODE **********************************************************************/
|
2010-07-21 16:03:44 +00:00
|
|
|
.code64
|
|
|
|
|
2011-10-14 08:33:22 +00:00
|
|
|
/* ceil(x) = - floor(-x)
|
|
|
|
*/
|
2010-07-21 16:03:44 +00:00
|
|
|
PUBLIC ceil
|
2011-10-14 08:33:22 +00:00
|
|
|
.PROC ceil
|
|
|
|
sub rsp, 16
|
|
|
|
.ENDPROLOG
|
|
|
|
|
|
|
|
/* Duplicate the bits into rax */
|
|
|
|
movd rax, xmm0
|
|
|
|
|
|
|
|
/* Invert the sign bit */
|
|
|
|
rol rax, 1
|
|
|
|
xor al, 1
|
|
|
|
ror rax, 1
|
|
|
|
|
|
|
|
/* Copy back to xmm0 */
|
|
|
|
movd xmm0, rax
|
|
|
|
|
|
|
|
/* Truncate xmm0 to integer (double precision) */
|
|
|
|
cvttsd2si rcx, xmm0
|
|
|
|
|
|
|
|
/* Shift all bits to the right, keeping the sign bit */
|
|
|
|
shr rax, 63
|
|
|
|
|
|
|
|
/* Substract the sign bit from the truncated value, so that
|
|
|
|
we get the correct result for negative values. */
|
|
|
|
sub rcx, rax
|
|
|
|
|
|
|
|
/* Now compensate for the previous negation */
|
|
|
|
neg rcx
|
|
|
|
|
|
|
|
/* Convert the result back to xmm0 (double precision) */
|
|
|
|
cvtsi2sd xmm0, rcx
|
|
|
|
|
|
|
|
add rsp, 16
|
2010-07-21 16:03:44 +00:00
|
|
|
ret
|
2011-10-14 08:33:22 +00:00
|
|
|
.ENDP
|
2010-07-21 16:03:44 +00:00
|
|
|
|
2011-02-10 10:30:43 +00:00
|
|
|
END
|