{
bool is_uint = (text[len - 1] == 'u' ||
text[len - 1] == 'U');
+ bool is_long = (text[len - 1] == 'l' || text[len - 1] == 'L');
const char *digits = text;
+ if (is_long)
+ is_uint = (text[len - 2] == 'u' && text[len - 1] == 'l') ||
+ (text[len - 2] == 'U' && text[len - 1] == 'L');
/* Skip "0x" */
if (base == 16)
digits += 2;
unsigned long long value = strtoull(digits, NULL, base);
- lval->n = (int)value;
+ if (is_long)
+ lval->n64 = (int64_t)value;
+ else
+ lval->n = (int)value;
- if (value > UINT_MAX) {
+ if (is_long && !is_uint && base == 10 && value > (uint64_t)LLONG_MAX + 1) {
+ /* Tries to catch unintentionally providing a negative value. */
+ _mesa_glsl_warning(lloc, state,
+ "signed literal value `%s' is interpreted as %lld",
+ text, lval->n64);
+ } else if (!is_long && value > UINT_MAX) {
/* Note that signed 0xffffffff is valid, not out of range! */
if (state->is_version(130, 300)) {
_mesa_glsl_error(lloc, state,
"signed literal value `%s' is interpreted as %d",
text, lval->n);
}
- return is_uint ? UINTCONSTANT : INTCONSTANT;
+ if (is_long)
+ return is_uint ? UINT64CONSTANT : INT64CONSTANT;
+ else
+ return is_uint ? UINTCONSTANT : INTCONSTANT;
}
#define LITERAL_INTEGER(base) \
\|= return OR_ASSIGN;
-= return SUB_ASSIGN;
-[1-9][0-9]*[uU]? {
+[1-9][0-9]*([uU]|[lL]|ul|UL)? {
return LITERAL_INTEGER(10);
}
-0[xX][0-9a-fA-F]+[uU]? {
+0[xX][0-9a-fA-F]+([uU]|[lL]|ul|UL)? {
return LITERAL_INTEGER(16);
}
-0[0-7]*[uU]? {
+0[0-7]*([uU]|[lL]|ul|UL)? {
return LITERAL_INTEGER(8);
}
}
}
+ir_constant::ir_constant(uint64_t u64, unsigned vector_elements)
+ : ir_rvalue(ir_type_constant)
+{
+ assert(vector_elements <= 4);
+ this->type = glsl_type::get_instance(GLSL_TYPE_UINT64, vector_elements, 1);
+ for (unsigned i = 0; i < vector_elements; i++) {
+ this->value.u64[i] = u64;
+ }
+ for (unsigned i = vector_elements; i < 16; i++) {
+ this->value.u64[i] = 0;
+ }
+}
+
+ir_constant::ir_constant(int64_t int64, unsigned vector_elements)
+ : ir_rvalue(ir_type_constant)
+{
+ assert(vector_elements <= 4);
+ this->type = glsl_type::get_instance(GLSL_TYPE_INT64, vector_elements, 1);
+ for (unsigned i = 0; i < vector_elements; i++) {
+ this->value.i64[i] = int64;
+ }
+ for (unsigned i = vector_elements; i < 16; i++) {
+ this->value.i64[i] = 0;
+ }
+}
+
ir_constant::ir_constant(bool b, unsigned vector_elements)
: ir_rvalue(ir_type_constant)
{
for (unsigned i = 0; i < type->components(); i++)
this->value.d[i] = value->value.d[0];
break;
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
+ for (unsigned i = 0; i < type->components(); i++)
+ this->value.u64[i] = value->value.u64[0];
+ break;
case GLSL_TYPE_BOOL:
for (unsigned i = 0; i < type->components(); i++)
this->value.b[i] = value->value.b[0];
case GLSL_TYPE_DOUBLE:
this->value.d[i] = value->get_double_component(j);
break;
+ case GLSL_TYPE_UINT64:
+ this->value.u64[i] = value->get_uint64_component(j);
+ break;
+ case GLSL_TYPE_INT64:
+ this->value.i64[i] = value->get_int64_component(j);
+ break;
default:
/* FINISHME: What to do? Exceptions are not the answer.
*/
case GLSL_TYPE_FLOAT: return ((int)this->value.f[i]) != 0;
case GLSL_TYPE_BOOL: return this->value.b[i];
case GLSL_TYPE_DOUBLE: return this->value.d[i] != 0.0;
+ case GLSL_TYPE_UINT64: return this->value.u64[i] != 0;
+ case GLSL_TYPE_INT64: return this->value.i64[i] != 0;
default: assert(!"Should not get here."); break;
}
case GLSL_TYPE_FLOAT: return this->value.f[i];
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0f : 0.0f;
case GLSL_TYPE_DOUBLE: return (float) this->value.d[i];
+ case GLSL_TYPE_UINT64: return (float) this->value.u64[i];
+ case GLSL_TYPE_INT64: return (float) this->value.i64[i];
default: assert(!"Should not get here."); break;
}
case GLSL_TYPE_FLOAT: return (double) this->value.f[i];
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0 : 0.0;
case GLSL_TYPE_DOUBLE: return this->value.d[i];
+ case GLSL_TYPE_UINT64: return (double) this->value.u64[i];
+ case GLSL_TYPE_INT64: return (double) this->value.i64[i];
default: assert(!"Should not get here."); break;
}
case GLSL_TYPE_FLOAT: return (int) this->value.f[i];
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
case GLSL_TYPE_DOUBLE: return (int) this->value.d[i];
+ case GLSL_TYPE_UINT64: return (int) this->value.u64[i];
+ case GLSL_TYPE_INT64: return (int) this->value.i64[i];
default: assert(!"Should not get here."); break;
}
case GLSL_TYPE_FLOAT: return (unsigned) this->value.f[i];
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
case GLSL_TYPE_DOUBLE: return (unsigned) this->value.d[i];
+ case GLSL_TYPE_UINT64: return (unsigned) this->value.u64[i];
+ case GLSL_TYPE_INT64: return (unsigned) this->value.i64[i];
+ default: assert(!"Should not get here."); break;
+ }
+
+ /* Must return something to make the compiler happy. This is clearly an
+ * error case.
+ */
+ return 0;
+}
+
+int64_t
+ir_constant::get_int64_component(unsigned i) const
+{
+ switch (this->type->base_type) {
+ case GLSL_TYPE_UINT: return this->value.u[i];
+ case GLSL_TYPE_INT: return this->value.i[i];
+ case GLSL_TYPE_FLOAT: return (int64_t) this->value.f[i];
+ case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
+ case GLSL_TYPE_DOUBLE: return (int64_t) this->value.d[i];
+ case GLSL_TYPE_UINT64: return (int64_t) this->value.u64[i];
+ case GLSL_TYPE_INT64: return this->value.i64[i];
+ default: assert(!"Should not get here."); break;
+ }
+
+ /* Must return something to make the compiler happy. This is clearly an
+ * error case.
+ */
+ return 0;
+}
+
+uint64_t
+ir_constant::get_uint64_component(unsigned i) const
+{
+ switch (this->type->base_type) {
+ case GLSL_TYPE_UINT: return this->value.u[i];
+ case GLSL_TYPE_INT: return this->value.i[i];
+ case GLSL_TYPE_FLOAT: return (uint64_t) this->value.f[i];
+ case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
+ case GLSL_TYPE_DOUBLE: return (uint64_t) this->value.d[i];
+ case GLSL_TYPE_UINT64: return this->value.u64[i];
+ case GLSL_TYPE_INT64: return (uint64_t) this->value.i64[i];
default: assert(!"Should not get here."); break;
}
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
case GLSL_TYPE_BOOL: {
unsigned int size = src->type->components();
assert (size <= this->type->components() - offset);
case GLSL_TYPE_DOUBLE:
value.d[i+offset] = src->get_double_component(i);
break;
+ case GLSL_TYPE_UINT64:
+ value.u64[i+offset] = src->get_uint64_component(i);
+ break;
+ case GLSL_TYPE_INT64:
+ value.i64[i+offset] = src->get_int64_component(i);
+ break;
default: // Shut up the compiler
break;
}
case GLSL_TYPE_DOUBLE:
value.d[i+offset] = src->get_double_component(id++);
break;
+ case GLSL_TYPE_UINT64:
+ value.u64[i+offset] = src->get_uint64_component(id++);
+ break;
+ case GLSL_TYPE_INT64:
+ value.i64[i+offset] = src->get_int64_component(id++);
+ break;
default:
assert(!"Should not get here.");
return;
if (this->value.d[i] != c->value.d[i])
return false;
break;
+ case GLSL_TYPE_UINT64:
+ if (this->value.u64[i] != c->value.u64[i])
+ return false;
+ break;
+ case GLSL_TYPE_INT64:
+ if (this->value.i64[i] != c->value.i64[i])
+ return false;
+ break;
default:
assert(!"Should not get here.");
return false;
if (this->value.d[c] != double(f))
return false;
break;
+ case GLSL_TYPE_UINT64:
+ if (this->value.u64[c] != uint64_t(i))
+ return false;
+ break;
+ case GLSL_TYPE_INT64:
+ if (this->value.i64[c] != i)
+ return false;
+ break;
default:
/* The only other base types are structures, arrays, and samplers.
* Samplers cannot be constants, and the others should have been