summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2009-08-14 12:02:06 +0100
committerJosé Fonseca <jfonseca@vmware.com>2009-08-29 09:21:32 +0100
commitc67570ba85e315d5e3b8a6271232e8975eae0171 (patch)
tree38e0fad240ddb5aed178e7d3f6f50a7d58fda69f
parent17aec9304ca86feac7ca29e17dda73a10cdd08a5 (diff)
llvmpipe: Clamp into range when writing integers.
-rw-r--r--src/gallium/drivers/llvmpipe/lp_test_main.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_test_main.c b/src/gallium/drivers/llvmpipe/lp_test_main.c
index af94efb8be..32ed0f6da3 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_main.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_main.c
@@ -136,38 +136,40 @@ write_elem(union lp_type type, void *dst, unsigned index, double value)
}
else {
double scale = lp_const_scale(type);
- value = round(value*scale);
+ long long lvalue = (long long)round(value*scale);
if(type.sign) {
+ lvalue = MIN2(lvalue, (1 << (type.width - 1)) - 1);
switch(type.width) {
case 8:
- *((int8_t *)dst + index) = (int8_t)value;
+ *((int8_t *)dst + index) = (int8_t)lvalue;
break;
case 16:
- *((int16_t *)dst + index) = (int16_t)value;
+ *((int16_t *)dst + index) = (int16_t)lvalue;
break;
case 32:
- *((int32_t *)dst + index) = (int32_t)value;
+ *((int32_t *)dst + index) = (int32_t)lvalue;
break;
case 64:
- *((int64_t *)dst + index) = (int32_t)value;
+ *((int64_t *)dst + index) = (int32_t)lvalue;
break;
default:
assert(0);
}
}
else {
+ lvalue = MIN2(lvalue, (1 << type.width) - 1);
switch(type.width) {
case 8:
- *((uint8_t *)dst + index) = (uint8_t)value;
+ *((uint8_t *)dst + index) = (uint8_t)lvalue;
break;
case 16:
- *((uint16_t *)dst + index) = (uint16_t)value;
+ *((uint16_t *)dst + index) = (uint16_t)lvalue;
break;
case 32:
- *((uint32_t *)dst + index) = (uint32_t)value;
+ *((uint32_t *)dst + index) = (uint32_t)lvalue;
break;
case 64:
- *((uint64_t *)dst + index) = (uint64_t)value;
+ *((uint64_t *)dst + index) = (uint64_t)lvalue;
break;
default:
assert(0);