aeabi_float.c revision 302408
1133094Ssimon/*
2143460Ssimon * Copyright (C) 2012 Andrew Turner
3133094Ssimon * All rights reserved.
4133094Ssimon *
5133094Ssimon * Redistribution and use in source and binary forms, with or without
6133094Ssimon * modification, are permitted provided that the following conditions
7133094Ssimon * are met:
8133094Ssimon * 1. Redistributions of source code must retain the above copyright
9133094Ssimon *    notice, this list of conditions and the following disclaimer.
10133094Ssimon * 2. Redistributions in binary form must reproduce the above copyright
11133094Ssimon *    notice, this list of conditions and the following disclaimer in the
12133094Ssimon *    documentation and/or other materials provided with the distribution.
13133094Ssimon *
14133094Ssimon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15133094Ssimon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16133094Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17133094Ssimon * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18133094Ssimon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19133094Ssimon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20133094Ssimon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21133094Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22133094Ssimon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23133094Ssimon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24133094Ssimon * SUCH DAMAGE.
25133094Ssimon *
26133094Ssimon */
27133094Ssimon
28133094Ssimon#include <sys/cdefs.h>
29133094Ssimon__FBSDID("$FreeBSD: stable/11/lib/libc/arm/aeabi/aeabi_float.c 273088 2014-10-14 14:27:51Z andrew $");
30133094Ssimon
31133094Ssimon#include "softfloat-for-gcc.h"
32133094Ssimon#include "milieu.h"
33133094Ssimon#include "softfloat.h"
34133094Ssimon
35133094Ssimon#include "aeabi_vfp.h"
36133094Ssimon
37133094Ssimonextern int _libc_arm_fpu_present;
38134652Sbrueffer
39133094Ssimonflag __unordsf2(float32, float32);
40133094Ssimon
41133094Ssimon/* These are written in asm and are only called from this file */
42133094Ssimonint __aeabi_fcmpeq_vfp(float32, float32);
43135126Sbruefferint __aeabi_fcmplt_vfp(float32, float32);
44133094Ssimonint __aeabi_fcmple_vfp(float32, float32);
45133343Ssimonint __aeabi_fcmpgt_vfp(float32, float32);
46144426Sbruefferint __aeabi_fcmpge_vfp(float32, float32);
47134264Ssimonint __aeabi_fcmpun_vfp(float32, float32);
48134401Ssimonint __aeabi_f2iz_vfp(float32);
49135126Sbruefferfloat64 __aeabi_f2d_vfp(float32);
50133094Ssimonfloat32 __aeabi_i2f_vfp(int);
51134316Sbruefferfloat32 __aeabi_fadd_vfp(float32, float32);
52157648Sbruefferfloat32 __aeabi_fdiv_vfp(float32, float32);
53153665Sbruefferfloat32 __aeabi_fmul_vfp(float32, float32);
54139404Sbruefferfloat32 __aeabi_fsub_vfp(float32, float32);
55133343Ssimon
56150242Sjoel/*
57135126Sbrueffer * Depending on the target these will:
58155296Sbrueffer *  On armv6 with a vfp call the above function, or
59133094Ssimon *  Call the softfloat function in the 3rd argument.
60135560Speter */
61133094Ssimonint AEABI_FUNC2(fcmpeq, float32, float32_eq)
62133094Ssimonint AEABI_FUNC2(fcmplt, float32, float32_lt)
63134826Ssimonint AEABI_FUNC2(fcmple, float32, float32_le)
64135126Sbruefferint AEABI_FUNC2_REV(fcmpge, float32, float32_le)
65133094Ssimonint AEABI_FUNC2_REV(fcmpgt, float32, float32_lt)
66135126Sbruefferint AEABI_FUNC2(fcmpun, float32, __unordsf2)
67135126Sbrueffer
68135336Sbruefferint AEABI_FUNC(f2iz, float32, float32_to_int32_round_to_zero)
69134786Sbruefferfloat64 AEABI_FUNC(f2d, float32, float32_to_float64)
70150293Sbruefferfloat32 AEABI_FUNC(i2f, int, int32_to_float32)
71134772Ssimon
72133094Ssimonfloat32 AEABI_FUNC2(fadd, float32, float32_add)
73135143Sbruefferfloat32 AEABI_FUNC2(fdiv, float32, float32_div)
74133778Ssimonfloat32 AEABI_FUNC2(fmul, float32, float32_mul)
75135120Ssimonfloat32 AEABI_FUNC2(fsub, float32, float32_sub)
76149874Sbrueffer
77133343Ssimonint
78134772Ssimon__aeabi_cfcmpeq_helper(float32 a, float32 b)
79135126Sbrueffer{
80133343Ssimon	int quiet = 0;
81134218Sbrueffer
82135126Sbrueffer	/* Check if a is a NaN */
83134273Sbrueffer	if ((a << 1) > 0xff000000u) {
84157274Sbrueffer		/* If it's a signalling NaN we will always signal */
85135126Sbrueffer		if ((a & 0x00400000u) == 0)
86135126Sbrueffer			return (0);
87159606Sbrueffer
88133094Ssimon		quiet = 1;
89134047Ssimon	}
90133457Ssimon
91138967Sbrueffer	/* Check if b is a NaN */
92135143Sbrueffer	if ((b << 1) > 0xff000000u) {
93135081Sbrueffer		/* If it's a signalling NaN we will always signal */
94133343Ssimon		if ((b & 0x00400000u) == 0)
95146397Sbrueffer			return (0);
96133343Ssimon
97141288Sbrueffer		quiet = 1;
98135143Sbrueffer	}
99143338Ssimon
100143783Sbrueffer	return (quiet);
101158111Sbrueffer}
102134316Sbrueffer