Author: post
Date: 2011-08-31 19:20:30 +0200 (Wed, 31 Aug 2011)
New Revision: 373
Modified:
RawSpeed/Common.h
RawSpeed/OrfDecoder.cpp
Log:
Eliminate a few branches in ORF Decoder. Should give slightly faster decoding.
Modified: RawSpeed/Common.h
===================================================================
--- RawSpeed/Common.h 2011-07-10 10:00:05 UTC (rev 372)
+++ RawSpeed/Common.h 2011-08-31 17:20:30 UTC (rev 373)
@@ -121,6 +121,9 @@
}
inline uint32 clampbits(int x, uint32 n) { uint32 _y_temp; if( (_y_temp=x>>n)
) x = ~_y_temp >> (32-n); return x;}
+/* This is faster - at least when compiled on visual studio 32 bits */
+inline int other_abs(int x) { int const mask = x >> 31; return (x + mask) ^
mask;}
+
/* Remove all spaces at the end of a string */
inline void TrimSpaces(string& str) {
Modified: RawSpeed/OrfDecoder.cpp
===================================================================
--- RawSpeed/OrfDecoder.cpp 2011-07-10 10:00:05 UTC (rev 372)
+++ RawSpeed/OrfDecoder.cpp 2011-08-31 17:20:30 UTC (rev 373)
@@ -128,6 +128,8 @@
memset(acarry0, 0, sizeof acarry0);
memset(acarry1, 0, sizeof acarry1);
ushort16* dest = (ushort16*) & data[y*pitch];
+ bool y_border = y < 2;
+ bool border = TRUE;
for (uint32 x = 0; x < w; x++) {
bits.checkPos();
bits.fill();
@@ -149,10 +151,10 @@
acarry0[1] = (diff * 3 + acarry0[1]) >> 5;
acarry0[2] = acarry0[0] > 16 ? 0 : acarry0[2] + 1;
- if (y < 2 || x < 2) {
- if (y < 2 && x < 2)
+ if (border) {
+ if (y_border && x < 2)
pred = 0;
- else if (y < 2)
+ else if (y_border)
pred = left0;
else {
pred = dest[-pitch+((int)x)];
@@ -166,13 +168,13 @@
int leftMinusNw = left0 - nw0;
int upMinusNw = up - nw0;
// Check if sign is different, and one is not zero
- if (((leftMinusNw) ^ (upMinusNw)) < 0 && (upMinusNw * leftMinusNw)) {
- if (abs(leftMinusNw) > 32 || abs(upMinusNw) > 32)
+ if (leftMinusNw * upMinusNw < 0) {
+ if (other_abs(leftMinusNw) > 32 || other_abs(upMinusNw) > 32)
pred = left0 + upMinusNw;
else
pred = (left0 + up) >> 1;
} else
- pred = abs(leftMinusNw) > abs(upMinusNw) ? left0 : up;
+ pred = other_abs(leftMinusNw) > other_abs(upMinusNw) ? left0 : up;
dest[x] = pred + ((diff << 2) | low);
// Set predictors
@@ -201,10 +203,10 @@
acarry1[1] = (diff * 3 + acarry1[1]) >> 5;
acarry1[2] = acarry1[0] > 16 ? 0 : acarry1[2] + 1;
- if (y < 2 || x < 2) {
- if (y < 2 && x < 2)
+ if (border) {
+ if (y_border && x < 2)
pred = 0;
- else if (y < 2)
+ else if (y_border)
pred = left1;
else {
pred = dest[-pitch+((int)x)];
@@ -219,13 +221,13 @@
int upMinusNw = up - nw1;
// Check if sign is different, and one is not zero
- if (((leftMinusNw) ^ (upMinusNw)) < 0 && (upMinusNw * leftMinusNw)) {
- if (abs(leftMinusNw) > 32 || abs(upMinusNw) > 32)
+ if (leftMinusNw * upMinusNw < 0) {
+ if (other_abs(leftMinusNw) > 32 || other_abs(upMinusNw) > 32)
pred = left1 + upMinusNw;
else
pred = (left1 + up) >> 1;
} else
- pred = abs(leftMinusNw) > abs(upMinusNw) ? left1 : up;
+ pred = other_abs(leftMinusNw) > other_abs(upMinusNw) ? left1 : up;
dest[x] = pred + ((diff << 2) | low);
@@ -233,6 +235,7 @@
left1 = dest[x];
nw1 = up;
}
+ border = y_border;
}
}
}
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit