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

Side by Side Diff: src/core/SkMath.cpp

Issue 1925913002: remove (now unused) SkDivBits (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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 | « include/core/SkMath.h ('k') | no next file » | 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 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkMathPriv.h" 8 #include "SkMathPriv.h"
9 #include "SkFixed.h" 9 #include "SkFixed.h"
10 #include "SkFloatBits.h" 10 #include "SkFloatBits.h"
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 if (x & 0x2) { 40 if (x & 0x2) {
41 sub_shift(zeros, x, 1); 41 sub_shift(zeros, x, 1);
42 } 42 }
43 43
44 return zeros; 44 return zeros;
45 } 45 }
46 46
47 /////////////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////////////
48 48
49 #define DIVBITS_ITER(n) \
50 case n: \
51 if ((numer = (numer << 1) - denom) >= 0) \
52 result |= 1 << (n - 1); else numer += denom
53
54 int32_t SkDivBits(int32_t numer, int32_t denom, int shift_bias) {
55 SkASSERT(denom != 0);
56 if (numer == 0) {
57 return 0;
58 }
59
60 // make numer and denom positive, and sign hold the resulting sign
61 int32_t sign = SkExtractSign(numer ^ denom);
62 numer = SkAbs32(numer);
63 denom = SkAbs32(denom);
64
65 int nbits = SkCLZ(numer) - 1;
66 int dbits = SkCLZ(denom) - 1;
67 int bits = shift_bias - nbits + dbits;
68
69 if (bits < 0) { // answer will underflow
70 return 0;
71 }
72 if (bits > 31) { // answer will overflow
73 return SkApplySign(SK_MaxS32, sign);
74 }
75
76 denom <<= dbits;
77 numer <<= nbits;
78
79 SkFixed result = 0;
80
81 // do the first one
82 if ((numer -= denom) >= 0) {
83 result = 1;
84 } else {
85 numer += denom;
86 }
87
88 // Now fall into our switch statement if there are more bits to compute
89 if (bits > 0) {
90 // make room for the rest of the answer bits
91 result <<= bits;
92 switch (bits) {
93 DIVBITS_ITER(31); DIVBITS_ITER(30); DIVBITS_ITER(29);
94 DIVBITS_ITER(28); DIVBITS_ITER(27); DIVBITS_ITER(26);
95 DIVBITS_ITER(25); DIVBITS_ITER(24); DIVBITS_ITER(23);
96 DIVBITS_ITER(22); DIVBITS_ITER(21); DIVBITS_ITER(20);
97 DIVBITS_ITER(19); DIVBITS_ITER(18); DIVBITS_ITER(17);
98 DIVBITS_ITER(16); DIVBITS_ITER(15); DIVBITS_ITER(14);
99 DIVBITS_ITER(13); DIVBITS_ITER(12); DIVBITS_ITER(11);
100 DIVBITS_ITER(10); DIVBITS_ITER( 9); DIVBITS_ITER( 8);
101 DIVBITS_ITER( 7); DIVBITS_ITER( 6); DIVBITS_ITER( 5);
102 DIVBITS_ITER( 4); DIVBITS_ITER( 3); DIVBITS_ITER( 2);
103 // we merge these last two together, makes GCC make better ARM
104 default:
105 DIVBITS_ITER( 1);
106 }
107 }
108
109 if (result < 0) {
110 result = SK_MaxS32;
111 }
112 return SkApplySign(result, sign);
113 }
114
115 /* www.worldserver.com/turk/computergraphics/FixedSqrt.pdf 49 /* www.worldserver.com/turk/computergraphics/FixedSqrt.pdf
116 */ 50 */
117 int32_t SkSqrtBits(int32_t x, int count) { 51 int32_t SkSqrtBits(int32_t x, int count) {
118 SkASSERT(x >= 0 && count > 0 && (unsigned)count <= 30); 52 SkASSERT(x >= 0 && count > 0 && (unsigned)count <= 30);
119 53
120 uint32_t root = 0; 54 uint32_t root = 0;
121 uint32_t remHi = 0; 55 uint32_t remHi = 0;
122 uint32_t remLo = x; 56 uint32_t remLo = x;
123 57
124 do { 58 do {
(...skipping 22 matching lines...) Expand all
147 if (SkScalarNearlyZero(*cosValue)) { 81 if (SkScalarNearlyZero(*cosValue)) {
148 *cosValue = 0; 82 *cosValue = 0;
149 } 83 }
150 } 84 }
151 85
152 if (SkScalarNearlyZero(sinValue)) { 86 if (SkScalarNearlyZero(sinValue)) {
153 sinValue = 0; 87 sinValue = 0;
154 } 88 }
155 return sinValue; 89 return sinValue;
156 } 90 }
OLDNEW
« no previous file with comments | « include/core/SkMath.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698