ntpd: code shrink (force not-inlining, stop returning structs)

function                                             old     new   delta
d_to_sfp                                               -     133    +133
lfp_to_d                                               -      84     +84
sfp_to_d                                               -      78     +78
d_to_lfp                                             141     137      -4
.rodata                                           103182  103174      -8
recv_and_process_peer_pkt                           2380    2173    -207
recv_and_process_client_pkt                          706     493    -213
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 0/4 up/down: 295/-432)         Total: -137 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2021-03-26 12:02:08 +01:00
parent c2bd0b6806
commit 1195782d79

View File

@ -552,13 +552,13 @@ gettime1900d(void)
} }
static void static void
d_to_tv(double d, struct timeval *tv) d_to_tv(struct timeval *tv, double d)
{ {
tv->tv_sec = (long)d; tv->tv_sec = (long)d;
tv->tv_usec = (d - tv->tv_sec) * 1000000; tv->tv_usec = (d - tv->tv_sec) * 1000000;
} }
static double static NOINLINE double
lfp_to_d(l_fixedpt_t lfp) lfp_to_d(l_fixedpt_t lfp)
{ {
double ret; double ret;
@ -567,7 +567,7 @@ lfp_to_d(l_fixedpt_t lfp)
ret = (double)lfp.int_partl + ((double)lfp.fractionl / UINT_MAX); ret = (double)lfp.int_partl + ((double)lfp.fractionl / UINT_MAX);
return ret; return ret;
} }
static double static NOINLINE double
sfp_to_d(s_fixedpt_t sfp) sfp_to_d(s_fixedpt_t sfp)
{ {
double ret; double ret;
@ -577,25 +577,25 @@ sfp_to_d(s_fixedpt_t sfp)
return ret; return ret;
} }
#if ENABLE_FEATURE_NTPD_SERVER #if ENABLE_FEATURE_NTPD_SERVER
static l_fixedpt_t static void
d_to_lfp(double d) d_to_lfp(l_fixedpt_t *lfp, double d)
{ {
l_fixedpt_t lfp; uint32_t intl;
lfp.int_partl = (uint32_t)d; uint32_t frac;
lfp.fractionl = (uint32_t)((d - lfp.int_partl) * UINT_MAX); intl = (uint32_t)d;
lfp.int_partl = htonl(lfp.int_partl); frac = (uint32_t)((d - intl) * UINT_MAX);
lfp.fractionl = htonl(lfp.fractionl); lfp->int_partl = htonl(intl);
return lfp; lfp->fractionl = htonl(frac);
} }
static s_fixedpt_t static NOINLINE void
d_to_sfp(double d) d_to_sfp(s_fixedpt_t *sfp, double d)
{ {
s_fixedpt_t sfp; uint16_t ints;
sfp.int_parts = (uint16_t)d; uint16_t frac;
sfp.fractions = (uint16_t)((d - sfp.int_parts) * USHRT_MAX); ints = (uint16_t)d;
sfp.int_parts = htons(sfp.int_parts); frac = (uint16_t)((d - ints) * USHRT_MAX);
sfp.fractions = htons(sfp.fractions); sfp->int_parts = htons(ints);
return sfp; sfp->fractions = htons(frac);
} }
#endif #endif
@ -1037,7 +1037,7 @@ step_time(double offset)
xgettimeofday(&tvc); xgettimeofday(&tvc);
dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset; dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset;
d_to_tv(dtime, &tvn); d_to_tv(&tvn, dtime);
xsettimeofday(&tvn); xsettimeofday(&tvn);
VERB2 { VERB2 {
@ -2117,17 +2117,17 @@ recv_and_process_client_pkt(void /*int fd*/)
msg.m_ppoll = G.poll_exp; msg.m_ppoll = G.poll_exp;
msg.m_precision_exp = G_precision_exp; msg.m_precision_exp = G_precision_exp;
/* this time was obtained between poll() and recv() */ /* this time was obtained between poll() and recv() */
msg.m_rectime = d_to_lfp(G.cur_time); d_to_lfp(&msg.m_rectime, G.cur_time);
msg.m_xmttime = d_to_lfp(gettime1900d()); /* this instant */ d_to_lfp(&msg.m_xmttime, gettime1900d()); /* this instant */
if (G.peer_cnt == 0) { if (G.peer_cnt == 0) {
/* we have no peers: "stratum 1 server" mode. reftime = our own time */ /* we have no peers: "stratum 1 server" mode. reftime = our own time */
G.reftime = G.cur_time; G.reftime = G.cur_time;
} }
msg.m_reftime = d_to_lfp(G.reftime); d_to_lfp(&msg.m_reftime, G.reftime);
msg.m_orgtime = query_xmttime; msg.m_orgtime = query_xmttime;
msg.m_rootdelay = d_to_sfp(G.rootdelay); d_to_sfp(&msg.m_rootdelay, G.rootdelay);
//simple code does not do this, fix simple code! //simple code does not do this, fix simple code!
msg.m_rootdisp = d_to_sfp(G.rootdisp); d_to_sfp(&msg.m_rootdisp, G.rootdisp);
//version = (query_status & VERSION_MASK); /* ... >> VERSION_SHIFT - done below instead */ //version = (query_status & VERSION_MASK); /* ... >> VERSION_SHIFT - done below instead */
msg.m_refid = G.refid; // (version > (3 << VERSION_SHIFT)) ? G.refid : G.refid3; msg.m_refid = G.refid; // (version > (3 << VERSION_SHIFT)) ? G.refid : G.refid3;