summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/llvmpipe/lp_bld_const.c
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2009-08-22 12:37:12 +0100
committerJosé Fonseca <jfonseca@vmware.com>2009-08-29 09:21:39 +0100
commit64cc71167f986f6cd29abb228295cf6441b07832 (patch)
tree4c7c26bf9563e041673fc9e2051374d30df23a50 /src/gallium/drivers/llvmpipe/lp_bld_const.c
parent53f9a1180ef5a24cd8ffe235e716a9061a129bb3 (diff)
llvmpipe: Get conversions working correctly for all integer types.
Diffstat (limited to 'src/gallium/drivers/llvmpipe/lp_bld_const.c')
-rw-r--r--src/gallium/drivers/llvmpipe/lp_bld_const.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_bld_const.c b/src/gallium/drivers/llvmpipe/lp_bld_const.c
index 991cf24a9ea..a205c33715b 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_const.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_const.c
@@ -41,6 +41,31 @@
#include "lp_bld_const.h"
+unsigned
+lp_mantissa(union lp_type type)
+{
+ assert(type.floating);
+
+ if(type.floating) {
+ switch(type.width) {
+ case 32:
+ return 23;
+ case 64:
+ return 53;
+ default:
+ assert(0);
+ return 0;
+ }
+ }
+ else {
+ if(type.sign)
+ return type.width - 1;
+ else
+ return type.width;
+ }
+}
+
+
/**
* Shift of the unity.
*
@@ -93,6 +118,77 @@ lp_const_scale(union lp_type type)
}
+/**
+ * Minimum value representable by the type.
+ */
+double
+lp_const_min(union lp_type type)
+{
+ unsigned bits;
+
+ if(!type.sign)
+ return 0.0;
+
+ if(type.norm)
+ return -1.0;
+
+ if (type.floating) {
+ switch(type.width) {
+ case 32:
+ return -FLT_MAX;
+ case 64:
+ return -DBL_MAX;
+ default:
+ assert(0);
+ return 0.0;
+ }
+ }
+
+ if(type.fixed)
+ /* FIXME: consider the fractional bits? */
+ bits = type.width / 2 - 1;
+ else
+ bits = type.width - 1;
+
+ return (double)-((long long)1 << bits);
+}
+
+
+/**
+ * Maximum value representable by the type.
+ */
+double
+lp_const_max(union lp_type type)
+{
+ unsigned bits;
+
+ if(type.norm)
+ return 1.0;
+
+ if (type.floating) {
+ switch(type.width) {
+ case 32:
+ return FLT_MAX;
+ case 64:
+ return DBL_MAX;
+ default:
+ assert(0);
+ return 0.0;
+ }
+ }
+
+ if(type.fixed)
+ bits = type.width / 2;
+ else
+ bits = type.width;
+
+ if(type.sign)
+ bits -= 1;
+
+ return (double)(((unsigned long long)1 << bits) - 1);
+}
+
+
double
lp_const_eps(union lp_type type)
{