Skip to content

Commit 73b3d88

Browse files
authored
Merge pull request #181 from CDLuminate/mipsport
Updated MIPS port
2 parents 3aa5c3b + a4b3fde commit 73b3d88

10 files changed

Lines changed: 628 additions & 1 deletion

File tree

.travis.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,38 @@ matrix:
6969
- libc6-dev-ppc64el-cross
7070
- qemu-user-static
7171
- binfmt-support
72+
73+
- os: linux
74+
env: FLAGS="CC=mips-linux-gnu-gcc" TEST_FLAGS="LDFLAGS=-static"
75+
addons:
76+
apt:
77+
sources:
78+
- sourceline: "deb http://archive.ubuntu.com/ubuntu/ xenial main universe"
79+
packages:
80+
- gcc-mips-linux-gnu
81+
- libc6-dev-mips-cross
82+
- qemu-user-binfmt
83+
84+
- os: linux
85+
env: FLAGS="CC=mipsel-linux-gnu-gcc" TEST_FLAGS="LDFLAGS=-static"
86+
addons:
87+
apt:
88+
sources:
89+
- sourceline: "deb http://archive.ubuntu.com/ubuntu/ xenial main universe"
90+
packages:
91+
- gcc-mipsel-linux-gnu
92+
- libc6-dev-mipsel-cross
93+
- qemu-user-binfmt
94+
95+
- os: linux
96+
env: FLAGS="CC=mips64el-linux-gnuabi64-gcc" TEST_FLAGS="LDFLAGS=-static"
97+
addons:
98+
apt:
99+
sources:
100+
- sourceline: "deb http://archive.ubuntu.com/ubuntu/ xenial main universe"
101+
packages:
102+
- gcc-mips64el-linux-gnuabi64
103+
- libc6-dev-mips64el-cross
104+
- qemu-user-binfmt
72105
notifications:
73106
email: false

Make.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ endif
6767
ifeq ($(ARCH),x86_64)
6868
override ARCH := amd64
6969
endif
70+
ifeq ($(findstring mips,$(ARCH)),mips)
71+
override ARCH := mips
72+
endif
7073

7174
# If CFLAGS does not contain a -O optimization flag, default to -O3
7275
ifeq ($(findstring -O,$(CFLAGS)),)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test/test-float: libopenlibm.$(OLM_MAJOR_MINOR_SHLIB_EXT)
7272
$(MAKE) -C test test-float
7373

7474
clean:
75-
rm -f aarch64/*.o amd64/*.o arm/*.o bsdsrc/*.o i387/*.o ld80/*.o ld128/*.o src/*.o powerpc/*.o
75+
rm -f aarch64/*.o amd64/*.o arm/*.o bsdsrc/*.o i387/*.o ld80/*.o ld128/*.o src/*.o powerpc/*.o mips/*.o
7676
rm -f libopenlibm.a libopenlibm.*$(SHLIB_EXT)*
7777
$(MAKE) -C test clean
7878

include/openlibm_fenv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <openlibm_fenv_i387.h>
1111
#elif defined(__powerpc__)
1212
#include <openlibm_fenv_powerpc.h>
13+
#elif defined(__mips__)
14+
#include <openlibm_fenv_mips.h>
1315
#else
1416
#error "Unsupported platform"
1517
#endif

include/openlibm_fenv_mips.h

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
/*-
2+
* Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24+
* SUCH DAMAGE.
25+
*
26+
* $FreeBSD$
27+
*/
28+
29+
#ifndef _FENV_H_
30+
#define _FENV_H_
31+
32+
#include <stdint.h>
33+
#include "cdefs-compat.h"
34+
35+
#ifndef __fenv_static
36+
#define __fenv_static static
37+
#endif
38+
39+
typedef uint32_t fenv_t;
40+
typedef uint32_t fexcept_t;
41+
42+
/* Exception flags */
43+
#ifdef __mips_soft_float
44+
#define _FPUSW_SHIFT 16
45+
#define FE_INVALID 0x0001
46+
#define FE_DIVBYZERO 0x0002
47+
#define FE_OVERFLOW 0x0004
48+
#define FE_UNDERFLOW 0x0008
49+
#define FE_INEXACT 0x0010
50+
#else
51+
#define _FCSR_CAUSE_SHIFT 10
52+
#define FE_INVALID 0x0040
53+
#define FE_DIVBYZERO 0x0020
54+
#define FE_OVERFLOW 0x0010
55+
#define FE_UNDERFLOW 0x0008
56+
#define FE_INEXACT 0x0004
57+
#endif
58+
#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
59+
FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
60+
61+
/* Rounding modes */
62+
#define FE_TONEAREST 0x0000
63+
#define FE_TOWARDZERO 0x0001
64+
#define FE_UPWARD 0x0002
65+
#define FE_DOWNWARD 0x0003
66+
#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
67+
FE_UPWARD | FE_TOWARDZERO)
68+
__BEGIN_DECLS
69+
70+
/* Default floating-point environment */
71+
extern const fenv_t __fe_dfl_env;
72+
#define FE_DFL_ENV (&__fe_dfl_env)
73+
74+
/* We need to be able to map status flag positions to mask flag positions */
75+
#define _ENABLE_SHIFT 5
76+
#define _ENABLE_MASK (FE_ALL_EXCEPT << _ENABLE_SHIFT)
77+
78+
#ifndef __mips_soft_float
79+
#define __cfc1(__fcsr) __asm __volatile("cfc1 %0, $31" : "=r" (__fcsr))
80+
#define __ctc1(__fcsr) __asm __volatile("ctc1 %0, $31" :: "r" (__fcsr))
81+
#endif
82+
83+
#ifdef __mips_soft_float
84+
int feclearexcept(int __excepts);
85+
int fegetexceptflag(fexcept_t *__flagp, int __excepts);
86+
int fesetexceptflag(const fexcept_t *__flagp, int __excepts);
87+
int feraiseexcept(int __excepts);
88+
int fetestexcept(int __excepts);
89+
int fegetround(void);
90+
int fesetround(int __round);
91+
int fegetenv(fenv_t *__envp);
92+
int feholdexcept(fenv_t *__envp);
93+
int fesetenv(const fenv_t *__envp);
94+
int feupdateenv(const fenv_t *__envp);
95+
#else
96+
__fenv_static inline int
97+
feclearexcept(int __excepts)
98+
{
99+
fexcept_t fcsr;
100+
101+
__excepts &= FE_ALL_EXCEPT;
102+
__cfc1(fcsr);
103+
fcsr &= ~(__excepts | (__excepts << _FCSR_CAUSE_SHIFT));
104+
__ctc1(fcsr);
105+
106+
return (0);
107+
}
108+
109+
__fenv_static inline int
110+
fegetexceptflag(fexcept_t *__flagp, int __excepts)
111+
{
112+
fexcept_t fcsr;
113+
114+
__excepts &= FE_ALL_EXCEPT;
115+
__cfc1(fcsr);
116+
*__flagp = fcsr & __excepts;
117+
118+
return (0);
119+
}
120+
121+
__fenv_static inline int
122+
fesetexceptflag(const fexcept_t *__flagp, int __excepts)
123+
{
124+
fexcept_t fcsr;
125+
126+
__excepts &= FE_ALL_EXCEPT;
127+
__cfc1(fcsr);
128+
fcsr &= ~__excepts;
129+
fcsr |= *__flagp & __excepts;
130+
__ctc1(fcsr);
131+
132+
return (0);
133+
}
134+
135+
__fenv_static inline int
136+
feraiseexcept(int __excepts)
137+
{
138+
fexcept_t fcsr;
139+
140+
__excepts &= FE_ALL_EXCEPT;
141+
__cfc1(fcsr);
142+
fcsr |= __excepts | (__excepts << _FCSR_CAUSE_SHIFT);
143+
__ctc1(fcsr);
144+
145+
return (0);
146+
}
147+
148+
__fenv_static inline int
149+
fetestexcept(int __excepts)
150+
{
151+
fexcept_t fcsr;
152+
153+
__excepts &= FE_ALL_EXCEPT;
154+
__cfc1(fcsr);
155+
156+
return (fcsr & __excepts);
157+
}
158+
159+
__fenv_static inline int
160+
fegetround(void)
161+
{
162+
fexcept_t fcsr;
163+
164+
__cfc1(fcsr);
165+
166+
return (fcsr & _ROUND_MASK);
167+
}
168+
169+
__fenv_static inline int
170+
fesetround(int __round)
171+
{
172+
fexcept_t fcsr;
173+
174+
if (__round & ~_ROUND_MASK)
175+
return (-1);
176+
177+
__cfc1(fcsr);
178+
fcsr &= ~_ROUND_MASK;
179+
fcsr |= __round;
180+
__ctc1(fcsr);
181+
182+
return (0);
183+
}
184+
185+
__fenv_static inline int
186+
fegetenv(fenv_t *__envp)
187+
{
188+
189+
__cfc1(*__envp);
190+
191+
return (0);
192+
}
193+
194+
__fenv_static inline int
195+
feholdexcept(fenv_t *__envp)
196+
{
197+
fexcept_t fcsr;
198+
199+
__cfc1(fcsr);
200+
*__envp = fcsr;
201+
fcsr &= ~(FE_ALL_EXCEPT | _ENABLE_MASK);
202+
__ctc1(fcsr);
203+
204+
return (0);
205+
}
206+
207+
__fenv_static inline int
208+
fesetenv(const fenv_t *__envp)
209+
{
210+
211+
__ctc1(*__envp);
212+
213+
return (0);
214+
}
215+
216+
__fenv_static inline int
217+
feupdateenv(const fenv_t *__envp)
218+
{
219+
fexcept_t fcsr;
220+
221+
__cfc1(fcsr);
222+
fesetenv(__envp);
223+
feraiseexcept(fcsr);
224+
225+
return (0);
226+
}
227+
#endif /* !__mips_soft_float */
228+
229+
#if __BSD_VISIBLE
230+
231+
/* We currently provide no external definitions of the functions below. */
232+
233+
#ifdef __mips_soft_float
234+
int feenableexcept(int __mask);
235+
int fedisableexcept(int __mask);
236+
int fegetexcept(void);
237+
#else
238+
static inline int
239+
feenableexcept(int __mask)
240+
{
241+
fenv_t __old_fcsr, __new_fcsr;
242+
243+
__cfc1(__old_fcsr);
244+
__new_fcsr = __old_fcsr | (__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT;
245+
__ctc1(__new_fcsr);
246+
247+
return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT);
248+
}
249+
250+
static inline int
251+
fedisableexcept(int __mask)
252+
{
253+
fenv_t __old_fcsr, __new_fcsr;
254+
255+
__cfc1(__old_fcsr);
256+
__new_fcsr = __old_fcsr & ~((__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT);
257+
__ctc1(__new_fcsr);
258+
259+
return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT);
260+
}
261+
262+
static inline int
263+
fegetexcept(void)
264+
{
265+
fexcept_t fcsr;
266+
267+
__cfc1(fcsr);
268+
269+
return ((fcsr & _ENABLE_MASK) >> _ENABLE_SHIFT);
270+
}
271+
272+
#endif /* !__mips_soft_float */
273+
274+
#endif /* __BSD_VISIBLE */
275+
276+
__END_DECLS
277+
278+
#endif /* !_FENV_H_ */

mips/Make.files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$(CUR_SRCS) = fenv.c

0 commit comments

Comments
 (0)