Commit 53507dd2 authored by vaillancour's avatar vaillancour
Browse files

Merge branch 'basop_noglob' of forge.3gpp.org:ivas-codec-pc/ivas-codec-basop into basop_noglob

parents eacf2155 c23c3a4b
Loading
Loading
Loading
Loading
+35 −25
Original line number Diff line number Diff line
@@ -159,40 +159,46 @@ Flag BASOP_Carry = 0;
#ifdef BASOP_NOGLOB_DEV_USE_GLOBALS
Flag Overflow = 0;
Flag Carry = 0;
#endif /* BASOP_NOGLOB_DEV_USE_GLOBALS */

#if defined BASOP_PRINT_ON_WARNING || defined BASOP_ABORT_ON_WARNING
int BASOP_saturation_warning_enable=1, BASOP_saturation_warning_disable_counter=0;
int BASOP_warnings_as_errors=0;
#endif
#if defined BASOP_NOGLOB_DEV_PRINT || defined BASOP_NOGLOB_DEV_ABORT
int overflow_warning_enable=1, overflow_warning_disable_counter=0;
int overflow_error_enable=0;

#ifdef BASOP_PRINT_ON_WARNING
#define B_HELPER_PRINT_WARNING() do { if (BASOP_saturation_warning_enable) { if(BASOP_warnings_as_errors) { print_basop_noglob_error(); } else { print_basop_noglob_warning(); } } } while(0)
#else
#define B_HELPER_PRINT_WARNING() do { (void)0; } while(0) /* no-op */
#endif
#else /* BASOP_NOGLOB */
Flag Overflow = 0;
Flag Carry = 0;
#endif /* BASOP_NOGLOB */

#ifdef BASOP_NOGLOB
#if defined BASOP_NOGLOB_DEV_ABORT
#define BASOP_TRIGGER_OVERFLOW_ERROR_OR_WARNING(error_enable, warning_enable) do { if ((error_enable) || (warning_enable)) { assert(0); } } while(0)
#elif defined BASOP_NOGLOB_DEV_PRINT
#define BASOP_TRIGGER_OVERFLOW_ERROR_OR_WARNING(error_enable, warning_enable) do { if (error_enable) { print_basop_noglob_error(); } else if (warning_enable) { print_basop_noglob_warning(); } } while(0)
#ifdef BASOP_ABORT_ON_WARNING
#define B_HELPER_ABORT() do { if (BASOP_saturation_warning_enable) { assert(0); } } while(0)
#else
#define BASOP_TRIGGER_OVERFLOW_ERROR_OR_WARNING(error_enable, warning_enable) do { (void)0; } while(0) /* no-op */
#define B_HELPER_ABORT() do { (void)0; } while(0) /* no-op */
#endif

#ifdef BASOP_NOGLOB_DEV_USE_GLOBALS
#define BASOP_SET_GLOBAL(global_flag, value) do { (global_flag) = (value); } while (0)
#define BASOP_GET_GLOBAL(global_flag) (global_flag)
#define B_HELPER_SET_GLOBAL(global_flag, value) do { (global_flag) = (value); } while (0)
#define B_HELPER_GET_GLOBAL(global_flag) (global_flag)
#else
#define BASOP_SET_GLOBAL(global_flag, value) do { (void)0; } while(0) /* no-op */
#define BASOP_GET_GLOBAL(global_flag) 0 /* Default to 0 */
#define B_HELPER_SET_GLOBAL(global_flag, value) do { (void)0; } while(0) /* no-op */
#define B_HELPER_GET_GLOBAL(global_flag) 0 /* Default to 0 */
#endif

void set_overflow(Flag *overflow) { if (overflow) *overflow = 1; else { BASOP_TRIGGER_OVERFLOW_ERROR_OR_WARNING(overflow_error_enable, overflow_warning_enable); BASOP_SET_GLOBAL(Overflow, 1); } }
void unset_overflow(Flag* overflow) { if (overflow) *overflow = 0;  else { BASOP_TRIGGER_OVERFLOW_ERROR_OR_WARNING(overflow_error_enable, overflow_warning_enable); BASOP_SET_GLOBAL(Overflow, 0); } }
void set_carry(Flag *carry) { if (carry) *carry = 1; else { BASOP_TRIGGER_OVERFLOW_ERROR_OR_WARNING(overflow_error_enable, overflow_warning_enable); BASOP_SET_GLOBAL(Carry, 1); } }
void unset_carry(Flag* carry) { if (carry) *carry = 0; else { BASOP_TRIGGER_OVERFLOW_ERROR_OR_WARNING(overflow_error_enable, overflow_warning_enable); BASOP_SET_GLOBAL(Carry, 0);} }
Flag get_carry(Flag* carry) { if (carry) return *carry; else { BASOP_TRIGGER_OVERFLOW_ERROR_OR_WARNING(overflow_error_enable, overflow_warning_enable); } return BASOP_GET_GLOBAL(Carry); }
void set_overflow(Flag *overflow) { if (overflow) *overflow = 1; else { B_HELPER_PRINT_WARNING(); B_HELPER_ABORT(); B_HELPER_SET_GLOBAL(Overflow, 1); } }
void unset_overflow(Flag* overflow) { if (overflow) *overflow = 0;  else { B_HELPER_PRINT_WARNING(); B_HELPER_ABORT(); B_HELPER_SET_GLOBAL(Overflow, 0); } }
void set_carry(Flag *carry) { if (carry) *carry = 1; else { B_HELPER_PRINT_WARNING(); B_HELPER_ABORT(); B_HELPER_SET_GLOBAL(Carry, 1); } }
void unset_carry(Flag* carry) { if (carry) *carry = 0; else { B_HELPER_PRINT_WARNING(); B_HELPER_ABORT(); B_HELPER_SET_GLOBAL(Carry, 0);} }
Flag get_carry(const Flag* carry) { if (carry) return *carry; else { B_HELPER_PRINT_WARNING(); B_HELPER_ABORT(); } return B_HELPER_GET_GLOBAL(Carry); }

#ifdef BASOP_NOGLOB_DEV_PRINT
/* Undef helper macros - these should only be used in functions above */
#undef B_HELPER_PRINT_WARNING
#undef B_HELPER_ABORT
#undef B_HELPER_SET_GLOBAL
#undef B_HELPER_GET_GLOBAL

#ifdef BASOP_PRINT_ON_WARNING
#include <stdio.h>
#if  defined(__unix__) || defined(__unix) || defined(__APPLE__)
#include <execinfo.h>
@@ -214,13 +220,17 @@ void print_stack(void) {

void print_basop_noglob_warning(void) {
  printf("[BASOP] Overflow occured. Call stack:\n");
  print_stack(); /* TODO(sgi): printStack from LC3 does not work out of the box */
  print_stack();
}
void print_basop_noglob_error(void) {
  printf("[BASOP] Overflow error occured. Call stack:\n");
  print_stack();
}
#endif
#endif /* BASOP_PRINT_ON_WARNING */

#else /* BASOP_NOGLOB */
Flag Overflow = 0;
Flag Carry = 0;
#endif /* BASOP_NOGLOB */


+43 −44
Original line number Diff line number Diff line
@@ -62,49 +62,64 @@
extern Flag BASOP_Overflow, BASOP_Overflow2;
extern Flag BASOP_Carry;
*/

#ifdef BASOP_NOGLOB_DEV_USE_GLOBALS
extern Flag Overflow;
extern Flag Carry;
#else
#define BASOP_NOGLOB_DECLARE_LOCAL
#endif

#if defined BASOP_NOGLOB_DEV_PRINT || defined BASOP_NOGLOB_DEV_ABORT
extern int overflow_count;
extern int overflow_warning_enable, overflow_warning_disable_counter;
extern int overflow_error_enable;
void set_overflow(Flag *overflow);
void unset_overflow(Flag* overflow);
void set_carry(Flag *carry);
void unset_carry(Flag* carry);
Flag get_carry(const Flag* carry);

#if defined BASOP_PRINT_ON_WARNING || defined BASOP_ABORT_ON_WARNING
extern int BASOP_saturation_warning_enable, BASOP_saturation_warning_disable_counter;
extern int BASOP_warnings_as_errors;

#define BASOP_SATURATE_WARNING_ON  {\
    overflow_warning_disable_counter--;\
    if (overflow_warning_disable_counter < 0) overflow_warning_disable_counter = 0;\
    if (overflow_warning_disable_counter == 0) {\
        overflow_warning_enable=1;\
#define BASOP_SATURATE_WARNING_ON() do  {\
    BASOP_saturation_warning_disable_counter--;\
    if (BASOP_saturation_warning_disable_counter < 0) BASOP_saturation_warning_disable_counter = 0;\
    if (BASOP_saturation_warning_disable_counter == 0) {\
        BASOP_saturation_warning_enable=1;\
    }\
}
#define BASOP_SATURATE_WARNING_OFF {\
    overflow_warning_enable=0;\
    overflow_warning_disable_counter++;\
}
#define BASOP_SATURATE_ERROR_ON  {\
    overflow_error_enable=1;\
}
#define BASOP_SATURATE_ERROR_OFF {\
    overflow_error_enable=0;\
}

#ifdef BASOP_NOGLOB_DEV_PRINT
} while(0)

#define BASOP_SATURATE_WARNING_OFF() do {\
    BASOP_saturation_warning_enable=0;\
    BASOP_saturation_warning_disable_counter++;\
} while(0)

#define BASOP_WARNINGS_AS_ERRORS_ON() do { BASOP_warnings_as_errors=1; } while(0)
#define BASOP_WARNINGS_AS_ERRORS_OFF() do { BASOP_warnings_as_errors=0; } while(0)
#else /* defined BASOP_PRINT_ON_WARNING || defined BASOP_ABORT_ON_WARNING */
#define BASOP_SATURATE_WARNING_ON() do { (void)0; } while(0) /* no-op */
#define BASOP_SATURATE_WARNING_OFF() do { (void)0; } while(0) /* no-op */
#define BASOP_WARNINGS_AS_ERRORS_ON() do { (void)0; } while(0) /* no-op */
#define BASOP_WARNINGS_AS_ERRORS_OFF() do { (void)0; } while(0) /* no-op */
#endif /* defined BASOP_PRINT_ON_WARNING || defined BASOP_ABORT_ON_WARNING */

#ifdef BASOP_PRINT_ON_WARNING
void print_basop_noglob_warning(void);
void print_basop_noglob_error(void);
#endif
#else
#define BASOP_SATURATE_WARNING_ON
#define BASOP_SATURATE_WARNING_OFF
#define BASOP_SATURATE_ERROR_ON
#define BASOP_SATURATE_ERROR_OFF
#endif

/* For backward compatibility only. New WARNINGS_AS_ERRORS macros are preferred for new code */
#define BASOP_SATURATE_ERROR_ON BASOP_WARNINGS_AS_ERRORS_ON();
#define BASOP_SATURATE_ERROR_OFF BASOP_WARNINGS_AS_ERRORS_OFF();
#else /* BASOP_NOGLOB */
extern Flag Overflow, Overflow2;
extern Flag Carry;

#define BASOP_SATURATE_WARNING_ON
#define BASOP_SATURATE_WARNING_OFF
#define BASOP_SATURATE_ERROR_ON
#define BASOP_SATURATE_ERROR_OFF
#endif /* BASOP_NOGLOB */
#define BASOP_CHECK()

/* Empty EVS specific definitions added to disable the macros in EVS without removing them*/
#define BASOP_SATURATE_WARNING_ON_EVS
@@ -112,28 +127,12 @@ extern Flag Carry;
#define BASOP_SATURATE_ERROR_ON_EVS
#define BASOP_SATURATE_ERROR_OFF_EVS

#ifndef BASOP_NOGLOB
#define BASOP_SATURATE_WARNING_ON
#define BASOP_SATURATE_WARNING_OFF
#define BASOP_SATURATE_ERROR_ON
#define BASOP_SATURATE_ERROR_OFF
#endif
#define BASOP_CHECK()

#define MAX_32 (Word32)0x7fffffffL
#define MIN_32 (Word32)0x80000000L

#define MAX_16 (Word16)0x7fff
#define MIN_16 (Word16)0x8000

#ifdef BASOP_NOGLOB
void set_overflow(Flag *overflow);
void unset_overflow(Flag* overflow);
void set_carry(Flag *carry);
void unset_carry(Flag* carry);
Flag get_carry(Flag* carry);
#endif /* BASOP_NOGLOB */

/*___________________________________________________________________________
 |                                                                           |
 |   Prototypes for basic arithmetic operators                               |
+10 −12
Original line number Diff line number Diff line
@@ -31,21 +31,19 @@
#define ENH_32_BIT_OPERATOR
#define BASOP_NOGLOB

#ifdef BASOP_NOGLOB
/* If enabled, global Overflow and Carry flags are used, like before BASOP_NOGLOB,
 * but overflow warnings and errors are still triggered */
 * but new BASOP warnings are still triggered */
// #define BASOP_NOGLOB_DEV_USE_GLOBALS

/* If enabled, all overflow warnings and errors are disabled in EVS routines */
// #define BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
/* If enabled, all BASOP warnings are disabled in EVS routines */
// #define BASOP_IGNORE_WARNINGS_IN_EVS

/* Macros below configure the behavior when an overflow warning or error is triggered.
 * If none is enabled, overflow warnings and errors are ignored. */
//#define BASOP_NOGLOB_DEV_PRINT /* If enabled, warnings and errors will be printed to stdout */
#define BASOP_NOGLOB_DEV_ABORT /* If enabled, any warning or error will cause the program to abort */

#if defined BASOP_NOGLOB && !defined BASOP_NOGLOB_DEV_USE_GLOBALS
#define BASOP_NOGLOB_DECLARE_LOCAL
#endif
/* Macros below configure the behavior when a BASOP warning is triggered.
 * If none is enabled, all warnings are ignored. */
// #define BASOP_PRINT_ON_WARNING /* If enabled, warnings will be printed to stdout */
#define BASOP_ABORT_ON_WARNING /* If enabled, any warning will cause the program to abort */
#endif /* BASOP_NOGLOB */

#include "patch.h"
/* both ALLOW_40bits and ALLOW_ENH_UL32 shall be enabled for the EVS codec.  */
+10 −20
Original line number Diff line number Diff line
@@ -80,18 +80,16 @@ int main(int argc, char *argv[])

    IF(st_fx->Opt_VOIP_fx)
    {
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
        BASOP_SATURATE_WARNING_OFF
        BASOP_SATURATE_ERROR_OFF
#endif
#ifdef SUPPORT_JBM_TRACEFILE
        IF( decodeVoip(st_fx, f_stream, f_synth, jbmTraceFileName, jbmFECoffsetFileName, quietMode ) != 0 )
#else
        IF( decodeVoip(st_fx, f_stream, f_synth, jbmFECoffsetFileName, quietMode ) != 0 )
#endif
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
        BASOP_SATURATE_WARNING_ON
        BASOP_SATURATE_ERROR_ON
#endif
        {
            free( st_fx );
@@ -167,26 +165,22 @@ int main(int argc, char *argv[])
            {
                IF ( st_fx->Opt_AMR_WB_fx )
                {
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
                    BASOP_SATURATE_WARNING_OFF
                    BASOP_SATURATE_ERROR_OFF
#endif
                    amr_wb_dec_fx( output,st_fx);
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
                    BASOP_SATURATE_WARNING_ON
                    BASOP_SATURATE_ERROR_ON
#endif
                }
                ELSE
                {
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
                    BASOP_SATURATE_WARNING_OFF
                    BASOP_SATURATE_ERROR_OFF
#endif
                    evs_dec_fx( st_fx, output, FRAMEMODE_NORMAL);
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
                    BASOP_SATURATE_WARNING_ON
                    BASOP_SATURATE_ERROR_ON
#endif
                }
            }
@@ -194,26 +188,22 @@ int main(int argc, char *argv[])
            {
                IF(st_fx->bfi_fx == 0)
                {
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
                    BASOP_SATURATE_WARNING_OFF
                    BASOP_SATURATE_ERROR_OFF
#endif
                    evs_dec_fx( st_fx, output, FRAMEMODE_NORMAL);
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
                    BASOP_SATURATE_WARNING_ON
                    BASOP_SATURATE_ERROR_ON
#endif
                }
                ELSE /* conceal */
                {
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
                    BASOP_SATURATE_WARNING_OFF
                    BASOP_SATURATE_ERROR_OFF
#endif
                    evs_dec_fx( st_fx, output, FRAMEMODE_MISSING);
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
                    BASOP_SATURATE_WARNING_ON
                    BASOP_SATURATE_ERROR_ON
#endif
                }
            }
+4 −8
Original line number Diff line number Diff line
@@ -237,14 +237,12 @@ int main( int argc, char** argv )
        IF ( st_fx->Opt_AMR_WB_fx )
        {
            SUB_WMOPS_INIT("amr_wb_enc");
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
            BASOP_SATURATE_WARNING_OFF
            BASOP_SATURATE_ERROR_OFF
#endif
            amr_wb_enc_fx( st_fx, data, n_samples);
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
            BASOP_SATURATE_WARNING_ON
            BASOP_SATURATE_ERROR_ON
#endif
            END_SUB_WMOPS;
        }
@@ -252,14 +250,12 @@ int main( int argc, char** argv )
        {
            SUB_WMOPS_INIT("evs_enc");
            /* EVS encoder*/
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
            BASOP_SATURATE_WARNING_OFF
            BASOP_SATURATE_ERROR_OFF
#endif
            evs_enc_fx( st_fx, data, st_fx->mem_hp20_in_fx, n_samples);
#ifdef BASOP_IGNORE_WARNINGS_AND_ERRORS_IN_EVS
#ifdef BASOP_IGNORE_WARNINGS_IN_EVS
            BASOP_SATURATE_WARNING_ON
            BASOP_SATURATE_ERROR_ON
#endif
            END_SUB_WMOPS;
        }