1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-28 20:41:30 +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
2 changed files with 3 additions and 28 deletions

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)); }
}
/****************************************************************/