Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 6b5b3a2

Browse files
peffgitster
authored andcommitted
ewah: unconditionally ntohll ewah data
Commit a201c20 tried to optimize out a loop like: for (i = 0; i < len; i++) data[i] = ntohll(data[i]); in the big-endian case, because we know that ntohll is a noop, and we do not need to pay the cost of the loop at all. However, it mistakenly assumed that __BYTE_ORDER was always defined, whereas it may not be on systems which do not define it by default, and where we did not need to define it to set up the ntohll macro. This includes OS X and Windows. We could muck with the ordering in compat/bswap.h to make sure it is defined unconditionally, but it is simpler to still to just execute the loop unconditionally. That avoids the application code knowing anything about these magic macros, and lets it depend only on having ntohll defined. And since the resulting loop looks like (on a big-endian system): for (i = 0; i < len; i++) data[i] = data[i]; any decent compiler can probably optimize it out. Original report and analysis by Brian Gernhardt. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a201c20 commit 6b5b3a2

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

ewah/ewah_io.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
113113
int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len)
114114
{
115115
uint8_t *ptr = map;
116+
size_t i;
116117

117118
self->bit_size = get_be32(ptr);
118119
ptr += sizeof(uint32_t);
@@ -135,13 +136,8 @@ int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len)
135136
memcpy(self->buffer, ptr, self->buffer_size * sizeof(uint64_t));
136137
ptr += self->buffer_size * sizeof(uint64_t);
137138

138-
#if __BYTE_ORDER != __BIG_ENDIAN
139-
{
140-
size_t i;
141-
for (i = 0; i < self->buffer_size; ++i)
142-
self->buffer[i] = ntohll(self->buffer[i]);
143-
}
144-
#endif
139+
for (i = 0; i < self->buffer_size; ++i)
140+
self->buffer[i] = ntohll(self->buffer[i]);
145141

146142
self->rlw = self->buffer + get_be32(ptr);
147143

0 commit comments

Comments
 (0)