Skip to content

Commit

Permalink
Improved trunc() function when no SSE4.1 is available
Browse files Browse the repository at this point in the history
Instead adding / substracting a magic constant, trunc() can now
take advantage of scalar conversion to 64-bit integer and back,
and use that instead.

In addition, changed some minor source code conventions.
  • Loading branch information
kobalicek committed Sep 1, 2023
1 parent 84e4b70 commit 24d60e5
Show file tree
Hide file tree
Showing 19 changed files with 686 additions and 926 deletions.
59 changes: 19 additions & 40 deletions src/mathpresso/mathpresso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@

namespace mathpresso {

// ============================================================================
// [mathpresso::mpOpInfo]
// ============================================================================
// mathPresso - OpInfo
// ===================

// Operator information, precedence and association. The table is mostly based
// on the C-language standard, but also adjusted to support MATHPRESSO specific
Expand Down Expand Up @@ -103,9 +102,8 @@ const OpInfo mpOpInfo[kOpCount] = {
#undef LTR
#undef ROW

// ============================================================================
// [mathpresso::mpAssertionFailure]
// ============================================================================
// MathPresso - Assertions
// =======================

void mpAssertionFailure(const char* file, int line, const char* msg) {
fprintf(stderr,
Expand All @@ -115,17 +113,15 @@ void mpAssertionFailure(const char* file, int line, const char* msg) {
::abort();
}

// ============================================================================
// [mathpresso::mpTraceError]
// ============================================================================
// MathPresso - Tracing
// ====================

MATHPRESSO_NOAPI Error mpTraceError(Error error) {
return error;
}

// ============================================================================
// [mathpresso::mpDummyFunc]
// ============================================================================
// MathPresso - Dummy Function
// ===========================

//! \internal
//!
Expand All @@ -136,9 +132,8 @@ static void mpDummyFunc(double* result, void*) {
*result = mpGetNan();
}

// ============================================================================
// [mathpresso::ContextInternalImpl]
// ============================================================================
// MathPresso - Context Impl
// =========================

//! \internal
//!
Expand Down Expand Up @@ -245,9 +240,8 @@ static Error mpContextMutable(Context* self, ContextInternalImpl** out) {
}
}

// ============================================================================
// [mathpresso::Context - Construction / Destruction]
// ============================================================================
// MathPresso - Context API
// ========================

Context::Context()
: _d(const_cast<ContextImpl*>(&mpContextNull)) {}
Expand All @@ -259,10 +253,6 @@ Context::~Context() {
mpContextRelease(_d);
}

// ============================================================================
// [mathpresso::Context - Copy / Reset]
// ============================================================================

Error Context::reset() {
mpContextRelease(
mpAtomicSetXchgT<ContextImpl*>(
Expand All @@ -278,10 +268,6 @@ Context& Context::operator=(const Context& other) {
return *this;
}

// ============================================================================
// [mathpresso::Context - Interface]
// ============================================================================

struct GlobalConstant {
char name[8];
double value;
Expand Down Expand Up @@ -414,17 +400,12 @@ Error Context::delSymbol(const char* name) {
return kErrorOk;
}

// ============================================================================
// [mathpresso::Expression - Construction / Destruction]
// ============================================================================
// MathPresso - Expression API
// ===========================

Expression::Expression() : _func(mpDummyFunc) {}
Expression::~Expression() { reset(); }

// ============================================================================
// [mathpresso::Expression - Interface]
// ============================================================================

Error Expression::compile(const Context& ctx, const char* body, unsigned int options, OutputLog* log) {
// Init options first.
options &= _kOptionsMask;
Expand Down Expand Up @@ -491,16 +472,14 @@ void Expression::reset() {
}
}

// ============================================================================
// [mathpresso::OutputLog - Construction / Destruction]
// ============================================================================
// MathPresso - OutputLog - API
// ============================

OutputLog::OutputLog() {}
OutputLog::~OutputLog() {}

// ============================================================================
// [mathpresso::ErrorReporter - Interface]
// ============================================================================
// MathPresso - Error Reporter API
// ===============================

void ErrorReporter::getLineAndColumn(uint32_t position, uint32_t& line, uint32_t& column) {
// Should't happen, but be defensive.
Expand Down Expand Up @@ -583,4 +562,4 @@ Error ErrorReporter::onError(Error error, uint32_t position, const String& msg)
return MATHPRESSO_TRACE_ERROR(error);
}

} // mathpresso namespace
} // {mathpresso}
Loading

0 comments on commit 24d60e5

Please sign in to comment.