<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jul 28, 2024 at 11:10 AM Ron Garret <<a href="mailto:ron@flownet.com" target="_blank">ron@flownet.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><div>Doesn't seem like it would be very hard.  They are the same ISA, just different encodings.</div><div><br></div><div><a href="https://stackoverflow.com/questions/28669905/what-is-the-difference-between-the-arm-thumb-and-thumb-2-instruction-encodings" target="_blank">https://stackoverflow.com/questions/28669905/what-is-the-difference-between-the-arm-thumb-and-thumb-2-instruction-encodings</a></div></div></div></blockquote><div><br></div><div>There is a lot of room for hair-splitting in terms of what constitutes an encoding and what does not.  That is certainly more true if you are talking about ARM being an alternate encoding for Thumb-2 and less true in the other direction.  That aside, if you have an ARM backend that does not excessively rely on the eccentricities of 32-bit ARM then, indeed, targeting Thumb should not be very hard.<br><br>Anyway, to emit Thumb, this could just require a refactoring of the backend to remove ARM-specific assumptions: instructions will encoding in 2-4 bytes instead of always 4, the IT instruction is required for conditional execution and not present on 32-bit ARM, and many instructions take 2 address instead of always having 3 addresses.  The smaller microcontrollers also do not offer the full ISA.<br></div><div><br></div><div>Fortunately, since you can run Thumb code side-by-side with ARM code this work can be done much less disruptively than targeting a new architecture.  It is real work but, again, not very hard.</div></div></div>