Fixed simplification of fma(a, b, c) (#6958)
This commit is contained in:
parent
8d2c4453ad
commit
d7853b9963
|
@ -8226,13 +8226,10 @@ void Tokenizer::simplifyMathFunctions()
|
||||||
tok->str(strNumber); // insert result into token list
|
tok->str(strNumber); // insert result into token list
|
||||||
simplifcationMade = true;
|
simplifcationMade = true;
|
||||||
} else if (Token::Match(tok, "fma|fmaf|fmal ( %any% , %any% , %any% )")) {
|
} else if (Token::Match(tok, "fma|fmaf|fmal ( %any% , %any% , %any% )")) {
|
||||||
// Simplify: fma(a,b,c) == > ( a ) * ( b ) + ( c )
|
// Simplify: fma(a,b,c) == > ( a * b + c )
|
||||||
// get parameters
|
tok->tokAt(3)->str("*");
|
||||||
const std::string& a(tok->strAt(2));
|
tok->tokAt(5)->str("+");
|
||||||
const std::string& b(tok->strAt(4));
|
tok->deleteThis(); // delete fma call
|
||||||
const std::string& c(tok->strAt(6));
|
|
||||||
tok->str("( " + a + " ) * ( " + b + " ) + ( " + c + " )"); // insert result into token list
|
|
||||||
tok->deleteNext(7); // delete fma call
|
|
||||||
simplifcationMade = true;
|
simplifcationMade = true;
|
||||||
} else if (Token::Match(tok, "sqrt|sqrtf|sqrtl|cbrt|cbrtf|cbrtl ( %num% )")) {
|
} else if (Token::Match(tok, "sqrt|sqrtf|sqrtl|cbrt|cbrtf|cbrtl ( %num% )")) {
|
||||||
// Simplify: sqrt(0) = 0 and cbrt(0) == 0
|
// Simplify: sqrt(0) = 0 and cbrt(0) == 0
|
||||||
|
|
|
@ -7231,15 +7231,15 @@ private:
|
||||||
void simplifyMathFunctions_fma() {
|
void simplifyMathFunctions_fma() {
|
||||||
// verify fma(), fmal(), fmaf() - simplifcation
|
// verify fma(), fmal(), fmaf() - simplifcation
|
||||||
const char code_fma[] ="int f(int a, int b, int c) { return fma(a,b,c); }";
|
const char code_fma[] ="int f(int a, int b, int c) { return fma(a,b,c); }";
|
||||||
const char expected_fma[] = "int f ( int a , int b , int c ) { return ( a ) * ( b ) + ( c ) ; }";
|
const char expected_fma[] = "int f ( int a , int b , int c ) { return ( a * b + c ) ; }";
|
||||||
ASSERT_EQUALS(expected_fma, tokenizeAndStringify(code_fma));
|
ASSERT_EQUALS(expected_fma, tokenizeAndStringify(code_fma));
|
||||||
|
|
||||||
const char code_fmaf[] ="float f ( float a , float b , float c ) { return fmaf(a,b,c); }";
|
const char code_fmaf[] ="float f ( float a , float b , float c ) { return fmaf(a,b,c); }";
|
||||||
const char expected_fmaf[] = "float f ( float a , float b , float c ) { return ( a ) * ( b ) + ( c ) ; }";
|
const char expected_fmaf[] = "float f ( float a , float b , float c ) { return ( a * b + c ) ; }";
|
||||||
ASSERT_EQUALS(expected_fmaf, tokenizeAndStringify(code_fmaf));
|
ASSERT_EQUALS(expected_fmaf, tokenizeAndStringify(code_fmaf));
|
||||||
|
|
||||||
const char code_fmal[] ="long double f ( long double a , long double b , long double c ) { return fmal(a,b,c); }";
|
const char code_fmal[] ="long double f ( long double a , long double b , long double c ) { return fmal(a,b,c); }";
|
||||||
const char expected_fmal[] = "long double f ( long double a , long double b , long double c ) { return ( a ) * ( b ) + ( c ) ; }";
|
const char expected_fmal[] = "long double f ( long double a , long double b , long double c ) { return ( a * b + c ) ; }";
|
||||||
ASSERT_EQUALS(expected_fmal, tokenizeAndStringify(code_fmal));
|
ASSERT_EQUALS(expected_fmal, tokenizeAndStringify(code_fmal));
|
||||||
|
|
||||||
const char code_fma1[] = "void f() {\n"
|
const char code_fma1[] = "void f() {\n"
|
||||||
|
@ -7255,9 +7255,9 @@ private:
|
||||||
"} ;";
|
"} ;";
|
||||||
|
|
||||||
const char current_fma1[] = "void f ( ) {\n"
|
const char current_fma1[] = "void f ( ) {\n"
|
||||||
"std :: cout << \"fma(1,2,3): \" << ( 1 ) * ( 2 ) + ( 3 ) << std :: endl ;\n"
|
"std :: cout << \"fma(1,2,3): \" << ( 1 * 2 + 3 ) << std :: endl ;\n"
|
||||||
"std :: cout << \"fmaf(1,2,3): \" << ( 1 ) * ( 2 ) + ( 3 ) << std :: endl ;\n"
|
"std :: cout << \"fmaf(1,2,3): \" << ( 1 * 2 + 3 ) << std :: endl ;\n"
|
||||||
"std :: cout << \"fmal(1,2,3): \" << ( 1 ) * ( 2 ) + ( 3 ) << std :: endl ;\n"
|
"std :: cout << \"fmal(1,2,3): \" << ( 1 * 2 + 3 ) << std :: endl ;\n"
|
||||||
"} ;";
|
"} ;";
|
||||||
TODO_ASSERT_EQUALS(expected_fma1, current_fma1,tokenizeAndStringify(code_fma1));
|
TODO_ASSERT_EQUALS(expected_fma1, current_fma1,tokenizeAndStringify(code_fma1));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue