Skip to content

Commit d717946

Browse files
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.
1 parent ca3f27d commit d717946

File tree

4 files changed

+1
-236
lines changed

4 files changed

+1
-236
lines changed

inc/inlnPS2.h

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -65,65 +65,6 @@
6565
/************************************************************************/
6666

6767

68-
#undef SWAP_WORDS
69-
#define SWAP_WORDS swapx
70-
71-
72-
extern inline const unsigned int swapx (unsigned int word)
73-
{
74-
asm("roll $16,%0" : "=g" (word) : "0" (word));
75-
return(word);
76-
}
77-
78-
79-
80-
extern inline const unsigned int word_swap_longword (unsigned int word)
81-
{
82-
asm("roll $16,%0" : "=r" (word) : "0" (word));
83-
84-
return(word);
85-
}
86-
87-
88-
89-
extern inline const unsigned short byte_swap_word (unsigned short word)
90-
{
91-
asm("rolw $8,%0" : "=r" (word) : "0" (word));
92-
93-
return(word);
94-
}
95-
96-
97-
98-
extern inline void word_swap_page(unsigned short * page, int count)
99-
{
100-
asm volatile("\
101-
pushl %edi \n\
102-
pushl %esi \n\
103-
pushl %ecx \n\
104-
cld");
105-
asm volatile("\
106-
movl %0,%%esi // word pointer. \n\
107-
movl %%esi,%%edi \n\
108-
movl %1,%%ecx // count" : : "g" (page), "g" (count));
109-
asm volatile("\
110-
lodsl \n\
111-
rolw $8,%ax \n\
112-
roll $16,%eax \n\
113-
rolw $8,%ax \n\
114-
stosl \n\
115-
loop .-13 \n\
116-
\n\
117-
// epilogue. \n\
118-
popl %ecx \n\
119-
popl %esi \n\
120-
popl %edi \
121-
");
122-
123-
}
124-
125-
126-
12768
/************************************************************************/
12869
/* */
12970
/* */

inc/inlndos.h

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -65,65 +65,6 @@
6565
/************************************************************************/
6666

6767

68-
#undef SWAP_WORDS
69-
#define SWAP_WORDS swapx
70-
71-
72-
extern inline unsigned int swapx (unsigned int word)
73-
{
74-
asm("rol %0,16" : "=g" (word) : "0" (word));
75-
return(word);
76-
}
77-
78-
79-
80-
extern inline unsigned int word_swap_longword (unsigned int word)
81-
{
82-
asm("rol %0,16" : "=r" (word) : "0" (word));
83-
84-
return(word);
85-
}
86-
87-
88-
89-
extern inline unsigned short byte_swap_word (unsigned short word)
90-
{
91-
asm("rol %0,8" : "=r" (word) : "0" (word));
92-
93-
return(word);
94-
}
95-
96-
97-
98-
extern inline void word_swap_page(unsigned short * page, int count)
99-
{
100-
asm volatile("\
101-
pushl edi \n\
102-
pushl esi \n\
103-
pushl ecx \n\
104-
cld");
105-
asm volatile("
106-
movl esi,%0 // word pointer. \n\
107-
movl edi,esi \n\
108-
movl ecx,%1 // count" : : "g" (page), "g" (count));
109-
asm volatile(" \
110-
lodsl \n\
111-
rol ax,8 \n\
112-
rol eax,16 \n\
113-
rol ax,8 \n\
114-
stosl \n\
115-
loop .-13 \n\
116-
\n\
117-
// epilogue. \n\
118-
popl ecx \n\
119-
popl esi \n\
120-
popl edi \n\
121-
");
122-
123-
}
124-
125-
126-
12768
/************************************************************************/
12869
/* */
12970
/* */

src/byteswap.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727

2828
#include "byteswapdefs.h"
2929

30-
#if defined(ISC)
31-
#include "inlnPS2.h"
32-
#else
33-
3430
/****************************************************************/
3531
/* */
3632
/* swap halves of a single 4-byte word */
@@ -49,23 +45,6 @@ unsigned short byte_swap_word(unsigned short word) {
4945
return (((word >> 8) & 0xff) | ((word & 0xff) << 8));
5046
}
5147

52-
/****************************************************************/
53-
/* */
54-
/* Word-swap a 2-word integer */
55-
/* Does NOT byte-swap the words themselves. */
56-
/* */
57-
/****************************************************************/
58-
/***
59-
unsigned int word_swap_longword(word)
60-
unsigned int word;
61-
{
62-
return( ((word>>16)&0xffff)+((word&0xffff)<<16) );
63-
} ***/
64-
#ifndef I386
65-
#define word_swap_longword(word) (((word >> 16) & 0xffff) | ((word & 0xffff) << 16))
66-
#endif
67-
#endif /* !ISC */
68-
6948
/****************************************************************/
7049
/* */
7150
/* Byte-swap a region wordcount words long */
@@ -77,7 +56,6 @@ void byte_swap_page(unsigned short *page, int wordcount) {
7756
for (i = 0; i < wordcount; i++) { *(page + i) = byte_swap_word(*(page + i)); }
7857
}
7958

80-
#ifndef GCC386
8159
/****************************************************************/
8260
/* */
8361
/* Byte- & word-swap a region wordcount long-words long */
@@ -90,9 +68,8 @@ void word_swap_page(unsigned short *page, int longwordcount) {
9068
for (i = 0; i < (longwordcount + longwordcount); i++) {
9169
*(page + i) = byte_swap_word(*(page + i));
9270
}
93-
for (i = 0; i < longwordcount; i++) { *(longpage + i) = word_swap_longword(*(longpage + i)); }
71+
for (i = 0; i < longwordcount; i++) { *(longpage + i) = swapx(*(longpage + i)); }
9472
}
95-
#endif /* GCC386 */
9673

9774
/****************************************************************/
9875
/* */

src/dsp386.il

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -34,100 +34,6 @@
3434
/************************************************************************/
3535

3636

37-
38-
/ swap the words in a long-word.
39-
.inline swapx,1
40-
movl 0(%esp),%eax
41-
rol $16,%eax
42-
.end
43-
44-
45-
/ swap the words in a long-word
46-
.inline word_swap_longword,1
47-
movl 0(%esp),%eax
48-
rol $16,%eax
49-
.end
50-
51-
/swap the bytes in a 16-bit word
52-
.inline byte_swap_word,1
53-
movl 0(%esp),%eax
54-
rolw $8,%ax
55-
.end
56-
57-
58-
.inline word_swap_page,8
59-
movl 4(%esp),%ecx / word count into the loop counter
60-
movl 0(%esp),%edx / address of the block to swap
61-
movl 0(%edx),%eax
62-
rolw $8,%ax
63-
roll $16,%eax
64-
rolw $8,%ax
65-
movl %eax,0(%edx)
66-
add $4,%edx
67-
loop .-20
68-
.end
69-
70-
.inline bit_reverse_region,16
71-
/args: (top width height rasterwidth)
72-
.noopt
73-
pushl %edi
74-
pushl %esi
75-
pushl %ebx
76-
movl 12(%esp),%edx /top
77-
movl %edx,%eax
78-
andl $-2,%edx
79-
movl %edx,12(%esp)
80-
andl $1,%eax
81-
shll $4,%eax
82-
addl 16(%esp),%eax /width
83-
movl 20(%esp),%edx /height
84-
/ 24(%esp) /rasterwidth, in words
85-
leal 31(%eax),%eax
86-
sarl $5,%eax
87-
leal (%eax,%eax),%eax
88-
movl %eax,16(%esp) / word wid now in width.
89-
cld / so we move up thru memory
90-
leal reversedbits,%ebx / for xlateb
91-
movl 12(%esp),%edi / starting init of word ptr
92-
sub $0,%edx
93-
jle .+63
94-
/ ..4:
95-
movl %edi,%esi /so both edi & esi are at start of line to swap
96-
97-
movl 16(%esp),%ecx / byte count to ecx
98-
leal (%ecx,%ecx),%ecx
99-
/ ..3:
100-
lodsb
101-
xlat
102-
stosb
103-
loop .-3 / ..3
104-
105-
movl 16(%esp),%ecx
106-
incl %ecx
107-
sarl $1,%ecx
108-
movl 12(%esp),%esi / must be into esi, then edi, to
109-
/ andl $-2,%edi / defeat the peephole optimizer.
110-
movl %esi,%edi
111-
/ ..5:
112-
lodsl
113-
rolw $8,%ax
114-
roll $16,%eax
115-
rolw $8,%ax
116-
stosl
117-
loop .-13 / ..5
118-
movl 12(%esp),%edi / word = word + rasterwidth
119-
addl 24(%esp),%edi
120-
addl 24(%esp),%edi
121-
movl %edi,12(%esp)
122-
decl %edx
123-
/ .L60: / at this point, starting word addr is in %edi
124-
jg .-59 / ..4
125-
popl %ebx
126-
popl %esi
127-
popl %edi
128-
.optim
129-
.end
130-
13137
/////////////////////////////
13238
//
13339
// Dispatch loop speedup functions for the 386i

0 commit comments

Comments
 (0)