5xxx functions from nbdkit.
authorRichard W.M. Jones <rjones@redhat.com>
Wed, 14 Oct 2020 14:55:41 +0000 (15:55 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Wed, 14 Oct 2020 14:55:49 +0000 (15:55 +0100)
2020-frama-c/5000-power-of-2.html [new file with mode: 0644]
2020-frama-c/5100-power-of-2.html [new file with mode: 0644]
2020-frama-c/5200-timeval.html [new file with mode: 0644]
2020-frama-c/5300-timeval.html [new file with mode: 0644]
2020-frama-c/5400-timeval.html [new file with mode: 0644]

diff --git a/2020-frama-c/5000-power-of-2.html b/2020-frama-c/5000-power-of-2.html
new file mode 100644 (file)
index 0000000..ccc3759
--- /dev/null
@@ -0,0 +1,18 @@
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+<link rel="stylesheet" href="style.css" type="text/css"/>
+<script src="code.js" type="text/javascript"></script>
+
+<h1>nbdkit is_power_of_2</h1>
+
+<pre class="code">
+  /* Returns true if v is a power of 2.
+   *
+   * Uses the algorithm described at
+   * http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
+   */
+  static inline bool
+  is_power_of_2 (unsigned long v)
+  {
+    return v && ((v & (v - 1)) == 0);
+  }
+</pre>
diff --git a/2020-frama-c/5100-power-of-2.html b/2020-frama-c/5100-power-of-2.html
new file mode 100644 (file)
index 0000000..c9c04c7
--- /dev/null
@@ -0,0 +1,20 @@
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+<link rel="stylesheet" href="style.css" type="text/css"/>
+<script src="code.js" type="text/javascript"></script>
+
+<h1>nbdkit is_power_of_2</h1>
+
+<pre class="code">
+  /*@
+    predicate positive_power_of_2 (integer i) =
+      i > 0 &&
+      (i == 1 || ((i & 1) == 0 && positive_power_of_2 (i >> 1)));
+
+    lemma positive_power_of_2 (1);
+    lemma positive_power_of_2 (2);
+    lemma positive_power_of_2 (4);
+    lemma !positive_power_of_2 (7);
+   */
+</pre>
+
+<a href="https://stackoverflow.com/questions/64268418/how-do-i-write-an-is-power-of-2-predicate-in-acsl">https://stackoverflow.com/questions/64268418/how-do-i-write-an-is-power-of-2-predicate-in-acsl</a>
diff --git a/2020-frama-c/5200-timeval.html b/2020-frama-c/5200-timeval.html
new file mode 100644 (file)
index 0000000..e303af9
--- /dev/null
@@ -0,0 +1,18 @@
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+<link rel="stylesheet" href="style.css" type="text/css"/>
+<script src="code.js" type="text/javascript"></script>
+
+<h1>nbdkit tvdiff_usec</h1>
+
+<pre class="code">
+  /* Return the number of µs (microseconds) in y - x. */
+  static inline int64_t
+  tvdiff_usec (const struct timeval *x, const struct timeval *y)
+  {
+    int64_t usec;
+
+    usec = (y->tv_sec - x->tv_sec) * 1000000;
+    usec += y->tv_usec - x->tv_usec;
+    return usec;
+  }
+</pre>
diff --git a/2020-frama-c/5300-timeval.html b/2020-frama-c/5300-timeval.html
new file mode 100644 (file)
index 0000000..0548d43
--- /dev/null
@@ -0,0 +1,30 @@
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+<link rel="stylesheet" href="style.css" type="text/css"/>
+<script src="code.js" type="text/javascript"></script>
+
+<h1>nbdkit tvdiff_usec</h1>
+
+<pre class="code">
+  <span class="comment">/*@
+    predicate valid_timeval (struct timeval tv) =
+      tv.tv_sec >= 0 && tv.tv_usec >= 0 && tv.tv_usec < 1000000;
+    logic integer tv_to_microseconds (struct timeval tv) =
+      tv.tv_sec * 1000000 + tv.tv_usec;
+   */</span>
+
+  /* Return the number of µs (microseconds) in y - x. */
+  <span class="comment">/*@
+    requires \valid_read (x) && \valid_read (y);
+    requires valid_timeval (*x) && valid_timeval (*y);
+    ensures \result == tv_to_microseconds (*y) - tv_to_microseconds (*x);
+   */</span>
+  static inline int64_t
+  tvdiff_usec (const struct timeval *x, const struct timeval *y)
+  {
+    int64_t usec;
+
+    usec = (y->tv_sec - x->tv_sec) * 1000000;
+    usec += y->tv_usec - x->tv_usec;
+    return usec;
+  }
+</pre>
diff --git a/2020-frama-c/5400-timeval.html b/2020-frama-c/5400-timeval.html
new file mode 100644 (file)
index 0000000..296d281
--- /dev/null
@@ -0,0 +1,30 @@
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+<link rel="stylesheet" href="style.css" type="text/css"/>
+<script src="code.js" type="text/javascript"></script>
+
+<h1>nbdkit tvdiff_usec</h1>
+
+<pre class="code">
+  /*@
+    requires \valid_read (x) && \valid_read (y);
+    requires valid_timeval (*x) && valid_timeval (*y);
+    requires \valid (r);
+    assigns *r;
+    behavior success:
+      ensures \result == 0;
+      ensures \let diff = tv_to_microseconds (*y) - tv_to_microseconds (*x);
+              INT64_MIN <= diff <= INT64_MAX &&
+              *r == diff;
+    behavior failure:
+      ensures \result == -1;
+      ensures *r == 0;
+      ensures \let diff = tv_to_microseconds (*y) - tv_to_microseconds (*x);
+              !(INT64_MIN <= diff <= INT64_MAX);
+    complete behaviors;
+    disjoint behaviors;
+   */
+  static inline int
+  tvdiff_usec (const struct timeval *x, const struct timeval *y,
+               int64_t *r)
+  ...
+</pre>