Skip to content

Commit

Permalink
jtagtap: optimize _no_delay() paths at -O3 like swdptap
Browse files Browse the repository at this point in the history
* Also update signature of jtagtap_tms_seq() (s/ticks/clock_cycles/)
  • Loading branch information
ALTracer committed Dec 31, 2023
1 parent 1c102fe commit f694b4c
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/platforms/common/jtagtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ jtag_proc_s jtag_proc;

static void jtagtap_reset(void);
static inline void platform_delay_busy(const uint32_t loops) __attribute__((always_inline));
static void jtagtap_tms_seq(uint32_t tms_states, size_t ticks);
static void jtagtap_tdi_tdo_seq(uint8_t *data_out, bool final_tms, const uint8_t *data_in, size_t clock_cycles);
static void jtagtap_tdi_seq(bool final_tms, const uint8_t *data_in, size_t clock_cycles);
static bool jtagtap_next(bool tms, bool tdi);
static void jtagtap_cycle(bool tms, bool tdi, size_t clock_cycles);
static void jtagtap_tms_seq(uint32_t tms_states, size_t clock_cycles) __attribute__((optimize(3)));
static void jtagtap_tdi_tdo_seq(uint8_t *data_out, bool final_tms, const uint8_t *data_in, size_t clock_cycles)
__attribute__((optimize(3)));
static void jtagtap_tdi_seq(bool final_tms, const uint8_t *data_in, size_t clock_cycles) __attribute__((optimize(3)));
static bool jtagtap_next(bool tms, bool tdi) __attribute__((optimize(3)));
static void jtagtap_cycle(bool tms, bool tdi, size_t clock_cycles) __attribute__((optimize(3)));

void jtagtap_init(void)
{
Expand Down Expand Up @@ -87,6 +88,8 @@ static bool jtagtap_next_clk_delay()
return result != 0;
}

static bool jtagtap_next_no_delay() __attribute__((optimize(3)));

static bool jtagtap_next_no_delay()
{
gpio_set(TCK_PORT, TCK_PIN);
Expand Down Expand Up @@ -118,6 +121,9 @@ static void jtagtap_tms_seq_clk_delay(uint32_t tms_states, const size_t clock_cy
}
}

static void jtagtap_tms_seq_no_delay(uint32_t tms_states, const size_t clock_cycles)
__attribute__((noinline, optimize(3)));

static void jtagtap_tms_seq_no_delay(uint32_t tms_states, const size_t clock_cycles)
{
bool state = tms_states & 1U;
Expand All @@ -134,13 +140,13 @@ static void jtagtap_tms_seq_no_delay(uint32_t tms_states, const size_t clock_cyc
}
}

static void jtagtap_tms_seq(const uint32_t tms_states, const size_t ticks)
static void jtagtap_tms_seq(const uint32_t tms_states, const size_t clock_cycles)
{
gpio_set(TDI_PORT, TDI_PIN);
if (target_clk_divider != UINT32_MAX)
jtagtap_tms_seq_clk_delay(tms_states, ticks);
jtagtap_tms_seq_clk_delay(tms_states, clock_cycles);
else
jtagtap_tms_seq_no_delay(tms_states, ticks);
jtagtap_tms_seq_no_delay(tms_states, clock_cycles);
}

static void jtagtap_tdi_tdo_seq_clk_delay(
Expand Down Expand Up @@ -176,6 +182,9 @@ static void jtagtap_tdi_tdo_seq_clk_delay(
}
}

static void jtagtap_tdi_tdo_seq_no_delay(const uint8_t *const data_in, uint8_t *const data_out, const bool final_tms,
const size_t clock_cycles) __attribute__((optimize(3)));

static void jtagtap_tdi_tdo_seq_no_delay(
const uint8_t *const data_in, uint8_t *const data_out, const bool final_tms, const size_t clock_cycles)
{
Expand Down Expand Up @@ -250,6 +259,9 @@ static void jtagtap_tdi_seq_clk_delay(const uint8_t *const data_in, const bool f
}
}

static void jtagtap_tdi_seq_no_delay(const uint8_t *const data_in, const bool final_tms, size_t clock_cycles)
__attribute__((optimize(3)));

static void jtagtap_tdi_seq_no_delay(const uint8_t *const data_in, const bool final_tms, size_t clock_cycles)
{
for (size_t cycle = 0; cycle < clock_cycles;) {
Expand Down Expand Up @@ -300,6 +312,8 @@ static void jtagtap_cycle_clk_delay(const size_t clock_cycles)
}
}

static void jtagtap_cycle_no_delay(const size_t clock_cycles) __attribute__((optimize(3)));

static void jtagtap_cycle_no_delay(const size_t clock_cycles)
{
for (size_t cycle = 0; cycle < clock_cycles; ++cycle) {
Expand Down

0 comments on commit f694b4c

Please sign in to comment.