summaryrefslogtreecommitdiff
path: root/gr-dtv
diff options
context:
space:
mode:
authorThomas Habets <habets@google.com>2019-11-20 12:30:19 +0000
committerMartin Braun <martin.braun@ettus.com>2020-01-04 22:35:12 -0800
commit27a466a9c8a03392270fadde9e5bafef5c062e61 (patch)
treeb7b8ce04ef2b95cb663fc06faad4a866062007e6 /gr-dtv
parent8c6657f5edad34f3a1058a676f737536be16ce20 (diff)
Replace many `const` variables with `constexpr`
constexpr is like const but (for variables) guarantees evaluation at compile time (as opposed to runtime). Likely this change will do nothing on its own (though it could, since it gives the compiler more information). But it still has benefits. It allows programmer to know that initialization is not expensive (it was done at compile time), and reduces risk of a refactoring regressing the compiletimeness. Runtime initialization can be nonobvious in larger codebases. E.g.: struct S { static int foo(); }; const int bar = S::foo(); // Called and initialized at *runtime*. int S::foo() { return 10; } With constexpr: struct S { static constexpr int foo(); }; constexpr int bar = S::foo(); // Error: used before definition. constexpr int S::foo() { return 10; } Initializing at runtime is not just startup costs, but also can save memory since it'll end up in a R/O section of a binary and therefore doesn't need to be swapped out, but can be shared (in the mmap() sense of the word).
Diffstat (limited to 'gr-dtv')
-rw-r--r--gr-dtv/include/gnuradio/dtv/atsc_consts.h18
-rw-r--r--gr-dtv/lib/atsc/atsc_equalizer_impl.h6
-rw-r--r--gr-dtv/lib/atsc/atsc_field_sync_mux_impl.h2
-rw-r--r--gr-dtv/lib/atsc/atsc_fs_checker_impl.h10
-rw-r--r--gr-dtv/lib/atsc/atsc_pnXXX_impl.h4
-rw-r--r--gr-dtv/lib/atsc/atsc_randomize.h4
-rw-r--r--gr-dtv/lib/atsc/atsc_single_viterbi.h2
-rw-r--r--gr-dtv/lib/atsc/atsc_syminfo_impl.h4
-rw-r--r--gr-dtv/lib/atsc/atsc_trellis_encoder_impl.h8
-rw-r--r--gr-dtv/lib/atsc/atsc_types.h22
-rw-r--r--gr-dtv/lib/atsc/atsc_viterbi_decoder_impl.h6
-rw-r--r--gr-dtv/lib/atsc/atsc_viterbi_mux.h10
-rw-r--r--gr-dtv/lib/dvbt/dvbt_reference_signals_impl.h16
13 files changed, 56 insertions, 56 deletions
diff --git a/gr-dtv/include/gnuradio/dtv/atsc_consts.h b/gr-dtv/include/gnuradio/dtv/atsc_consts.h
index 291bc7ed62..e5d6450d1c 100644
--- a/gr-dtv/include/gnuradio/dtv/atsc_consts.h
+++ b/gr-dtv/include/gnuradio/dtv/atsc_consts.h
@@ -29,17 +29,17 @@ namespace gr {
namespace dtv {
// These will go into an mpeg_consts.h once other mod/demods are done
-static const int ATSC_MPEG_DATA_LENGTH = 187;
-static const int ATSC_MPEG_PKT_LENGTH = 188; // sync + data
-static const int ATSC_MPEG_RS_ENCODED_LENGTH = 207;
-static const int MPEG_SYNC_BYTE = 0x47;
-static const int MPEG_TRANSPORT_ERROR_BIT = 0x80; // top bit of byte after SYNC
+static constexpr int ATSC_MPEG_DATA_LENGTH = 187;
+static constexpr int ATSC_MPEG_PKT_LENGTH = 188; // sync + data
+static constexpr int ATSC_MPEG_RS_ENCODED_LENGTH = 207;
+static constexpr int MPEG_SYNC_BYTE = 0x47;
+static constexpr int MPEG_TRANSPORT_ERROR_BIT = 0x80; // top bit of byte after SYNC
// ATSC specific constants
-static const double ATSC_SYMBOL_RATE = 4.5e6 / 286 * 684; // ~10.76 MHz
-static const double ATSC_DATA_SEGMENT_RATE = ATSC_SYMBOL_RATE / 832; // ~12.935 kHz
-static const int ATSC_DATA_SEGMENT_LENGTH = 832; // includes 4 sync symbols at beginning
-static const int ATSC_DSEGS_PER_FIELD = 312; // regular data segs / field
+static constexpr double ATSC_SYMBOL_RATE = 4.5e6 / 286 * 684; // ~10.76 MHz
+static constexpr double ATSC_DATA_SEGMENT_RATE = ATSC_SYMBOL_RATE / 832; // ~12.935 kHz
+static constexpr int ATSC_DATA_SEGMENT_LENGTH = 832; // includes 4 sync symbols at beginning
+static constexpr int ATSC_DSEGS_PER_FIELD = 312; // regular data segs / field
} /* namespace dtv */
} /* namespace gr */
diff --git a/gr-dtv/lib/atsc/atsc_equalizer_impl.h b/gr-dtv/lib/atsc/atsc_equalizer_impl.h
index 70bf046078..787a93b6da 100644
--- a/gr-dtv/lib/atsc/atsc_equalizer_impl.h
+++ b/gr-dtv/lib/atsc/atsc_equalizer_impl.h
@@ -33,11 +33,11 @@ namespace dtv {
class atsc_equalizer_impl : public atsc_equalizer
{
private:
- static const int NTAPS = 64;
- static const int NPRETAPS = (int)(NTAPS * 0.8); // probably should be either .2 or .8
+ static constexpr int NTAPS = 64;
+ static constexpr int NPRETAPS = (int)(NTAPS * 0.8); // probably should be either .2 or .8
// the length of the field sync pattern that we know unequivocally
- static const int KNOWN_FIELD_SYNC_LENGTH = 4 + 511 + 3 * 63;
+ static constexpr int KNOWN_FIELD_SYNC_LENGTH = 4 + 511 + 3 * 63;
float training_sequence1[KNOWN_FIELD_SYNC_LENGTH];
float training_sequence2[KNOWN_FIELD_SYNC_LENGTH];
diff --git a/gr-dtv/lib/atsc/atsc_field_sync_mux_impl.h b/gr-dtv/lib/atsc/atsc_field_sync_mux_impl.h
index 8399252fa2..e90cf8b8c6 100644
--- a/gr-dtv/lib/atsc/atsc_field_sync_mux_impl.h
+++ b/gr-dtv/lib/atsc/atsc_field_sync_mux_impl.h
@@ -31,7 +31,7 @@ namespace dtv {
class atsc_field_sync_mux_impl : public atsc_field_sync_mux
{
private:
- static const int N_SAVED_SYMBOLS = 12;
+ static constexpr int N_SAVED_SYMBOLS = 12;
bool d_already_output_field_sync;
unsigned char d_saved_symbols[N_SAVED_SYMBOLS];
diff --git a/gr-dtv/lib/atsc/atsc_fs_checker_impl.h b/gr-dtv/lib/atsc/atsc_fs_checker_impl.h
index 2f8325277b..b14cba00e5 100644
--- a/gr-dtv/lib/atsc/atsc_fs_checker_impl.h
+++ b/gr-dtv/lib/atsc/atsc_fs_checker_impl.h
@@ -32,7 +32,7 @@ namespace dtv {
class atsc_fs_checker_impl : public atsc_fs_checker
{
private:
- static const int SRSIZE = 1024; // must be power of two
+ static constexpr int SRSIZE = 1024; // must be power of two
int d_index; // points at oldest sample
float d_sample_sr[SRSIZE]; // sample shift register
atsc::syminfo d_tag_sr[SRSIZE]; // tag shift register
@@ -40,10 +40,10 @@ private:
int d_field_num;
int d_segment_num;
- static const int OFFSET_511 = 4; // offset to second PN 63 pattern
- static const int LENGTH_511 = 511; // length of PN 63 pattern
- static const int OFFSET_2ND_63 = 578; // offset to second PN 63 pattern
- static const int LENGTH_2ND_63 = 63; // length of PN 63 pattern
+ static constexpr int OFFSET_511 = 4; // offset to second PN 63 pattern
+ static constexpr int LENGTH_511 = 511; // length of PN 63 pattern
+ static constexpr int OFFSET_2ND_63 = 578; // offset to second PN 63 pattern
+ static constexpr int LENGTH_2ND_63 = 63; // length of PN 63 pattern
inline static int wrap(int index) { return index & (SRSIZE - 1); }
inline static int incr(int index) { return wrap(index + 1); }
diff --git a/gr-dtv/lib/atsc/atsc_pnXXX_impl.h b/gr-dtv/lib/atsc/atsc_pnXXX_impl.h
index da07b779e5..7f25b7c0b5 100644
--- a/gr-dtv/lib/atsc/atsc_pnXXX_impl.h
+++ b/gr-dtv/lib/atsc/atsc_pnXXX_impl.h
@@ -25,7 +25,7 @@
#include <gnuradio/dtv/api.h>
-const unsigned char atsc_pn511[511] = {
+constexpr unsigned char atsc_pn511[511] = {
0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0,
1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1,
@@ -59,7 +59,7 @@ const unsigned char atsc_pn511[511] = {
0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0
};
-const unsigned char atsc_pn63[63] = { 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1,
+constexpr unsigned char atsc_pn63[63] = { 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1,
0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1,
1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0,
0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0 };
diff --git a/gr-dtv/lib/atsc/atsc_randomize.h b/gr-dtv/lib/atsc/atsc_randomize.h
index 48331cdab8..2792c445fc 100644
--- a/gr-dtv/lib/atsc/atsc_randomize.h
+++ b/gr-dtv/lib/atsc/atsc_randomize.h
@@ -84,8 +84,8 @@ private:
unsigned int d_state;
- static const unsigned int PRELOAD_VALUE = 0x018f; /* 0xf180 bit reversed */
- static const unsigned int MASK = 0xa638;
+ static constexpr unsigned int PRELOAD_VALUE = 0x018f; /* 0xf180 bit reversed */
+ static constexpr unsigned int MASK = 0xa638;
static unsigned char s_output_map[1 << 14];
static bool s_output_map_initialized_p;
};
diff --git a/gr-dtv/lib/atsc/atsc_single_viterbi.h b/gr-dtv/lib/atsc/atsc_single_viterbi.h
index fbfd673915..739b3ac1c5 100644
--- a/gr-dtv/lib/atsc/atsc_single_viterbi.h
+++ b/gr-dtv/lib/atsc/atsc_single_viterbi.h
@@ -31,7 +31,7 @@ class atsc_single_viterbi
public:
atsc_single_viterbi();
- static const unsigned int TB_LEN = 32;
+ static constexpr unsigned int TB_LEN = 32;
/*!
* \p INPUT ideally takes on the values +/- 1,3,5,7
diff --git a/gr-dtv/lib/atsc/atsc_syminfo_impl.h b/gr-dtv/lib/atsc/atsc_syminfo_impl.h
index c12f47c6b9..971e4416ec 100644
--- a/gr-dtv/lib/atsc/atsc_syminfo_impl.h
+++ b/gr-dtv/lib/atsc/atsc_syminfo_impl.h
@@ -26,8 +26,8 @@ namespace gr {
namespace dtv {
namespace atsc {
-static const unsigned int SI_SEGMENT_NUM_MASK = 0x1ff;
-static const unsigned int SI_FIELD_SYNC_SEGMENT_NUM =
+static constexpr unsigned int SI_SEGMENT_NUM_MASK = 0x1ff;
+static constexpr unsigned int SI_FIELD_SYNC_SEGMENT_NUM =
SI_SEGMENT_NUM_MASK; // conceptually -1
struct syminfo {
diff --git a/gr-dtv/lib/atsc/atsc_trellis_encoder_impl.h b/gr-dtv/lib/atsc/atsc_trellis_encoder_impl.h
index 9b7160c478..537aaa01c1 100644
--- a/gr-dtv/lib/atsc/atsc_trellis_encoder_impl.h
+++ b/gr-dtv/lib/atsc/atsc_trellis_encoder_impl.h
@@ -34,10 +34,10 @@ private:
bool debug;
/* How many separate Trellis encoders / Viterbi decoders run in parallel */
- static const int NCODERS = 12;
- static const int SEGMENT_SIZE = ATSC_MPEG_RS_ENCODED_LENGTH;
- static const int INPUT_SIZE = (SEGMENT_SIZE * 12);
- static const int OUTPUT_SIZE = (ATSC_DATA_SEGMENT_LENGTH * 12);
+ static constexpr int NCODERS = 12;
+ static constexpr int SEGMENT_SIZE = ATSC_MPEG_RS_ENCODED_LENGTH;
+ static constexpr int INPUT_SIZE = (SEGMENT_SIZE * 12);
+ static constexpr int OUTPUT_SIZE = (ATSC_DATA_SEGMENT_LENGTH * 12);
void reset();
void encode(atsc_data_segment out[NCODERS],
diff --git a/gr-dtv/lib/atsc/atsc_types.h b/gr-dtv/lib/atsc/atsc_types.h
index c27ef1c451..a728351c80 100644
--- a/gr-dtv/lib/atsc/atsc_types.h
+++ b/gr-dtv/lib/atsc/atsc_types.h
@@ -149,33 +149,33 @@ public:
protected:
// these three are mutually exclusive
// This is a regular data segment.
- static const int fl_regular_seg = 0x0001;
+ static constexpr int fl_regular_seg = 0x0001;
// This is a field sync segment, for 1st half of a field.
- static const int fl_field_sync1 = 0x0002;
+ static constexpr int fl_field_sync1 = 0x0002;
// This is a field sync segment, for 2nd half of a field.
- static const int fl_field_sync2 = 0x0004;
+ static constexpr int fl_field_sync2 = 0x0004;
// This bit is on ONLY when fl_regular_seg is set AND when this is
// the first regular data segment AFTER a field sync segment. This
// segment causes various processing modules to reset.
- static const int fl_first_regular_seg = 0x0008;
+ static constexpr int fl_first_regular_seg = 0x0008;
// which field are we in?
- static const int fl_field2 = 0x0010; // else field 1
+ static constexpr int fl_field2 = 0x0010; // else field 1
// This bit is set when Reed-Solomon decoding detects an error that it
// can't correct. Note that other error detection (e.g. Viterbi) do not
// set it, since Reed-Solomon will correct many of those. This bit is
// then copied into the final Transport Stream packet so that MPEG
// software can see that the 188-byte data segment has been corrupted.
- static const int fl_transport_error = 0x0020;
+ static constexpr int fl_transport_error = 0x0020;
};
class atsc_mpeg_packet
{
public:
- static const int NPAD = 68;
+ static constexpr int NPAD = 68;
unsigned char data[ATSC_MPEG_DATA_LENGTH + 1]; // first byte is sync
unsigned char _pad_[NPAD]; // pad to power of 2 (256)
@@ -194,7 +194,7 @@ public:
class atsc_mpeg_packet_no_sync
{
public:
- static const int NPAD = 65;
+ static constexpr int NPAD = 65;
plinfo pli;
unsigned char data[ATSC_MPEG_DATA_LENGTH];
unsigned char _pad_[NPAD]; // pad to power of 2 (256)
@@ -214,7 +214,7 @@ public:
class atsc_mpeg_packet_rs_encoded
{
public:
- static const int NPAD = 45;
+ static constexpr int NPAD = 45;
plinfo pli;
unsigned char data[ATSC_MPEG_RS_ENCODED_LENGTH];
unsigned char _pad_[NPAD]; // pad to power of 2 (256)
@@ -237,7 +237,7 @@ public:
class atsc_data_segment
{
public:
- static const int NPAD = 188;
+ static constexpr int NPAD = 188;
plinfo pli;
unsigned char data[ATSC_DATA_SEGMENT_LENGTH];
unsigned char _pad_[NPAD]; // pad to power of 2 (1024)
@@ -263,7 +263,7 @@ public:
class atsc_soft_data_segment
{
public:
- static const int NPAD = 764;
+ static constexpr int NPAD = 764;
plinfo pli;
float data[ATSC_DATA_SEGMENT_LENGTH];
unsigned char _pad_[NPAD]; // pad to power of 2 (4096)
diff --git a/gr-dtv/lib/atsc/atsc_viterbi_decoder_impl.h b/gr-dtv/lib/atsc/atsc_viterbi_decoder_impl.h
index 07b15efa1f..279e97645b 100644
--- a/gr-dtv/lib/atsc/atsc_viterbi_decoder_impl.h
+++ b/gr-dtv/lib/atsc/atsc_viterbi_decoder_impl.h
@@ -51,9 +51,9 @@ class atsc_viterbi_decoder_impl : public atsc_viterbi_decoder
private:
typedef interleaver_fifo<unsigned char> fifo_t;
- static const int SEGMENT_SIZE = ATSC_MPEG_RS_ENCODED_LENGTH; // 207
- static const int OUTPUT_SIZE = (SEGMENT_SIZE * 12);
- static const int INPUT_SIZE = (ATSC_DATA_SEGMENT_LENGTH * 12);
+ static constexpr int SEGMENT_SIZE = ATSC_MPEG_RS_ENCODED_LENGTH; // 207
+ static constexpr int OUTPUT_SIZE = (SEGMENT_SIZE * 12);
+ static constexpr int INPUT_SIZE = (ATSC_DATA_SEGMENT_LENGTH * 12);
single_viterbi_t viterbi[NCODERS];
fifo_t* fifo[NCODERS];
diff --git a/gr-dtv/lib/atsc/atsc_viterbi_mux.h b/gr-dtv/lib/atsc/atsc_viterbi_mux.h
index 2beb49e08a..5430720ff0 100644
--- a/gr-dtv/lib/atsc/atsc_viterbi_mux.h
+++ b/gr-dtv/lib/atsc/atsc_viterbi_mux.h
@@ -5,13 +5,13 @@
* Generated by 'atsc_viterbi_gen.cc'.
*/
-const unsigned int sync_symbol_indices_max = 12;
-const unsigned int sync_symbol_indices[12] = {
+constexpr unsigned int sync_symbol_indices_max = 12;
+constexpr unsigned int sync_symbol_indices[12] = {
0, 832, 1664, 2496, 3328, 4160, 4992, 5824, 6656, 7488, 8320, 9152,
};
-const unsigned int enco_which_max = 828;
-const unsigned int enco_which_syms[12][828] = {
+constexpr unsigned int enco_which_max = 828;
+constexpr unsigned int enco_which_syms[12][828] = {
/* 0 */
{
4, 16, 28, 40, 52, 64, 76, 88, 100, 112, 124, 136, 148,
@@ -818,7 +818,7 @@ const unsigned int enco_which_syms[12][828] = {
},
};
-const unsigned int enco_which_dibits[12][828] = {
+constexpr unsigned int enco_which_dibits[12][828] = {
/* 0 */
{
6, 4, 2, 0, 102, 100, 98, 96, 198, 196, 194,
diff --git a/gr-dtv/lib/dvbt/dvbt_reference_signals_impl.h b/gr-dtv/lib/dvbt/dvbt_reference_signals_impl.h
index 04eded8be7..be12c18ed4 100644
--- a/gr-dtv/lib/dvbt/dvbt_reference_signals_impl.h
+++ b/gr-dtv/lib/dvbt/dvbt_reference_signals_impl.h
@@ -27,16 +27,16 @@
#include <vector>
// This should eventually go into a const file
-const int SYMBOLS_PER_FRAME = 68;
-const int FRAMES_PER_SUPERFRAME = 4;
+constexpr int SYMBOLS_PER_FRAME = 68;
+constexpr int FRAMES_PER_SUPERFRAME = 4;
-const int SCATTERED_PILOT_SIZE_2k = 142;
-const int CONTINUAL_PILOT_SIZE_2k = 45;
-const int TPS_PILOT_SIZE_2k = 17;
+constexpr int SCATTERED_PILOT_SIZE_2k = 142;
+constexpr int CONTINUAL_PILOT_SIZE_2k = 45;
+constexpr int TPS_PILOT_SIZE_2k = 17;
-const int SCATTERED_PILOT_SIZE_8k = 568;
-const int CONTINUAL_PILOT_SIZE_8k = 177;
-const int TPS_PILOT_SIZE_8k = 68;
+constexpr int SCATTERED_PILOT_SIZE_8k = 568;
+constexpr int CONTINUAL_PILOT_SIZE_8k = 177;
+constexpr int TPS_PILOT_SIZE_8k = 68;
namespace gr {
namespace dtv {