bitmatch.ml
bitstring.ml
bitstring.mli
+bitstring_c.c
bitstring_config.ml.in
bitstring_objinfo.ml
bitstring_persistent.ml
TIME = @TIME@
GPROF = @GPROF@
+OCAMLLIB = @OCAMLLIB@
+
pkg_cil = @pkg_cil@
pkg_extlib = @pkg_extlib@
OCAMLDOCFLAGS = -html -sort
+CC = @CC@
+CFLAGS = @CFLAGS@ -Wall -Werror -fPIC -I$(OCAMLLIB)
+
+LIBRARY_PATH = @abs_top_builddir@
+LD_LIBRARY_PATH = @abs_top_builddir@
+export LIBRARY_PATH
+export LD_LIBRARY_PATH
+
SUBDIRS =
ifneq ($(pkg_cil),no)
ifneq ($(pkg_extlib),no)
bitstring-objinfo
@for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done
-bitstring.cma: bitstring_types.cmo bitstring_config.cmo bitstring.cmo \
- bitmatch.cmo
- $(OCAMLFIND) ocamlc -a -o $@ $^
+bitstring.cma: bitstring_types.cmo bitstring_config.cmo \
+ bitstring_c.o bitstring.cmo bitmatch.cmo
+ $(OCAMLMKLIB) -o bitstring $^
bitstring_persistent.cma: bitstring_persistent.cmo
$(OCAMLFIND) ocamlc -a -o $@ $^
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) $(OCAMLCPACKAGES) \
-I +camlp4 -pp camlp4of -c $<
-bitstring.cmxa: bitstring_types.cmx bitstring_config.cmx bitstring.cmx \
- bitmatch.cmx
- $(OCAMLFIND) ocamlopt -a -o $@ $^
+bitstring.cmxa: bitstring_types.cmx bitstring_config.cmx \
+ bitstring_c.o bitstring.cmx bitmatch.cmx
+ $(OCAMLMKLIB) -o bitstring $^
bitstring_persistent.cmxa: bitstring_persistent.cmx
$(OCAMLFIND) ocamlopt -a -o $@ $^
# Install.
install:
- ocamlfind install bitstring META *.mli *.cmx *.cma *.cmxa *.a \
+ ocamlfind install bitstring META *.mli *.cmx *.cma *.cmxa *.a *.so \
bitstring.cmi \
bitstring_persistent.cmi \
pa_bitstring.cmo
let minus_one = -1
let ff = 0xff
- (* Create a mask so many bits wide. *)
- let mask bits =
- if bits < 30 then
- pred (one << bits)
- else if bits = 30 then
- max_int
- else if bits = 31 then
- minus_one
- else
- invalid_arg "Bitstring.I.mask"
+ (* Create a mask 0-31 bits wide. *)
+ external mask : int -> int = "ocaml_bitstring_I_mask" "noalloc"
(* Byte swap an int of a given size. *)
let byteswap v bits =
--- /dev/null
+/* Bitstring library.
+ * Copyright (C) 2008 Red Hat Inc., Richard W.M. Jones
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version,
+ * with the OCaml linking exception described in COPYING.LIB.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * $Id: bitstring.ml 146 2008-08-20 16:58:33Z richard.wm.jones $
+ */
+
+/* This file contains hand-coded, optimized C implementations of
+ * certain very frequently used functions.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <caml/mlvalues.h>
+#include <caml/fail.h>
+
+/* Return a mask of 0-31 bits wide. */
+CAMLprim value
+ocaml_bitstring_I_mask (value bitsv)
+{
+ int bits = Int_val (bitsv);
+
+ if (bits <= 31)
+ return Val_int ((1 << bits) - 1);
+ else
+ caml_invalid_argument ("Bitstring.I.mask");
+}