Merge pull request #584 from egaburov/d-suffix
Added fortran notation double precision support
This commit is contained in:
20
lex.ll
20
lex.ll
@@ -76,7 +76,7 @@ static int allTokens[] = {
|
||||
TOKEN_TASK, TOKEN_TRUE, TOKEN_TYPEDEF, TOKEN_UNIFORM, TOKEN_UNMASKED,
|
||||
TOKEN_UNSIGNED, TOKEN_VARYING, TOKEN_VOID, TOKEN_WHILE,
|
||||
TOKEN_STRING_C_LITERAL, TOKEN_DOTDOTDOT,
|
||||
TOKEN_FLOAT_CONSTANT,
|
||||
TOKEN_FLOAT_CONSTANT, TOKEN_DOUBLE_CONSTANT,
|
||||
TOKEN_INT8_CONSTANT, TOKEN_UINT8_CONSTANT,
|
||||
TOKEN_INT16_CONSTANT, TOKEN_UINT16_CONSTANT,
|
||||
TOKEN_INT32_CONSTANT, TOKEN_UINT32_CONSTANT,
|
||||
@@ -152,6 +152,7 @@ void ParserInit() {
|
||||
tokenToName[TOKEN_STRING_C_LITERAL] = "\"C\"";
|
||||
tokenToName[TOKEN_DOTDOTDOT] = "...";
|
||||
tokenToName[TOKEN_FLOAT_CONSTANT] = "TOKEN_FLOAT_CONSTANT";
|
||||
tokenToName[TOKEN_DOUBLE_CONSTANT] = "TOKEN_DOUBLE_CONSTANT";
|
||||
tokenToName[TOKEN_INT8_CONSTANT] = "TOKEN_INT8_CONSTANT";
|
||||
tokenToName[TOKEN_UINT8_CONSTANT] = "TOKEN_UINT8_CONSTANT";
|
||||
tokenToName[TOKEN_INT16_CONSTANT] = "TOKEN_INT16_CONSTANT";
|
||||
@@ -266,6 +267,7 @@ void ParserInit() {
|
||||
tokenNameRemap["TOKEN_STRING_C_LITERAL"] = "\"C\"";
|
||||
tokenNameRemap["TOKEN_DOTDOTDOT"] = "\'...\'";
|
||||
tokenNameRemap["TOKEN_FLOAT_CONSTANT"] = "float constant";
|
||||
tokenNameRemap["TOKEN_DOUBLE_CONSTANT"] = "double constant";
|
||||
tokenNameRemap["TOKEN_INT8_CONSTANT"] = "int8 constant";
|
||||
tokenNameRemap["TOKEN_UINT8_CONSTANT"] = "unsigned int8 constant";
|
||||
tokenNameRemap["TOKEN_INT16_CONSTANT"] = "int16 constant";
|
||||
@@ -343,6 +345,9 @@ INT_NUMBER (([0-9]+)|(0x[0-9a-fA-F]+)|(0b[01]+))[uUlL]*[kMG]?[uUlL]*
|
||||
INT_NUMBER_DOTDOTDOT (([0-9]+)|(0x[0-9a-fA-F]+)|(0b[01]+))[uUlL]*[kMG]?[uUlL]*\.\.\.
|
||||
FLOAT_NUMBER (([0-9]+|(([0-9]+\.[0-9]*[fF]?)|(\.[0-9]+)))([eE][-+]?[0-9]+)?[fF]?)
|
||||
HEX_FLOAT_NUMBER (0x[01](\.[0-9a-fA-F]*)?p[-+]?[0-9]+[fF]?)
|
||||
FORTRAN_DOUBLE_NUMBER (([0-9]+\.[0-9]*[dD])|([0-9]+\.[0-9]*[dD][-+]?[0-9]+)|([0-9]+[dD][-+]?[0-9]+))
|
||||
|
||||
|
||||
|
||||
IDENT [a-zA-Z_][a-zA-Z_0-9]*
|
||||
ZO_SWIZZLE ([01]+[w-z]+)+|([01]+[rgba]+)+|([01]+[uv]+)+
|
||||
@@ -437,6 +442,17 @@ L?\"(\\.|[^\\"])*\" { lStringConst(&yylval, &yylloc); return TOKEN_STRING_LITERA
|
||||
return lParseInteger(true);
|
||||
}
|
||||
|
||||
{FORTRAN_DOUBLE_NUMBER} {
|
||||
RT;
|
||||
{
|
||||
int i = 0;
|
||||
while (yytext[i] != 'd' && yytext[i] != 'D') i++;
|
||||
yytext[i] = 'E';
|
||||
}
|
||||
yylval.doubleVal = atof(yytext);
|
||||
return TOKEN_DOUBLE_CONSTANT;
|
||||
}
|
||||
|
||||
|
||||
{FLOAT_NUMBER} {
|
||||
RT;
|
||||
@@ -450,6 +466,8 @@ L?\"(\\.|[^\\"])*\" { lStringConst(&yylval, &yylloc); return TOKEN_STRING_LITERA
|
||||
return TOKEN_FLOAT_CONSTANT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
"++" { RT; return TOKEN_INC_OP; }
|
||||
"--" { RT; return TOKEN_DEC_OP; }
|
||||
"<<" { RT; return TOKEN_LEFT_OP; }
|
||||
|
||||
11
parse.yy
11
parse.yy
@@ -149,7 +149,8 @@ struct ForeachDimension {
|
||||
|
||||
%union {
|
||||
uint64_t intVal;
|
||||
float floatVal;
|
||||
float floatVal;
|
||||
double doubleVal;
|
||||
std::string *stringVal;
|
||||
const char *constCharPtr;
|
||||
|
||||
@@ -185,7 +186,7 @@ struct ForeachDimension {
|
||||
%token TOKEN_INT64_CONSTANT TOKEN_UINT64_CONSTANT
|
||||
%token TOKEN_INT32DOTDOTDOT_CONSTANT TOKEN_UINT32DOTDOTDOT_CONSTANT
|
||||
%token TOKEN_INT64DOTDOTDOT_CONSTANT TOKEN_UINT64DOTDOTDOT_CONSTANT
|
||||
%token TOKEN_FLOAT_CONSTANT TOKEN_STRING_C_LITERAL
|
||||
%token TOKEN_FLOAT_CONSTANT TOKEN_DOUBLE_CONSTANT TOKEN_STRING_C_LITERAL
|
||||
%token TOKEN_IDENTIFIER TOKEN_STRING_LITERAL TOKEN_TYPE_NAME TOKEN_NULL
|
||||
%token TOKEN_PTR_OP TOKEN_INC_OP TOKEN_DEC_OP TOKEN_LEFT_OP TOKEN_RIGHT_OP
|
||||
%token TOKEN_LE_OP TOKEN_GE_OP TOKEN_EQ_OP TOKEN_NE_OP
|
||||
@@ -327,7 +328,11 @@ primary_expression
|
||||
}
|
||||
| TOKEN_FLOAT_CONSTANT {
|
||||
$$ = new ConstExpr(AtomicType::UniformFloat->GetAsConstType(),
|
||||
(float)yylval.floatVal, @1);
|
||||
yylval.floatVal, @1);
|
||||
}
|
||||
| TOKEN_DOUBLE_CONSTANT {
|
||||
$$ = new ConstExpr(AtomicType::UniformDouble->GetAsConstType(),
|
||||
yylval.doubleVal, @1);
|
||||
}
|
||||
| TOKEN_TRUE {
|
||||
$$ = new ConstExpr(AtomicType::UniformBool->GetAsConstType(), true, @1);
|
||||
|
||||
16
stdlib.ispc
16
stdlib.ispc
@@ -1559,6 +1559,18 @@ static inline uniform float clamp(uniform float v, uniform float low, uniform fl
|
||||
return min(max(v, low), high);
|
||||
}
|
||||
|
||||
// double
|
||||
|
||||
__declspec(safe,cost2)
|
||||
static inline double clamp(double v, double low, double high) {
|
||||
return min(max(v, low), high);
|
||||
}
|
||||
|
||||
__declspec(safe,cost2)
|
||||
static inline uniform double clamp(uniform double v, uniform double low, uniform double high) {
|
||||
return min(max(v, low), high);
|
||||
}
|
||||
|
||||
// int8
|
||||
|
||||
__declspec(safe,cost2)
|
||||
@@ -2552,7 +2564,7 @@ static inline float acos(float v) {
|
||||
|
||||
__declspec(safe)
|
||||
static inline double acos(const double v) {
|
||||
return 1.57079637050628662109375 - asin(v);
|
||||
return 1.57079637050628662109375d0 - asin(v);
|
||||
}
|
||||
|
||||
|
||||
@@ -2563,7 +2575,7 @@ static inline uniform float acos(uniform float v) {
|
||||
|
||||
__declspec(safe)
|
||||
static inline uniform double acos(const uniform double v) {
|
||||
return 1.57079637050628662109375 - asin(v);
|
||||
return 1.57079637050628662109375d0 - asin(v);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user