unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
blob 9609c2588b6691efc62a96db72c073d81013ae09 3584 bytes (raw)
name: packages/patches/abseil-cpp-20200923.3-duration-test.patch 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 
This patch is taken from upstream and helps the test pass on all architectures.

The adjustment to absl/numeric/internal/bits.h was removed since the file
didn't appear in the git checkout.

From b0735979d778a768caee207f01f327535cbd2140 Mon Sep 17 00:00:00 2001
From: Abseil Team <absl-team@google.com>
Date: Tue, 2 Mar 2021 14:28:07 -0800
Subject: [PATCH] Export of internal Abseil changes

--
a74bdb72c3a6983e08a805938dd0e20e97d55bba by Abseil Team <absl-team@google.com>:

Fix typo: calcualte -> calculate

PiperOrigin-RevId: 360515509

--
3ddf8ac194e81a13e9de095e59dd061c1beacfe3 by Benjamin Barenblat <bbaren@google.com>:

Make tests tolerant of FMA contraction

Weaken Duration.ToDoubleSecondsCheckEdgeCases and
Duration.ToDoubleSecondsCheckRandom to make them less sensitive to fused
multiply/add contraction.

PiperOrigin-RevId: 360297653
GitOrigin-RevId: a74bdb72c3a6983e08a805938dd0e20e97d55bba
Change-Id: I0c55383bc13040ea77511c4130d142368103dc57
---
 absl/numeric/internal/bits.h |  2 +-
 absl/time/duration_test.cc   | 18 +++++++++++-------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/absl/time/duration_test.cc b/absl/time/duration_test.cc
index 4d85a2c4f45..fb28fa987f6 100644
--- a/absl/time/duration_test.cc
+++ b/absl/time/duration_test.cc
@@ -1369,10 +1369,13 @@ TEST(Duration, SmallConversions) {
   EXPECT_THAT(ToTimeval(absl::Nanoseconds(2000)), TimevalMatcher(tv));
 }
 
-void VerifySameAsMul(double time_as_seconds, int* const misses) {
+void VerifyApproxSameAsMul(double time_as_seconds, int* const misses) {
   auto direct_seconds = absl::Seconds(time_as_seconds);
   auto mul_by_one_second = time_as_seconds * absl::Seconds(1);
-  if (direct_seconds != mul_by_one_second) {
+  // These are expected to differ by up to one tick due to fused multiply/add
+  // contraction.
+  if (absl::AbsDuration(direct_seconds - mul_by_one_second) >
+      absl::time_internal::MakeDuration(0, 1u)) {
     if (*misses > 10) return;
     ASSERT_LE(++(*misses), 10) << "Too many errors, not reporting more.";
     EXPECT_EQ(direct_seconds, mul_by_one_second)
@@ -1384,7 +1387,8 @@ void VerifySameAsMul(double time_as_seconds, int* const misses) {
 // For a variety of interesting durations, we find the exact point
 // where one double converts to that duration, and the very next double
 // converts to the next duration.  For both of those points, verify that
-// Seconds(point) returns the same duration as point * Seconds(1.0)
+// Seconds(point) returns a duration near point * Seconds(1.0). (They may
+// not be exactly equal due to fused multiply/add contraction.)
 TEST(Duration, ToDoubleSecondsCheckEdgeCases) {
   constexpr uint32_t kTicksPerSecond = absl::time_internal::kTicksPerSecond;
   constexpr auto duration_tick = absl::time_internal::MakeDuration(0, 1u);
@@ -1423,8 +1427,8 @@ TEST(Duration, ToDoubleSecondsCheckEdgeCases) {
         }
         // Now low_edge is the highest double that converts to Duration d,
         // and high_edge is the lowest double that converts to Duration after_d.
-        VerifySameAsMul(low_edge, &misses);
-        VerifySameAsMul(high_edge, &misses);
+        VerifyApproxSameAsMul(low_edge, &misses);
+        VerifyApproxSameAsMul(high_edge, &misses);
       }
     }
   }
@@ -1444,8 +1448,8 @@ TEST(Duration, ToDoubleSecondsCheckRandom) {
   int misses = 0;
   for (int i = 0; i < 1000000; ++i) {
     double d = std::exp(uniform(gen));
-    VerifySameAsMul(d, &misses);
-    VerifySameAsMul(-d, &misses);
+    VerifyApproxSameAsMul(d, &misses);
+    VerifyApproxSameAsMul(-d, &misses);
   }
 }
 

debug log:

solving 9609c2588b6691efc62a96db72c073d81013ae09 ...
found 9609c2588b6691efc62a96db72c073d81013ae09 in https://git.savannah.gnu.org/cgit/guix.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).