summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/llvmpipe/lp_test_main.c
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2009-08-08 23:10:59 +0100
committerJosé Fonseca <jfonseca@vmware.com>2009-08-29 09:21:26 +0100
commit60584affcfd444e7733b01612bc72f43c83b5e06 (patch)
tree29185fc6d24da73a73cdd82354031070cede2847 /src/gallium/drivers/llvmpipe/lp_test_main.c
parent145de19548157ad1ba0c314e38a44168e462bb4c (diff)
llvmpipe: Handle more conversions.
Not all successfully yet though..
Diffstat (limited to 'src/gallium/drivers/llvmpipe/lp_test_main.c')
-rw-r--r--src/gallium/drivers/llvmpipe/lp_test_main.c83
1 files changed, 35 insertions, 48 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_test_main.c b/src/gallium/drivers/llvmpipe/lp_test_main.c
index 34e6bf31fc..af94efb8be 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_main.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_main.c
@@ -42,8 +42,9 @@ void
dump_type(FILE *fp,
union lp_type type)
{
- fprintf(fp, "%s%u%sx%u",
- type.floating ? "f" : (type.fixed ? "h" : (type.sign ? "s" : "u")),
+ fprintf(fp, "%s%s%u%sx%u",
+ type.sign ? (type.floating || type.fixed ? "" : "s") : "u",
+ type.floating ? "f" : (type.fixed ? "h" : "i"),
type.width,
type.norm ? "n" : "",
type.length);
@@ -114,11 +115,13 @@ read_elem(union lp_type type, const void *src, unsigned index)
void
-write_elem(union lp_type type, void *dst, unsigned index, double src)
+write_elem(union lp_type type, void *dst, unsigned index, double value)
{
- double scale = lp_const_scale(type);
- double value = scale*src;
assert(index < type.length);
+ if(!type.sign && value < 0.0)
+ value = 0.0;
+ if(type.norm && value > 1.0)
+ value = 1.0;
if (type.floating) {
switch(type.width) {
case 32:
@@ -132,19 +135,21 @@ write_elem(union lp_type type, void *dst, unsigned index, double src)
}
}
else {
+ double scale = lp_const_scale(type);
+ value = round(value*scale);
if(type.sign) {
switch(type.width) {
case 8:
- *((int8_t *)dst + index) = (int8_t)round(value);
+ *((int8_t *)dst + index) = (int8_t)value;
break;
case 16:
- *((int16_t *)dst + index) = (int16_t)round(value);
+ *((int16_t *)dst + index) = (int16_t)value;
break;
case 32:
- *((int32_t *)dst + index) = (int32_t)round(value);
+ *((int32_t *)dst + index) = (int32_t)value;
break;
case 64:
- *((int64_t *)dst + index) = (int32_t)round(value);
+ *((int64_t *)dst + index) = (int32_t)value;
break;
default:
assert(0);
@@ -153,16 +158,16 @@ write_elem(union lp_type type, void *dst, unsigned index, double src)
else {
switch(type.width) {
case 8:
- *((uint8_t *)dst + index) = (uint8_t)round(value);
+ *((uint8_t *)dst + index) = (uint8_t)value;
break;
case 16:
- *((uint16_t *)dst + index) = (uint16_t)round(value);
+ *((uint16_t *)dst + index) = (uint16_t)value;
break;
case 32:
- *((uint32_t *)dst + index) = (uint32_t)round(value);
+ *((uint32_t *)dst + index) = (uint32_t)value;
break;
case 64:
- *((uint64_t *)dst + index) = (uint64_t)round(value);
+ *((uint64_t *)dst + index) = (uint64_t)value;
break;
default:
assert(0);
@@ -175,43 +180,25 @@ write_elem(union lp_type type, void *dst, unsigned index, double src)
void
random_elem(union lp_type type, void *dst, unsigned index)
{
+ double value;
assert(index < type.length);
- if (type.floating) {
- double value = (double)random()/(double)RAND_MAX;
- if(!type.norm) {
- value += (double)random();
- if(random() & 1)
- value = -value;
- }
- switch(type.width) {
- case 32:
- *((float *)dst + index) = (float)value;
- break;
- case 64:
- *((double *)dst + index) = value;
- break;
- default:
- assert(0);
- }
- }
- else {
- switch(type.width) {
- case 8:
- *((uint8_t *)dst + index) = (uint8_t)random();
- break;
- case 16:
- *((uint16_t *)dst + index) = (uint16_t)random();
- break;
- case 32:
- *((uint32_t *)dst + index) = (uint32_t)random();
- break;
- case 64:
- *((uint64_t *)dst + index) = (uint64_t)random();
- break;
- default:
- assert(0);
- }
+ value = (double)random()/(double)RAND_MAX;
+ if(!type.norm) {
+ unsigned long long mask;
+ if (type.floating)
+ mask = ~(unsigned long long)0;
+ else if (type.fixed)
+ mask = ((unsigned long long)1 << (type.width / 2)) - 1;
+ else if (type.sign)
+ mask = ((unsigned long long)1 << (type.width - 1)) - 1;
+ else
+ mask = ((unsigned long long)1 << type.width) - 1;
+ value += (double)(mask & random());
}
+ if(!type.sign)
+ if(random() & 1)
+ value = -value;
+ write_elem(type, dst, index, value);
}