revert to using the unions. looks nicer and passes the tests.

This commit is contained in:
Axel Kohlmeyer
2022-12-29 19:10:15 -05:00
parent 67156420d4
commit 49eb9ca5fd
2 changed files with 20 additions and 12 deletions

View File

@ -32,7 +32,8 @@
#include "lepton/CompiledExpression.h"
#include "lepton/Operation.h"
#include "lepton/ParsedExpression.h"
#include <cstring>
#include <cinttypes>
#include <utility>
using namespace Lepton;
@ -515,6 +516,12 @@ void CompiledExpression::generateTwoArgCall(a64::Compiler& c, arm::Vec& dest, ar
}
#else
union int64_to_double {
int64_to_double(const int64_t &_i) { i = _i; }
int64_t i;
double d;
};
void CompiledExpression::generateJitCode() {
const CpuInfo& cpu = CpuInfo::host();
if (!cpu.hasFeature(CpuFeatures::X86::kAVX))
@ -549,7 +556,7 @@ void CompiledExpression::generateJitCode() {
// Find the constant value (if any) used by this operation.
Operation& op = *operation[step];
double value = 0.0;
double value;
if (op.getId() == Operation::CONSTANT)
value = dynamic_cast<Operation::Constant&>(op).getValue();
else if (op.getId() == Operation::ADD_CONSTANT)
@ -562,10 +569,8 @@ void CompiledExpression::generateJitCode() {
value = 1.0;
else if (op.getId() == Operation::DELTA)
value = 1.0;
else if (op.getId() == Operation::ABS) {
long long mask = 0x7FFFFFFFFFFFFFFF;
memcpy(&value, &mask, sizeof(mask));
}
else if (op.getId() == Operation::ABS)
value = int64_to_double(0x7FFFFFFFFFFFFFFF).d;
else if (op.getId() == Operation::POWER_CONSTANT) {
if (stepGroup[step] == -1)
value = dynamic_cast<Operation::PowerConstant&>(op).getValue();

View File

@ -33,7 +33,6 @@
#include "lepton/Operation.h"
#include "lepton/ParsedExpression.h"
#include <algorithm>
#include <cstring>
#include <utility>
using namespace Lepton;
@ -574,6 +573,12 @@ void CompiledVectorExpression::generateTwoArgCall(a64::Compiler& c, arm::Vec& de
}
#else
union int_to_float {
int_to_float(const int &_i) { i = _i; }
int i;
float f;
};
void CompiledVectorExpression::generateJitCode() {
const CpuInfo& cpu = CpuInfo::host();
if (!cpu.hasFeature(CpuFeatures::X86::kAVX))
@ -611,7 +616,7 @@ void CompiledVectorExpression::generateJitCode() {
// Find the constant value (if any) used by this operation.
Operation& op = *operation[step];
double value = 0.0;
double value;
if (op.getId() == Operation::CONSTANT)
value = dynamic_cast<Operation::Constant&> (op).getValue();
else if (op.getId() == Operation::ADD_CONSTANT)
@ -624,10 +629,8 @@ void CompiledVectorExpression::generateJitCode() {
value = 1.0;
else if (op.getId() == Operation::DELTA)
value = 1.0;
else if (op.getId() == Operation::ABS) {
int mask = 0x7FFFFFFF;
memcpy(&value, &mask, sizeof(mask));
}
else if (op.getId() == Operation::ABS)
value = int_to_float(0x7FFFFFFF).f;
else if (op.getId() == Operation::POWER_CONSTANT) {
if (stepGroup[step] == -1)
value = dynamic_cast<Operation::PowerConstant&> (op).getValue();