Open luyahan opened 3 years ago
I alter code by add volatile for Inputs(volatile Inputs inputs = {src1, src2};
) :
struct Inputs {
double src1_;
double src2_;
};
struct Results {
// Check all register aliasing possibilities in order to exercise all
// code-paths in the macro masm.
double min_abc_;
double min_aab_;
double min_aba_;
double max_abc_;
double max_aab_;
double max_aba_;
};
auto f = AssembleCode<F4>(
GenerateMacroFloat64MinMax<DoubleRegister, Inputs, Results>);
#define CHECK_MINMAX(src1, src2, min, max) \
do { \
volatile Inputs inputs = {src1, src2}; \
Results results; \
f.Call((void*)&inputs, &results, 0, 0, 0); \
CHECK_EQ(bit_cast<uint64_t>(min), bit_cast<uint64_t>(results.min_abc_)); \
CHECK_EQ(bit_cast<uint64_t>(min), bit_cast<uint64_t>(results.min_aab_)); \
CHECK_EQ(bit_cast<uint64_t>(min), bit_cast<uint64_t>(results.min_aba_)); \
CHECK_EQ(bit_cast<uint64_t>(max), bit_cast<uint64_t>(results.max_abc_)); \
CHECK_EQ(bit_cast<uint64_t>(max), bit_cast<uint64_t>(results.max_aab_)); \
CHECK_EQ(bit_cast<uint64_t>(max), bit_cast<uint64_t>(results.max_aba_)); \
/* Use a bit_cast to correctly identify -0.0 and NaNs. */ \
} while (0)
the case pass. @fw-brice @penguinwu May it be a bug for gcc -o3 ?
I alter code by add volatile for Inputs(volatile Inputs inputs = {src1, src2};
) :
struct Inputs {
double src1_;
double src2_;
};
struct Results {
// Check all register aliasing possibilities in order to exercise all
// code-paths in the macro masm.
double min_abc_;
double min_aab_;
double min_aba_;
double max_abc_;
double max_aab_;
double max_aba_;
};
auto f = AssembleCode<F4>(
GenerateMacroFloat64MinMax<DoubleRegister, Inputs, Results>);
#define CHECK_MINMAX(src1, src2, min, max) \
do { \
volatile Inputs inputs = {src1, src2}; \
Results results; \
f.Call((void*)&inputs, &results, 0, 0, 0); \
CHECK_EQ(bit_cast<uint64_t>(min), bit_cast<uint64_t>(results.min_abc_)); \
CHECK_EQ(bit_cast<uint64_t>(min), bit_cast<uint64_t>(results.min_aab_)); \
CHECK_EQ(bit_cast<uint64_t>(min), bit_cast<uint64_t>(results.min_aba_)); \
CHECK_EQ(bit_cast<uint64_t>(max), bit_cast<uint64_t>(results.max_abc_)); \
CHECK_EQ(bit_cast<uint64_t>(max), bit_cast<uint64_t>(results.max_aab_)); \
CHECK_EQ(bit_cast<uint64_t>(max), bit_cast<uint64_t>(results.max_aba_)); \
/* Use a bit_cast to correctly identify -0.0 and NaNs. */ \
} while (0)
the case pass. @fw-brice @penguinwu May it be a bug for gcc -o3 ?
Hmm, this test is single-threaded, why would volatile
make a difference? Could you take a closer look at the gcc code-gen to see if it can be explained?
Hmm, this test is single-threaded, why would
volatile
make a difference? Could you take a closer look at the gcc code-gen to see if it can be explained?
It may be pass the args by a0,a1 but a1 has a wrong value
Hmm, this test is single-threaded, why would
volatile
make a difference? Could you take a closer look at the gcc code-gen to see if it can be explained?
i run a test :
#include <iostream>
#include <climits>
struct Inputs {
double src1_;
double src2_;
};
double fun(void* a) {
double r = 0;
asm ("fld ft0, 8(%1)\n\t"
"fld ft1, 0(%1)\n\t"
"fadd.d %0, ft0, ft1\n\t"
: "=f"(r)
: "r"(a));
return r;
}
#define CHECK_MINMAX(src1, src2, min, max) \
do { \
Inputs inputs = {src1, src2}; \
std::cout << fun((void*)&inputs) << std::endl; \
} while (0)
int main() {
CHECK_MINMAX(0.1,0.2,0,0);
CHECK_MINMAX(0.3,0.9,0,0);
}
It out:
0.1
0.1
but if i add volatile on asm :
#include <iostream>
#include <climits>
struct Inputs {
double src1_;
double src2_;
};
double fun(void* a) {
double r = 0;
asm volatile("fld ft0, 8(%1)\n\t"
"fld ft1, 0(%1)\n\t"
"fadd.d %0, ft0, ft1\n\t"
: "=f"(r)
: "r"(a));
return r;
}
#define CHECK_MINMAX(src1, src2, min, max) \
do { \
Inputs inputs = {src1, src2}; \
std::cout << fun((void*)&inputs) << std::endl; \
} while (0)
int main() {
CHECK_MINMAX(0.1,0.2,0,0);
CHECK_MINMAX(0.3,0.9,0,0);
}
it out :
0.3
1.2
Describe the bug A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior:
riscv64.native.release
Expected behavior A clear and concise description of what you expected to happen.
Errors/Logs
Additional context Add any other context about the problem here.