You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
980 B

/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: printf function
* Author: SmartMedia_BSP
* Create: 2020-06-04
*/
#include <td_type.h>
#include <stdlib.h>
uint32_t div64_32(uint64_t *num, uint32_t div)
{
uint64_t remainder;
uint64_t d = div;
uint64_t quotient = 0;
uint64_t q = 1;
uint32_t high;
if (num == NULL) {
return 0;
}
remainder = *num;
high = (*num) >> 32; /* shift 32 bit */
if ((div != 0) && (high >= div)) {
high /= div;
quotient = (uint64_t)high << 32; /* shift 32 bit */
remainder -= (uint64_t)(high * div) << 32; /* shift 32 bit */
}
while ((int64_t)d > 0 && d < remainder) {
d = d + d;
q = q + q;
}
do {
if (remainder >= d) {
remainder -= d;
quotient += q;
}
d >>= 1;
q >>= 1;
} while (q);
*num = quotient;
return remainder;
}