From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 1C4317FD90 for ; Sat, 17 Dec 2016 14:02:01 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=christoph.hoeger@tu-berlin.de; spf=None smtp.mailfrom=christoph.hoeger@tu-berlin.de; spf=None smtp.helo=postmaster@mail.tu-berlin.de Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of christoph.hoeger@tu-berlin.de) identity=pra; client-ip=130.149.7.33; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="christoph.hoeger@tu-berlin.de"; x-sender="christoph.hoeger@tu-berlin.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of christoph.hoeger@tu-berlin.de) identity=mailfrom; client-ip=130.149.7.33; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="christoph.hoeger@tu-berlin.de"; x-sender="christoph.hoeger@tu-berlin.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail.tu-berlin.de) identity=helo; client-ip=130.149.7.33; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="christoph.hoeger@tu-berlin.de"; x-sender="postmaster@mail.tu-berlin.de"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A8zNWVxa0AFKj/K6cs9cLjP3/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZpsW9bnLW6fgltlLVR4KTs6sC0LuN9f+7EjBdqdbZ6TZZL8wKD0dEwe?= =?us-ascii?q?wt3CUeQ+e9QXXhK/DrayFoVO9jb3RCu0+BDE5OBczlbEfTqHDhpRQbGxH4KBYn?= =?us-ascii?q?br+tQt2a3IyL0LW58pjXKxhTiSCmKed5JRCy6AHQrdU+gI14K693xAGf8VVSfO?= =?us-ascii?q?ED7mNyJEmPmA780ecu85N5u3Bbu+gg7NJHSaW8f6M1QrFCJCg7dmo4/snqs1/P?= =?us-ascii?q?QF3ctTMnTmwKn08QUED+5xbgU8Kpvw=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AXAAD0NVVYhyEHlYJcSQYMgwwBAQEBA?= =?us-ascii?q?YF/uTWCCog8PxQBAQEBAQEBAQEBARIBAQEKCwkJHTCCMxiCR4EzAl8NBgIBAYh?= =?us-ascii?q?nBJpBkACCKIs9D4gziWgLLYJdBZkugUKBS4IYgXyVboY0kigfhRIMV4FpcYh3A?= =?us-ascii?q?QEB?= X-IPAS-Result: =?us-ascii?q?A0AXAAD0NVVYhyEHlYJcSQYMgwwBAQEBAYF/uTWCCog8PxQ?= =?us-ascii?q?BAQEBAQEBAQEBARIBAQEKCwkJHTCCMxiCR4EzAl8NBgIBAYhnBJpBkACCKIs9D?= =?us-ascii?q?4gziWgLLYJdBZkugUKBS4IYgXyVboY0kigfhRIMV4FpcYh3AQEB?= X-IronPort-AV: E=Sophos;i="5.33,363,1477954800"; d="asc'?scan'208";a="250506397" Received: from mail.tu-berlin.de ([130.149.7.33]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2016 14:02:00 +0100 X-tubIT-Incoming-IP: 91.66.22.179 Received: from ip5b4216b3.dynamic.kabel-deutschland.de ([91.66.22.179] helo=[192.168.178.42]) by mail.tu-berlin.de (exim-4.84_2/mailfrontend-8) with esmtpa for id 1cIEcg-0005ak-m7; Sat, 17 Dec 2016 14:01:59 +0100 To: caml users From: =?UTF-8?Q?Christoph_H=c3=b6ger?= Organization: =?UTF-8?Q?Technische_Universit=c3=a4t_Berlin?= Message-ID: <7bc766a2-d460-524b-35ca-89609a34b719@tu-berlin.de> Date: Sat, 17 Dec 2016 14:01:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7jQMAU5h6CRL7mhVAumv0EqQlWeKWpP87" X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2016.12.17.124815 X-PMX-Spam: Gauge=IIIIIII, Probability=0%, Report='' Subject: [Caml-list] Closing the performance gap to C This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7jQMAU5h6CRL7mhVAumv0EqQlWeKWpP87 Content-Type: multipart/mixed; boundary="Fs9oaNuoO7cWmhIoIHUAQuCCc82ML9XkM"; protected-headers="v1" From: =?UTF-8?Q?Christoph_H=c3=b6ger?= To: caml users Message-ID: <7bc766a2-d460-524b-35ca-89609a34b719@tu-berlin.de> Subject: Closing the performance gap to C --Fs9oaNuoO7cWmhIoIHUAQuCCc82ML9XkM Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Dear all, find attached two simple runge-kutta iteration schemes. One is written in C, the other in OCaml. I compared the runtime of both and gcc (-O2) produces an executable that is roughly 30% faster (to be more precise: 3.52s vs. 2.63s). That is in itself quite pleasing, I think. I do not understand however, what causes this difference. Admittedly, the generated assembly looks completely different, but both compilers inline all functions and generate one big loop. Ocaml generates a lot more scaffolding, but that is to be expected. There is however an interesting particularity: OCaml generates 6 calls to cos, while gcc only needs 3 (and one direct jump). Surprisingly, there are also calls to cosh, acos and pretty much any other trigonometric function (initialization of constants, maybe?) However, the true culprit seems to be an excess of instructions between the different calls to cos. This is what happens between the first two calls to cos: gcc: jmpq 400530 nop nopw %cs:0x0(%rax,%rax,1) sub $0x38,%rsp movsd %xmm0,0x10(%rsp) movapd %xmm1,%xmm0 movsd %xmm2,0x18(%rsp) movsd %xmm1,0x8(%rsp) callq 400530 ocamlopt: callq 401a60 mulsd (%r12),%xmm0 movsd %xmm0,0x10(%rsp) sub $0x10,%r15 lea 0x25c7b6(%rip),%rax cmp (%rax),%r15 jb 404a8a lea 0x8(%r15),%rax movq $0x4fd,-0x8(%rax) movsd 0x32319(%rip),%xmm1 movapd %xmm1,%xmm2 mulsd %xmm0,%xmm2 addsd 0x0(%r13),%xmm2 movsd %xmm2,(%rax) movapd %xmm1,%xmm0 mulsd (%r12),%xmm0 addsd (%rbx),%xmm0 callq 401a60 Is this caused by some underlying difference in the representation of numeric values (i.e. tagged ints) or is it reasonable to attack this issue as a hobby experiment? thanks for any advice, Christoph --=20 Christoph H=C3=B6ger Technische Universit=C3=A4t Berlin Fakult=C3=A4t IV - Elektrotechnik und Informatik =C3=9Cbersetzerbau und Programmiersprachen Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin Tel.: +49 (30) 314-24890 E-Mail: christoph.hoeger@tu-berlin.de --Fs9oaNuoO7cWmhIoIHUAQuCCc82ML9XkM-- --7jQMAU5h6CRL7mhVAumv0EqQlWeKWpP87 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlhVN0YACgkQhMBO4cVSGS9iKQCgrhS/DU7aAqyjvtwkvcK1jj79 1acAmgLONeye62CVjHm1P468vO8xQxNO =mr/P -----END PGP SIGNATURE----- --7jQMAU5h6CRL7mhVAumv0EqQlWeKWpP87--