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