Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Unified Diff: Source/wtf/asm/SaturatedArithmeticARM.h

Issue 378253003: Saturated arithmetic changed to use templates to fix build-issues (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixing up code layout issues Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« Source/platform/LayoutUnit.h ('K') | « Source/wtf/SaturatedArithmeticTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/asm/SaturatedArithmeticARM.h
diff --git a/Source/wtf/asm/SaturatedArithmeticARM.h b/Source/wtf/asm/SaturatedArithmeticARM.h
index 5527cacf9b2a3f47988c7963d2d2101cc8353b9e..9911b1eac14ca8ff0bb0253c0dbcd68e81541cf5 100644
--- a/Source/wtf/asm/SaturatedArithmeticARM.h
+++ b/Source/wtf/asm/SaturatedArithmeticARM.h
@@ -33,71 +33,49 @@ ALWAYS_INLINE int32_t saturatedSubtraction(int32_t a, int32_t b)
return result;
}
-inline int getMaxSaturatedSetResultForTesting(int FractionalShift)
+inline int getMaxSaturatedSetResultForTesting(int fractionalShift)
{
// For ARM Asm version the set function maxes out to the biggest
// possible integer part with the fractional part zero'd out.
// e.g. 0x7fffffc0.
- return std::numeric_limits<int>::max() & ~((1 << FractionalShift)-1);
+ return std::numeric_limits<int>::max() & ~((1 << fractionalShift)-1);
}
-inline int getMinSaturatedSetResultForTesting(int FractionalShift)
+inline int getMinSaturatedSetResultForTesting(int fractionalShift)
{
return std::numeric_limits<int>::min();
}
-ALWAYS_INLINE int saturatedSet(int value, int FractionalShift)
+template<size_t saturate, size_t fractionalShift>
+ALWAYS_INLINE int saturatedSetSigned(int value)
{
- // Figure out how many bits are left for storing the integer part of
- // the fixed point number, and saturate our input to that
- const int saturate = 32 - FractionalShift;
-
int result;
-
- // The following ARM code will Saturate the passed value to the number of
- // bits used for the whole part of the fixed point representation, then
- // shift it up into place. This will result in the low <FractionShift> bits
- // all being 0's. When the value saturates this gives a different result
- // to from the C++ case; in the C++ code a saturated value has all the low
- // bits set to 1 (for a +ve number at least). This cannot be done rapidly
- // in ARM ... we live with the difference, for the sake of speed.
-
+ // To allow all compilers to correctly build this asm we need to use
+ // template specialization to ensure that the "n" parameters are
+ // compile-time constant values.
asm("ssat %[output],%[saturate],%[value]\n\t"
"lsl %[output],%[shift]"
: [output] "=r" (result)
: [value] "r" (value),
[saturate] "n" (saturate),
- [shift] "n" (FractionalShift));
+ [shift] "n" (fractionalShift));
return result;
}
-
-ALWAYS_INLINE int saturatedSet(unsigned value, int FractionalShift)
+template<size_t saturate, size_t fractionalShift>
+ALWAYS_INLINE int saturatedSetUnsigned(unsigned value)
{
- // Here we are being passed an unsigned value to saturate,
- // even though the result is returned as a signed integer. The ARM
- // instruction for unsigned saturation therefore needs to be given one
- // less bit (i.e. the sign bit) for the saturation to work correctly; hence
- // the '31' below.
- const int saturate = 31 - FractionalShift;
-
- // The following ARM code will Saturate the passed value to the number of
- // bits used for the whole part of the fixed point representation, then
- // shift it up into place. This will result in the low <FractionShift> bits
- // all being 0's. When the value saturates this gives a different result
- // to from the C++ case; in the C++ code a saturated value has all the low
- // bits set to 1. This cannot be done rapidly in ARM, so we live with the
- // difference, for the sake of speed.
-
int result;
-
+ // To allow all compilers to correctly build this asm we need to use
+ // template specialization to ensure that the "n" parameters are
+ // compile-time constant values.
asm("usat %[output],%[saturate],%[value]\n\t"
"lsl %[output],%[shift]"
: [output] "=r" (result)
: [value] "r" (value),
[saturate] "n" (saturate),
- [shift] "n" (FractionalShift));
+ [shift] "n" (fractionalShift));
return result;
}
« Source/platform/LayoutUnit.h ('K') | « Source/wtf/SaturatedArithmeticTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698