summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/jpeg.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/apps/plugins/jpeg.c b/apps/plugins/jpeg.c
index 5ecd394..9a32a8c 100644
--- a/apps/plugins/jpeg.c
+++ b/apps/plugins/jpeg.c
@@ -200,12 +200,11 @@ INLINE unsigned range_limit(int value)
);
return value;
#elif defined(CPU_ARM)
- asm (
- "adds %[v], %[v], #128\n" /* value += 128 */
- "movmi %[v], #0 \n" /* clip to 0 if negative result */
- "cmp %[v], #255 \n" /* did we exceed 255? */
- "movgt %[v], #255 \n" /* yes, clip to limit */
- :
+ asm ( /* Note: Uses knowledge that only the low byte of the result is used */
+ "add %[v], %[v], #128 \n" /* value += 128 */
+ "cmp %[v], #255 \n" /* out of range 0..255? */
+ "mvnhi %[v], %[v], asr #31 \n" /* yes: set all bits to ~(sign_bit) */
+ : /* outputs */
[v]"+r"(value)
);
return value;