1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-15 15:57:13 +00:00

Improve implementation of word_swap_page() and remove unused code (#447)

word_swap_page() should only touch each 32-bit word once to change
  the byte order from ABCD to DCBA rather than twice doing a transform
  of the entire region from ABCD to BADC and then again to DCBA

  The compiler provided ntohl() usually gets favorable optimizations
  applied, so use it for the byte reordering.

  With word_swap_page() rewritten, byte_swap_word() is superfluous.
This commit is contained in:
Nick Briggs 2022-10-30 15:49:32 -07:00 committed by GitHub
parent 71e2d9f3e0
commit 6e38d50829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 28 deletions

View File

@ -10,16 +10,6 @@ static inline unsigned int swapx(unsigned int word) {
return (((word >> 16) & 0xffff) | ((word & 0xffff) << 16));
}
/****************************************************************/
/* */
/* Byte-swap a single 2-byte word */
/* */
/****************************************************************/
static inline unsigned short byte_swap_word(unsigned short word) {
return ((word >> 8) | (unsigned short)((word & 0xff) << 8));
}
void byte_swap_page(unsigned short *page, int wordcount);
void word_swap_page(unsigned short *page, int longwordcount);
void bit_reverse_region(unsigned short *top, int width, int height, int rasterwidth);
#ifdef RESWAPPEDCODESTREAM

View File

@ -19,33 +19,18 @@
/* */
/***************************************************************************/
#include <arpa/inet.h>
#include "byteswapdefs.h"
#include "lsptypes.h"
/****************************************************************/
/* */
/* Byte-swap a region wordcount words long */
/* This does NOT swap words in a long-word! */
/* */
/****************************************************************/
void byte_swap_page(unsigned short *page, int wordcount) {
int i;
for (i = 0; i < wordcount; i++) { *(page + i) = byte_swap_word(*(page + i)); }
}
/****************************************************************/
/* */
/* Byte- & word-swap a region wordcount long-words long */
/* */
/****************************************************************/
void word_swap_page(unsigned short *page, int longwordcount) {
int i;
unsigned int *longpage;
longpage = (unsigned int *)page;
for (i = 0; i < (longwordcount + longwordcount); i++) {
*(page + i) = byte_swap_word(*(page + i));
}
for (i = 0; i < longwordcount; i++) { *(longpage + i) = swapx(*(longpage + i)); }
unsigned int *longpage = (unsigned int *)page;
for (int i = 0; i < longwordcount; i++) { *(longpage + i) = ntohl(*(longpage + i)); }
}
/****************************************************************/