From 5fd33d1f980dc32467bef87b31c6bacd30cab740 Mon Sep 17 00:00:00 2001 From: flatmush Date: Thu, 3 Mar 2011 11:51:10 +0000 Subject: Updated lerp6 and lerp16 (LinEar inteRPolation) to use the new int64 header so that it can be used with FIXMATH_NO_64BIT. Included "int64.h" in "fixmath.h" so that 64-bit integer support is now part of the libraries functionality. --- libfixmath/fix16.c | 21 ++++++++++----------- libfixmath/fix16.h | 2 +- libfixmath/fixmath.h | 1 + 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libfixmath/fix16.c b/libfixmath/fix16.c index d162554..91c5841 100644 --- a/libfixmath/fix16.c +++ b/libfixmath/fix16.c @@ -1,4 +1,5 @@ #include "fix16.h" +#include "int64.h" @@ -219,23 +220,21 @@ fix16_t fix16_sdiv(fix16_t inArg0, fix16_t inArg1) { -#ifndef FIXMATH_NO_64BIT fix16_t fix16_lerp8(fix16_t inArg0, fix16_t inArg1, uint8_t inFract) { - int64_t tempOut; - tempOut = ((int64_t)inArg0 * (256 - inFract)); - tempOut += ((int64_t)inArg1 * inFract); - tempOut >>= 8; - return (fix16_t)tempOut; + int64_t tempOut = int64_mul_i32_i32(inArg0, ((1 << 8) - inFract)); + tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract)); + tempOut = int64_shift(tempOut, -8); + return (fix16_t)int64_lo(tempOut); } fix16_t fix16_lerp16(fix16_t inArg0, fix16_t inArg1, uint16_t inFract) { - int64_t tempOut; - tempOut = ((int64_t)inArg0 * (fix16_one - inFract)); - tempOut += ((int64_t)inArg1 * inFract); - tempOut >>= 16; - return (fix16_t)tempOut; + int64_t tempOut = int64_mul_i32_i32(inArg0, ((1 << 16) - inFract)); + tempOut = int64_add(tempOut, int64_mul_i32_i32(inArg1, inFract)); + tempOut = int64_shift(tempOut, -16); + return (fix16_t)int64_lo(tempOut); } +#ifndef FIXMATH_NO_64BIT fix16_t fix16_lerp32(fix16_t inArg0, fix16_t inArg1, uint32_t inFract) { int64_t tempOut; tempOut = ((int64_t)inArg0 * (0 - inFract)); diff --git a/libfixmath/fix16.h b/libfixmath/fix16.h index 300bb72..dfb8cb7 100644 --- a/libfixmath/fix16.h +++ b/libfixmath/fix16.h @@ -72,11 +72,11 @@ extern fix16_t fix16_sdiv(fix16_t inArg0, fix16_t inArg1); -#ifndef FIXMATH_NO_64BIT /*! Returns the linear interpolation: (inArg0 * (1 - inFract)) + (inArg1 * inFract) */ extern fix16_t fix16_lerp8(fix16_t inArg0, fix16_t inArg1, uint8_t inFract); extern fix16_t fix16_lerp16(fix16_t inArg0, fix16_t inArg1, uint16_t inFract); +#ifndef FIXMATH_NO_64BIT extern fix16_t fix16_lerp32(fix16_t inArg0, fix16_t inArg1, uint32_t inFract); #endif diff --git a/libfixmath/fixmath.h b/libfixmath/fixmath.h index ed35f7d..cd0d20a 100644 --- a/libfixmath/fixmath.h +++ b/libfixmath/fixmath.h @@ -12,6 +12,7 @@ extern "C" */ #include "uint32.h" +#include "int64.h" #include "fract32.h" #include "fix16.h" -- cgit v1.2.3