From e2a91e6de5fdcd370b903b2670e76be14c60dc09 Mon Sep 17 00:00:00 2001 From: egaburov Date: Mon, 16 Sep 2013 15:54:32 +0200 Subject: [PATCH 1/4] added support for "d"-suffix --- lex.ll | 20 +++++++++++++++++++- parse.yy | 11 ++++++++--- stdlib.ispc | 12 ++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/lex.ll b/lex.ll index 8baa627a..c2990ccc 100644 --- a/lex.ll +++ b/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,8 @@ 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]?) +DOUBLE_NUMBER (([0-9]+|(([0-9]+\.[0-9]*[dD]?)|(\.[0-9]+)))([dD][-+]?[0-9]+)?[dD]?) +HEX_DOUBLE_NUMBER (0x[01](\.[0-9a-fA-F]*)?p[-+]?[0-9]+[dD]?) IDENT [a-zA-Z_][a-zA-Z_0-9]* ZO_SWIZZLE ([01]+[w-z]+)+|([01]+[rgba]+)+|([01]+[uv]+)+ @@ -438,6 +442,7 @@ L?\"(\\.|[^\\"])*\" { lStringConst(&yylval, &yylloc); return TOKEN_STRING_LITERA } + {FLOAT_NUMBER} { RT; yylval.floatVal = (float)atof(yytext); @@ -450,6 +455,19 @@ L?\"(\\.|[^\\"])*\" { lStringConst(&yylval, &yylloc); return TOKEN_STRING_LITERA return TOKEN_FLOAT_CONSTANT; } +{DOUBLE_NUMBER} { + RT; + yylval.doubleVal = atof(yytext); + return TOKEN_DOUBLE_CONSTANT; +} + +{HEX_DOUBLE_NUMBER} { + RT; + yylval.doubleVal = lParseHexFloat(yytext); + return TOKEN_DOUBLE_CONSTANT; +} + + "++" { RT; return TOKEN_INC_OP; } "--" { RT; return TOKEN_DEC_OP; } "<<" { RT; return TOKEN_LEFT_OP; } diff --git a/parse.yy b/parse.yy index 9a2b4fc3..933a3455 100644 --- a/parse.yy +++ b/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); diff --git a/stdlib.ispc b/stdlib.ispc index 6d7ee051..0d5c4efd 100644 --- a/stdlib.ispc +++ b/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) From 233249048127b94cdb073e694f18987b643741d2 Mon Sep 17 00:00:00 2001 From: egaburov Date: Mon, 16 Sep 2013 16:31:41 +0200 Subject: [PATCH 2/4] added fortran_double_constant --- lex.ll | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lex.ll b/lex.ll index c2990ccc..3d88a23a 100644 --- a/lex.ll +++ b/lex.ll @@ -345,8 +345,7 @@ 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]?) -DOUBLE_NUMBER (([0-9]+|(([0-9]+\.[0-9]*[dD]?)|(\.[0-9]+)))([dD][-+]?[0-9]+)?[dD]?) -HEX_DOUBLE_NUMBER (0x[01](\.[0-9a-fA-F]*)?p[-+]?[0-9]+[dD]?) +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]+)+ @@ -455,18 +454,19 @@ L?\"(\\.|[^\\"])*\" { lStringConst(&yylval, &yylloc); return TOKEN_STRING_LITERA return TOKEN_FLOAT_CONSTANT; } -{DOUBLE_NUMBER} { +{FORTRAN_DOUBLE_NUMBER} { RT; + { + int i = 0; + while (yytext[i] != 'd') i++; + if ((yytext[i+1] >= '0' && yytext[i+1] <= '9') + || yytext[i+1] == '+' || yytext[i+1] == '-') + yytext[i] = 'E'; + } yylval.doubleVal = atof(yytext); return TOKEN_DOUBLE_CONSTANT; } -{HEX_DOUBLE_NUMBER} { - RT; - yylval.doubleVal = lParseHexFloat(yytext); - return TOKEN_DOUBLE_CONSTANT; -} - "++" { RT; return TOKEN_INC_OP; } "--" { RT; return TOKEN_DEC_OP; } From 6fd21d988d999b62aa0e2832cd93ccdb4ca78f77 Mon Sep 17 00:00:00 2001 From: Evghenii Date: Mon, 16 Sep 2013 17:15:02 +0200 Subject: [PATCH 3/4] fixed lexer to properly read fortran-notation double constants --- lex.ll | 26 +++++++++++++------------- stdlib.ispc | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lex.ll b/lex.ll index 3d88a23a..ca318dbb 100644 --- a/lex.ll +++ b/lex.ll @@ -345,7 +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])) +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]+)+ @@ -440,6 +442,16 @@ L?\"(\\.|[^\\"])*\" { lStringConst(&yylval, &yylloc); return TOKEN_STRING_LITERA return lParseInteger(true); } +{FORTRAN_DOUBLE_NUMBER} { + RT; + { + int i = 0; + while (yytext[i] != 'd') i++; + yytext[i] = 'E'; + } + yylval.doubleVal = atof(yytext); + return TOKEN_DOUBLE_CONSTANT; +} {FLOAT_NUMBER} { @@ -454,18 +466,6 @@ L?\"(\\.|[^\\"])*\" { lStringConst(&yylval, &yylloc); return TOKEN_STRING_LITERA return TOKEN_FLOAT_CONSTANT; } -{FORTRAN_DOUBLE_NUMBER} { - RT; - { - int i = 0; - while (yytext[i] != 'd') i++; - if ((yytext[i+1] >= '0' && yytext[i+1] <= '9') - || yytext[i+1] == '+' || yytext[i+1] == '-') - yytext[i] = 'E'; - } - yylval.doubleVal = atof(yytext); - return TOKEN_DOUBLE_CONSTANT; -} "++" { RT; return TOKEN_INC_OP; } diff --git a/stdlib.ispc b/stdlib.ispc index 0d5c4efd..9b02d0ba 100644 --- a/stdlib.ispc +++ b/stdlib.ispc @@ -2564,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); } @@ -2575,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); } From eef4e11768222914ffb93ccc1ab698e1cfbd7922 Mon Sep 17 00:00:00 2001 From: egaburov Date: Mon, 16 Sep 2013 17:25:13 +0200 Subject: [PATCH 4/4] now it is also case nonsensitive --- lex.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lex.ll b/lex.ll index ca318dbb..f1dcaa6f 100644 --- a/lex.ll +++ b/lex.ll @@ -446,7 +446,7 @@ L?\"(\\.|[^\\"])*\" { lStringConst(&yylval, &yylloc); return TOKEN_STRING_LITERA RT; { int i = 0; - while (yytext[i] != 'd') i++; + while (yytext[i] != 'd' && yytext[i] != 'D') i++; yytext[i] = 'E'; } yylval.doubleVal = atof(yytext);