xref: /minix3/lib/libc/arch/i386/gen/flt_rounds.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: flt_rounds.S,v 1.10 2014/05/23 02:34:19 uebayasi Exp $	*/
22fe8fb19SBen Gras
32fe8fb19SBen Gras#include <machine/asm.h>
42fe8fb19SBen Gras
5f14fb602SLionel Sambuc/*
6f14fb602SLionel Sambuc * 00 0 round to zero
7f14fb602SLionel Sambuc * 01 1 round to nearest
8f14fb602SLionel Sambuc * 10 2 round to positive infinity
9f14fb602SLionel Sambuc * 11 3 round to negative infinity
10f14fb602SLionel Sambuc */
112fe8fb19SBen Gras	.text
122fe8fb19SBen Gras	_ALIGN_TEXT
132fe8fb19SBen GrasENTRY(__flt_rounds)
14f14fb602SLionel Sambuc	fnstcw	-4(%esp)
15f14fb602SLionel Sambuc	movl	-4(%esp), %ecx
16f14fb602SLionel Sambuc	shrl	$9, %ecx
17f14fb602SLionel Sambuc	andl	$6, %ecx
18f14fb602SLionel Sambuc	movl	$0x2d, %eax	/* 0x2d = 00.10.11.01 */
19f14fb602SLionel Sambuc	sarl	%cl, %eax	/* 0,1,2,3 -> 1,3,2,0 */
202fe8fb19SBen Gras	andl	$3, %eax
212fe8fb19SBen Gras	ret
22*0a6a1f1dSLionel SambucEND(__flt_rounds)
23