Skip to content

Commit

Permalink
more lto debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bscottm committed Jan 9, 2025
1 parent df82146 commit 799e626
Showing 1 changed file with 52 additions and 13 deletions.
65 changes: 52 additions & 13 deletions sim_fio.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,61 @@ sim_byte_swap_data (bptr, size, count);

void sim_byte_swap_data (void *bptr, size_t size, size_t count)
{
size_t j;
unsigned char by, *sptr, *dptr;
size_t j;
uint8 by, *sptr, *dptr;

if (sim_end || (count == 0) || (size == sizeof (char)))
return;
sptr = (uint8 *) bptr;

for (j = 0; j < count; j++) { /* loop on items */
switch (size) {
case sizeof(uint16):
#if defined(__GNUC__) || defined(__clang__)
*((uint16 *) sptr) = __builtin_bswap16 (*((uint16 *) sptr));
#elif defined(_MSC_VER)
*((uint16 *) sptr) = _byteswap_ushort (*((uint16 *) sptr));
#else
goto loser;
#endif
break;

if (sim_end || (count == 0) || (size == sizeof (char)))
return;
dptr = sptr = (unsigned char *) bptr;
for (j = 0; j < count; j++) { /* loop on items */
size_t k;
const size_t midpoint = (size + 1) / 2;
case sizeof(uint32):
#if defined(__GNUC__) || defined(__clang__)
*((uint32 *) sptr) = __builtin_bswap32 (*((uint32 *) sptr));
#elif defined(_MSC_VER)
*((uint32 *) sptr) = _byteswap_ulong (*((uint32 *) sptr));
#else
goto loser;
#endif
break;

case sizeof(t_uint64):
#if defined(__GNUC__) || defined(__clang__)
*((t_uint64 *) sptr) = __builtin_bswap64 (*((t_uint64 *) sptr));
#elif defined(_MSC_VER)
*((t_uint64 *) sptr) = _byteswap_uint64 (*((t_uint64 *) sptr));
#else
goto loser;
#endif
break;

for (k = size - 1; k >= midpoint; k--) {
by = *sptr; /* swap end-for-end */
*sptr++ = *(dptr + k);
*(dptr + k) = by;
default:
loser:
{
size_t k;
const size_t midpoint = (size + 1) / 2;

dptr = sptr + size - 1;
for (k = size - 1; k >= midpoint; k--) {
by = *sptr; /* swap end-for-end */
*sptr++ = *dptr;
*dptr-- = by;
}
}
break;
}
sptr = dptr = dptr + size; /* next item */
sptr += size; /* next item */
}
}

Expand Down

0 comments on commit 799e626

Please sign in to comment.