Skip to content

Commit ba43b36

Browse files
authored
Merge pull request #151 from JuliaLang/sf/archmageddon
Fixup architecture woes
2 parents 1581174 + d6c4935 commit ba43b36

8 files changed

Lines changed: 159 additions & 92 deletions

File tree

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,28 @@ matrix:
4646
- qemu-user-static
4747
- binfmt-support
4848

49+
- os: linux
50+
env: FLAGS="CC=arm-linux-gnueabihf-gcc" TEST_FLAGS="LDFLAGS=-static"
51+
addons:
52+
apt:
53+
packages:
54+
- gcc-arm-linux-gnueabihf
55+
- libc6-dev-armhf-cross
56+
- qemu-user-static
57+
- binfmt-support
58+
59+
# This works, but only if qemu-user-static is >= v2.4. This is not the
60+
# case on the default trusty images, so we add a PPA that has qemu 2.5
61+
- os: linux
62+
env: FLAGS="CC=powerpc64le-linux-gnu-gcc" TEST_FLAGS="LDFLAGS=-static"
63+
addons:
64+
apt:
65+
sources:
66+
- sourceline: "ppa:gns3/qemu"
67+
packages:
68+
- gcc-powerpc64le-linux-gnu
69+
- libc6-dev-ppc64el-cross
70+
- qemu-user-static
71+
- binfmt-support
4972
notifications:
5073
email: false

Make.inc

Lines changed: 66 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# -*- mode: makefile-gmake -*-
22

3+
# Default build rule for any Makefile in this project: all
4+
default: all
5+
36
OS := $(shell uname)
47
# Do not forget to bump SOMINOR when changing VERSION,
58
# and SOMAJOR when breaking ABI in a backward-incompatible way
@@ -13,9 +16,9 @@ libdir = $(prefix)/lib
1316
includedir = $(prefix)/include
1417

1518
ifeq ($(OS), FreeBSD)
16-
pkgconfigdir = $(prefix)/libdata/pkgconfig
19+
pkgconfigdir = $(prefix)/libdata/pkgconfig
1720
else
18-
pkgconfigdir = $(libdir)/pkgconfig
21+
pkgconfigdir = $(libdir)/pkgconfig
1922
endif
2023

2124
USEGCC = 1
@@ -45,56 +48,27 @@ CFLAGS_add += -fno-gnu89-inline -fno-builtin
4548
endif
4649

4750
ARCH ?= $(shell $(CC) -dumpmachine | sed "s/\([^-]*\).*$$/\1/")
48-
ARCH_ORIGIN := $(origin ARCH)
4951

5052
ifeq ($(ARCH),mingw32)
5153
$(error "the mingw32 compiler you are using fails the openblas testsuite. please see the Julia README.windows.md document for a replacement")
5254
endif
5355

54-
CFLAGS_add += -std=c99 -Wall -I$(OPENLIBM_HOME) -I$(OPENLIBM_HOME)/include -I$(OPENLIBM_HOME)/ld80 -I$(OPENLIBM_HOME)/$(ARCH) -I$(OPENLIBM_HOME)/src -DASSEMBLER -D__BSD_VISIBLE -Wno-implicit-function-declaration
55-
56-
default: all
57-
58-
# *int / *intf need to be built with -O0
59-
src/%int.c.o: src/%int.c
60-
$(CC) $(CPPFLAGS) -O0 $(CFLAGS_add) -c $< -o $@
61-
62-
src/%intf.c.o: src/%intf.c
63-
$(CC) $(CPPFLAGS) -O0 $(CFLAGS_add) -c $< -o $@
64-
65-
%.c.o: %.c
66-
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add) -c $< -o $@
67-
68-
%.S.o: %.S
69-
$(CC) $(CPPFLAGS) $(SFLAGS) $(SFLAGS_add) $(filter -m% -B% -I% -D%,$(CFLAGS_add)) -c $< -o $@
70-
7156
# OS-specific stuff
72-
REAL_ARCH := $(ARCH)
7357
ifeq ($(findstring arm,$(ARCH)),arm)
7458
override ARCH := arm
75-
endif
76-
ifeq ($(ARCH),aarch64)
77-
override ARCH := arm
59+
MARCH ?= armv7-a
60+
CFLAGS_add += -mhard-float
7861
endif
7962
ifeq ($(findstring powerpc,$(ARCH)),powerpc)
8063
override ARCH := powerpc
8164
endif
8265
ifeq ($(findstring ppc,$(ARCH)),ppc)
8366
override ARCH := powerpc
8467
endif
85-
ifeq ($(ARCH),i386)
68+
ifneq ($(filter $(ARCH),i386 i486 i586 i686 i387 i487 i587 i687),)
8669
override ARCH := i387
70+
MARCH ?= i686
8771
endif
88-
ifeq ($(ARCH),i486)
89-
override ARCH := i387
90-
endif
91-
ifeq ($(ARCH),i586)
92-
override ARCH := i387
93-
endif
94-
ifeq ($(ARCH),i686)
95-
override ARCH := i387
96-
endif
97-
9872
ifeq ($(ARCH),x86_64)
9973
override ARCH := amd64
10074
endif
@@ -109,51 +83,68 @@ override OS=WINNT
10983
endif
11084

11185
#keep these if statements separate
112-
11386
ifeq ($(OS), WINNT)
114-
SHLIB_EXT = dll
115-
SONAME_FLAG = -soname
116-
CFLAGS_add += -nodefaultlibs
117-
shlibdir = $(bindir)
87+
SHLIB_EXT = dll
88+
SONAME_FLAG = -soname
89+
CFLAGS_add += -nodefaultlibs
90+
shlibdir = $(bindir)
11891
else
119-
ifeq ($(OS), Darwin)
120-
SHLIB_EXT = dylib
121-
SONAME_FLAG = -install_name
122-
else
123-
SHLIB_EXT = so
124-
SONAME_FLAG = -soname
125-
endif
126-
CFLAGS_add += -fPIC
127-
shlibdir = $(libdir)
128-
endif
129-
130-
# The target specific FLAGS_add
131-
ifeq ($(ARCH_ORIGIN),file)
132-
CFLAGS_add_TARGET_$(ARCH) :=
133-
SFLAGS_add_TARGET_$(ARCH) :=
134-
LDFLAGS_add_TARGET_$(ARCH) :=
92+
ifeq ($(OS), Darwin)
93+
SHLIB_EXT = dylib
94+
SONAME_FLAG = -install_name
13595
else
96+
SHLIB_EXT = so
97+
SONAME_FLAG = -soname
98+
endif
99+
CFLAGS_add += -fPIC
100+
shlibdir = $(libdir)
101+
endif
102+
103+
# Add `-march` to our CFLAGS if it's defined
104+
ifneq ($(MARCH),)
105+
CFLAGS_arch += -march=$(MARCH)
106+
endif
107+
136108
ifeq ($(ARCH),i387)
137-
CFLAGS_add_TARGET_$(ARCH) := -m32 -march=$(REAL_ARCH)
138-
SFLAGS_add_TARGET_$(ARCH) := -m32 -march=$(REAL_ARCH)
139-
LDFLAGS_add_TARGET_$(ARCH) := -m32 -march=$(REAL_ARCH)
140-
endif
141-
CFLAGS_add_TARGET_x86_64 := -m64
142-
SFLAGS_add_TARGET_x86_64 := -m64
143-
LDFLAGS_add_TARGET_x86_64 := -m64
144-
# Arm
145-
ifeq ($(ARCH),arm)
146-
ifneq ($(REAL_ARCH),arm)
147-
CFLAGS_add_TARGET_$(ARCH) := -march=$(REAL_ARCH)
148-
SFLAGS_add_TARGET_$(ARCH) := -march=$(REAL_ARCH)
149-
LDFLAGS_add_TARGET_$(ARCH) := -march=$(REAL_ARCH)
150-
else
151-
$(error No known generic arm cflags. Please specify arch type)
109+
CFLAGS_arch += -m32
110+
SFLAGS_arch += -m32
111+
LDFLAGS_arch += -m32
152112
endif
113+
114+
ifeq ($(ARCH),amd64)
115+
CFLAGS_arch += -m64
116+
SFLAGS_arch += -m64
117+
LDFLAGS_arch += -m64
153118
endif
119+
120+
# Add our "arch"-related FLAGS in. We separate arch-related flags out so that
121+
# we can conveniently get at them for targets that don't want the rest of
122+
# *FLAGS_add, such as the testing Makefile targets
123+
CFLAGS_add += $(CFLAGS_arch)
124+
SFLAGS_add += $(SFLAGS_arch)
125+
LDFLAGS_add += $(LDFLAGS_arch)
126+
127+
CFLAGS_add += -std=c99 -Wall -I$(OPENLIBM_HOME) -I$(OPENLIBM_HOME)/include -I$(OPENLIBM_HOME)/$(ARCH) -I$(OPENLIBM_HOME)/src -DASSEMBLER -D__BSD_VISIBLE -Wno-implicit-function-declaration
128+
ifneq ($(filter $(ARCH),i387 amd64 aarch64 powerpc),)
129+
CFLAGS_add += -I$(OPENLIBM_HOME)/ld80
154130
endif
155131

156-
# Actually finish setting the FLAGS_add
157-
CFLAGS_add += $(CFLAGS_add_TARGET_$(ARCH))
158-
LDFLAGS_add += $(LDFLAGS_add_TARGET_$(ARCH))
159-
SFLAGS_add += $(SFLAGS_add_TARGET_$(ARCH))
132+
133+
# *int / *intf need to be built with -O0
134+
src/%int.c.o: src/%int.c
135+
$(CC) $(CPPFLAGS) -O0 $(CFLAGS_add) -c $< -o $@
136+
137+
src/%intf.c.o: src/%intf.c
138+
$(CC) $(CPPFLAGS) -O0 $(CFLAGS_add) -c $< -o $@
139+
140+
%.c.o: %.c
141+
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add) -c $< -o $@
142+
143+
%.S.o: %.S
144+
$(CC) $(CPPFLAGS) $(SFLAGS) $(SFLAGS_add) $(filter -m% -B% -I% -D%,$(CFLAGS_add)) -c $< -o $@
145+
146+
147+
# Makefile debugging trick:
148+
# call print-VARIABLE to see the runtime value of any variable
149+
print-%:
150+
@echo '$*=$($*)'

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ OPENLIBM_HOME=$(abspath .)
22
include ./Make.inc
33

44
SUBDIRS = src $(ARCH) bsdsrc
5-
ifneq ($(ARCH), arm)
6-
ifneq ($(ARCH), powerpc)
5+
# Add ld80 directory on x86 and x64
6+
ifneq ($(filter $(ARCH),i387 amd64),)
77
SUBDIRS += ld80
88
endif
9-
endif
109

1110
define INC_template
1211
TEST=test
@@ -68,7 +67,7 @@ test/test-float: libopenlibm.$(OLM_MAJOR_MINOR_SHLIB_EXT)
6867
$(MAKE) -C test test-float
6968

7069
clean:
71-
rm -f amd64/*.o arm/*.o bsdsrc/*.o i387/*.o ld128/*.o ld80/*.o src/*.o
70+
rm -f aarch64/*.o amd64/*.o arm/*.o bsdsrc/*.o i387/*.o ld80/*.o ld128/*.o src/*.o powerpc/*.o
7271
rm -f libopenlibm.a libopenlibm.*$(SHLIB_EXT)*
7372
$(MAKE) -C test clean
7473

aarch64/Make.files

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

aarch64/fenv.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*-
2+
* Copyright (c) 2004 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: src/lib/msun/arm/fenv.c,v 1.3 2011/10/16 05:37:56 das Exp $
27+
*/
28+
29+
#define __fenv_static
30+
#include <openlibm_fenv.h>
31+
32+
#ifdef __GNUC_GNU_INLINE__
33+
#error "This file must be compiled with C99 'inline' semantics"
34+
#endif
35+
36+
/*
37+
* Hopefully the system ID byte is immutable, so it's valid to use
38+
* this as a default environment.
39+
*/
40+
const fenv_t __fe_dfl_env = 0;
41+
42+
extern inline int feclearexcept(int __excepts);
43+
extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts);
44+
extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts);
45+
extern inline int feraiseexcept(int __excepts);
46+
extern inline int fetestexcept(int __excepts);
47+
extern inline int fegetround(void);
48+
extern inline int fesetround(int __round);
49+
extern inline int fegetenv(fenv_t *__envp);
50+
extern inline int feholdexcept(fenv_t *__envp);
51+
extern inline int fesetenv(const fenv_t *__envp);
52+
extern inline int feupdateenv(const fenv_t *__envp);

include/openlibm_fenv_arm.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ extern const fenv_t __fe_dfl_env;
6969
#if defined(__aarch64__)
7070
#define __rfs(__fpsr) __asm __volatile("mrs %0,fpsr" : "=r" (*(__fpsr)))
7171
#define __wfs(__fpsr) __asm __volatile("msr fpsr,%0" : : "r" (__fpsr))
72-
#elif defined(ARM_HARD_FLOAT)
73-
#define __rfs(__fpsr) __asm __volatile("rfs %0" : "=r" (*(__fpsr)))
74-
#define __wfs(__fpsr) __asm __volatile("wfs %0" : : "r" (__fpsr))
72+
/* Test for hardware support for ARM floating point operations, explicitly
73+
checking for float and double support, see "ARM C Language Extensions", 6.5.1 */
74+
#elif defined(__ARM_FP) && (__ARM_FP & 0x0C) != 0
75+
#define __rfs(__fpsr) __asm __volatile("vmrs %0,fpscr" : "=&r" (*(__fpsr)))
76+
#define __wfs(__fpsr) __asm __volatile("vmsr fpscr,%0" : : "r" (__fpsr))
7577
#else
76-
#define __rfs(__fpsr)
78+
#define __rfs(__fpsr) (*(__fpsr) = 0)
7779
#define __wfs(__fpsr)
7880
#endif
7981

src/Make.files

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ ifneq ($(OS), WINNT)
3636
$(CUR_SRCS) += s_nan.c
3737
endif
3838

39-
ifneq ($(ARCH), arm)
40-
ifneq ($(ARCH), powerpc)
39+
# Add in long double functions for x86 and x64
40+
ifneq ($(filter $(ARCH),i387 amd64),)
4141
# C99 long double functions
4242
$(CUR_SRCS) += s_copysignl.c s_fabsl.c s_llrintl.c s_lrintl.c s_modfl.c
4343

@@ -57,7 +57,6 @@ $(CUR_SRCS) += e_acosl.c e_asinl.c e_atan2l.c e_fmodl.c \
5757
s_catanl.c s_csinl.c s_cacosl.c s_cexpl.c s_csinhl.c s_ccoshl.c \
5858
s_clogl.c s_ctanhl.c s_ccosl.c s_cbrtl.c
5959
endif
60-
endif
6160

6261
# C99 complex functions
6362
$(CUR_SRCS) += s_ccosh.c s_ccoshf.c s_cexp.c s_cexpf.c \

test/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ all: test-double test-float # test-double-system test-float-system
1212
bench: bench-syslibm bench-openlibm
1313

1414
test-double: test-double.c libm-test.c libm-test-ulps.h
15-
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add_TARGET_$(ARCH)) $(LDFLAGS) $@.c -D__BSD_VISIBLE -I ../include -I../src $(OPENLIBM_LIB) -o $@
15+
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_arch) $(LDFLAGS) $(LDFLAGS_arch) $@.c -D__BSD_VISIBLE -I ../include -I../src $(OPENLIBM_LIB) -o $@
1616

1717
test-float: test-float.c libm-test.c libm-test-ulps.h
18-
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add_TARGET_$(ARCH)) $(LDFLAGS) $@.c -D__BSD_VISIBLE -I ../include -I../src $(OPENLIBM_LIB) -o $@
18+
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_arch) $(LDFLAGS) $(LDFLAGS_arch) $@.c -D__BSD_VISIBLE -I ../include -I../src $(OPENLIBM_LIB) -o $@
1919

2020
test-double-system: test-double.c libm-test.c libm-test-ulps.h
21-
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add_TARGET_$(ARCH)) $(LDFLAGS) $< -DSYS_MATH_H -lm -o $@
21+
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_arch) $(LDFLAGS) $(LDFLAGS_arch) $< -DSYS_MATH_H -lm -o $@
2222

2323
test-float-system: test-float.c libm-test.c libm-test-ulps.h
24-
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add_TARGET_$(ARCH)) $(LDFLAGS) $< -DSYS_MATH_H -lm -o $@
24+
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_arch) $(LDFLAGS) $(LDFLAGS_arch) $< -DSYS_MATH_H -lm -o $@
2525

2626
bench-openlibm: libm-bench.cpp
27-
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add_TARGET_$(ARCH)) $(LDFLAGS) $< $(OPENLIBM_LIB) -o $@
27+
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_arch) $(LDFLAGS) $(LDFLAGS_arch) $< $(OPENLIBM_LIB) -o $@
2828

2929
bench-syslibm: libm-bench.cpp
30-
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_add_TARGET_$(ARCH)) $(LDFLAGS) $< -lm -o $@
30+
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_arch) $(LDFLAGS) $(LDFLAGS_arch) $< -lm -o $@
3131

3232
clean:
3333
rm -fr test-double test-float test-double-system test-float-system bench-openlibm bench-syslibm *.dSYM

0 commit comments

Comments
 (0)