Re: RE : RE : [fpc-pascal] Reversing bit-order of byte

2012-05-07 Thread Koenraad Lelong
On 04-05-12 14:53, Koenraad Lelong wrote: On 04-05-12 14:31, Thomas Schatzl wrote: ... Compared to the other variants (e.g. with the multiplies, except for the table lookup) you already save a lot of cycles - although I guess they would be sufficiently fast anyway, considering the typical

Re: RE : RE : [fpc-pascal] Reversing bit-order of byte

2012-05-07 Thread Geoffrey Barton
On 7 May 2012, at 13:26, fpc-pascal-requ...@lists.freepascal.org wrote: Message: 4 Date: Mon, 07 May 2012 12:59:58 +0200 From: Koenraad Lelong ko...@de-brouwerij.be Subject: Re: RE : RE : [fpc-pascal] Reversing bit-order of byte To: fpc-pascal@lists.freepascal.org Message-ID: 4fa7ab2e

Re: RE : RE : [fpc-pascal] Reversing bit-order of byte

2012-05-04 Thread Koenraad Lelong
On 03-05-12 13:27, Thomas Schatzl wrote: ... function reverse(b : byte) : byte; assembler; nostackframe; asm rbit r0, r0 // rbit reverses the whole word, so now you have // your value in bits 31-24... so shift right by that amount // should fix this up (bits 23-0 contain junk, we

Re: RE : RE : [fpc-pascal] Reversing bit-order of byte

2012-05-04 Thread Koenraad Lelong
On 03-05-12 13:27, Thomas Schatzl wrote: ... function reverse(b : byte) : byte; assembler; nostackframe; asm .long 0xe6ff0f30 // rbit r0, r0 lsr r0, r0, #23 end; Hi, I've been looking a bit further at this. I disassembled the code and this is the result : 8000150: e6ff0f30

Re: RE : RE : [fpc-pascal] Reversing bit-order of byte

2012-05-04 Thread Thomas Schatzl
Hi, On Fri, 2012-05-04 at 14:14 +0200, Koenraad Lelong wrote: On 03-05-12 13:27, Thomas Schatzl wrote: ... function reverse(b : byte) : byte; assembler; nostackframe; asm .long 0xe6ff0f30 // rbit r0, r0 lsr r0, r0, #23 end; Hi, I've been looking a bit further at this. I

Re: RE : RE : [fpc-pascal] Reversing bit-order of byte

2012-05-04 Thread Koenraad Lelong
On 04-05-12 14:31, Thomas Schatzl wrote: It might be good to compile with -Cparmv6 (or -Cparmv7, do not know what type the processor you use is), this generates a better return instruction (bx lr) - and for the rbit instruction you need armv6 already. Wouldn't it be possible to do rbit

[fpc-pascal] Reversing bit-order of byte

2012-05-03 Thread Koenraad Lelong
Hi, I'm porting a driver, originally written in C, for an LCD to be used with an embedded arm-processor (STM32). The original driver uses SPI, my driver will use a USART in synchronous mode because the STM32 has no SPI for 9-bit. Unfortunately, the bit-order is reversed between SPI and USART

Re: [fpc-pascal] Reversing bit-order of byte

2012-05-03 Thread Honza
Dne 3.5.2012 9:11 Koenraad Lelong fpas...@brouwerij.homelinux.net napsal(a): Does anyone knows an efficient way to reverse bit-order of a byte for the arm-processor ? Lookup from a 256 byte precomputed table? Or I misunderstood the task. -jan ___

Re: [fpc-pascal] Reversing bit-order of byte

2012-05-03 Thread Mark Morgan Lloyd
Koenraad Lelong wrote: Hi, I'm porting a driver, originally written in C, for an LCD to be used with an embedded arm-processor (STM32). The original driver uses SPI, my driver will use a USART in synchronous mode because the STM32 has no SPI for 9-bit. Unfortunately, the bit-order is

Re: [fpc-pascal] Reversing bit-order of byte

2012-05-03 Thread Thomas Schatzl
Hi, On Thu, 2012-05-03 at 07:55 +, Mark Morgan Lloyd wrote: Koenraad Lelong wrote: Hi, I'm porting a driver, originally written in C, for an LCD to be used with an embedded arm-processor (STM32). The original driver uses SPI, my driver will use a USART in synchronous mode

RE : [fpc-pascal] Reversing bit-order of byte

2012-05-03 Thread Ludo Brands
Hi, I'm porting a driver, originally written in C, for an LCD to be used with an embedded arm-processor (STM32). The original driver uses SPI, my driver will use a USART in synchronous mode because the STM32 has no SPI for 9-bit. Unfortunately, the bit-order is reversed between SPI

Re: [fpc-pascal] Reversing bit-order of byte

2012-05-03 Thread David Butler
If you want to go assembly: function ReverseBits(const Value: LongWord): LongWord; register; assembler; asm BSWAP EAX MOV EDX, EAX AND EAX, 0h SHR EAX, 1 AND EDX, 0h SHL EDX, 1 OR EAX, EDX MOV EDX, EAX

Re: RE : [fpc-pascal] Reversing bit-order of byte

2012-05-03 Thread Koenraad Lelong
On 03-05-12 10:45, Ludo Brands wrote: You might also look into the RBIT instruction which does this in one cpu cycle. See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489c/Cihjgdi d.html and applied to the STM32 USART http://forum.micromouseonline.com/viewtopic.php?f=7t=460

RE : RE : [fpc-pascal] Reversing bit-order of byte

2012-05-03 Thread Ludo Brands
Thanks all for your replies. I already found the RBIT-instruction. I also found out I need to study the arm assembly language ;-) But how do I get my variable ? Is that in some register ? Is there any documentation about such things ? Then I can use inline assembly. ARM has

Re: RE : RE : [fpc-pascal] Reversing bit-order of byte

2012-05-03 Thread Thomas Schatzl
Hi, On Thu, 2012-05-03 at 12:54 +0200, Ludo Brands wrote: Thanks all for your replies. I already found the RBIT-instruction. I also found out I need to study the arm assembly language ;-) But how do I get my variable ? Is that in some register ? Is there any documentation

Re: [fpc-pascal] Reversing bit-order of byte

2012-05-03 Thread Sven Barth
On 03.05.2012 10:50, David Butler wrote: If you want to go assembly: function ReverseBits(const Value: LongWord): LongWord; register; assembler; asm BSWAP EAX MOV EDX, EAX AND EAX, 0h SHR EAX, 1 AND EDX, 0h SHL EDX,