summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2015-07-31 15:05:10 -0700
committerMatt Turner <mattst88@gmail.com>2015-08-06 15:32:15 -0700
commit1057ee60e226f9c07b73cb340bae167a5a65e8b0 (patch)
treed6ff1c060bbc2c4a29e568452e693c118aea6f9e
parentbe70171bbce9bda1ea1e5effdde7194d5a957064 (diff)
mesa: Optimize (UN)CLAMPED_FLOAT_TO_USHORT macros.dead/lround
-rw-r--r--src/mesa/main/macros.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h
index d03f9e12ea0..f40a85f6d0c 100644
--- a/src/mesa/main/macros.h
+++ b/src/mesa/main/macros.h
@@ -131,10 +131,32 @@ extern GLfloat _mesa_ubyte_to_float_color_tab[256];
#define SHORT_TO_USHORT(s) ((s) < 0 ? 0 : ((GLushort) (((s) * 65535 / 32767))))
#define INT_TO_USHORT(i) ((i) < 0 ? 0 : ((GLushort) ((i) >> 15)))
#define UINT_TO_USHORT(i) ((i) < 0 ? 0 : ((GLushort) ((i) >> 16)))
-#define UNCLAMPED_FLOAT_TO_USHORT(us, f) \
- us = ( (GLushort) _mesa_lroundevenf( CLAMP((f), 0.0F, 1.0F) * 65535.0F) )
-#define CLAMPED_FLOAT_TO_USHORT(us, f) \
- us = ( (GLushort) _mesa_lroundevenf( (f) * 65535.0F) )
+
+/**
+ * UNCLAMPED_FLOAT_TO_USHORT: clamp float to [0,1] and map to ushort in [0,65535]
+ */
+#define UNCLAMPED_FLOAT_TO_USHORT(US, FLT) \
+ do { \
+ fi_type __tmp; \
+ __tmp.f = (FLT); \
+ if (__tmp.i < 0) \
+ US = (GLushort) 0; \
+ else if (__tmp.i >= IEEE_ONE) \
+ US = (GLushort) 65535; \
+ else { \
+ __tmp.f = __tmp.f + (1 << 23); \
+ US = (GLushort) __tmp.i; \
+ } \
+ } while (0)
+/**
+ * CLAMPED_FLOAT_TO_USHORT: map float known to be in [0,1] to ushort in [0,65535]
+ */
+#define CLAMPED_FLOAT_TO_USHORT(US, FLT) \
+ do { \
+ fi_type __tmp; \
+ __tmp.f = (FLT) + (1 << 23); \
+ US = (GLushort) __tmp.i; \
+ } while (0)
#define UNCLAMPED_FLOAT_TO_SHORT(s, f) \
s = ( (GLshort) _mesa_lroundevenf( CLAMP((f), -1.0F, 1.0F) * 32767.0F) )