Skip to content

Commit d3cfb2f

Browse files
iii-igbtucker
authored andcommitted
Fix s390 build
The goal of this patch is to make isa-l testsuite pass on s390 with minimal changes to the library. The one and only reason isa-l does not work on s390 at the moment is that s390 is big-endian, and isa-l assumes little-endian at a lot of places. There are two flavors of this: loading/storing integers from/to memory, and overlapping structs. Loads/stores are already helpfully wrapped by unaligned.h header, so replace the functions there with endianness-aware variants. Solve struct member overlap by reversing their order on big-endian. Also, fix a couple of usages of uninitialized memory in the testsuite (found with MemorySanitizer). Fixes s390x part of #188. Change-Id: Iaf14a113bd266900192cc8b44212f8a47a8c7753 Signed-off-by: Ilya Leoshkevich <[email protected]>
1 parent 3b3d7cc commit d3cfb2f

17 files changed

+313
-169
lines changed

erasure_code/ec_base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void gf_vect_mul_init(unsigned char c, unsigned char *tbl)
171171
unsigned char c4 = (c2 << 1) ^ ((c2 & 0x80) ? 0x1d : 0); //Mult by GF{2}
172172
unsigned char c8 = (c4 << 1) ^ ((c4 & 0x80) ? 0x1d : 0); //Mult by GF{2}
173173

174-
#if __WORDSIZE == 64 || _WIN64 || __x86_64__
174+
#if (__WORDSIZE == 64 || _WIN64 || __x86_64__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
175175
unsigned long long v1, v2, v4, v8, *t;
176176
unsigned long long v10, v20, v40, v80;
177177
unsigned char c17, c18, c20, c24;

igzip/bitbuf2.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#define inline __inline
3737
#endif
3838

39-
4039
/* MAX_BITBUF_BIT WRITE is the maximum number of bits than can be safely written
4140
* by consecutive calls of write_bits. Note this assumes the bitbuf is in a
4241
* state that is possible at the exit of write_bits */
@@ -60,28 +59,28 @@ static inline int is_full(struct BitBuf2 *me)
6059
return (me->m_out_buf > me->m_out_end);
6160
}
6261

63-
static inline uint8_t * buffer_ptr(struct BitBuf2 *me)
62+
static inline uint8_t *buffer_ptr(struct BitBuf2 *me)
6463
{
6564
return me->m_out_buf;
6665
}
6766

6867
static inline uint32_t buffer_used(struct BitBuf2 *me)
6968
{
70-
return (uint32_t)(me->m_out_buf - me->m_out_start);
69+
return (uint32_t) (me->m_out_buf - me->m_out_start);
7170
}
7271

7372
static inline uint32_t buffer_bits_used(struct BitBuf2 *me)
7473
{
75-
return (8 * (uint32_t)(me->m_out_buf - me->m_out_start) + me->m_bit_count);
74+
return (8 * (uint32_t) (me->m_out_buf - me->m_out_start) + me->m_bit_count);
7675
}
7776

7877
static inline void flush_bits(struct BitBuf2 *me)
7978
{
8079
uint32_t bits;
81-
store_u64(me->m_out_buf, me->m_bits);
80+
store_le_u64(me->m_out_buf, me->m_bits);
8281
bits = me->m_bit_count & ~7;
8382
me->m_bit_count -= bits;
84-
me->m_out_buf += bits/8;
83+
me->m_out_buf += bits / 8;
8584
me->m_bits >>= bits;
8685

8786
}
@@ -91,7 +90,7 @@ static inline void flush(struct BitBuf2 *me)
9190
{
9291
uint32_t bytes;
9392
if (me->m_bit_count) {
94-
store_u64(me->m_out_buf, me->m_bits);
93+
store_le_u64(me->m_out_buf, me->m_bits);
9594
bytes = (me->m_bit_count + 7) / 8;
9695
me->m_out_buf += bytes;
9796
}
@@ -114,14 +113,14 @@ static inline void write_bits_unsafe(struct BitBuf2 *me, uint64_t code, uint32_t
114113
}
115114

116115
static inline void write_bits(struct BitBuf2 *me, uint64_t code, uint32_t count)
117-
{ /* Assumes there is space to fit code into m_bits. */
116+
{ /* Assumes there is space to fit code into m_bits. */
118117
me->m_bits |= code << me->m_bit_count;
119118
me->m_bit_count += count;
120119
flush_bits(me);
121120
}
122121

123122
static inline void write_bits_flush(struct BitBuf2 *me, uint64_t code, uint32_t count)
124-
{ /* Assumes there is space to fit code into m_bits. */
123+
{ /* Assumes there is space to fit code into m_bits. */
125124
me->m_bits |= code << me->m_bit_count;
126125
me->m_bit_count += count;
127126
flush(me);

igzip/encode_df.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@
2020
#define ICF_CODE_LEN 32
2121

2222
struct deflate_icf {
23+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
2324
uint32_t lit_len:LIT_LEN_BIT_COUNT;
2425
uint32_t lit_dist:DIST_LIT_BIT_COUNT;
2526
uint32_t dist_extra:ICF_CODE_LEN - DIST_LIT_BIT_COUNT - ICF_DIST_OFFSET;
27+
#else
28+
uint32_t dist_extra:ICF_CODE_LEN - DIST_LIT_BIT_COUNT - ICF_DIST_OFFSET;
29+
uint32_t lit_dist:DIST_LIT_BIT_COUNT;
30+
uint32_t lit_len:LIT_LEN_BIT_COUNT;
31+
#endif
2632
};
2733

2834
struct deflate_icf *encode_deflate_icf(struct deflate_icf *next_in, struct deflate_icf *end_in,
29-
struct BitBuf2 *bb, struct hufftables_icf * hufftables);
35+
struct BitBuf2 *bb, struct hufftables_icf *hufftables);
3036
#endif

igzip/generate_custom_hufftables.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int len
291291
memset(last_seen, 0, sizeof(histogram->hash_table)); /* Initialize last_seen to be 0. */
292292

293293
for (current = start_stream; current < end_dict - 4; current++) {
294-
literal = load_u32(current);
294+
literal = load_le_u32(current);
295295
hash = compute_hash(literal) & LVL0_HASH_MASK;
296296
last_seen[hash] = (current - start_stream) & 0xFFFF;
297297
}
298298

299299
for (current = start_stream + dict_length; current < end_stream - 3; current++) {
300-
literal = load_u32(current);
300+
literal = load_le_u32(current);
301301
hash = compute_hash(literal) & LVL0_HASH_MASK;
302302
seen = last_seen[hash];
303303
last_seen[hash] = (current - start_stream) & 0xFFFF;
@@ -317,7 +317,7 @@ void isal_update_histogram_dict(uint8_t * start_stream, int dict_length, int len
317317
end = end_stream - 3;
318318
next_hash++;
319319
for (; next_hash < end; next_hash++) {
320-
literal = load_u32(next_hash);
320+
literal = load_le_u32(next_hash);
321321
hash = compute_hash(literal) & LVL0_HASH_MASK;
322322
last_seen[hash] = (next_hash - start_stream) & 0xFFFF;
323323
}

igzip/huff_codes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ void isal_update_histogram_base(uint8_t * start_stream, int length,
680680
end_stream = start_stream + length;
681681
memset(last_seen, 0, sizeof(histogram->hash_table)); /* Initialize last_seen to be 0. */
682682
for (current = start_stream; current < end_stream - 3; current++) {
683-
literal = load_u32(current);
683+
literal = load_le_u32(current);
684684
hash = compute_hash(literal) & LVL0_HASH_MASK;
685685
seen = last_seen[hash];
686686
last_seen[hash] = (current - start_stream) & 0xFFFF;
@@ -700,7 +700,7 @@ void isal_update_histogram_base(uint8_t * start_stream, int length,
700700
end = end_stream - 3;
701701
next_hash++;
702702
for (; next_hash < end; next_hash++) {
703-
literal = load_u32(next_hash);
703+
literal = load_le_u32(next_hash);
704704
hash = compute_hash(literal) & LVL0_HASH_MASK;
705705
last_seen[hash] = (next_hash - start_stream) & 0xFFFF;
706706
}

igzip/huff_codes.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,40 @@
104104
*/
105105
struct huff_code {
106106
union {
107-
struct {
108-
uint32_t code_and_extra:24;
109-
uint32_t length2:8;
110-
};
107+
struct {
108+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
109+
uint32_t code_and_extra:24;
110+
uint32_t length2:8;
111+
#else
112+
uint32_t length2:8;
113+
uint32_t code_and_extra:24;
114+
#endif
115+
};
111116

112117
struct {
118+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
113119
uint16_t code;
114120
uint8_t extra_bit_count;
115121
uint8_t length;
122+
#else
123+
uint8_t length;
124+
uint8_t extra_bit_count;
125+
uint16_t code;
126+
#endif
116127
};
117128

118129
uint32_t code_and_length;
119130
};
120131
};
121132

122133
struct tree_node {
134+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
123135
uint32_t child;
124136
uint32_t depth;
137+
#else
138+
uint32_t depth;
139+
uint32_t child;
140+
#endif
125141
};
126142

127143
struct heap_tree {
@@ -164,7 +180,7 @@ struct hufftables_icf {
164180
* with the set hufftable
165181
*/
166182
uint64_t
167-
create_hufftables_icf(struct BitBuf2 *bb, struct hufftables_icf * hufftables,
168-
struct isal_mod_hist *hist, uint32_t end_of_block);
183+
create_hufftables_icf(struct BitBuf2 *bb, struct hufftables_icf *hufftables,
184+
struct isal_mod_hist *hist, uint32_t end_of_block);
169185

170186
#endif

0 commit comments

Comments
 (0)