work around pointer aliasing issue with JIT enabled

This commit is contained in:
Axel Kohlmeyer
2022-12-27 17:43:31 -05:00
parent efc2e96a9e
commit c63f1647fb
2 changed files with 18 additions and 4 deletions

View File

@ -38,6 +38,7 @@ using namespace Lepton;
using namespace std;
#ifdef LEPTON_USE_JIT
using namespace asmjit;
#include <cinttypes>
#endif
CompiledExpression::CompiledExpression() : jitCode(NULL) {
@ -513,6 +514,12 @@ void CompiledExpression::generateTwoArgCall(a64::Compiler& c, arm::Vec& dest, ar
invoke->setRet(0, dest);
}
#else
union int64_vs_double {
int64_t i;
double d;
};
void CompiledExpression::generateJitCode() {
const CpuInfo& cpu = CpuInfo::host();
if (!cpu.hasFeature(CpuFeatures::X86::kAVX))
@ -561,8 +568,9 @@ void CompiledExpression::generateJitCode() {
else if (op.getId() == Operation::DELTA)
value = 1.0;
else if (op.getId() == Operation::ABS) {
long long mask = 0x7FFFFFFFFFFFFFFF;
value = *reinterpret_cast<double*>(&mask);
int64_vs_double mask;
mask.i = 0x7FFFFFFFFFFFFFFF;
value = mask.d;
}
else if (op.getId() == Operation::POWER_CONSTANT) {
if (stepGroup[step] == -1)

View File

@ -573,6 +573,11 @@ void CompiledVectorExpression::generateTwoArgCall(a64::Compiler& c, arm::Vec& de
}
#else
union int_vs_float {
int i;
float f;
};
void CompiledVectorExpression::generateJitCode() {
const CpuInfo& cpu = CpuInfo::host();
if (!cpu.hasFeature(CpuFeatures::X86::kAVX))
@ -624,8 +629,9 @@ void CompiledVectorExpression::generateJitCode() {
else if (op.getId() == Operation::DELTA)
value = 1.0;
else if (op.getId() == Operation::ABS) {
int mask = 0x7FFFFFFF;
value = *reinterpret_cast<float*>(&mask);
int_vs_float mask;
mask.i = 0x7FFFFFFF;
value = mask.f;
}
else if (op.getId() == Operation::POWER_CONSTANT) {
if (stepGroup[step] == -1)