1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-29 04:51:28 +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

@@ -27,10 +27,6 @@
#include "byteswapdefs.h"
#if defined(ISC)
#include "inlnPS2.h"
#else
/****************************************************************/
/* */
/* swap halves of a single 4-byte word */
@@ -49,23 +45,6 @@ unsigned short byte_swap_word(unsigned short word) {
return (((word >> 8) & 0xff) | ((word & 0xff) << 8));
}
/****************************************************************/
/* */
/* Word-swap a 2-word integer */
/* Does NOT byte-swap the words themselves. */
/* */
/****************************************************************/
/***
unsigned int word_swap_longword(word)
unsigned int word;
{
return( ((word>>16)&0xffff)+((word&0xffff)<<16) );
} ***/
#ifndef I386
#define word_swap_longword(word) (((word >> 16) & 0xffff) | ((word & 0xffff) << 16))
#endif
#endif /* !ISC */
/****************************************************************/
/* */
/* Byte-swap a region wordcount words long */
@@ -77,7 +56,6 @@ void byte_swap_page(unsigned short *page, int wordcount) {
for (i = 0; i < wordcount; i++) { *(page + i) = byte_swap_word(*(page + i)); }
}
#ifndef GCC386
/****************************************************************/
/* */
/* Byte- & word-swap a region wordcount long-words long */
@@ -90,9 +68,8 @@ void word_swap_page(unsigned short *page, int longwordcount) {
for (i = 0; i < (longwordcount + longwordcount); i++) {
*(page + i) = byte_swap_word(*(page + i));
}
for (i = 0; i < longwordcount; i++) { *(longpage + i) = word_swap_longword(*(longpage + i)); }
for (i = 0; i < longwordcount; i++) { *(longpage + i) = swapx(*(longpage + i)); }
}
#endif /* GCC386 */
/****************************************************************/
/* */

View File

@@ -34,100 +34,6 @@
/************************************************************************/
/ swap the words in a long-word.
.inline swapx,1
movl 0(%esp),%eax
rol $16,%eax
.end
/ swap the words in a long-word
.inline word_swap_longword,1
movl 0(%esp),%eax
rol $16,%eax
.end
/swap the bytes in a 16-bit word
.inline byte_swap_word,1
movl 0(%esp),%eax
rolw $8,%ax
.end
.inline word_swap_page,8
movl 4(%esp),%ecx / word count into the loop counter
movl 0(%esp),%edx / address of the block to swap
movl 0(%edx),%eax
rolw $8,%ax
roll $16,%eax
rolw $8,%ax
movl %eax,0(%edx)
add $4,%edx
loop .-20
.end
.inline bit_reverse_region,16
/args: (top width height rasterwidth)
.noopt
pushl %edi
pushl %esi
pushl %ebx
movl 12(%esp),%edx /top
movl %edx,%eax
andl $-2,%edx
movl %edx,12(%esp)
andl $1,%eax
shll $4,%eax
addl 16(%esp),%eax /width
movl 20(%esp),%edx /height
/ 24(%esp) /rasterwidth, in words
leal 31(%eax),%eax
sarl $5,%eax
leal (%eax,%eax),%eax
movl %eax,16(%esp) / word wid now in width.
cld / so we move up thru memory
leal reversedbits,%ebx / for xlateb
movl 12(%esp),%edi / starting init of word ptr
sub $0,%edx
jle .+63
/ ..4:
movl %edi,%esi /so both edi & esi are at start of line to swap
movl 16(%esp),%ecx / byte count to ecx
leal (%ecx,%ecx),%ecx
/ ..3:
lodsb
xlat
stosb
loop .-3 / ..3
movl 16(%esp),%ecx
incl %ecx
sarl $1,%ecx
movl 12(%esp),%esi / must be into esi, then edi, to
/ andl $-2,%edi / defeat the peephole optimizer.
movl %esi,%edi
/ ..5:
lodsl
rolw $8,%ax
roll $16,%eax
rolw $8,%ax
stosl
loop .-13 / ..5
movl 12(%esp),%edi / word = word + rasterwidth
addl 24(%esp),%edi
addl 24(%esp),%edi
movl %edi,12(%esp)
decl %edx
/ .L60: / at this point, starting word addr is in %edi
jg .-59 / ..4
popl %ebx
popl %esi
popl %edi
.optim
.end
/////////////////////////////
//
// Dispatch loop speedup functions for the 386i