1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 23 */ 24 /* 25 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 .file "nextafterf.s" 30 31 #include "libm.h" 32 LIBM_ANSI_PRAGMA_WEAK(nextafterf,function) 33 #include "libm_synonyms.h" 34 35 .data 36 .align 4 37 Fmaxf: .long 0x7f7fffff 38 Fminf: .long 0x1 39 ftmpf: .long 0 40 41 42 ENTRY(nextafterf) 43 pushl %ebp 44 movl %esp,%ebp 45 movl $0,%eax /// upper half of %eax must be initialized 46 flds 12(%ebp) / y 47 subl $4,%esp 48 flds 8(%ebp) / x, y 49 fucom / x : y 50 fstsw %ax 51 sahf 52 jp .NaN 53 je .equal 54 fstp %st(1) / x 55 ja .bigger 56 / x < y 57 ftst / x : 0 58 movl $0x1,-4(%ebp) / -4(%ebp) contains Fminf 59 fnstsw %ax 60 sahf 61 je .final 62 ja .addulp 63 jb .subulp 64 .bigger: 65 / x > y 66 ftst / x : 0 67 movl $0x80000001,-4(%ebp) / -4(%ebp) contains -Fminf 68 fnstsw %ax 69 sahf 70 je .final 71 jb .addulp 72 .subulp: 73 movl 8(%ebp),%eax / x 74 subl $1,%eax / x - ulp 75 movl %eax,-4(%ebp) 76 jmp .final 77 .addulp: 78 movl 8(%ebp),%eax / x 79 addl $1,%eax / x + ulp 80 movl %eax,-4(%ebp) 81 82 .final: 83 fstp %st(0) / empty 84 flds -4(%ebp) / z 85 andl $0x7f800000,%eax 86 jz .underflow 87 cmpl $0x7f800000,%eax 88 je .overflow 89 jmp .return 90 .overflow: 91 PIC_SETUP(1) 92 flds PIC_L(Fmaxf) / Fmaxf, z 93 fmul %st(0),%st / overflow-to-Inf, z 94 fstps PIC_L(ftmpf) / z & create overflow signal 95 PIC_WRAPUP 96 jmp .return 97 .underflow: 98 PIC_SETUP(2) 99 flds PIC_L(Fminf) / Fminf, z 100 fmul %st(0),%st / underflow-to-0, z 101 fstps PIC_L(ftmpf) / z & create underflow signal 102 PIC_WRAPUP 103 jmp .return 104 .equal: 105 fstp %st(0) / C99 says to return y when x == y 106 jmp .return 107 .NaN: 108 faddp %st,%st(1) / x+y 109 .return: 110 fwait 111 leave 112 ret 113 .align 4 114 SET_SIZE(nextafterf)