1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-05-03 23:09:34 +00:00

Cleanup byteswap.c a bit (#154)

* Remove word_swap_longword.

This was the same as `swapx` and not used except in one place which
now uses `swapx` instead.

* Remove assembly versions of swapx, byte_swap_word, word_swap_page.

`swapx` and `byte_swap_word` were defined as:

```
extern inline const unsigned int swapx (unsigned int word)
{
   asm("roll  $16,%0" : "=g" (word) : "0" (word));
   return(word);
}

extern inline const unsigned short byte_swap_word (unsigned short word)
{
   asm("rolw  $8,%0" : "=r" (word) : "0" (word));

   return(word);
}
```

But the generated code from the C version is:

```
(lldb) disassemble -n swapx
ldex`swapx:
ldex[0x10002e0d0] <+0>:  pushq  %rbp
ldex[0x10002e0d1] <+1>:  movq   %rsp, %rbp
ldex[0x10002e0d4] <+4>:  movl   %edi, %eax
ldex[0x10002e0d6] <+6>:  roll   $0x10, %eax
ldex[0x10002e0d9] <+9>:  popq   %rbp
ldex[0x10002e0da] <+10>: retq

(lldb) disassemble -n byte_swap_word
ldex`byte_swap_word:
ldex[0x10002e0e0] <+0>:  pushq  %rbp
ldex[0x10002e0e1] <+1>:  movq   %rsp, %rbp
ldex[0x10002e0e4] <+4>:  rolw   $0x8, %di
ldex[0x10002e0e8] <+8>:  movzwl %di, %eax
ldex[0x10002e0eb] <+11>: popq   %rbp
ldex[0x10002e0ec] <+12>: retq
```

So we don't really stand to gain by re-enabling this old assembler code.

We would gain from switching to C99 or C11 and improving our
inlining.

* Remove 386 asm version of bit_reverse_region.

This is implemented in C and the code isn't actually set up to
allow using the assembler version.
This commit is contained in:
Bruce Mitchener
2021-01-01 01:29:19 +07:00
committed by GitHub
parent ca3f27db1f
commit d717946929
4 changed files with 1 additions and 236 deletions

View File

@@ -65,65 +65,6 @@
/************************************************************************/
#undef SWAP_WORDS
#define SWAP_WORDS swapx
extern inline const unsigned int swapx (unsigned int word)
{
asm("roll $16,%0" : "=g" (word) : "0" (word));
return(word);
}
extern inline const unsigned int word_swap_longword (unsigned int word)
{
asm("roll $16,%0" : "=r" (word) : "0" (word));
return(word);
}
extern inline const unsigned short byte_swap_word (unsigned short word)
{
asm("rolw $8,%0" : "=r" (word) : "0" (word));
return(word);
}
extern inline void word_swap_page(unsigned short * page, int count)
{
asm volatile("\
pushl %edi \n\
pushl %esi \n\
pushl %ecx \n\
cld");
asm volatile("\
movl %0,%%esi // word pointer. \n\
movl %%esi,%%edi \n\
movl %1,%%ecx // count" : : "g" (page), "g" (count));
asm volatile("\
lodsl \n\
rolw $8,%ax \n\
roll $16,%eax \n\
rolw $8,%ax \n\
stosl \n\
loop .-13 \n\
\n\
// epilogue. \n\
popl %ecx \n\
popl %esi \n\
popl %edi \
");
}
/************************************************************************/
/* */
/* */

View File

@@ -65,65 +65,6 @@
/************************************************************************/
#undef SWAP_WORDS
#define SWAP_WORDS swapx
extern inline unsigned int swapx (unsigned int word)
{
asm("rol %0,16" : "=g" (word) : "0" (word));
return(word);
}
extern inline unsigned int word_swap_longword (unsigned int word)
{
asm("rol %0,16" : "=r" (word) : "0" (word));
return(word);
}
extern inline unsigned short byte_swap_word (unsigned short word)
{
asm("rol %0,8" : "=r" (word) : "0" (word));
return(word);
}
extern inline void word_swap_page(unsigned short * page, int count)
{
asm volatile("\
pushl edi \n\
pushl esi \n\
pushl ecx \n\
cld");
asm volatile("
movl esi,%0 // word pointer. \n\
movl edi,esi \n\
movl ecx,%1 // count" : : "g" (page), "g" (count));
asm volatile(" \
lodsl \n\
rol ax,8 \n\
rol eax,16 \n\
rol ax,8 \n\
stosl \n\
loop .-13 \n\
\n\
// epilogue. \n\
popl ecx \n\
popl esi \n\
popl edi \n\
");
}
/************************************************************************/
/* */
/* */