[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] possible 4.1.2 bug
From: |
John Regehr |
Subject: |
RE: [avr-gcc-list] possible 4.1.2 bug |
Date: |
Wed, 28 Mar 2007 22:48:44 -0600 (MDT) |
Hi Eric-
I went and looked at the original code and it does use a 32-bit int, see
below. I screwed this up while creating a small example to send to the
list -- the specific case I was looking at casts a 16-bit int into 32 and
I propagated the smaller variable too far forwards.
Not clear by how much this beats divide-by-4096 using avr-gcc intrinsics,
but I imagine by a good bit (assuming it's correct).
This is from the "Megasquirt AVR" firmware that I've been messing with.
Open-source engine control -- fun stuff.
John Regehr
static inline uint16_t div4096(uint32_t a) {
uint16_t result;
asm(
"\n"
"swap %B1 \n\t"
"swap %C1 \n\t"
"swap %D1 \n\t"
"ldi %A1, 0xf0 \n\t"
"eor %D1, %C1 \n\t"
"and %D1, %A1 \n\t"
"eor %D1, %C1 \n\t"
"eor %C1, %B1 \n\t"
"and %C1, %A1 \n\t"
"eor %C1, %B1 \n\t"
"movw %A0, %C1 \n\t"
: "=&r" (result)
: "r" (a)
);
return result;
}