Improvements to constant folding.

We can now do constant folding with all basic datatypes (the previous
implementation handled int32 well, but had limited, if any, coverage
for other datatypes.)

Reduced a bit of repeated code in the constant folding implementation
through template helper functions.
This commit is contained in:
Matt Pharr
2013-07-22 16:12:02 -07:00
parent abf43ad01d
commit 564e61c828
7 changed files with 267 additions and 270 deletions

81
expr.h
View File

@@ -409,71 +409,22 @@ public:
Expr *Optimize();
int EstimateCost() const;
/** Return the ConstExpr's values as booleans, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsBool(bool *, bool forceVarying = false) const;
/** Return the ConstExpr's values as int8s, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsInt8(int8_t *, bool forceVarying = false) const;
/** Return the ConstExpr's values as uint8s, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsUInt8(uint8_t *, bool forceVarying = false) const;
/** Return the ConstExpr's values as int16s, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsInt16(int16_t *, bool forceVarying = false) const;
/** Return the ConstExpr's values as uint16s, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsUInt16(uint16_t *, bool forceVarying = false) const;
/** Return the ConstExpr's values as int32s, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsInt32(int32_t *, bool forceVarying = false) const;
/** Return the ConstExpr's values as uint32s, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsUInt32(uint32_t *, bool forceVarying = false) const;
/** Return the ConstExpr's values as floats, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsFloat(float *, bool forceVarying = false) const;
/** Return the ConstExpr's values as int64s, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsInt64(int64_t *, bool forceVarying = false) const;
/** Return the ConstExpr's values as uint64s, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsUInt64(uint64_t *, bool forceVarying = false) const;
/** Return the ConstExpr's values as doubles, doing type conversion
from the actual type if needed. If forceVarying is true, then type
convert to 'varying' so as to always return a number of values
equal to the target vector width into the given pointer. */
int AsDouble(double *, bool forceVarying = false) const;
/** Return the ConstExpr's values as the given pointer type, doing type
conversion from the actual type if needed. If forceVarying is
true, then type convert to 'varying' so as to always return a
number of values equal to the target vector width into the given
pointer. */
int GetValues(bool *, bool forceVarying = false) const;
int GetValues(int8_t *, bool forceVarying = false) const;
int GetValues(uint8_t *, bool forceVarying = false) const;
int GetValues(int16_t *, bool forceVarying = false) const;
int GetValues(uint16_t *, bool forceVarying = false) const;
int GetValues(int32_t *, bool forceVarying = false) const;
int GetValues(uint32_t *, bool forceVarying = false) const;
int GetValues(float *, bool forceVarying = false) const;
int GetValues(int64_t *, bool forceVarying = false) const;
int GetValues(uint64_t *, bool forceVarying = false) const;
int GetValues(double *, bool forceVarying = false) const;
/** Return the number of values in the ConstExpr; should be either 1,
if it has uniform type, or the target's vector width if it's