Fix leadz

This commit is contained in:
Anthony Scemama 2023-04-20 10:55:32 +02:00
parent ed374af81f
commit 3c77e8267d
5 changed files with 274 additions and 274 deletions

View File

@ -10,14 +10,14 @@ Requirements
* BLAS/LAPACK : Linear algebra
* LaCaml : LAPACK OCaml interface
* gmp : GNU Multiple Precision arithmetic library
* Zarith : Arbitrary-precision integers
* GetOpt : Parsing of command-line
* gmp : GNU Multiple Precision arithmetic library
* odoc-ltxhtml : https://github.com/akabe/odoc-ltxhtml
* Alcotest : Lightweight testing framework
* odoc-ltxhtml : https://github.com/akabe/odoc-ltxhtml
```bash
opam install dune lacaml getopt alcotest zarith
opam install dune lacaml getopt alcotest zarith camlp-streams
```
To use the Intel MKL library:

View File

@ -73,12 +73,12 @@ CAMLprim value popcnt_bytecode(value i) {
/* [[file:~/QCaml/common/util.org::*Trailz][Trailz:1]] */
CAMLprim int32_t trailz(int64_t i) {
return __builtin_ctzll (i);
return i == 0L ? 64 : __builtin_ctzll (i);
}
CAMLprim value trailz_bytecode(value i) {
return caml_copy_int32(__builtin_ctzll (Int64_val(i)));
return caml_copy_int32(i == 0L ? 64 : __builtin_ctzll (Int64_val(i)));
}
/* Trailz:1 ends here */
@ -87,11 +87,11 @@ CAMLprim value trailz_bytecode(value i) {
/* [[file:~/QCaml/common/util.org::*Leadz][Leadz:1]] */
CAMLprim int32_t leadz(int64_t i) {
return __builtin_clzll(i);
return i == 0L ? 64 : __builtin_clzll(i);
}
CAMLprim value leadz_bytecode(value i) {
return caml_copy_int32(__builtin_clzll (Int64_val(i)));
return caml_copy_int32(i == 0L ? 64 : __builtin_clzll (Int64_val(i)));
}
/* Leadz:1 ends here */

View File

@ -134,12 +134,12 @@ let popcnt i = (popcnt [@inlined] ) i |> Int32.to_int
#+begin_src c :tangle (eval c) :exports none
CAMLprim int32_t trailz(int64_t i) {
return __builtin_ctzll (i);
return i == 0L ? 64 : __builtin_ctzll (i);
}
CAMLprim value trailz_bytecode(value i) {
return caml_copy_int32(__builtin_ctzll (Int64_val(i)));
return caml_copy_int32(i == 0L ? 64 : __builtin_ctzll (Int64_val(i)));
}
#+end_src
@ -158,12 +158,12 @@ let trailz i = trailz i |> Int32.to_int
#+begin_src c :tangle (eval c) :exports none
CAMLprim int32_t leadz(int64_t i) {
return __builtin_clzll(i);
return i == 0L ? 64 : __builtin_clzll(i);
}
CAMLprim value leadz_bytecode(value i) {
return caml_copy_int32(__builtin_clzll (Int64_val(i)));
return caml_copy_int32(i == 0L ? 64 : __builtin_clzll (Int64_val(i)));
}
#+end_src

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2022-12-13 Tue 10:55 -->
<!-- 2023-04-20 Thu 10:54 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Top-level</title>
@ -250,18 +250,18 @@ org_html_manager.setup(); // activate after the parameters are set
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org4f42024">1. Summary</a></li>
<li><a href="#orgd03da44">1. Summary</a></li>
</ul>
</div>
</div>
<div id="outline-container-org4f42024" class="outline-2">
<h2 id="org4f42024"><span class="section-number-2">1</span> Summary</h2>
<div id="outline-container-orgd03da44" class="outline-2">
<h2 id="orgd03da44"><span class="section-number-2">1</span> Summary</h2>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: Anthony Scemama</p>
<p class="date">Created: 2022-12-13 Tue 10:55</p>
<p class="date">Created: 2023-04-20 Thu 10:54</p>
<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>