Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a few int64 primitives use [@@unboxed] stubs on 32bits #2146

Merged
merged 4 commits into from Nov 13, 2018

Conversation

Projects
None yet
3 participants
@diml
Copy link
Member

commented Nov 12, 2018

This patch updates a few of the int64 primitives to use [@@unboxed] stubs on 32 bit systems. This allows to get rid of a few allocations on 32bits. The following primitives are updated: add, sub, mul, div, rem, bitand, bitor and bitxor.

Ref: MPR#7246

@diml diml force-pushed the diml:unboxed-int64-on-32bits branch from 78eef60 to 65a2296 Nov 12, 2018

let u64 = Unboxed_integer Pint64 in
let rec make_args = function 0 -> [] | n -> u64 :: make_args (n - 1) in
Primitive.make ~name ~native_name:(name ^ "_native")
~alloc:false

This comment has been minimized.

Copy link
@alainfrisch

alainfrisch Nov 12, 2018

Contributor

alloc:false is incompatible with primitives that can raise (div and mod). It could be useful to deal with the zero-dividend when generating the cmm code (as in safe_divmod_bi) and use a C-primitives that doesn't raise (and thus can indeed be marked as noalloc), but I'm not sure it's worth the trouble.

This comment has been minimized.

Copy link
@diml

diml Nov 12, 2018

Author Member

Oops, indeed. Fixed.

@alainfrisch
Copy link
Contributor

left a comment

LGTM

diml added some commits Nov 12, 2018

@diml

This comment has been minimized.

Copy link
Member Author

commented Nov 13, 2018

While I was at it, I added tests for lib-int64 (I just copied the ones for lib-int). I'll merge once CI passes.

@diml diml merged commit 4fadd45 into ocaml:trunk Nov 13, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@damiendoligez

This comment has been minimized.

Copy link
Member

commented Nov 14, 2018

Breaks the build on MacOS:

gcc -O2 -fno-strict-aliasing -fwrapv -Wall -Werror -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  -DOCAML_STDLIB_DIR='"/tmp/ocaml/trunk/lib/ocaml"'   -Wl,-no_compact_unwind -o ocamlrun prims.o libcamlrun.a -lpthread 
Undefined symbols for architecture x86_64:
  "_caml_int64_addncaml_int64_add_native", referenced from:
      _caml_builtin_cprim in prims.o
  "_caml_int64_andncaml_int64_and_native", referenced from:
      _caml_builtin_cprim in prims.o
  "_caml_int64_divncaml_int64_div_native", referenced from:
      _caml_builtin_cprim in prims.o
  "_caml_int64_modncaml_int64_mod_native", referenced from:
      _caml_builtin_cprim in prims.o
  "_caml_int64_mulncaml_int64_mul_native", referenced from:
      _caml_builtin_cprim in prims.o
  "_caml_int64_negncaml_int64_neg_native", referenced from:
      _caml_builtin_cprim in prims.o
  "_caml_int64_orncaml_int64_or_native", referenced from:
      _caml_builtin_cprim in prims.o
  "_caml_int64_subncaml_int64_sub_native", referenced from:
      _caml_builtin_cprim in prims.o
  "_caml_int64_xorncaml_int64_xor_native", referenced from:
      _caml_builtin_cprim in prims.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@damiendoligez

This comment has been minimized.

Copy link
Member

commented Nov 14, 2018

It looks like MacOS's sed doesn't allow you to use \n in a string to represent LF.

@damiendoligez

This comment has been minimized.

Copy link
Member

commented Nov 14, 2018

Here's a sed-based solution:

sed -n -e '/^CAMLprim_int64_[0-9]([a-z0-9_][a-z0-9_]*)/{
s/^CAMLprim_int64_[0-9](\([a-z0-9_][a-z0-9_]*\)).*/caml_int64_\1/p
s/$/_native/p
}'
@damiendoligez

This comment has been minimized.

Copy link
Member

commented Nov 14, 2018

On MacOS, gnumake is at version 3.81 and doesn't handle newlines in single-quoted strings correctly, so our best bet is to use the gen_primitives.sh script in the Makefile.

@diml

This comment has been minimized.

Copy link
Member Author

commented Nov 14, 2018

@damiendoligez does the current gen_primitives.sh script works on OSX or does it need to be changed? It contains a newline as well in the sed command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.