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:
@@ -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)); }
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user