Skip to content

Commit

Permalink
ci: test with openlibm (#3)
Browse files Browse the repository at this point in the history
* make: link with openlibm

* libm: use openlibm

Replace include:
+ `<math.h>` => `<openlibm_math.h>`
+ `<fenv.h>` => `<openlibm_fenv.h>`
+ `<complex.h>` => `<openlibm_complex.h>`

* ci: add Openlibm

* ci: skip when modify non-source
  • Loading branch information
inky authored Feb 24, 2024
1 parent 7e0ceaf commit abde35c
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 20 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/glibc.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Glibc
on:
push:
paths-ignore:
- 'README.md'
- '.gitignore'
- 'doc/**'
paths:
- '.github/workflows/glibc.yml'
- 'src/**'
- 'config.mak.def'
- 'Makefile'
branches:
- main
tags: ['*']
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/musl.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Musl
on:
push:
paths-ignore:
- 'README.md'
- '.gitignore'
- 'doc/**'
paths:
- '.github/workflows/musl.yml'
- 'src/**'
- 'config.mak.def'
- 'Makefile'
branches:
- main
tags: ['*']
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/openlibm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Openlibm
on:
push:
paths:
- '.github/workflows/openlibm.yml'
- 'src/**'
- 'config.mak.def'
- 'Makefile'
- 'openlibm.mk'
branches:
- main
tags: ['*']
pull_request:
workflow_dispatch:

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
test:
name: ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout Openlibm
uses: actions/checkout@v4
with:
repository: 'JuliaMath/openlibm'
path: 'libm/openlibm'
- name: Env Version
run: |
gcc --version
ld --version
ldd --version
- name: Build Openlibm
run: make -C libm/openlibm -j`nproc`
- name: Run Test
run: make -j`nproc` USE_OPENLIBM=1
- name: Show Test Result
run: cat src/REPORT
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
config.mak
options.h
REPORT

libm/
28 changes: 24 additions & 4 deletions config.mak.def
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
# Use openlibm, otherwise use system libm
USE_OPENLIBM:=0

# Build and link flags
CFLAGS += -pipe -std=c99 -D_POSIX_C_SOURCE=200809L -Wall -Wno-unused-function -Wno-missing-braces -Wno-unused -Wno-overflow
CFLAGS += -Wno-unknown-pragmas -fno-builtin -frounding-math
CFLAGS += -Werror=implicit-function-declaration -Werror=implicit-int -Werror=pointer-sign -Werror=pointer-arith
CFLAGS += -g
LDFLAGS += -g
LDLIBS += -lpthread -lm -lrt
LDLIBS += -lpthread -lrt

# Choose libm
ifneq ($(USE_OPENLIBM), 1)
LDLIBS += -lm
# glibc specific settings
CFLAGS += -D_FILE_OFFSET_BITS=64
LDLIBS += -lcrypt -ldl -lresolv -lutil -lpthread
else # Use openlibm
include openlibm.mk

CFLAGS += $(CFLAGS_add)
LDFLAGS += $(LDFLAGS_add)
LDLIBS += $(OPENLIBM_LIB)
endif # USE_OPENLIBM

# glibc specific settings
CFLAGS += -D_FILE_OFFSET_BITS=64
LDLIBS += -lcrypt -ldl -lresolv -lutil -lpthread

# Makefile debugging trick:
# call print-VARIABLE to see the runtime value of any variable
# (hardened against any special characters appearing in the output)
print-%:
@echo '$*=$(subst ','\'',$(subst $(newline),\n,$($*)))'
21 changes: 21 additions & 0 deletions openlibm.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# config for build openlibm
# export:
# - CFLAGS_add
# - LDFLAGS_add
# - OPENLIBM_LIB

# ---- OpenlibM settings
OPENLIBM_HOME?=$(abspath libm/openlibm)
include $(OPENLIBM_HOME)/Make.inc

# Set rpath of tests to builddir for loading shared library
OPENLIBM_LIB = -L$(OPENLIBM_HOME) -lopenlibm
ifneq ($(OS),WINNT)
ifneq ($(OS),Darwin)
OPENLIBM_LIB += -Wl,-rpath=$(OPENLIBM_HOME)
endif
else # WINNT
CFLAGS_add += -DIMPORT_EXPORTS
endif

CFLAGS_add += -DUSE_OPENLIBM
8 changes: 7 additions & 1 deletion src/api/complex.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <complex.h>
// XXX: Use openlibm
#ifdef USE_OPENLIBM
# include <openlibm_complex.h>
#else
# include <complex.h>
#endif // USE_OPENLIBM

#define T(t) (t*)0;
static void f()
{
Expand Down
8 changes: 7 additions & 1 deletion src/api/fenv.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <fenv.h>
// XXX: Use openlibm
#ifdef USE_OPENLIBM
# include <openlibm_fenv.h>
#else
# include <fenv.h>
#endif // USE_OPENLIBM

#define T(t) (t*)0;
#define F(t,n) {t *y = &x.n;}
#define C(n) switch(n){case n:;}
Expand Down
8 changes: 7 additions & 1 deletion src/api/math.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <math.h>
// XXX: Use openlibm
#ifdef USE_OPENLIBM
# include <openlibm_math.h>
#else
# include <math.h>
#endif // USE_OPENLIBM

#define T(t) (t*)0;
#define C(n) switch(n){case n:;}
#define I(t,e) {t x[sizeof(t)==sizeof(e)] = {e};}
Expand Down
11 changes: 8 additions & 3 deletions src/common/mtest.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include <fenv.h>
// XXX: Use openlibm
#ifdef USE_OPENLIBM
# include <openlibm_fenv.h>
# include <openlibm_math.h>
#else
# include <fenv.h>
# include <math.h>
#endif // USE_OPENLIBM
#include <float.h>
#include <math.h>

#undef RN
#undef RZ
Expand Down Expand Up @@ -132,4 +138,3 @@ static int checkcr(long double y, long double ywant, int r)
return isnan(y);
return y == ywant && signbit(y) == signbit(ywant);
}

7 changes: 6 additions & 1 deletion src/math/fpclassify.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include <stdio.h>
#include <math.h>
// XXX: Use openlibm
#ifdef USE_OPENLIBM
# include <openlibm_math.h>
#else
# include <math.h>
#endif // USE_OPENLIBM

#define T(a,b) {__LINE__, a, b},
#define length(a) (sizeof(a)/sizeof*(a))
Expand Down
1 change: 0 additions & 1 deletion src/math/isless.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <math.h>
#include "mtest.h"
#include "test.h"

Expand Down

0 comments on commit abde35c

Please sign in to comment.