xref: /minix3/lib/libm/arch/vax/n_scalbn.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
184d9c625SLionel Sambuc/*-
284d9c625SLionel Sambuc * Copyright (c) 2011 The NetBSD Foundation, Inc.
384d9c625SLionel Sambuc * All rights reserved.
484d9c625SLionel Sambuc *
584d9c625SLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation
684d9c625SLionel Sambuc * by Matt Thomas of 3am Software Foundry.
784d9c625SLionel Sambuc *
884d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without
984d9c625SLionel Sambuc * modification, are permitted provided that the following conditions
1084d9c625SLionel Sambuc * are met:
1184d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
1284d9c625SLionel Sambuc *    notice, this list of conditions and the following disclaimer.
1384d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
1484d9c625SLionel Sambuc *    notice, this list of conditions and the following disclaimer in the
1584d9c625SLionel Sambuc *    documentation and/or other materials provided with the distribution.
1684d9c625SLionel Sambuc *
1784d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1884d9c625SLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1984d9c625SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2084d9c625SLionel Sambuc * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2184d9c625SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2284d9c625SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2384d9c625SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2484d9c625SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2584d9c625SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2684d9c625SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2784d9c625SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
2884d9c625SLionel Sambuc */
2984d9c625SLionel Sambuc
3084d9c625SLionel Sambuc#include <machine/asm.h>
3184d9c625SLionel Sambuc#include <sys/errno.h>
3284d9c625SLionel Sambuc
33*0a6a1f1dSLionel SambucRCSID("$NetBSD: n_scalbn.S,v 1.5 2014/02/03 21:22:21 martin Exp $")
3484d9c625SLionel Sambuc
3584d9c625SLionel SambucWEAK_ALIAS(scalbn,_scalbn)
36*0a6a1f1dSLionel SambucWEAK_ALIAS(scalbnl,_scalbnl)
37*0a6a1f1dSLionel SambucWEAK_ALIAS(scalbnf,_scalbnf)
3884d9c625SLionel SambucWEAK_ALIAS(ldexp,_scalbn)
3984d9c625SLionel SambucWEAK_ALIAS(ldexpf,_scalbnf)
4084d9c625SLionel SambucWEAK_ALIAS(ldexpl,_scalbnl)
4184d9c625SLionel Sambuc
4284d9c625SLionel SambucENTRY(_scalbnf, 0)
4384d9c625SLionel Sambuc	cvtfd	4(%ap), %r0
4484d9c625SLionel Sambuc	movl	8(%ap), %r2
4584d9c625SLionel Sambuc	jr	1f
4684d9c625SLionel Sambuc
4784d9c625SLionel SambucALTENTRY(_scalbnl)
4884d9c625SLionel SambucENTRY(_scalbn, 0)
4984d9c625SLionel Sambuc	movd	4(%ap), %r0
5084d9c625SLionel Sambuc	movl	12(%ap), %r2
5184d9c625SLionel Sambuc
5284d9c625SLionel Sambuc	/*
5384d9c625SLionel Sambuc	 * First see if the result will be within bounds
5484d9c625SLionel Sambuc	 */
5584d9c625SLionel Sambuc1:	cmpl	%r2,$(256+55)
5684d9c625SLionel Sambuc	jgeq	overflow
5784d9c625SLionel Sambuc	cmpl	%r2,$-(256+55)
5884d9c625SLionel Sambuc	jleq	underflow
5984d9c625SLionel Sambuc
6084d9c625SLionel Sambuc	extzv	$7, $9, %r0, %r3	/* extract exponent */
6184d9c625SLionel Sambuc	jneq	5f			/* 0 * N is still 0 */
6284d9c625SLionel Sambuc	cmpw	%r3, $-256		/* is this a NAN? */
6384d9c625SLionel Sambuc	jgtr	2f			/*    nope */
6484d9c625SLionel Sambuc	ret
6584d9c625SLionel Sambuc
6684d9c625SLionel Sambuc2:	movzbl	%r3, %r3		/* clear sign bit */
6784d9c625SLionel Sambuc	addl2	%r2, %r3		/* add to exponent */
6884d9c625SLionel Sambuc	jleq	underflow		/*   <= 0? */
6984d9c625SLionel Sambuc
7084d9c625SLionel Sambuc3:	jbs	$8, %r3, overflow	/* did exponent overflow? */
7184d9c625SLionel Sambuc	insv	$7, $8, %r3, %r0	/* replace exponent */
7284d9c625SLionel Sambuc	ret
7384d9c625SLionel Sambuc
7484d9c625SLionel Sambucunderflow:
7584d9c625SLionel Sambuc	clrq	%r0			/* return 0.0 */
7684d9c625SLionel Sambuc	jr	copysign		/* or mabye -0.0 */
7784d9c625SLionel Sambucoverflow:
7884d9c625SLionel Sambuc	pushl	$ERANGE			/* overflow */
7984d9c625SLionel Sambuc	calls	$1, _C_LABEL(infnan)	/* possibly signal */
8084d9c625SLionel Sambuccopysign:
8184d9c625SLionel Sambuc	jbc	$15, 4(%ap), 5f		/* if clear, don't set sign-bit */
8284d9c625SLionel Sambuc	bisw2	$0x8000, %r0		/* preserve sign-bit */
8384d9c625SLionel Sambuc5:
8484d9c625SLionel Sambuc	ret
85