From c010d773fc239bd74f177acde5341baa5cbd784f Mon Sep 17 00:00:00 2001 From: schodet Date: Sun, 9 Oct 2005 12:42:47 +0000 Subject: Ajout de l'arondie sur la multiplication. --- n/avr/modules/math/fixed/fixed.h | 3 ++- n/avr/modules/math/fixed/fixed_mul_f824.avr.S | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'n/avr/modules/math') diff --git a/n/avr/modules/math/fixed/fixed.h b/n/avr/modules/math/fixed/fixed.h index 9c031dc..2337b1c 100644 --- a/n/avr/modules/math/fixed/fixed.h +++ b/n/avr/modules/math/fixed/fixed.h @@ -54,7 +54,8 @@ fixed_div_f824 (int32_t a, int32_t b); #else /* HOST */ /** Multiply f8.24 by f8.24, return f8.24. */ -#define fixed_mul_f824(a, b) (((uint64_t) (a) * (uint64_t) (b)) >> 24) +#define fixed_mul_f824(a, b) (((uint64_t) (a) * (uint64_t) (b) \ + + 0x800000LL) >> 24) /** Divide f8.24 by f8.24, return f8.24. */ #define fixed_div_f824(a, b) (((uint64_t) (a) << 24) / (uint64_t) (b)) diff --git a/n/avr/modules/math/fixed/fixed_mul_f824.avr.S b/n/avr/modules/math/fixed/fixed_mul_f824.avr.S index 853dcb6..9da807d 100644 --- a/n/avr/modules/math/fixed/fixed_mul_f824.avr.S +++ b/n/avr/modules/math/fixed/fixed_mul_f824.avr.S @@ -51,10 +51,11 @@ ; avoided. ; All multiplications results are added together. If the result is negative, ; do the sign extension (the sbc instructions). +; Result is rounded to the nearest value. ; ; Perfs: -; 91 cycles -; 10989 per second, per MHz +; 96 cycles +; 10416 per second, per MHz #define dummy1 r25 #define dummy0 r24 @@ -111,6 +112,11 @@ fixed_mul_f824_asm: add m1, r0 adc m2, r1 adc m3, z +; Rounding, m0 is dropped. + ldi m0, 0x80 + add m1, m0 + adc m2, z + adc m3, z ; Shift. movw m0, m2 ; Upper word. -- cgit v1.2.3