xref: /original-bsd/lib/libc/sparc/gen/fixunsdfsi.s (revision 2a2d38a8)
1faa62e94Storek/*
2*2a2d38a8Sbostic * Copyright (c) 1992, 1993
3*2a2d38a8Sbostic *	The Regents of the University of California.  All rights reserved.
4faa62e94Storek *
5faa62e94Storek * This software was developed by the Computer Systems Engineering group
6faa62e94Storek * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7faa62e94Storek * contributed to Berkeley.
8faa62e94Storek *
9faa62e94Storek * %sccs.include.redist.c%
10faa62e94Storek *
11faa62e94Storek * from: $Header: fixunsdfsi.s,v 1.3 91/10/08 00:03:15 torek Exp $
12faa62e94Storek */
13faa62e94Storek
14faa62e94Storek#if defined(LIBC_SCCS) && !defined(lint)
15*2a2d38a8Sbostic	.asciz "@(#)fixunsdfsi.s	8.1 (Berkeley) 06/04/93"
16faa62e94Storek#endif /* LIBC_SCCS and not lint */
17faa62e94Storek
18faa62e94Storek/*
19faa62e94Storek * Convert double to unsigned integer (for gcc).
20faa62e94Storek *
21faa62e94Storek * I have made the output for NaN agree with the Sun compiler, not
22faa62e94Storek * that it really matters, by using `fbul,a'.
23faa62e94Storek */
24faa62e94Storek
25faa62e94Storek#include "DEFS.h"
26faa62e94Storek
27faa62e94Storek	.align	8
28faa62e94StorekLbig:
29faa62e94Storek	.word	0x41e00000		! .double 0r2147483648.0e+00
30faa62e94Storek	.word	0			! (who me, not trust the assembler?)
31faa62e94Storek
32faa62e94StorekENTRY(__fixunsdfsi)
33faa62e94Storek	sub	%sp, 8, %sp
34faa62e94Storek	std	%o0, [%sp + 64]		! get argument into fpu reg
35faa62e94Storek	ldd	[%sp + 64], %f0
36faa62e94Storek	sethi	%hi(Lbig), %g1
37faa62e94Storek	ldd	[%g1 + %lo(Lbig)], %f2
38faa62e94Storek	fcmped	%f0, %f2		! d < 2^31, or NaN, or -Inf?
39faa62e94Storek	nop				! (fpop2 delay)
40faa62e94Storek	fbul,a	1f			! if so, use fdtoi to convert to int
41faa62e94Storek	fdtoi	%f0, %f0		!        (this includes negatives!)
42faa62e94Storek
43faa62e94Storek	! d does not fit in an int, so subtract 2^31, convert,
44faa62e94Storek	! and add 2^31 again (sigh).  Just hope the intermediate
45faa62e94Storek	! fits (if not, the result is undefined anyway).
46faa62e94Storek
47faa62e94Storek	fsubd	%f0, %f2, %f0		! d -= 2^31
48faa62e94Storek	fdtoi	%f0, %f0		! convert to int
49faa62e94Storek	st	%f0, [%sp + 64]		! move into return reg
50faa62e94Storek	ld	[%sp + 64], %o0
51faa62e94Storek	sethi	%hi(0x80000000), %o1
52faa62e94Storek	add	%o0, %o1, %o0		! add 2^31
53faa62e94Storek	retl
54faa62e94Storek	add	%sp, 8, %sp
55faa62e94Storek
56faa62e94Storek1:
57faa62e94Storek	st	%f0, [%sp + 64]		! return result
58faa62e94Storek	ld	[%sp + 64], %o0
59faa62e94Storek	retl
60faa62e94Storek	add	%sp, 8, %sp
61