Skip to content

Commit

Permalink
Merge pull request #94 from ocaml/simplified-configuration
Browse files Browse the repository at this point in the history
Remove source preprocessing and simplify configuration
  • Loading branch information
xavierleroy authored Jan 19, 2021
2 parents 842fb20 + c0b72f8 commit b229acf
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 340 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ jobs:
run: make
- name: Run the testsuite
run: make -C tests test

MacOS:
runs-on: macos-latest
steps:
- name: Install packages
run: brew install ocaml ocaml-findlib gmp
- name: Checkout
uses: actions/checkout@v2
- name: configure tree
run: ./configure
- name: Build
run: make
- name: Run the testsuite
run: make -C tests test
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
*.so
Makefile
depend
z.ml
z.mli
z_features.h
zarith_version.ml
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ However, small integers are represented as unboxed Caml integers, to save
space and improve performance. Big integers are allocated in the Caml heap,
bypassing GMP's memory management and achieving better GC behavior than e.g.
the MLGMP library.
Computations on small integers use a special, faster path (coded in assembly
for some platforms and functions) eschewing calls to GMP, while computations
on large intergers use the low-level MPN functions from GMP.
Computations on small integers use a special, faster path (in C or OCaml)
eschewing calls to GMP, while computations on large intergers use the
low-level MPN functions from GMP.

Arbitrary-precision integers can be compared correctly using OCaml's
polymorphic comparison operators (`=`, `<`, `>`, etc.).
Expand All @@ -32,7 +32,6 @@ Additional features include:
* OCaml, version 4.04.0 or later.
* Either the GMP library or the MPIR library, including development files.
* GCC or Clang or a gcc-compatible C compiler and assembler (other compilers may work).
* The Perl programming language.
* The Findlib package manager (optional, recommended).


Expand Down Expand Up @@ -95,8 +94,8 @@ See LICENSE file for details.

## AUTHORS

* Antoine Miné, Université Pierre et Marie Curie, formerly ENS Paris.
* Xavier Leroy, INRIA Paris-Rocquencourt.
* Antoine Miné, Sorbonne Université, formerly at ENS Paris.
* Xavier Leroy, Collège de France, formerly at Inria Paris.
* Pascal Cuoq, TrustInSoft.
* Christophe Troestler (toplevel module)

Expand All @@ -116,17 +115,12 @@ INRIA Rocquencourt (Institut national de recherche en informatique, France).
Source files | Description
--------------------|-----------------------------------------
configure | configuration script
caml_z.c | C implementation of all functions
caml_z_*.S | asm implementation for a few functions
z_pp.pl | script to generate z.ml[i] from z.ml[i]p
z.ml[i]p | templates used to generate z.ml[i]p
z.ml[i] | Z module and implementation for small integers
caml_z.c | C implementation
big_int_z.ml[i] | wrapper to provide a Big_int compatible API to Z
q.ml[i] | rational library, pure OCaml on top of Z
zarith_top.ml | toplevel module to provide pretty-printing
projet.mak | builds Z, Q and the tests
zarith.opam | package description for opam
z_mlgmpidl.ml[i] | conversion between Zarith and MLGMPIDL
tests/ | simple regression tests and benchmarks

Note: `z_pp.pl` simply scans the asm file (if any) to see which functions have
an asm implementation. It then fixes the external statements in .mlp and
.mlip accordingly.
The argument to `z_pp.pl` is the suffix `*` of the `caml_z_*.S` to use (guessed by configure).
21 changes: 0 additions & 21 deletions caml_z.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <mpir.h>
#endif

#include "z_features.h"
#include "zarith.h"

#ifdef __cplusplus
Expand All @@ -50,9 +49,7 @@ extern "C" {
#include <caml/intext.h>
#include <caml/callback.h>
#include <caml/intext.h>
#ifdef Z_OCAML_HASH
#include <caml/hash.h>
#endif

#define inline __inline

Expand Down Expand Up @@ -103,16 +100,6 @@ extern "C" {
*/
#define Z_CUSTOM_BLOCK 1

/* whether the "compare_ext" operation over custom blocks is supported.
This operation is required for OCaml's generic comparisons to
operate properly over values of type Z.t.
The compare_ext operation is supported in OCaml since version 3.12.1.
*/
/*
#define Z_OCAML_COMPARE_EXT 0
now set by configure
*/

/*---------------------------------------------------
DATA STRUCTURES
---------------------------------------------------*/
Expand Down Expand Up @@ -3244,10 +3231,6 @@ int ml_z_custom_compare(value arg1, value arg2)
return r;
}

#ifndef Z_OCAML_HASH
#define caml_hash_mix_uint32(h,n) ((h) * 65599 + (n))
#endif

static intnat ml_z_custom_hash(value v)
{
Z_DECL(v);
Expand Down Expand Up @@ -3380,11 +3363,7 @@ struct custom_operations ml_z_custom_ops = {
ml_z_custom_hash,
ml_z_custom_serialize,
ml_z_custom_deserialize,
#if Z_OCAML_COMPARE_EXT
ml_z_custom_compare,
#else
custom_compare_ext_default,
#endif
#ifndef Z_OCAML_LEGACY_CUSTOM_OPERATIONS
custom_fixed_length_default
#endif
Expand Down
84 changes: 0 additions & 84 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ host='auto'
gmp='auto'
perf='no'

ar="${AR}"
[ -z "$ar" ] && ar='ar'
ocaml='ocaml'
ocamlc='ocamlc'
ocamlopt='ocamlopt'
Expand All @@ -32,7 +30,6 @@ ocamldep='ocamldep'
ocamldoc='ocamldoc'
ccinc="$CPPFLAGS"
cclib="$LDFLAGS"
asopt="$ASFLAGS"
ccdef=''
mlflags="$OCAMLFLAGS"
mloptflags="$OCAMLOPTFLAGS"
Expand All @@ -55,18 +52,14 @@ usage: configure [options]
where options include:
-installdir dir installation directory
-ocamllibdir dir ocaml library directory
-host arch host type, for platform-specific asm code
-noasm disable platform-specific asm code
-gmp use GMP library (default if found)
-mpir use MPIR library instead of GMP
-perf enable performance statistics
-prefixnonocaml add for non ocaml tool, e.g. -prefixnonocaml x86_64-w64-mingw32-
Environment variables that affect configuration:
AR archiver tool
CC C compiler to use (default: try gcc, then cc)
CFLAGS extra flags to pass to the C compiler
ASFLAGS extra flags to pass to the assembler
CPPFLAGS extra includes, e.g. -I/path/to/gmp/include
LDFLAGS extra link flags, e.g. -L/path/to/gmp/lib
OCAMLFLAGS extra flags to pass to the ocamlc Caml compiler
Expand All @@ -90,11 +83,6 @@ while : ; do
-no-ocamlfind|--no-ocamlfind)
ocamlfind="no"
shift;;
-host|--host)
host="$2"
shift;;
-noasm|--no-asm)
host='none';;
-help|--help)
help;;
-gmp|--gmp)
Expand Down Expand Up @@ -211,9 +199,6 @@ searchbinreq $ocamlc
searchbinreq $ocamldep
searchbinreq $ocamlmklib
searchbinreq $ocamldoc
searchbin $ar
if test $? -eq 0; then ar=$prefixnonocaml$ar; searchbinreq $ar; fi
searchbinreq perl

if test -n "$CC"; then
searchbinreq "$CC"
Expand Down Expand Up @@ -309,62 +294,6 @@ if test "x$host" = 'xauto'; then
fi
fi


# set arch from host

arch='none'
case $host in
x86_64-*linux-gnu|x86_64-kfreebsd-gnu)
ccdef="-DZ_ELF -DZ_DOT_LABEL_PREFIX $ccdef"
if test $wordsize = 32; then
# 32-bit OCaml on a 64-bit host
arch='i686'
ccopt="-m32 $ccopt"
asopt="-m32 $asopt"
else
arch='x86_64'
fi
;;
i486-*linux-gnu|i686-*linux-gnu|i486-kfreebsd-gnu)
ccdef="-DZ_ELF -DZ_DOT_LABEL_PREFIX $ccdef"
arch='i686';;
i686-*cygwin)
if test "x$wordsize" = "x64"; then
ccdef="-DZ_COFF $ccdef"
arch='x86_64_mingw64'
else
ccdef="-DZ_UNDERSCORE_PREFIX -DZ_COFF $ccdef"
arch='i686'
fi
;;
i386-*darwin* | x86_64-*darwin*)
ccdef="-DZ_UNDERSCORE_PREFIX -DZ_MACOS $ccdef"
if test "x$wordsize" = "x64"; then
ccopt="-arch x86_64 $ccopt"
asopt="-arch x86_64 $asopt"
arch='x86_64'
checkcc
else
ccopt="-arch i386 $ccopt"
asopt="-arch i386 $asopt"
arch='i686'
checkcc
fi
;;
armv7*-gnueabi)
arch='arm'
;;
none)
;;
*)
echo "unknown host $host";;
esac

if test "$arch" != 'none'; then
if test ! -f "caml_z_${arch}.S"; then arch='none'; fi
fi


# check GMP, MPIR

if test "$gmp" = 'gmp' -o "$gmp" = 'auto'; then
Expand Down Expand Up @@ -406,14 +335,6 @@ case "$ocamlver" in
;;
esac

# Extended comparisons available since 3.12.1
echo "OCaml extended comparison supported"
ccdef="-DZ_OCAML_COMPARE_EXT $ccdef"

# New hash functions available since 4.00.0
echo "OCaml new hash functions available"
ccdef="-DZ_OCAML_HASH $ccdef"

# -bin-annot available since 4.00.0
echo "OCaml supports -bin-annot to produce documentation"
hasbinannot='yes'
Expand Down Expand Up @@ -443,11 +364,8 @@ OCAMLFLAGS=$mlflags
OCAMLOPTFLAGS=$mloptflags
OCAMLINC=$mlinc
CFLAGS=$ccinc $ccdef $ccopt
ASFLAGS=$ccdef $asopt
LIBS=$cclib
ARCH=$arch
INSTALLDIR=$installdir
AR=$ar
INSTALL=install
OCAMLFIND=ocamlfind
INSTMETH=$instmeth
Expand All @@ -468,11 +386,9 @@ detected configuration:
native-code: $hasocamlopt
dynamic linking: $hasdynlink
asm path: $arch
defines: $ccdef
libraries: $cclib
C options: $ccopt
asm options $asopt
installation path: $installdir
installation method $instmeth
Expand Down
15 changes: 6 additions & 9 deletions project.mak
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ endif
###############

CSRC = caml_z.c
SSRC = $(wildcard caml_z_$(ARCH).S)
MLSRC = z.ml q.ml big_int_Z.ml
MLSRC = zarith_version.ml z.ml q.ml big_int_Z.ml
MLISRC = z.mli q.mli big_int_Z.mli

AUTOGEN = z.ml z.mli z_features.h
AUTOGEN = zarith_version.ml

CMIOBJ = $(MLISRC:%.mli=%.cmi)
CMXOBJ = $(MLISRC:%.mli=%.cmx)
Expand Down Expand Up @@ -80,7 +79,7 @@ zarith.cmxa: $(MLSRC:%.ml=%.cmx)
zarith.cmxs: zarith.cmxa libzarith.$(LIBSUFFIX)
$(OCAMLOPT) -shared -o $@ -I . zarith.cmxa -linkall

libzarith.$(LIBSUFFIX): $(SSRC:%.S=%.$(OBJSUFFIX)) $(CSRC:%.c=%.$(OBJSUFFIX))
libzarith.$(LIBSUFFIX): $(CSRC:%.c=%.$(OBJSUFFIX))
$(OCAMLMKLIB) -failsafe -o zarith $+ $(LIBS)

zarith_top.cma: zarith_top.cmo
Expand All @@ -90,7 +89,8 @@ doc: $(MLISRC)
mkdir -p html
$(OCAMLDOC) -html -d html -charset utf8 $+


zarith_version.ml: META
(echo "let"; grep "version" META | head -1) > zarith_version.ml

# install targets
#################
Expand Down Expand Up @@ -122,9 +122,6 @@ endif
# rules
#######

$(AUTOGEN): z.mlp z.mlip $(SSRC) z_pp.pl
./z_pp.pl $(ARCH)

%.cmi: %.mli
$(OCAMLC) $(OCAMLFLAGS) $(OCAMLINC) -c $<

Expand Down Expand Up @@ -152,7 +149,7 @@ depend: $(AUTOGEN)

include depend

$(CSRC:%.c=%.$(OBJSUFFIX)): z_features.h zarith.h
$(CSRC:%.c=%.$(OBJSUFFIX)): zarith.h

.PHONY: clean
.PHONY: tests
Loading

0 comments on commit b229acf

Please sign in to comment.