Home | History | Annotate | Line # | Download | only in i386
systfloat.S revision 1.2
      1 /* $NetBSD: systfloat.S,v 1.2 2001/03/13 07:43:19 ross Exp $ */
      2 
      3 /* This is a derivative work. */
      4 
      5 /*-
      6  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      7  * All rights reserved.
      8  *
      9  * This code is derived from software contributed to The NetBSD Foundation
     10  * by Ross Harvey.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *        This product includes software developed by the NetBSD
     23  *        Foundation, Inc. and its contributors.
     24  * 4. Neither the name of The NetBSD Foundation nor the names of its
     25  *    contributors may be used to endorse or promote products derived
     26  *    from this software without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     38  * POSSIBILITY OF SUCH DAMAGE.
     39  */
     40 
     41 /*
     42 ===============================================================================
     43 
     44 This GNU assembler source file is part of TestFloat, Release 2a, a package
     45 of programs for testing the correctness of floating-point arithmetic
     46 complying to the IEC/IEEE Standard for Floating-Point.
     47 
     48 Written by John R. Hauser.  More information is available through the Web
     49 page `http://HTTP.CS.Berkeley.EDU/~jhauser/arithmetic/TestFloat.html'.
     50 
     51 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort
     52 has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
     53 TIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO
     54 PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
     55 AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
     56 
     57 Derivative works are acceptable, even for commercial purposes, so long as
     58 (1) they include prominent notice that the work is derivative, and (2) they
     59 include prominent notice akin to these four paragraphs for those parts of
     60 this code that are retained.
     61 
     62 ===============================================================================
     63 */
     64 
     65 	.text
     66 
     67 /*
     68 -------------------------------------------------------------------------------
     69 -------------------------------------------------------------------------------
     70 */
     71 
     72 #include <machine/asm.h>
     73 
     74 ENTRY(syst_int32_to_floatx80)
     75 	fildl 8(%esp)
     76 	movl 4(%esp),%eax
     77 	fstpt (%eax)
     78 	ret $4
     79 
     80 /*
     81 -------------------------------------------------------------------------------
     82 -------------------------------------------------------------------------------
     83 */
     84 
     85 ENTRY(syst_int64_to_floatx80)
     86 	fildq 8(%esp)
     87 	movl 4(%esp),%eax
     88 	fstpt (%eax)
     89 	ret $4
     90 
     91 /*
     92 -------------------------------------------------------------------------------
     93 -------------------------------------------------------------------------------
     94 */
     95 ENTRY(syst_float32_to_floatx80)
     96 	flds 8(%esp)
     97 	movl 4(%esp),%eax
     98 	fstpt (%eax)
     99 	ret $4
    100 
    101 /*
    102 -------------------------------------------------------------------------------
    103 -------------------------------------------------------------------------------
    104 */
    105 ENTRY(syst_float64_to_floatx80)
    106 	fldl 8(%esp)
    107 	movl 4(%esp),%eax
    108 	fstpt (%eax)
    109 	ret $4
    110 
    111 /*
    112 -------------------------------------------------------------------------------
    113 -------------------------------------------------------------------------------
    114 */
    115 ENTRY(syst_floatx80_to_int32)
    116 	fldt 4(%esp)
    117 	subl $4,%esp
    118 	fistpl (%esp)
    119 	movl (%esp),%eax
    120 	addl $4,%esp
    121 	ret
    122 
    123 /*
    124 -------------------------------------------------------------------------------
    125 -------------------------------------------------------------------------------
    126 */
    127 ENTRY(syst_floatx80_to_int64)
    128 	fldt 4(%esp)
    129 	subl $8,%esp
    130 	fistpq (%esp)
    131 	movl (%esp),%eax
    132 	movl 4(%esp),%edx
    133 	addl $8,%esp
    134 	ret
    135 
    136 /*
    137 -------------------------------------------------------------------------------
    138 -------------------------------------------------------------------------------
    139 */
    140 ENTRY(syst_floatx80_to_float32)
    141 	fldt 4(%esp)
    142 	subl $4,%esp
    143 	fstps (%esp)
    144 	movl (%esp),%eax
    145 	addl $4,%esp
    146 	ret
    147 
    148 /*
    149 -------------------------------------------------------------------------------
    150 -------------------------------------------------------------------------------
    151 */
    152 ENTRY(syst_floatx80_to_float64)
    153 	fldt 4(%esp)
    154 	subl $8,%esp
    155 	fstpl (%esp)
    156 	movl 4(%esp),%edx
    157 	movl (%esp),%eax
    158 	addl $8,%esp
    159 	ret
    160 
    161 /*
    162 -------------------------------------------------------------------------------
    163 -------------------------------------------------------------------------------
    164 */
    165 ENTRY(syst_floatx80_round_to_int)
    166 	fldt 8(%esp)
    167 	frndint
    168 	movl 4(%esp),%eax
    169 	fstpt (%eax)
    170 	ret $4
    171 
    172 /*
    173 -------------------------------------------------------------------------------
    174 -------------------------------------------------------------------------------
    175 */
    176 ENTRY(syst_floatx80_add)
    177 	fldt 8(%esp)
    178 	fldt 20(%esp)
    179 	faddp
    180 	movl 4(%esp),%eax
    181 	fstpt (%eax)
    182 	ret $4
    183 
    184 /*
    185 -------------------------------------------------------------------------------
    186 -------------------------------------------------------------------------------
    187 */
    188 ENTRY(syst_floatx80_sub)
    189 	fldt 8(%esp)
    190 	fldt 20(%esp)
    191 	fsubrp
    192 	movl 4(%esp),%eax
    193 	fstpt (%eax)
    194 	ret $4
    195 
    196 /*
    197 -------------------------------------------------------------------------------
    198 -------------------------------------------------------------------------------
    199 */
    200 ENTRY(syst_floatx80_mul)
    201 	fldt 8(%esp)
    202 	fldt 20(%esp)
    203 	fmulp
    204 	movl 4(%esp),%eax
    205 	fstpt (%eax)
    206 	ret $4
    207 
    208 /*
    209 -------------------------------------------------------------------------------
    210 -------------------------------------------------------------------------------
    211 */
    212 ENTRY(syst_floatx80_div)
    213 	fldt 8(%esp)
    214 	fldt 20(%esp)
    215 	fdivrp
    216 	movl 4(%esp),%eax
    217 	fstpt (%eax)
    218 	ret $4
    219 
    220 /*
    221 -------------------------------------------------------------------------------
    222 -------------------------------------------------------------------------------
    223 */
    224 ENTRY(syst_floatx80_rem)
    225 	fldt 20(%esp)
    226 	fldt 8(%esp)
    227 floatx80_rem_loop:
    228 	fprem1
    229 	fnstsw %ax
    230 	btw $10,%ax
    231 	jc floatx80_rem_loop
    232 	movl 4(%esp),%eax
    233 	fstpt (%eax)
    234 	fstp %st(0)
    235 	ret $4
    236 
    237 /*
    238 -------------------------------------------------------------------------------
    239 -------------------------------------------------------------------------------
    240 */
    241 ENTRY(syst_floatx80_sqrt)
    242 	fldt 8(%esp)
    243 	fsqrt
    244 	movl 4(%esp),%eax
    245 	fstpt (%eax)
    246 	ret $4
    247 
    248 /*
    249 -------------------------------------------------------------------------------
    250 -------------------------------------------------------------------------------
    251 */
    252 ENTRY(syst_floatx80_eq)
    253 	fldt 16(%esp)
    254 	fldt 4(%esp)
    255 	fucompp
    256 	fnstsw %ax
    257 	andw $17664,%ax
    258 	cmpw $16384,%ax
    259 	seteb %al
    260 	movzb %al,%eax
    261 	ret
    262 
    263 /*
    264 -------------------------------------------------------------------------------
    265 -------------------------------------------------------------------------------
    266 */
    267 ENTRY(syst_floatx80_le)
    268 	fldt 4(%esp)
    269 	fldt 16(%esp)
    270 	fcompp
    271 	fnstsw %ax
    272 	notl %eax
    273 	shrl $8,%eax
    274 	andl $1,%eax
    275 	ret
    276 
    277 /*
    278 -------------------------------------------------------------------------------
    279 -------------------------------------------------------------------------------
    280 */
    281 ENTRY(syst_floatx80_lt)
    282 	fldt 4(%esp)
    283 	fldt 16(%esp)
    284 	fcompp
    285 	fnstsw %ax
    286 	andw $17664,%ax
    287 	setzb %al
    288 	movzb %al,%eax
    289 	ret
    290 
    291 /*
    292 -------------------------------------------------------------------------------
    293 -------------------------------------------------------------------------------
    294 */
    295 ENTRY(syst_floatx80_eq_signaling)
    296 	fldt 16(%esp)
    297 	fldt 4(%esp)
    298 	fcompp
    299 	fnstsw %ax
    300 	andw $17664,%ax
    301 	cmpw $16384,%ax
    302 	seteb %al
    303 	movzb %al,%eax
    304 	ret
    305 
    306 /*
    307 -------------------------------------------------------------------------------
    308 -------------------------------------------------------------------------------
    309 */
    310 ENTRY(syst_floatx80_le_quiet)
    311 	fldt 4(%esp)
    312 	fldt 16(%esp)
    313 	fucompp
    314 	fnstsw %ax
    315 	notl %eax
    316 	shrl $8,%eax
    317 	andl $1,%eax
    318 	ret
    319 
    320 /*
    321 -------------------------------------------------------------------------------
    322 -------------------------------------------------------------------------------
    323 */
    324 
    325 ENTRY(syst_floatx80_lt_quiet)
    326 	fldt 4(%esp)
    327 	fldt 16(%esp)
    328 	fucompp
    329 	fnstsw %ax
    330 	andw $17664,%ax
    331 	setzb %al
    332 	movzb %al,%eax
    333 	ret
    334 
    335 /*
    336 -------------------------------------------------------------------------------
    337 -------------------------------------------------------------------------------
    338 */
    339 
    340 ENTRY(syst_floatx80_to_int32_round_to_zero)
    341 	pushl %ebp
    342 	movl %esp,%ebp
    343 	subl $12,%esp
    344 	fldt 8(%ebp)
    345 	fnstcw -4(%ebp)
    346 	movl -4(%ebp),%edx
    347 	movb $12,%dh
    348 	movl %edx,-12(%ebp)
    349 	fldcw -12(%ebp)
    350 	fistpl -12(%ebp)
    351 	movl -12(%ebp),%eax
    352 	fldcw -4(%ebp)
    353 	leave
    354 	ret
    355 
    356 /*
    357 -------------------------------------------------------------------------------
    358 -------------------------------------------------------------------------------
    359 */
    360 
    361 ENTRY(syst_floatx80_to_int64_round_to_zero)
    362 	pushl %ebp
    363 	movl %esp,%ebp
    364 	subl $12,%esp
    365 	fldt 8(%ebp)
    366 	fnstcw -4(%ebp)
    367 	movl -4(%ebp),%ecx
    368 	movb $12,%ch
    369 	movl %ecx,-12(%ebp)
    370 	fldcw -12(%ebp)
    371 	fistpq -12(%ebp)
    372 	movl -12(%ebp),%eax
    373 	movl -8(%ebp),%edx
    374 	fldcw -4(%ebp)
    375 	leave
    376 	ret
    377