Skip to content

Commit 4c1cad5

Browse files
authored
Merge pull request aous72#160 from aous72/addressing_lto
This address the illegal instruction issue when -flto flag is used (link time optimization) as details in this thread https://bugzilla.redhat.com/show_bug.cgi?id=2307795
2 parents 811f3a2 + c262935 commit 4c1cad5

11 files changed

+103
-91
lines changed

src/core/codestream/ojph_codeblock_fun.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ namespace ojph {
158158
tx_from_cb64 = NULL;
159159
}
160160
encode_cb64 = ojph_encode_codeblock64;
161+
bool result = initialize_block_encoder_tables();
162+
assert(result); ojph_unused(result);
161163

162164
#ifndef OJPH_DISABLE_SIMD
163165

src/core/coding/ojph_block_decoder32.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ namespace ojph {
578578
/** @brief State structure for reading and unstuffing of forward-growing
579579
* bitstreams; these are: MagSgn and SPP bitstreams
580580
*/
581-
struct frwd_struct {
581+
struct frwd_struct32 {
582582
const ui8* data; //!<pointer to bitstream
583583
ui64 tmp; //!<temporary buffer of read data
584584
ui32 bits; //!<number of bits stored in tmp
@@ -601,12 +601,12 @@ namespace ojph {
601601
* Reading can go beyond the end of buffer by up to 3 bytes.
602602
*
603603
* @tparam X is the value fed in when the bitstream is exhausted
604-
* @param [in] msp is a pointer to frwd_struct structure
604+
* @param [in] msp is a pointer to frwd_struct32 structure
605605
*
606606
*/
607607
template<int X>
608608
static inline
609-
void frwd_read(frwd_struct *msp)
609+
void frwd_read(frwd_struct32 *msp)
610610
{
611611
assert(msp->bits <= 32); // assert that there is a space for 32 bits
612612

@@ -653,17 +653,17 @@ namespace ojph {
653653
}
654654

655655
//************************************************************************/
656-
/** @brief Initialize frwd_struct struct and reads some bytes
656+
/** @brief Initialize frwd_struct32 struct and reads some bytes
657657
*
658658
* @tparam X is the value fed in when the bitstream is exhausted.
659659
* See frwd_read regarding the template
660-
* @param [in] msp is a pointer to frwd_struct
660+
* @param [in] msp is a pointer to frwd_struct32
661661
* @param [in] data is a pointer to the start of data
662662
* @param [in] size is the number of byte in the bitstream
663663
*/
664664
template<int X>
665665
static inline
666-
void frwd_init(frwd_struct *msp, const ui8* data, int size)
666+
void frwd_init(frwd_struct32 *msp, const ui8* data, int size)
667667
{
668668
msp->data = data;
669669
msp->tmp = 0;
@@ -689,29 +689,29 @@ namespace ojph {
689689
}
690690

691691
//************************************************************************/
692-
/** @brief Consume num_bits bits from the bitstream of frwd_struct
692+
/** @brief Consume num_bits bits from the bitstream of frwd_struct32
693693
*
694-
* @param [in] msp is a pointer to frwd_struct
694+
* @param [in] msp is a pointer to frwd_struct32
695695
* @param [in] num_bits is the number of bit to consume
696696
*/
697697
static inline
698-
void frwd_advance(frwd_struct *msp, ui32 num_bits)
698+
void frwd_advance(frwd_struct32 *msp, ui32 num_bits)
699699
{
700700
assert(num_bits <= msp->bits);
701701
msp->tmp >>= num_bits; // consume num_bits
702702
msp->bits -= num_bits;
703703
}
704704

705705
//************************************************************************/
706-
/** @brief Fetches 32 bits from the frwd_struct bitstream
706+
/** @brief Fetches 32 bits from the frwd_struct32 bitstream
707707
*
708708
* @tparam X is the value fed in when the bitstream is exhausted.
709709
* See frwd_read regarding the template
710-
* @param [in] msp is a pointer to frwd_struct
710+
* @param [in] msp is a pointer to frwd_struct32
711711
*/
712712
template<int X>
713713
static inline
714-
ui32 frwd_fetch(frwd_struct *msp)
714+
ui32 frwd_fetch(frwd_struct32 *msp)
715715
{
716716
if (msp->bits < 32)
717717
{
@@ -1099,7 +1099,7 @@ namespace ojph {
10991099
const int v_n_size = 512 + 4;
11001100
ui32 v_n_scratch[v_n_size] = {0}; // 2+ kB
11011101

1102-
frwd_struct magsgn;
1102+
frwd_struct32 magsgn;
11031103
frwd_init<0xFF>(&magsgn, coded_data, lcup - scup);
11041104

11051105
ui16 *sp = scratch;
@@ -1368,7 +1368,7 @@ namespace ojph {
13681368
// We add an extra 8 entries, just in case we need more
13691369
ui16 prev_row_sig[256 + 8] = {0}; // 528 Bytes
13701370

1371-
frwd_struct sigprop;
1371+
frwd_struct32 sigprop;
13721372
frwd_init<0>(&sigprop, coded_data + lengths1, (int)lengths2);
13731373

13741374
for (ui32 y = 0; y < height; y += 4)

src/core/coding/ojph_block_decoder64.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ namespace ojph {
530530
/** @brief State structure for reading and unstuffing of forward-growing
531531
* bitstreams; these are: MagSgn and SPP bitstreams
532532
*/
533-
struct frwd_struct {
533+
struct frwd_struct64 {
534534
const ui8* data; //!<pointer to bitstream
535535
ui64 tmp; //!<temporary buffer of read data
536536
ui32 bits; //!<number of bits stored in tmp
@@ -553,12 +553,12 @@ namespace ojph {
553553
* Reading can go beyond the end of buffer by up to 3 bytes.
554554
*
555555
* @tparam X is the value fed in when the bitstream is exhausted
556-
* @param [in] msp is a pointer to frwd_struct structure
556+
* @param [in] msp is a pointer to frwd_struct64 structure
557557
*
558558
*/
559559
template<int X>
560560
static inline
561-
void frwd_read(frwd_struct *msp)
561+
void frwd_read(frwd_struct64 *msp)
562562
{
563563
assert(msp->bits <= 32); // assert that there is a space for 32 bits
564564

@@ -617,12 +617,12 @@ namespace ojph {
617617
* MSB of the next byte is set 0 and must be ignored during decoding.
618618
*
619619
* @tparam X is the value fed in when the bitstream is exhausted
620-
* @param [in] msp is a pointer to frwd_struct structure
620+
* @param [in] msp is a pointer to frwd_struct64 structure
621621
*
622622
*/
623623
template<ui8 X>
624624
static inline
625-
void frwd_read8(frwd_struct *msp)
625+
void frwd_read8(frwd_struct64 *msp)
626626
{
627627
ui8 val = X;
628628
if (msp->size > 0) {
@@ -640,17 +640,17 @@ namespace ojph {
640640
}
641641

642642
//************************************************************************/
643-
/** @brief Initialize frwd_struct struct and reads some bytes
643+
/** @brief Initialize frwd_struct64 struct and reads some bytes
644644
*
645645
* @tparam X is the value fed in when the bitstream is exhausted.
646646
* See frwd_read regarding the template
647-
* @param [in] msp is a pointer to frwd_struct
647+
* @param [in] msp is a pointer to frwd_struct64
648648
* @param [in] data is a pointer to the start of data
649649
* @param [in] size is the number of byte in the bitstream
650650
*/
651651
template<int X>
652652
static inline
653-
void frwd_init(frwd_struct *msp, const ui8* data, int size)
653+
void frwd_init(frwd_struct64 *msp, const ui8* data, int size)
654654
{
655655
msp->data = data;
656656
msp->tmp = 0;
@@ -676,17 +676,17 @@ namespace ojph {
676676
}
677677

678678
//************************************************************************/
679-
/** @brief Initialize frwd_struct struct and reads some bytes
679+
/** @brief Initialize frwd_struct64 struct and reads some bytes
680680
*
681681
* @tparam X is the value fed in when the bitstream is exhausted.
682682
* See frwd_read regarding the template
683-
* @param [in] msp is a pointer to frwd_struct
683+
* @param [in] msp is a pointer to frwd_struct64
684684
* @param [in] data is a pointer to the start of data
685685
* @param [in] size is the number of byte in the bitstream
686686
*/
687687
template<ui8 X>
688688
static inline
689-
void frwd_init8(frwd_struct *msp, const ui8* data, int size)
689+
void frwd_init8(frwd_struct64 *msp, const ui8* data, int size)
690690
{
691691
msp->data = data;
692692
msp->tmp = 0;
@@ -697,29 +697,29 @@ namespace ojph {
697697
}
698698

699699
//************************************************************************/
700-
/** @brief Consume num_bits bits from the bitstream of frwd_struct
700+
/** @brief Consume num_bits bits from the bitstream of frwd_struct64
701701
*
702-
* @param [in] msp is a pointer to frwd_struct
702+
* @param [in] msp is a pointer to frwd_struct64
703703
* @param [in] num_bits is the number of bit to consume
704704
*/
705705
static inline
706-
void frwd_advance(frwd_struct *msp, ui32 num_bits)
706+
void frwd_advance(frwd_struct64 *msp, ui32 num_bits)
707707
{
708708
assert(num_bits <= msp->bits);
709709
msp->tmp >>= num_bits; // consume num_bits
710710
msp->bits -= num_bits;
711711
}
712712

713713
//************************************************************************/
714-
/** @brief Fetches 32 bits from the frwd_struct bitstream
714+
/** @brief Fetches 32 bits from the frwd_struct64 bitstream
715715
*
716716
* @tparam X is the value fed in when the bitstream is exhausted.
717717
* See frwd_read regarding the template
718-
* @param [in] msp is a pointer to frwd_struct
718+
* @param [in] msp is a pointer to frwd_struct64
719719
*/
720720
template<int X>
721721
static inline
722-
ui32 frwd_fetch(frwd_struct *msp)
722+
ui32 frwd_fetch(frwd_struct64 *msp)
723723
{
724724
if (msp->bits < 32)
725725
{
@@ -731,15 +731,15 @@ namespace ojph {
731731
}
732732

733733
//************************************************************************/
734-
/** @brief Fetches up to 64 bits from the frwd_struct bitstream
734+
/** @brief Fetches up to 64 bits from the frwd_struct64 bitstream
735735
*
736736
* @tparam X is the value fed in when the bitstream is exhausted.
737737
* See frwd_read regarding the template
738-
* @param [in] msp is a pointer to frwd_struct
738+
* @param [in] msp is a pointer to frwd_struct64
739739
*/
740740
template<ui8 X>
741741
static inline
742-
ui64 frwd_fetch64(frwd_struct *msp)
742+
ui64 frwd_fetch64(frwd_struct64 *msp)
743743
{
744744
while (msp->bits <= 56)
745745
frwd_read8<X>(msp);
@@ -1147,7 +1147,7 @@ namespace ojph {
11471147
const int v_n_size = 512 + 4;
11481148
ui64 v_n_scratch[v_n_size] = {0}; // 4+ kB
11491149

1150-
frwd_struct magsgn;
1150+
frwd_struct64 magsgn;
11511151
frwd_init8<0xFF>(&magsgn, coded_data, lcup - scup);
11521152

11531153
const ui16 *sp = scratch;
@@ -1415,7 +1415,7 @@ namespace ojph {
14151415
// We add an extra 8 entries, just in case we need more
14161416
ui16 prev_row_sig[256 + 8] = {0}; // 528 Bytes
14171417

1418-
frwd_struct sigprop;
1418+
frwd_struct64 sigprop;
14191419
frwd_init<0>(&sigprop, coded_data + lengths1, (int)lengths2);
14201420

14211421
for (ui32 y = 0; y < height; y += 4)

src/core/coding/ojph_block_decoder_avx2.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ namespace ojph {
582582
/** @brief State structure for reading and unstuffing of forward-growing
583583
* bitstreams; these are: MagSgn and SPP bitstreams
584584
*/
585-
struct frwd_struct {
585+
struct frwd_struct_avx2 {
586586
const ui8* data; //!<pointer to bitstream
587587
ui8 tmp[48]; //!<temporary buffer of read data + 16 extra
588588
ui32 bits; //!<number of bits stored in tmp
@@ -605,12 +605,12 @@ namespace ojph {
605605
* Reading can go beyond the end of buffer by up to 16 bytes.
606606
*
607607
* @tparam X is the value fed in when the bitstream is exhausted
608-
* @param [in] msp is a pointer to frwd_struct structure
608+
* @param [in] msp is a pointer to frwd_struct_avx2 structure
609609
*
610610
*/
611611
template<int X>
612612
static inline
613-
void frwd_read(frwd_struct *msp)
613+
void frwd_read(frwd_struct_avx2 *msp)
614614
{
615615
assert(msp->bits <= 128);
616616

@@ -689,17 +689,17 @@ namespace ojph {
689689
}
690690

691691
//************************************************************************/
692-
/** @brief Initialize frwd_struct struct and reads some bytes
692+
/** @brief Initialize frwd_struct_avx2 struct and reads some bytes
693693
*
694694
* @tparam X is the value fed in when the bitstream is exhausted.
695695
* See frwd_read regarding the template
696-
* @param [in] msp is a pointer to frwd_struct
696+
* @param [in] msp is a pointer to frwd_struct_avx2
697697
* @param [in] data is a pointer to the start of data
698698
* @param [in] size is the number of byte in the bitstream
699699
*/
700700
template<int X>
701701
static inline
702-
void frwd_init(frwd_struct *msp, const ui8* data, int size)
702+
void frwd_init(frwd_struct_avx2 *msp, const ui8* data, int size)
703703
{
704704
msp->data = data;
705705
_mm_storeu_si128((__m128i *)msp->tmp, _mm_setzero_si128());
@@ -714,13 +714,13 @@ namespace ojph {
714714
}
715715

716716
//************************************************************************/
717-
/** @brief Consume num_bits bits from the bitstream of frwd_struct
717+
/** @brief Consume num_bits bits from the bitstream of frwd_struct_avx2
718718
*
719-
* @param [in] msp is a pointer to frwd_struct
719+
* @param [in] msp is a pointer to frwd_struct_avx2
720720
* @param [in] num_bits is the number of bit to consume
721721
*/
722722
static inline
723-
void frwd_advance(frwd_struct *msp, ui32 num_bits)
723+
void frwd_advance(frwd_struct_avx2 *msp, ui32 num_bits)
724724
{
725725
assert(num_bits > 0 && num_bits <= msp->bits && num_bits < 128);
726726
msp->bits -= num_bits;
@@ -752,15 +752,15 @@ namespace ojph {
752752
}
753753

754754
//************************************************************************/
755-
/** @brief Fetches 32 bits from the frwd_struct bitstream
755+
/** @brief Fetches 32 bits from the frwd_struct_avx2 bitstream
756756
*
757757
* @tparam X is the value fed in when the bitstream is exhausted.
758758
* See frwd_read regarding the template
759-
* @param [in] msp is a pointer to frwd_struct
759+
* @param [in] msp is a pointer to frwd_struct_avx2
760760
*/
761761
template<int X>
762762
static inline
763-
__m128i frwd_fetch(frwd_struct *msp)
763+
__m128i frwd_fetch(frwd_struct_avx2 *msp)
764764
{
765765
if (msp->bits <= 128)
766766
{
@@ -782,7 +782,7 @@ namespace ojph {
782782
* @param vn used for handling E values (stores v_n values)
783783
* @return __m256i decoded two quads
784784
*/
785-
static inline __m256i decode_two_quad32_avx2(__m256i inf_u_q, __m256i U_q, frwd_struct* magsgn, ui32 p, __m128i& vn) {
785+
static inline __m256i decode_two_quad32_avx2(__m256i inf_u_q, __m256i U_q, frwd_struct_avx2* magsgn, ui32 p, __m128i& vn) {
786786
__m256i row = _mm256_setzero_si256();
787787

788788
// we keeps e_k, e_1, and rho in w2
@@ -896,7 +896,7 @@ namespace ojph {
896896
* @return __m128i decoded quad
897897
*/
898898

899-
static inline __m256i decode_four_quad16(const __m128i inf_u_q, __m128i U_q, frwd_struct* magsgn, ui32 p, __m128i& vn) {
899+
static inline __m256i decode_four_quad16(const __m128i inf_u_q, __m128i U_q, frwd_struct_avx2* magsgn, ui32 p, __m128i& vn) {
900900

901901
__m256i w0; // workers
902902
__m256i insig; // lanes hold FF's if samples are insignificant
@@ -1435,7 +1435,7 @@ namespace ojph {
14351435
const int v_n_size = 512 + 16;
14361436
ui32 v_n_scratch[2 * v_n_size] = {0}; // 4+ kB
14371437

1438-
frwd_struct magsgn;
1438+
frwd_struct_avx2 magsgn;
14391439
frwd_init<0xFF>(&magsgn, coded_data, lcup - scup);
14401440

14411441
const __m256i avx_mmsbp2 = _mm256_set1_epi32((int)mmsbp2);
@@ -1551,7 +1551,7 @@ namespace ojph {
15511551
ui16 v_n_scratch[v_n_size] = {0}; // 1+ kB
15521552
ui32 v_n_scratch_32[v_n_size] = {0}; // 2+ kB
15531553

1554-
frwd_struct magsgn;
1554+
frwd_struct_avx2 magsgn;
15551555
frwd_init<0xFF>(&magsgn, coded_data, lcup - scup);
15561556

15571557
{
@@ -1728,7 +1728,7 @@ namespace ojph {
17281728
// We add an extra 8 entries, just in case we need more
17291729
ui16 prev_row_sig[256 + 8] = {0}; // 528 Bytes
17301730

1731-
frwd_struct sigprop;
1731+
frwd_struct_avx2 sigprop;
17321732
frwd_init<0>(&sigprop, coded_data + lengths1, (int)lengths2);
17331733

17341734
for (ui32 y = 0; y < height; y += 4)

0 commit comments

Comments
 (0)