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

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

Issue 18539004: ARM Skia NEON patches - 04 - Clean SkFixed / SkLONGLONG (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove SkLONGLONG + use int64_t where there was an existing long long SkFixed implementation Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/core/Sk64.cpp ('k') | tests/MathTest.cpp » ('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 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 "SkCordic.h" 9 #include "SkCordic.h"
10 #include "SkFloatBits.h" 10 #include "SkFloatBits.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 #ifdef SK_DEBUGx 98 #ifdef SK_DEBUGx
99 int32_t tmp = hi >> shift; 99 int32_t tmp = hi >> shift;
100 SkASSERT(tmp == 0 || tmp == -1); 100 SkASSERT(tmp == 0 || tmp == -1);
101 #endif 101 #endif
102 // we want (hi << (32 - shift)) | (lo >> shift) but rounded 102 // we want (hi << (32 - shift)) | (lo >> shift) but rounded
103 int roundBit = (lo >> (shift - 1)) & 1; 103 int roundBit = (lo >> (shift - 1)) & 1;
104 return ((hi << (32 - shift)) | (lo >> shift)) + roundBit; 104 return ((hi << (32 - shift)) | (lo >> shift)) + roundBit;
105 } 105 }
106 } 106 }
107 107
108 SkFixed SkFixedMul_portable(SkFixed a, SkFixed b) {
109 #if 0
110 Sk64 tmp;
111
112 tmp.setMul(a, b);
113 tmp.shiftRight(16);
114 return tmp.fLo;
115 #elif defined(SkLONGLONG)
116 return static_cast<SkFixed>((SkLONGLONG)a * b >> 16);
117 #else
118 int sa = SkExtractSign(a);
119 int sb = SkExtractSign(b);
120 // now make them positive
121 a = SkApplySign(a, sa);
122 b = SkApplySign(b, sb);
123
124 uint32_t ah = a >> 16;
125 uint32_t al = a & 0xFFFF;
126 uint32_t bh = b >> 16;
127 uint32_t bl = b & 0xFFFF;
128
129 uint32_t R = ah * b + al * bh + (al * bl >> 16);
130
131 return SkApplySign(R, sa ^ sb);
132 #endif
133 }
134
135 SkFract SkFractMul_portable(SkFract a, SkFract b) {
136 #if 0
137 Sk64 tmp;
138 tmp.setMul(a, b);
139 return tmp.getFract();
140 #elif defined(SkLONGLONG)
141 return static_cast<SkFract>((SkLONGLONG)a * b >> 30);
142 #else
143 int sa = SkExtractSign(a);
144 int sb = SkExtractSign(b);
145 // now make them positive
146 a = SkApplySign(a, sa);
147 b = SkApplySign(b, sb);
148
149 uint32_t ah = a >> 16;
150 uint32_t al = a & 0xFFFF;
151 uint32_t bh = b >> 16;
152 uint32_t bl = b & 0xFFFF;
153
154 uint32_t A = ah * bh;
155 uint32_t B = ah * bl + al * bh;
156 uint32_t C = al * bl;
157
158 /* [ A ]
159 [ B ]
160 [ C ]
161 */
162 uint32_t Lo = C + (B << 16);
163 uint32_t Hi = A + (B >>16) + (Lo < C);
164
165 SkASSERT((Hi >> 29) == 0); // else overflow
166
167 int32_t R = (Hi << 2) + (Lo >> 30);
168
169 return SkApplySign(R, sa ^ sb);
170 #endif
171 }
172
173 int SkFixedMulCommon(SkFixed a, int b, int bias) { 108 int SkFixedMulCommon(SkFixed a, int b, int bias) {
174 // this function only works if b is 16bits 109 // this function only works if b is 16bits
175 SkASSERT(b == (int16_t)b); 110 SkASSERT(b == (int16_t)b);
176 SkASSERT(b >= 0); 111 SkASSERT(b >= 0);
177 112
178 int sa = SkExtractSign(a); 113 int sa = SkExtractSign(a);
179 a = SkApplySign(a, sa); 114 a = SkApplySign(a, sa);
180 uint32_t ah = a >> 16; 115 uint32_t ah = a >> 16;
181 uint32_t al = a & 0xFFFF; 116 uint32_t al = a & 0xFFFF;
182 uint32_t R = ah * b + ((al * b + bias) >> 16); 117 uint32_t R = ah * b + ((al * b + bias) >> 16);
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } 443 }
509 444
510 /////////////////////////////////////////////////////////////////////////////// 445 ///////////////////////////////////////////////////////////////////////////////
511 446
512 SkFixed SkFixedTan(SkFixed radians) { return SkCordicTan(radians); } 447 SkFixed SkFixedTan(SkFixed radians) { return SkCordicTan(radians); }
513 SkFixed SkFixedASin(SkFixed x) { return SkCordicASin(x); } 448 SkFixed SkFixedASin(SkFixed x) { return SkCordicASin(x); }
514 SkFixed SkFixedACos(SkFixed x) { return SkCordicACos(x); } 449 SkFixed SkFixedACos(SkFixed x) { return SkCordicACos(x); }
515 SkFixed SkFixedATan2(SkFixed y, SkFixed x) { return SkCordicATan2(y, x); } 450 SkFixed SkFixedATan2(SkFixed y, SkFixed x) { return SkCordicATan2(y, x); }
516 SkFixed SkFixedExp(SkFixed x) { return SkCordicExp(x); } 451 SkFixed SkFixedExp(SkFixed x) { return SkCordicExp(x); }
517 SkFixed SkFixedLog(SkFixed x) { return SkCordicLog(x); } 452 SkFixed SkFixedLog(SkFixed x) { return SkCordicLog(x); }
OLDNEW
« no previous file with comments | « src/core/Sk64.cpp ('k') | tests/MathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698