eina: Eina_Fp API + Eina_Mempool TODOS

This commit is contained in:
Ghislain Loaec 2014-10-02 10:25:26 +02:00 committed by Cedric BAIL
parent 7dd6c353e2
commit 0001e36d39
3 changed files with 510 additions and 81 deletions

View File

@ -20,6 +20,24 @@
#ifndef EINA_FP_H_
# define EINA_FP_H_
/**
* @addtogroup Eina_Data_Types_Group Data Types
*
* @{
*/
/**
* @addtogroup Eina_Containers_Group Containers
*
* @{
*/
/**
* @defgroup Eina_Hash_Group Fp
*
* @{
*/
#include "eina_types.h"
#ifdef _MSC_VER
@ -32,81 +50,414 @@ typedef signed int int32_t;
#define EINA_F32P32_PI 0x00000003243f6a89
/**
* @typedef Eina_F32p32
* Type for floating point number where the size of the integer part is 32bits
* and the size of the decimal part is 32bits
*/
typedef int64_t Eina_F32p32;
/**
* @typedef Eina_F16p16
* Type for floating point number where the size of the integer part is 16bits
* and the size of the decimal part is 16bits
*/
typedef int32_t Eina_F16p16;
/**
* @typedef Eina_F8p24
* Type for floating point number where the size of the integer part is 8bits
* and the size of the decimal part is 24bits
*/
typedef int32_t Eina_F8p24;
/**
* @brief Create a new Eina_F32p32 floating point number from standard 32 bits
* integer
*
* @param v 32bits integer value to convert
* @return The value converted into Eina_F32p32 format
*/
static inline Eina_F32p32 eina_f32p32_int_from(int32_t v);
/**
* @brief Create a new standard 32bits integer from Eina_F32p32 floating point
* number
*
* @param v Eina_F32p32 value to convert
* @return The value converted into 32bits integer
*/
static inline int32_t eina_f32p32_int_to(Eina_F32p32 v);
/**
* @brief Create a new Eina_F32p32 floating point number from standard double
*
* @param v double value to convert
* @return The value converted into Eina_F32p32 format
*/
static inline Eina_F32p32 eina_f32p32_double_from(double v);
/**
* @brief Create a new standard double from Eina_F32p32 floating point
* number
*
* @param v Eina_F32p32 value to convert
* @return The value converted into double
*/
static inline double eina_f32p32_double_to(Eina_F32p32 v);
static inline Eina_F32p32 eina_f32p32_add(Eina_F32p32 a,
Eina_F32p32 b);
static inline Eina_F32p32 eina_f32p32_sub(Eina_F32p32 a,
Eina_F32p32 b);
static inline Eina_F32p32 eina_f32p32_mul(Eina_F32p32 a,
Eina_F32p32 b);
static inline Eina_F32p32 eina_f32p32_scale(Eina_F32p32 a,
int b);
static inline Eina_F32p32 eina_f32p32_div(Eina_F32p32 a,
Eina_F32p32 b);
/**
* @brief Calculates the sum of two Eina_F32p32 floating point numbers
*
* @param a The first number
* @param b The second number
* @return The sum result of the two numbers @p a + @p b
*/
static inline Eina_F32p32 eina_f32p32_add(Eina_F32p32 a, Eina_F32p32 b);
/**
* @brief Calculates the substraction of two Eina_F32p32 floating point numbers
*
* @param a The first number
* @param b The substracted number
* @return The substaction result of the two numbers @p a - @p b
*/
static inline Eina_F32p32 eina_f32p32_sub(Eina_F32p32 a, Eina_F32p32 b);
/**
* @brief Calculates the multiplication of two Eina_F32p32 floating point numbers
*
* @param a The first number
* @param b The second number
* @return The mutliplication result of the two numbers @p a * @p b
*
* To prevent overflow during multiplication we need to reduce the precision of
* the fraction part Shift both values to only contain 16 bit of the fraction
* part (rounded). After multiplication we again have a value with a 32-bit
* fraction part.
*/
static inline Eina_F32p32 eina_f32p32_mul(Eina_F32p32 a, Eina_F32p32 b);
/**
* @brief Calculates the scale multiplication of one Eina_F32p32 floating point
* number with an integer
*
* @param a The Eina_F32p32 number
* @param b The integer value
* @return The mutliplication result of the two numbers @p a * @p b
*/
static inline Eina_F32p32 eina_f32p32_scale(Eina_F32p32 a, int b);
/**
* @brief Calculates the division of two Eina_F32p32 floating point numbers
*
* @param a The numerator number
* @param b The denominator number
* @return The division result of the two numbers @p a / @p b
*/
static inline Eina_F32p32 eina_f32p32_div(Eina_F32p32 a, Eina_F32p32 b);
/**
* @brief Calculates the square root of an Eina_F32p32 floating point number
*
* @param a The number to calculate the square root from
* @return The square root result for the number @p a
*/
static inline Eina_F32p32 eina_f32p32_sqrt(Eina_F32p32 a);
/**
* @brief Get the absolute value of the integer part of and Eina_F32p32 floating
* point number
*
* @param a The floating point number
* @return The positive integer part of the number @p a
*/
static inline unsigned int eina_f32p32_fracc_get(Eina_F32p32 v);
// dont use llabs - issues if not on 64bit
#define eina_fp32p32_llabs(a) ((a < 0) ? -(a) : (a))
/**
* @brief Calculates the cosinus of a floating point number
*
* @param a The angle in radians to calculate the cosinus from.
* @return The cosinus value of the angle @p a
*/
EAPI Eina_F32p32 eina_f32p32_cos(Eina_F32p32 a);
/**
* @brief Calculates the sinus of a floating point number
*
* @param a The angle in radians to calculate the sinus from.
* @return The cosinus value of the angle @p a
*/
EAPI Eina_F32p32 eina_f32p32_sin(Eina_F32p32 a);
#define EINA_F16P16_ONE (1 << 16)
#define EINA_F16P16_HALF (1 << 15)
/**
* @brief Create a new Eina_F16p316 floating point number from standard 32 bits
* integer
*
* @param v 32bits integer value to convert
* @return The value converted into Eina_F16p16 format
*/
static inline Eina_F16p16 eina_f16p16_int_from(int32_t v);
/**
* @brief Create a new standard 32bits integer from Eina_F16p16 floating point
* number
*
* @param v Eina_F16p16 value to convert
* @return The value converted into 32bits integer
*/
static inline int32_t eina_f16p16_int_to(Eina_F16p16 v);
/**
* @brief Create a new Eina_F16p16 floating point number from standard double
*
* @param v double value to convert
* @return The value converted into Eina_F16p16 format
*/
static inline Eina_F16p16 eina_f16p16_double_from(double v);
/**
* @brief Create a new standard double from Eina_F16p16 floating point
* number
*
* @param v Eina_F16p16 value to convert
* @return The value converted into double
*/
static inline double eina_f16p16_double_to(Eina_F16p16 v);
/**
* @brief Create a new Eina_F16p16 floating point number from standard float
*
* @param v float value to convert
* @return The value converted into Eina_F16p16 format
*/
static inline Eina_F16p16 eina_f16p16_float_from(float v);
/**
* @brief Create a new standard float from Eina_F16p16 floating point
* number
*
* @param v Eina_F16p16 value to convert
* @return The value converted into float
*/
static inline float eina_f16p16_float_to(Eina_F16p16 v);
static inline Eina_F16p16 eina_f16p16_add(Eina_F16p16 a,
Eina_F16p16 b);
static inline Eina_F16p16 eina_f16p16_sub(Eina_F16p16 a,
Eina_F16p16 b);
static inline Eina_F16p16 eina_f16p16_mul(Eina_F16p16 a,
Eina_F16p16 b);
static inline Eina_F16p16 eina_f16p16_scale(Eina_F16p16 a,
int b);
static inline Eina_F16p16 eina_f16p16_div(Eina_F16p16 a,
Eina_F16p16 b);
/**
* @brief Calculates the sum of two Eina_F16p16 floating point numbers
*
* @param a The first number
* @param b The second number
* @return The sum result of the two numbers @p a + @p b
*/
static inline Eina_F16p16 eina_f16p16_add(Eina_F16p16 a, Eina_F16p16 b);
/**
* @brief Calculates the substraction of two Eina_F16p16 floating point numbers
*
* @param a The first number
* @param b The substracted number
* @return The substaction result of the two numbers @p a - @p b
*/
static inline Eina_F16p16 eina_f16p16_sub(Eina_F16p16 a, Eina_F16p16 b);
/**
* @brief Calculates the multiplication of two Eina_F16p16 floating point numbers
*
* @param a The first number
* @param b The second number
* @return The mutliplication result of the two numbers @p a * @p b
*/
static inline Eina_F16p16 eina_f16p16_mul(Eina_F16p16 a, Eina_F16p16 b);
/**
* @brief Calculates the scale multiplication of one Eina_F16p16 floating point
* number with an integer
*
* @param a The Eina_F16p16 number
* @param b The integer value
* @return The mutliplication result of the two numbers @p a * @p b
*/
static inline Eina_F16p16 eina_f16p16_scale(Eina_F16p16 a, int b);
/**
* @brief Calculates the division of two Eina_F16p16 floating point numbers
*
* @param a The numerator number
* @param b The denominator number
* @return The division result of the two numbers @p a / @p b
*/
static inline Eina_F16p16 eina_f16p16_div(Eina_F16p16 a, Eina_F16p16 b);
/**
* @brief Calculates the square root of an Eina_F16p16 floating point number
*
* @param a The number to calculate the square root from
* @return The square root result for the number @p a
*/
static inline Eina_F16p16 eina_f16p16_sqrt(Eina_F16p16 a);
/**
* @brief Get the absolute value of the integer part of and Eina_F16p16 floating
* point number
*
* @param a The floating point number
* @return The positive integer part of the number @p a
*/
static inline unsigned int eina_f16p16_fracc_get(Eina_F16p16 v);
/**
* @brief Create a new Eina_F16p316 floating point number from standard 32 bits
* integer
*
* @param v 32bits integer value to convert
* @return The value converted into Eina_F8p24 format
*/
static inline Eina_F8p24 eina_f8p24_int_from(int32_t v);
/**
* @brief Create a new standard 32bits integer from Eina_F8p24 floating point
* number
*
* @param v Eina_F8p24 value to convert
* @return The value converted into 32bits integer
*/
static inline int32_t eina_f8p24_int_to(Eina_F8p24 v);
/**
* @brief Create a new Eina_F8p24 floating point number from standard float
*
* @param v float value to convert
* @return The value converted into Eina_F8p24 format
*/
static inline Eina_F8p24 eina_f8p24_float_from(float v);
/**
* @brief Create a new standard float from Eina_F8p24 floating point
* number
*
* @param v Eina_F8p24 value to convert
* @return The value converted into float
*/
static inline float eina_f8p24_float_to(Eina_F8p24 v);
static inline Eina_F8p24 eina_f8p24_add(Eina_F8p24 a,
Eina_F8p24 b);
static inline Eina_F8p24 eina_f8p24_sub(Eina_F8p24 a,
Eina_F8p24 b);
static inline Eina_F8p24 eina_f8p24_mul(Eina_F8p24 a,
Eina_F8p24 b);
static inline Eina_F8p24 eina_f8p24_scale(Eina_F8p24 a,
int b);
static inline Eina_F8p24 eina_f8p24_div(Eina_F8p24 a,
Eina_F8p24 b);
/**
* @brief Calculates the sum of two Eina_F8p24 floating point numbers
*
* @param a The first number
* @param b The second number
* @return The sum result of the two numbers @p a + @p b
*/
static inline Eina_F8p24 eina_f8p24_add(Eina_F8p24 a, Eina_F8p24 b);
/**
* @brief Calculates the substraction of two Eina_F8p24 floating point numbers
*
* @param a The first number
* @param b The substracted number
* @return The substaction result of the two numbers @p a - @p b
*/
static inline Eina_F8p24 eina_f8p24_sub(Eina_F8p24 a, Eina_F8p24 b);
/**
* @brief Calculates the multiplication of two Eina_F8p24 floating point numbers
*
* @param a The first number
* @param b The second number
* @return The mutliplication result of the two numbers @p a * @p b
*/
static inline Eina_F8p24 eina_f8p24_mul(Eina_F8p24 a, Eina_F8p24 b);
/**
* @brief Calculates the scale multiplication of one Eina_F8p24 floating point
* number with an integer
*
* @param a The Eina_F16p16 number
* @param b The integer value
* @return The mutliplication result of the two numbers @p a * @p b
*/
static inline Eina_F8p24 eina_f8p24_scale(Eina_F8p24 a, int b);
/**
* @brief Calculates the division of two Eina_F8p24 floating point numbers
*
* @param a The numerator number
* @param b The denominator number
* @return The division result of the two numbers @p a / @p b
*/
static inline Eina_F8p24 eina_f8p24_div(Eina_F8p24 a, Eina_F8p24 b);
/**
* @brief Calculates the square root of an Eina_F8p24 floating point number
*
* @param a The number to calculate the square root from
* @return The square root result for the number @p a
*/
static inline Eina_F8p24 eina_f8p24_sqrt(Eina_F8p24 a);
/**
* @brief Get the absolute value of the integer part of and Eina_F8p24 floating
* point number
*
* @param a The floating point number
* @return The positive integer part of the number @p a
*/
static inline unsigned int eina_f8p24_fracc_get(Eina_F8p24 v);
/**
* @brief Converts an Eina_F16p16 floating point number into Eina_F32p32 format
*
* @param a The Eina_F16p16 floating point number
* @return The converted Eina_F32p32 floating point number
*/
static inline Eina_F32p32 eina_f16p16_to_f32p32(Eina_F16p16 a);
/**
* @brief Converts an Eina_F8p24 floating point number into Eina_F32p32 format
*
* @param a The Eina_F8p24 floating point number
* @return The converted Eina_F32p32 floating point number
*/
static inline Eina_F32p32 eina_f8p24_to_f32p32(Eina_F8p24 a);
/**
* @brief Converts an Eina_F32p32 floating point number into Eina_F16p16 format
*
* @param a The Eina_F32p32 floating point number
* @return The converted Eina_F16p16 floating point number
*/
static inline Eina_F16p16 eina_f32p32_to_f16p16(Eina_F32p32 a);
/**
* @brief Converts an Eina_F8p24 floating point number into Eina_F16p16 format
*
* @param a The Eina_F8p24 floating point number
* @return The converted Eina_F16p16 floating point number
*/
static inline Eina_F16p16 eina_f8p24_to_f16p16(Eina_F8p24 a);
/**
* @brief Converts an Eina_F32p32 floating point number into Eina_F8p24 format
*
* @param a The Eina_F32p32 floating point number
* @return The converted Eina_F8p16 floating point number
*/
static inline Eina_F8p24 eina_f32p32_to_f8p24(Eina_F32p32 a);
/**
* @brief Converts an Eina_F16p16 floating point number into Eina_F8p16 format
*
* @param a The Eina_F16p16 floating point number
* @return The converted Eina_F8p16 floating point number
*/
static inline Eina_F8p24 eina_f16p16_to_f8p24(Eina_F16p16 a);
#include "eina_inline_f32p32.x"
@ -114,4 +465,11 @@ static inline Eina_F8p24 eina_f16p16_to_f8p24(Eina_F16p16 a);
#include "eina_inline_f8p24.x"
#include "eina_inline_fp.x"
/**
* @}
*/
/**
* @}
*/
#endif

View File

@ -68,53 +68,18 @@ struct _Eina_Mempool
Eina_Mempool_Backend_ABI2 *backend2;
};
/**
* @brief Re-allocate an amount memory by the given mempool.
*
* @param mp The mempool.
* @param element The element to re-allocate.
* @param size The size in bytes to re-allocate.
* @return The newly re-allocated data.
*
* This function re-allocates and returns @p element with @p size bytes using the
* mempool @p mp. If not used anymore, the data must be freed with eina_mempool_free().
* @warning No checks are done for @p mp.
*/
static inline void *
eina_mempool_realloc(Eina_Mempool *mp, void *element, unsigned int size)
{
return mp->backend.realloc(mp->backend_data, element, size);
}
/**
* @brief Allocate memory using the given mempool.
*
* @param mp The mempool.
* @param size The size in bytes to allocate.
* @return The newly allocated data.
*
* This function allocates and returns @p size bytes using the mempool @p mp.
* If not used anymore, the data must be freed with eina_mempool_free().
* @warning No checks are done for @p mp.
*/
static inline void *
eina_mempool_malloc(Eina_Mempool *mp, unsigned int size)
{
return mp->backend.alloc(mp->backend_data, size);
}
/**
* @brief Allocate and zero memory using the given mempool.
*
* @param mp The mempool.
* @param size The size in bytes to allocate.
* @return The newly allocated data.
*
* This function allocates, zeroes, and returns @p size bytes using the mempool @p mp.
* If not used anymore, the data must be freed with eina_mempool_free().
* @warning No checks are done for @p mp.
* @since 1.2
*/
static inline void *
eina_mempool_calloc(Eina_Mempool *mp, unsigned int size)
{
@ -124,17 +89,6 @@ eina_mempool_calloc(Eina_Mempool *mp, unsigned int size)
return r;
}
/**
* @brief Free resources previously allocated by the given mempool.
*
* @param mp The mempool.
* @param element The data to free.
*
* This function frees @p element allocated by @p mp. @p element must
* have been obtained from eina_mempool_malloc(), eina_mempool_calloc(), or
* eina_mempool_realloc().
* @warning No checks are done for @p mp.
*/
static inline void
eina_mempool_free(Eina_Mempool *mp, void *element)
{

View File

@ -39,8 +39,8 @@
* @li @c pass_through: it just call malloc() and free(). It may be
* faster on some computers than using our own allocators (like having
* a huge L2 cache, over 4MB).
* @li @c one_big: It call just one time malloc for the requested number
* of items. Useful when you know in advance how many object of some
* @li @c one_big: It calls just one time malloc for the requested number
* of items. Useful when you know in advance how many objects of some
* type will live during the life of the mempool.
*/
@ -78,22 +78,139 @@ typedef void (*Eina_Mempool_Repack_Cb)(void *dst, void *src, void *data);
EAPI extern Eina_Error EINA_ERROR_NOT_MEMPOOL_MODULE;
/**
*
* @brief TODO
*
* @param module
* @param context
* @param options
* @return Newly allocated mempool instance, NULL otherwise.
*
*/
EAPI Eina_Mempool *eina_mempool_add(const char *module, const char *context, const char *options, ...) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
/**
*
* @brief TODO
*
* @param mp The mempools
*
*/
EAPI void eina_mempool_del(Eina_Mempool *mp) EINA_ARG_NONNULL(1);
/**
* @brief Re-allocate an amount memory by the given mempool.
*
* @param mp The mempool.
* @param element The element to re-allocate.
* @param size The size in bytes to re-allocate.
* @return The newly re-allocated data.
*
* This function re-allocates and returns @p element with @p size bytes using the
* mempool @p mp. If not used anymore, the data must be freed with eina_mempool_free().
* @warning No checks are done for @p mp.
*/
static inline void *eina_mempool_realloc(Eina_Mempool *mp, void *element, unsigned int size) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
/**
* @brief Allocate memory using the given mempool.
*
* @param mp The mempool.
* @param size The size in bytes to allocate.
* @return The newly allocated data.
*
* This function allocates and returns @p size bytes using the mempool @p mp.
* If not used anymore, the data must be freed with eina_mempool_free().
* @warning No checks are done for @p mp.
*/
static inline void *eina_mempool_malloc(Eina_Mempool *mp, unsigned int size) EINA_MALLOC EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
/**
* @brief Allocate and zero memory using the given mempool.
*
* @param mp The mempool.
* @param size The size in bytes to allocate.
* @return The newly allocated data.
*
* This function allocates, zeroes, and returns @p size bytes using the mempool @p mp.
* If not used anymore, the data must be freed with eina_mempool_free().
* @warning No checks are done for @p mp.
* @since 1.2
*/
static inline void *eina_mempool_calloc(Eina_Mempool *mp, unsigned int size) EINA_MALLOC EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
/**
* @brief Free resources previously allocated by the given mempool.
*
* @param mp The mempool.
* @param element The data to free.
*
* This function frees @p element allocated by @p mp. @p element must
* have been obtained from eina_mempool_malloc(), eina_mempool_calloc(), or
* eina_mempool_realloc().
* @warning No checks are done for @p mp.
*/
static inline void eina_mempool_free(Eina_Mempool *mp, void *element) EINA_ARG_NONNULL(1);
EAPI void eina_mempool_repack(Eina_Mempool *mp,
Eina_Mempool_Repack_Cb cb,
void *data) EINA_ARG_NONNULL(1, 2);
/**
*
* @brief TODO
*
* @param mp The mempool
* @param cb The after repack callback
* @param data The data
*
*/
EAPI void eina_mempool_repack(Eina_Mempool *mp, Eina_Mempool_Repack_Cb cb, void *data) EINA_ARG_NONNULL(1, 2);
/**
*
* @brief TODO (garbage collect)
*
* @param mp The mempool
*
*/
EAPI void eina_mempool_gc(Eina_Mempool *mp) EINA_ARG_NONNULL(1);
/**
*
* @brief TODO
*
* @param mp The mempool
*
*/
EAPI void eina_mempool_statistics(Eina_Mempool *mp) EINA_ARG_NONNULL(1);
/**
*
* @brief TODO
*
* @param be The backend
* @return #EINA_TRUE if backend has been correctly registered, #EINA_FALSE
* otherwise.
*
*/
EAPI Eina_Bool eina_mempool_register(Eina_Mempool_Backend *be) EINA_ARG_NONNULL(1);
/**
*
* @brief TODO
*
* @param be The backend
*
*/
EAPI void eina_mempool_unregister(Eina_Mempool_Backend *be) EINA_ARG_NONNULL(1);
/**
*
* @brief TODO
*
* @param size
* @return #EINA_TRUE if backend has been correctly registered, #EINA_FALSE
* otherwise.
*
*/
static inline unsigned int eina_mempool_alignof(unsigned int size);
#include "eina_inline_mempool.x"