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

Side by Side Diff: Source/wtf/SaturatedArithmeticTest.cpp

Issue 346913004: Some inline ARM assembly for saturated arithmetic, a small speed-up for (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Implicit casting removed 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 unified diff | Download patch
« no previous file with comments | « Source/wtf/SaturatedArithmetic.h ('k') | Source/wtf/asm/SaturatedArithmeticARM.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, Google Inc. All rights reserved. 2 * Copyright (c) 2012, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 EXPECT_EQ(INT_MIN, saturatedSubtraction(INT_MIN, 0)); 97 EXPECT_EQ(INT_MIN, saturatedSubtraction(INT_MIN, 0));
98 EXPECT_EQ(INT_MIN + 1, saturatedSubtraction(INT_MIN + 1, 0)); 98 EXPECT_EQ(INT_MIN + 1, saturatedSubtraction(INT_MIN + 1, 0));
99 EXPECT_EQ(INT_MIN, saturatedSubtraction(INT_MIN + 1, 1)); 99 EXPECT_EQ(INT_MIN, saturatedSubtraction(INT_MIN + 1, 1));
100 EXPECT_EQ(INT_MIN, saturatedSubtraction(INT_MIN + 1, 2)); 100 EXPECT_EQ(INT_MIN, saturatedSubtraction(INT_MIN + 1, 2));
101 101
102 EXPECT_EQ(0, saturatedSubtraction(INT_MIN, INT_MIN)); 102 EXPECT_EQ(0, saturatedSubtraction(INT_MIN, INT_MIN));
103 EXPECT_EQ(0, saturatedSubtraction(INT_MAX, INT_MAX)); 103 EXPECT_EQ(0, saturatedSubtraction(INT_MAX, INT_MAX));
104 EXPECT_EQ(INT_MAX, saturatedSubtraction(INT_MAX, INT_MIN)); 104 EXPECT_EQ(INT_MAX, saturatedSubtraction(INT_MAX, INT_MIN));
105 } 105 }
106 106
107 TEST(SaturatedArithmeticTest, SetSigned)
108 {
109 const int kFractionBits = 6;
110 const int intMaxForLayoutUnit = INT_MAX >> kFractionBits;
111 const int intMinForLayoutUnit = INT_MIN >> kFractionBits;
112
113 EXPECT_EQ(0, saturatedSet(0, kFractionBits));
114
115 // Internally the max number we can represent (without saturating)
116 // is all the (non-sign) bits set except for the bottom n fraction bits
117 const int maxInternalRepresentation = INT_MAX ^ ((1 << kFractionBits)-1);
118 EXPECT_EQ(maxInternalRepresentation,
119 saturatedSet(intMaxForLayoutUnit, kFractionBits));
120
121 EXPECT_EQ(getMaxSaturatedSetResultForTesting(kFractionBits),
122 saturatedSet(intMaxForLayoutUnit + 100, kFractionBits));
123
124 EXPECT_EQ((intMaxForLayoutUnit - 100) << kFractionBits,
125 saturatedSet(intMaxForLayoutUnit - 100, kFractionBits));
126
127 EXPECT_EQ(getMinSaturatedSetResultForTesting(kFractionBits),
128 saturatedSet(intMinForLayoutUnit, kFractionBits));
129
130 EXPECT_EQ(getMinSaturatedSetResultForTesting(kFractionBits),
131 saturatedSet(intMinForLayoutUnit - 100, kFractionBits));
132
133 EXPECT_EQ((intMinForLayoutUnit + 100) << kFractionBits,
134 saturatedSet(intMinForLayoutUnit + 100, kFractionBits));
135 }
136
137 TEST(SaturatedArithmeticTest, SetUnsigned)
138 {
139 const int kFractionBits = 6;
140 const int intMaxForLayoutUnit = INT_MAX >> kFractionBits;
141
142 EXPECT_EQ(0, saturatedSet((unsigned)0, kFractionBits));
143
144 EXPECT_EQ(getMaxSaturatedSetResultForTesting(kFractionBits),
145 saturatedSet((unsigned)intMaxForLayoutUnit, kFractionBits));
146
147 const unsigned kOverflowed = intMaxForLayoutUnit + 100;
148 EXPECT_EQ(getMaxSaturatedSetResultForTesting(kFractionBits),
149 saturatedSet(kOverflowed, kFractionBits));
150
151 const unsigned kNotOverflowed = intMaxForLayoutUnit - 100;
152 EXPECT_EQ((intMaxForLayoutUnit - 100) << kFractionBits,
153 saturatedSet(kNotOverflowed, kFractionBits));
154 }
155
156
107 } // namespace 157 } // namespace
OLDNEW
« no previous file with comments | « Source/wtf/SaturatedArithmetic.h ('k') | Source/wtf/asm/SaturatedArithmeticARM.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698