34 lines
2.3 KiB
HTML
34 lines
2.3 KiB
HTML
---
|
|
layout: post
|
|
title: Code size for bit reversing algorithms
|
|
redirect_from:
|
|
- /01524451814
|
|
---
|
|
<body>
|
|
I want to add support for "LSB first" to bitbang SPI in circuitpython. Probably the best way to do this is to optionally reverse the bits in each byte according to a flag setting.
|
|
|
|
<p>Code space is always at a premium, so I investigated several code fragments for bit reversal to find out which was smallest on arm and xtensa. These code fragments are gathered from the internet. The loop is the smallest alternative on both architectures, but the 16-element look up table is not much bigger (on arm, the difference is bigger on xtensa) and is probably faster.
|
|
|
|
<p>arm-none-eabi-gcc-7.2.1 -Os -mthumb
|
|
<pre>
|
|
text data bss dec hex filename
|
|
40 0 0 40 28 bitrev_loop.o
|
|
44 0 0 44 2c bitrev_lut16.o
|
|
44 0 0 44 2c bitrev_shifts1.o
|
|
44 0 0 44 2c bitrev_twiddle1.o
|
|
</pre>
|
|
|
|
<p>xtensa-lx106-elf-gcc-4.8.5 -Os
|
|
<pre>
|
|
text data bss dec hex filename
|
|
40 0 0 40 28 bitrev_loop.o
|
|
53 0 0 53 35 bitrev_lut16.o
|
|
57 0 0 57 39 bitrev_shifts1.o
|
|
52 0 0 52 34 bitrev_twiddle1.o
|
|
</pre>
|
|
|
|
|
|
<p><br><p><b>Files currently attached to this page:</b>
|
|
<table cellpadding=5 style="width:auto!important; clear:none!important"><col><col style="text-align: right"><tr bgcolor=#eeeeee><td><a href="https://media.unpythonic.net/emergent-files/01524451814/bitrev_loop.c">bitrev_loop.c</a></td><td>138 bytes</td></tr><tr bgcolor=#dddddd><td><a href="https://media.unpythonic.net/emergent-files/01524451814/bitrev_lut16.c">bitrev_lut16.c</a></td><td>281 bytes</td></tr><tr bgcolor=#eeeeee><td><a href="https://media.unpythonic.net/emergent-files/01524451814/bitrev_shifts1.c">bitrev_shifts1.c</a></td><td>193 bytes</td></tr><tr bgcolor=#dddddd><td><a href="https://media.unpythonic.net/emergent-files/01524451814/bitrev_twiddle1.c">bitrev_twiddle1.c</a></td><td>178 bytes</td></tr></table><p><br><br><font size=-2>Entry first conceived on 23 April 2018, 2:50 UTC, last modified on 6 July 2019, 21:49 UTC</font>
|
|
</body>
|
|
</html><!--Imported with do-aether-page on Sat Jul 6 17:23:33 CDT 2019-->
|