diff options
author | Artjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com> | 2022-04-04 16:12:00 +0300 |
---|---|---|
committer | Artjoms Rimdjonoks <artjoms.rimdjonoks@zabbix.com> | 2022-04-04 16:12:00 +0300 |
commit | c2b40f22048878b527b6949cc11ab29ec2ffe599 (patch) | |
tree | 8ceafb025bc6a65c989a0282d6182b2128c374f0 /src | |
parent | 3d5ce84a5279b9787a3b3690f044b02546116046 (diff) |
.......... [DEV-2130] appended zbx_ to public uinc, udiv and umul functions
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/zbxalgo/int128.c | 19 | ||||
-rw-r--r-- | src/libs/zbxdbcache/dbcache.c | 12 |
2 files changed, 18 insertions, 13 deletions
diff --git a/src/libs/zbxalgo/int128.c b/src/libs/zbxalgo/int128.c index 9367e6ea839..d4d43974e3c 100644 --- a/src/libs/zbxalgo/int128.c +++ b/src/libs/zbxalgo/int128.c @@ -116,6 +116,9 @@ static int ucmp128_128(const zbx_uint128_t *value1, const zbx_uint128_t *value2) return value1->lo < value2->lo ? -1 : 1; } +/* 128 bit unsigned integer handling */ +#define uset128(base, hi64, lo64) (base)->hi = hi64; (base)->lo = lo64 + /****************************************************************************** * * * Purpose: Multiplication of 64 bit unsigned integer with 32 bit unsigned * @@ -127,7 +130,7 @@ static int ucmp128_128(const zbx_uint128_t *value1, const zbx_uint128_t *value2) * shift - [IN] the number of bits to shift the result by before * * adding it to the base value. * * * - * Comments: This is a helper function for umul64_64 implementation. * + * Comments: This is a helper function for zbx_umul64_64 implementation. * * * ******************************************************************************/ static void umul64_32_shift(zbx_uint128_t *base, zbx_uint64_t value, zbx_uint64_t factor, int shift) @@ -136,11 +139,11 @@ static void umul64_32_shift(zbx_uint128_t *base, zbx_uint64_t value, zbx_uint64_ uset128(&buffer, 0, (value & UINT32_BIT_MASK) * factor); ushiftl128(&buffer, shift); - uinc128_128(base, &buffer); + zbx_uinc128_128(base, &buffer); uset128(&buffer, 0, (value >> UINT32_BIT_COUNT) * factor); ushiftl128(&buffer, UINT32_BIT_COUNT + shift); - uinc128_128(base, &buffer); + zbx_uinc128_128(base, &buffer); } /****************************************************************************** @@ -152,7 +155,7 @@ static void umul64_32_shift(zbx_uint128_t *base, zbx_uint64_t value, zbx_uint64_ * value - [IN] the value to increment by. * * * ******************************************************************************/ -void uinc128_64(zbx_uint128_t *base, zbx_uint64_t value) +void zbx_uinc128_64(zbx_uint128_t *base, zbx_uint64_t value) { zbx_uint64_t low = base->lo; @@ -171,7 +174,7 @@ void uinc128_64(zbx_uint128_t *base, zbx_uint64_t value) * value - [IN] the value to increment by. * * * ******************************************************************************/ -void uinc128_128(zbx_uint128_t *base, const zbx_uint128_t *value) +void zbx_uinc128_128(zbx_uint128_t *base, const zbx_uint128_t *value) { zbx_uint64_t low = base->lo; @@ -191,7 +194,7 @@ void uinc128_128(zbx_uint128_t *base, const zbx_uint128_t *value) * factor - [IN] the factor to multiply by. * * * ******************************************************************************/ -void umul64_64(zbx_uint128_t *result, zbx_uint64_t value, zbx_uint64_t factor) +void zbx_umul64_64(zbx_uint128_t *result, zbx_uint64_t value, zbx_uint64_t factor) { uset128(result, 0, 0); /* multiply the value with lower double word of factor and add the result */ @@ -210,7 +213,7 @@ void umul64_64(zbx_uint128_t *result, zbx_uint64_t value, zbx_uint64_t factor) * value - [IN] the divisor. * * * ******************************************************************************/ -void udiv128_64(zbx_uint128_t *result, const zbx_uint128_t *dividend, zbx_uint64_t value) +void zbx_udiv128_64(zbx_uint128_t *result, const zbx_uint128_t *dividend, zbx_uint64_t value) { zbx_uint128_t reminder, divisor; zbx_uint64_t result_mask = __UINT64_C(1) << (UINT64_BIT_COUNT - 1); @@ -257,3 +260,5 @@ void udiv128_64(zbx_uint128_t *result, const zbx_uint128_t *dividend, zbx_uint64 /* reminder is less than 64 bits, proceed with 64bit division */ result->lo |= reminder.lo / value; } + +#undef uset128 diff --git a/src/libs/zbxdbcache/dbcache.c b/src/libs/zbxdbcache/dbcache.c index 6edb09afaa7..8df2bb41450 100644 --- a/src/libs/zbxdbcache/dbcache.c +++ b/src/libs/zbxdbcache/dbcache.c @@ -408,7 +408,7 @@ static void dc_insert_trends_in_db(ZBX_DC_TREND *trends, int trends_num, unsigne zbx_uint128_t avg; /* calculate the trend average value */ - udiv128_64(&avg, &trend->value_avg.ui64, trend->num); + zbx_udiv128_64(&avg, &trend->value_avg.ui64, trend->num); zbx_db_insert_add_values(&db_insert, trend->itemid, trend->clock, trend->num, trend->value_min.ui64, avg.lo, trend->value_max.ui64); @@ -543,9 +543,9 @@ static void dc_trends_update_uint(ZBX_DC_TREND *trend, DB_ROW row, int num, size trend->value_max.ui64 = value_max.ui64; /* calculate the trend average value */ - umul64_64(&avg, num, value_avg.ui64); - uinc128_128(&trend->value_avg.ui64, &avg); - udiv128_64(&avg, &trend->value_avg.ui64, trend->num + num); + zbx_umul64_64(&avg, num, value_avg.ui64); + zbx_uinc128_128(&trend->value_avg.ui64, &avg); + zbx_udiv128_64(&avg, &trend->value_avg.ui64, trend->num + num); trend->num += num; @@ -818,7 +818,7 @@ static void DCadd_trend(const ZBX_DC_HISTORY *history, ZBX_DC_TREND **trends, in trend->value_min.ui64 = history->value.ui64; if (trend->num == 0 || history->value.ui64 > trend->value_max.ui64) trend->value_max.ui64 = history->value.ui64; - uinc128_64(&trend->value_avg.ui64, history->value.ui64); + zbx_uinc128_64(&trend->value_avg.ui64, history->value.ui64); break; } trend->num++; @@ -1188,7 +1188,7 @@ static void DCexport_trends(const ZBX_DC_TREND *trends, int trends_num, zbx_hash break; case ITEM_VALUE_TYPE_UINT64: zbx_json_adduint64(&json, ZBX_PROTO_TAG_MIN, trend->value_min.ui64); - udiv128_64(&avg, &trend->value_avg.ui64, trend->num); + zbx_udiv128_64(&avg, &trend->value_avg.ui64, trend->num); zbx_json_adduint64(&json, ZBX_PROTO_TAG_AVG, avg.lo); zbx_json_adduint64(&json, ZBX_PROTO_TAG_MAX, trend->value_max.ui64); break; |