<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>ColdFire/68K Microcontrollers and ProcessorsのトピックBYTEREV.L Equivalent Instruction for ISA_B</title>
    <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/BYTEREV-L-Equivalent-Instruction-for-ISA-B/m-p/804212#M13522</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am implementing some code from another vendor on a MCF5485 that has ISA_B. In one of the files it has the following line of code:&lt;/P&gt;&lt;P&gt;static inline asm U32 __declspec(register_abi) sharkssl_byteswap (U32 d) { byterev.l d0 }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When compiling, i get the warning: "Illegal instruction for this processor". When looking at the reference manual for MCF5485, i found a similar instruction 'swap' that i could use. But from my understanding, the 'swap' instruction only swaps most significant words (i.e.&amp;nbsp;MSW of Dx ↔ LSW of Dx) where 'byterev.l' reverses the bytes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;using 'byterev.l':&lt;/P&gt;&lt;P&gt;new Dx[31:24] = old Dx[7:0]&lt;/P&gt;&lt;P&gt;new Dx[23:16] = old Dx[15:8]&lt;/P&gt;&lt;P&gt;new Dx[15:8] = old Dx[23:16]&lt;/P&gt;&lt;P&gt;new Dx[7:0] = old Dx[31:24]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;using 'swap':&lt;/P&gt;&lt;P&gt;new Dx[31:24] = old Dx[15:8]&lt;/P&gt;&lt;P&gt;new Dx[23:16] = old Dx[7:0]&lt;/P&gt;&lt;P&gt;new Dx[15:8] = old Dx[31:24]&lt;/P&gt;&lt;P&gt;new Dx[7:0] = old Dx[23:16]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a method that allows me to perform the same operation as 'byterev.l' using instructions included in ISA_B?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Jul 2018 15:16:45 GMT</pubDate>
    <dc:creator>jose_enriquez</dc:creator>
    <dc:date>2018-07-11T15:16:45Z</dc:date>
    <item>
      <title>BYTEREV.L Equivalent Instruction for ISA_B</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/BYTEREV-L-Equivalent-Instruction-for-ISA-B/m-p/804212#M13522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am implementing some code from another vendor on a MCF5485 that has ISA_B. In one of the files it has the following line of code:&lt;/P&gt;&lt;P&gt;static inline asm U32 __declspec(register_abi) sharkssl_byteswap (U32 d) { byterev.l d0 }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When compiling, i get the warning: "Illegal instruction for this processor". When looking at the reference manual for MCF5485, i found a similar instruction 'swap' that i could use. But from my understanding, the 'swap' instruction only swaps most significant words (i.e.&amp;nbsp;MSW of Dx ↔ LSW of Dx) where 'byterev.l' reverses the bytes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;using 'byterev.l':&lt;/P&gt;&lt;P&gt;new Dx[31:24] = old Dx[7:0]&lt;/P&gt;&lt;P&gt;new Dx[23:16] = old Dx[15:8]&lt;/P&gt;&lt;P&gt;new Dx[15:8] = old Dx[23:16]&lt;/P&gt;&lt;P&gt;new Dx[7:0] = old Dx[31:24]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;using 'swap':&lt;/P&gt;&lt;P&gt;new Dx[31:24] = old Dx[15:8]&lt;/P&gt;&lt;P&gt;new Dx[23:16] = old Dx[7:0]&lt;/P&gt;&lt;P&gt;new Dx[15:8] = old Dx[31:24]&lt;/P&gt;&lt;P&gt;new Dx[7:0] = old Dx[23:16]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a method that allows me to perform the same operation as 'byterev.l' using instructions included in ISA_B?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Jul 2018 15:16:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/BYTEREV-L-Equivalent-Instruction-for-ISA-B/m-p/804212#M13522</guid>
      <dc:creator>jose_enriquez</dc:creator>
      <dc:date>2018-07-11T15:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: BYTEREV.L Equivalent Instruction for ISA_B</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/BYTEREV-L-Equivalent-Instruction-for-ISA-B/m-p/804213#M13523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems that you did not use the CodeWarrior IDE. Please make reference from this post on how to use the reverse bytes function:&lt;A _jive_internal="true" class="link-titled" href="https://community.nxp.com/message/69179?commentID=69179#comment-69179" title="https://community.nxp.com/message/69179?commentID=69179#comment-69179"&gt;https://community.nxp.com/message/69179&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jul 2018 08:30:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/BYTEREV-L-Equivalent-Instruction-for-ISA-B/m-p/804213#M13523</guid>
      <dc:creator>miduo</dc:creator>
      <dc:date>2018-07-13T08:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: BYTEREV.L Equivalent Instruction for ISA_B</title>
      <link>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/BYTEREV-L-Equivalent-Instruction-for-ISA-B/m-p/804214#M13524</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's that same question in this forum from 9 years ago:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.nxp.com/message/56006?commentID=56006#comment-56006" rel="nofollow noopener noreferrer" target="_blank"&gt;https://community.nxp.com/message/56006?commentID=56006#comment-56006&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What functions you end up using depends on whether raw speed is important for this function in your application.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have access to the Linux Sources (and we all do, just download them) there are plenty of examples on how to do operations like this on different CPUs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;They also have "generic, works in C, slowly on any CPU" definitions like the one Fang pointed you to in the linked post. If you're only doing this in one-shot startup code (or code that can be written to do that), then use that. If your code is deep in the middle of processing a lot of data fast, then you may have to look for faster alternatives. As an example of where this matters, the SKHA Hardware in these chips have all the bytes reversed in the control registers, so to get any real performance out of them I had to use byterev:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-comment-small" href="https://community.nxp.com/thread/303776?commentID=314878#comment-314878" rel="nofollow noopener noreferrer" target="_blank"&gt;https://community.nxp.com/message/314878?commentID=314878#comment-314878&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's arch/m68k/include/asm/swab.h:&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;#ifndef _M68K_SWAB_H
#define _M68K_SWAB_H

#include &amp;lt;linux/types.h&amp;gt;
#include &amp;lt;linux/compiler.h&amp;gt;

#define __SWAB_64_THRU_32__

#if defined (__mcfisaaplus__) || defined (__mcfisac__)
static inline __attribute_const__ __u32 __arch_swab32(__u32 val)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm__("byterev %0" : "=d" (val) : "0" (val));
&amp;nbsp;&amp;nbsp;&amp;nbsp; return val;
}

#define __arch_swab32 __arch_swab32
#elif !defined(__mcoldfire__)

static inline __attribute_const__ __u32 __arch_swab32(__u32 val)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm__("rolw #8,%0; swap %0; rolw #8,%0" : "=d" (val) : "0" (val));
&amp;nbsp;&amp;nbsp;&amp;nbsp; return val;
}
#define __arch_swab32 __arch_swab32
#endif

#endif /* _M68K_SWAB_H */
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here's that code in the current tree:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://elixir.bootlin.com/linux/latest/source/arch/m68k/include/uapi/asm/swab.h#L11" rel="nofollow noopener noreferrer" target="_blank"&gt;https://elixir.bootlin.com/linux/latest/source/arch/m68k/include/uapi/asm/swab.h#L11&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here's the bad news. Note the "!defined(__mcoldfire__)" line above? That's because the M68k could perform word rotates, but the Coldfire can't so it can't use that trick.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's some other tricks (and someone who doesn't know the difference between bits and bytes):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F22012483%2Fhow-to-reverse-the-4-bytes-of-an-unsigned-integer" rel="nofollow noopener noreferrer" target="_blank"&gt;https://stackoverflow.com/questions/22012483/how-to-reverse-the-4-bytes-of-an-unsigned-integer&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Byte reversal functions are required for writing network code on little-endian machines. They use htons() and htonl() (for host-to-network order short/long) and the identical functions ntohs() and ntohl(), but they usually only generate code on little-endian machines and compile out on big-endian ones like ColdFire. But there may be some neat ideas in code like that.&lt;/P&gt;&lt;P&gt;You can always perform this function in one instruction if you have a 16 Gigabyte lookup table. &lt;SPAN class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;&lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2018 08:05:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/ColdFire-68K-Microcontrollers/BYTEREV-L-Equivalent-Instruction-for-ISA-B/m-p/804214#M13524</guid>
      <dc:creator>TomE</dc:creator>
      <dc:date>2018-07-19T08:05:56Z</dc:date>
    </item>
  </channel>
</rss>

