Re: at2 swap_nibbles
Andreas Fink <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <[email protected]> |
On Dienstag, November 26, 2002, at 03:21 Uhr, Richard Braakman wrote: > On Mon, Nov 25, 2002 at 07:05:23PM +0100, Andreas Fink wrote: >> how about this: >> >> #define HI_NIBBLE(a) ( (int)a >> 4 & 0x0F) >> #define LOW_NIBBLE(a) ( (int)a & 0x0F) >> #define SWAP_NIBBLE(a) (( HI_NIBBLE(a) | (LOW_NIBBLE(a) << 4)) & 0xFF) >> >> This would work as a macro and has the advantage that the CPU can run >> it pretty much native. > > Except that casting to int brings back the original sign-extension bug > :) not really as we XOR away all the bits we don't need. > > If swap_nibbles is used only in the at2 driver, then you can make it a > static function and expect the compiler to inline it. If it's used in > multiple files, then it's better off as a real library function in > gwlib > somewhere. (octstr_swap_nibbles perhaps?) > > If you need a really fast nibble swapper, then a table lookup is > probably > best. It'll only be a 256-byte table. I wouldn't bother with that > kind > of optimization unless profiling shows that it matters. > > the table approach is an interesting idea. Anyhow, Oded, finish the patch in the way it works. If macro or function doesn't really matter. I really wonder why the AT driver works at all right now with this bug. Andreas Fink Fink Consulting GmbH --------------------------------------------------------------- Tel: +41-61-6666332 Fax: +41-61-6666331 Mobile: +41-79-2457333 Address: Clarastrasse 3, 4058 Basel, Switzerland E-Mail: [email protected] Homepage: http://www.finkconsulting.com ---------------------------------------------------------------