Contains code for a floating point emulation. More...
#include "global.hpp"
#include "util.hpp"
#include <SDL_types.h>
#include <boost/utility/enable_if.hpp>
#include <cassert>
#include <cmath>
Go to the source code of this file.
Classes | |
class | floating_point_emulation::tfloat< T, S > |
Template class for the emulation. More... | |
struct | floating_point_emulation::detail::tscale< T, S, E > |
struct | floating_point_emulation::detail::tscale< T, 0 > |
struct | floating_point_emulation::detail::tscale< double, S, typename boost::enable_if_c< S!=0 >::type > |
struct | floating_point_emulation::detail::tscale< Sint32, S, typename boost::enable_if_c< S!=0 >::type > |
struct | floating_point_emulation::detail::tfloor< T, S > |
struct | floating_point_emulation::detail::tfloor< double, S > |
struct | floating_point_emulation::detail::tfloor< Sint32, S > |
struct | floating_point_emulation::detail::tidiv< T, S > |
struct | floating_point_emulation::detail::tidiv< T, 8 > |
class | floating_point_emulation::tfloat< T, S > |
Template class for the emulation. More... | |
Namespaces | |
floating_point_emulation | |
floating_point_emulation::detail | |
Macros | |
#define | FLOATING_POINT_EMULATION_RANGE_CHECK_THROW |
#define | FLOATING_POINT_EMULATION_RANGE_CHECK |
#define | FLOATING_POINT_EMULATION_RANGE_CHECK_OBJECT(object) |
#define | FLOATING_POINT_EMULATION_TRACER_ENTRY(interval) |
#define | FLOATING_POINT_EMULATION_TRACER_COUNT(marker) |
Typedefs | |
typedef floating_point_emulation::tfloat < double, 0 > | tfloat |
Functions | |
template<class T , unsigned S> | |
T | floating_point_emulation::detail::load (int value) |
template<class T , unsigned S> | |
T | floating_point_emulation::detail::load (double value) |
template<class R , class T , unsigned S> | |
R | floating_point_emulation::detail::store (T value) |
void | floating_point_emulation::detail::sal (double &lhs, unsigned rhs) |
Shift arithmetically left. More... | |
void | floating_point_emulation::detail::sal (Sint32 &lhs, unsigned rhs) |
Shift arithmetically left. More... | |
void | floating_point_emulation::detail::sar (double &lhs, unsigned rhs) |
Shift arithmetically right. More... | |
void | floating_point_emulation::detail::sar (Sint32 &lhs, unsigned rhs) |
Shift arithmetically right. More... | |
template<class T , unsigned S> | |
bool | floating_point_emulation::operator== (const int lhs, const tfloat< T, S > rhs) |
template<class T , unsigned S> | |
bool | floating_point_emulation::operator== (const double lhs, const tfloat< T, S > rhs) |
template<class T , unsigned S> | |
bool | floating_point_emulation::operator!= (const int lhs, const tfloat< T, S > rhs) |
template<class T , unsigned S> | |
bool | floating_point_emulation::operator!= (const double lhs, const tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator* (tfloat< T, S > lhs, const tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator* (tfloat< T, S > lhs, const int rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator* (tfloat< T, S > lhs, const double rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator* (const int lhs, tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator* (const double lhs, tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator/ (tfloat< T, S > lhs, const tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator/ (tfloat< T, S > lhs, const int rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator/ (tfloat< T, S > lhs, const double rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator/ (const int lhs, tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator/ (const double lhs, tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator+ (tfloat< T, S > lhs, const tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator+ (tfloat< T, S > lhs, const int rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator+ (tfloat< T, S > lhs, const double rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator+ (const int lhs, const tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator+ (const double lhs, const tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator- (tfloat< T, S > lhs, const tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator- (tfloat< T, S > lhs, const int rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator- (tfloat< T, S > lhs, const double rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator- (const int lhs, tfloat< T, S > rhs) |
template<class T , unsigned S> | |
tfloat< T, S > | floating_point_emulation::operator- (const double lhs, tfloat< T, S > rhs) |
template<class T , unsigned S> | |
int | floating_point_emulation::floor (tfloat< T, S > lhs) |
Contains code for a floating point emulation.
Depending on some compiler switches the code can use floating point code or fixed point code. The code is still work-in-progress.
At the moment three emulation modi are supported:
double
, not shifted.double
, shifted 8 bits (for debugging).In the comments some conventions are used:
There are several define's to control the compilation.
FLOATING_POINT_EMULATION_USE_SCALED_INT When this macro is defined the tfloat is defined as the 32-bit scaled integer. If not the tfloat is defined as a double
, whether or not the value is shifted depends on FLOATING_POINT_EMULATION_ENABLE_RANGE_CHECK
.
FLOATING_POINT_EMULATION_ENABLE_RANGE_CHECK This macro can only be defined if FLOATING_POINT_EMULATION_USE_SCALED_INT
is not defined. This macro shifts the doubles
so it can be checked against the range of the scaled int. (It would have been possible to scale the validation range as well, but this feels easier to check.)
FLOATING_POINT_EMULATION_ENABLE_RANGE_CHECK_THROW This macro can only be defined if FLOATING_POINT_EMULATION_ENABLE_RANGE_CHECK
is defined. Instead of printing a warning and then go on it throws an exception if the range check fails. This is intended to aid debugging and should not be enabled in production code.
FLOATING_POINT_EMULATION_TRACER_ENABLE This macro allows to place trace markers in the code. When using the markers it's possible to gather statistics regarding the code paths being executed. This can be used to analyze execution and add branch prediction markers.
Definition in file floating_point_emulation.hpp.
#define FLOATING_POINT_EMULATION_RANGE_CHECK |
Definition at line 118 of file floating_point_emulation.hpp.
Referenced by floating_point_emulation::tfloat< T, S >::operator*=(), floating_point_emulation::tfloat< T, S >::operator+=(), floating_point_emulation::tfloat< T, S >::operator-=(), floating_point_emulation::tfloat< T, S >::operator/=(), floating_point_emulation::tfloat< T, S >::operator=(), and floating_point_emulation::tfloat< T, S >::tfloat().
#define FLOATING_POINT_EMULATION_RANGE_CHECK_OBJECT | ( | object | ) |
Definition at line 121 of file floating_point_emulation.hpp.
Referenced by floating_point_emulation::detail::tidiv< T, S >::idiv(), and floating_point_emulation::detail::tidiv< T, 8 >::idiv().
#define FLOATING_POINT_EMULATION_RANGE_CHECK_THROW |
Definition at line 90 of file floating_point_emulation.hpp.
#define FLOATING_POINT_EMULATION_TRACER_COUNT | ( | marker | ) |
Definition at line 135 of file floating_point_emulation.hpp.
Referenced by floating_point_emulation::detail::tidiv< T, 8 >::idiv().
#define FLOATING_POINT_EMULATION_TRACER_ENTRY | ( | interval | ) |
Definition at line 131 of file floating_point_emulation.hpp.
Referenced by floating_point_emulation::detail::tidiv< T, 8 >::idiv().
typedef floating_point_emulation::tfloat<double, 0> tfloat |
Definition at line 1158 of file floating_point_emulation.hpp.