Title: [282852] trunk/Source/WTF
Revision
282852
Author
[email protected]
Date
2021-09-21 17:11:35 -0700 (Tue, 21 Sep 2021)

Log Message

[WTF] Use Int128 in MediaTime
https://bugs.webkit.org/show_bug.cgi?id=230575

Reviewed by Eric Carlson.

Previously, __int128_t exists only in 64bit clang and GCC environments. But now
we always have Int128. Int128 is __int128_t in 64bit clang and GCC, and Int128 library
implementation in the other environments. So we always use Int128 code in MediaTime.

* wtf/MediaTime.cpp:
(WTF::MediaTime::setTimeScale):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (282851 => 282852)


--- trunk/Source/WTF/ChangeLog	2021-09-22 00:04:34 UTC (rev 282851)
+++ trunk/Source/WTF/ChangeLog	2021-09-22 00:11:35 UTC (rev 282852)
@@ -1,3 +1,17 @@
+2021-09-21  Yusuke Suzuki  <[email protected]>
+
+        [WTF] Use Int128 in MediaTime
+        https://bugs.webkit.org/show_bug.cgi?id=230575
+
+        Reviewed by Eric Carlson.
+
+        Previously, __int128_t exists only in 64bit clang and GCC environments. But now
+        we always have Int128. Int128 is __int128_t in 64bit clang and GCC, and Int128 library
+        implementation in the other environments. So we always use Int128 code in MediaTime.
+
+        * wtf/MediaTime.cpp:
+        (WTF::MediaTime::setTimeScale):
+
 2021-09-21  Chris Dumez  <[email protected]>
 
         Drop makeRefPtr() and use RefPtr { } directly instead

Modified: trunk/Source/WTF/wtf/MediaTime.cpp (282851 => 282852)


--- trunk/Source/WTF/wtf/MediaTime.cpp	2021-09-22 00:04:34 UTC (rev 282851)
+++ trunk/Source/WTF/wtf/MediaTime.cpp	2021-09-22 00:11:35 UTC (rev 282852)
@@ -33,6 +33,7 @@
 #include <cstdlib>
 #include <wtf/Assertions.h>
 #include <wtf/CheckedArithmetic.h>
+#include <wtf/Int128.h>
 #include <wtf/JSONValues.h>
 #include <wtf/MathExtras.h>
 #include <wtf/PrintStream.h>
@@ -488,9 +489,8 @@
 
     timeScale = std::min(MaximumTimeScale, timeScale);
 
-#if HAVE(INT128_T)
-    __int128_t newValue = static_cast<__int128_t>(m_timeValue) * timeScale;
-    int64_t remainder = newValue % m_timeScale;
+    Int128 newValue = static_cast<Int128>(m_timeValue) * timeScale;
+    int64_t remainder = static_cast<int64_t>(newValue % m_timeScale);
     newValue = newValue / m_timeScale;
 
     if (newValue < std::numeric_limits<int64_t>::min()) {
@@ -502,19 +502,8 @@
         *this = positiveInfiniteTime();
         return;
     }
-#else
-    int64_t newValue = m_timeValue / m_timeScale;
-    int64_t partialRemainder = (m_timeValue % m_timeScale) * timeScale;
-    int64_t remainder = partialRemainder % m_timeScale;
 
-    if (!safeMultiply<int64_t>(newValue, static_cast<int64_t>(timeScale), newValue)
-        || !safeAdd(newValue, partialRemainder / m_timeScale, newValue)) {
-        *this = newValue < 0 ? negativeInfiniteTime() : positiveInfiniteTime();
-        return;
-    }
-#endif
-
-    m_timeValue = newValue;
+    m_timeValue = static_cast<int64_t>(newValue);
     std::swap(m_timeScale, timeScale);
 
     if (!remainder)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to