本文整理汇总了C++中rounddown函数的典型用法代码示例。如果您正苦于以下问题:C++ rounddown函数的具体用法?C++ rounddown怎么用?C++ rounddown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rounddown函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sparse_dump_mark
/*
* Include or exclude pages in a sparse dump, by half-open virtual
* address interval (which may wrap around the end of the space).
*/
static void
sparse_dump_mark(vaddr_t vbegin, vaddr_t vend, int includep)
{
pmap_t pmap;
paddr_t p;
vaddr_t v;
/*
* If a partial page is called for, the whole page must be included.
*/
if (includep) {
vbegin = rounddown(vbegin, PAGE_SIZE);
vend = roundup(vend, PAGE_SIZE);
} else {
vbegin = roundup(vbegin, PAGE_SIZE);
vend = rounddown(vend, PAGE_SIZE);
}
pmap = pmap_kernel();
for (v = vbegin; v != vend; v += PAGE_SIZE) {
if (pmap_extract(pmap, v, &p)) {
if (includep)
setbit(sparse_dump_physmap, p/PAGE_SIZE);
else
clrbit(sparse_dump_physmap, p/PAGE_SIZE);
}
}
}
示例2: __xvip_dma_try_format
static void
__xvip_dma_try_format(struct xvip_dma *dma, struct v4l2_pix_format *pix,
const struct xvip_video_format **fmtinfo)
{
const struct xvip_video_format *info;
unsigned int min_width;
unsigned int max_width;
unsigned int min_bpl;
unsigned int max_bpl;
unsigned int width;
unsigned int align;
unsigned int bpl;
/* Retrieve format information and select the default format if the
* requested format isn't supported.
*/
info = xvip_get_format_by_fourcc(pix->pixelformat);
if (IS_ERR(info))
info = xvip_get_format_by_fourcc(XVIP_DMA_DEF_FORMAT);
pix->pixelformat = info->fourcc;
pix->colorspace = V4L2_COLORSPACE_SRGB;
pix->field = V4L2_FIELD_NONE;
/* The transfer alignment requirements are expressed in bytes. Compute
* the minimum and maximum values, clamp the requested width and convert
* it back to pixels.
*/
align = lcm(dma->align, info->bpp);
min_width = roundup(XVIP_DMA_MIN_WIDTH, align);
max_width = rounddown(XVIP_DMA_MAX_WIDTH, align);
width = rounddown(pix->width * info->bpp, align);
pix->width = clamp(width, min_width, max_width) / info->bpp;
pix->height = clamp(pix->height, XVIP_DMA_MIN_HEIGHT,
XVIP_DMA_MAX_HEIGHT);
/* Clamp the requested bytes per line value. If the maximum bytes per
* line value is zero, the module doesn't support user configurable line
* sizes. Override the requested value with the minimum in that case.
*/
min_bpl = pix->width * info->bpp;
max_bpl = rounddown(XVIP_DMA_MAX_WIDTH, dma->align);
bpl = rounddown(pix->bytesperline, dma->align);
pix->bytesperline = clamp(bpl, min_bpl, max_bpl);
pix->sizeimage = pix->bytesperline * pix->height;
if (fmtinfo)
*fmtinfo = info;
}
示例3: pcm512x_pllin_dac_rate
static unsigned long pcm512x_pllin_dac_rate(struct snd_soc_dai *dai,
unsigned long osr_rate,
unsigned long pllin_rate)
{
struct snd_soc_codec *codec = dai->codec;
struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
unsigned long dac_rate;
if (!pcm512x->pll_out)
return 0; /* no PLL to bypass, force SCK as DAC input */
if (pllin_rate % osr_rate)
return 0; /* futile, quit early */
/* run DAC no faster than 6144000 Hz */
for (dac_rate = rounddown(pcm512x_dac_max(pcm512x, 6144000), osr_rate);
dac_rate;
dac_rate -= osr_rate) {
if (pllin_rate / dac_rate > 128)
return 0; /* DAC divider would be too big */
if (!(pllin_rate % dac_rate))
return dac_rate;
dac_rate -= osr_rate;
}
return 0;
}
示例4: update_range__
static void update_range__(struct sw_flow_match *match,
size_t offset, size_t size, bool is_mask)
{
struct sw_flow_key_range *range = NULL;
size_t start = rounddown(offset, sizeof(long));
size_t end = roundup(offset + size, sizeof(long));
if (!is_mask)
range = &match->range;
else if (match->mask)
range = &match->mask->range;
if (!range)
return;
if (range->start == range->end) {
range->start = start;
range->end = end;
return;
}
if (range->start > start)
range->start = start;
if (range->end < end)
range->end = end;
}
示例5: chacha20_simd
static int chacha20_simd(struct blkcipher_desc *desc, struct scatterlist *dst,
struct scatterlist *src, unsigned int nbytes)
{
struct blkcipher_walk walk;
u32 state[16];
int err;
if (nbytes <= CHACHA20_BLOCK_SIZE || !may_use_simd())
return crypto_chacha20_crypt(desc, dst, src, nbytes);
blkcipher_walk_init(&walk, dst, src, nbytes);
err = blkcipher_walk_virt_block(desc, &walk, CHACHA20_BLOCK_SIZE);
crypto_chacha20_init(state, crypto_blkcipher_ctx(desc->tfm), walk.iv);
kernel_neon_begin();
while (walk.nbytes >= CHACHA20_BLOCK_SIZE) {
chacha20_dosimd(state, walk.dst.virt.addr, walk.src.virt.addr,
rounddown(walk.nbytes, CHACHA20_BLOCK_SIZE));
err = blkcipher_walk_done(desc, &walk,
walk.nbytes % CHACHA20_BLOCK_SIZE);
}
if (walk.nbytes) {
chacha20_dosimd(state, walk.dst.virt.addr, walk.src.virt.addr,
walk.nbytes);
err = blkcipher_walk_done(desc, &walk, 0);
}
kernel_neon_end();
return err;
}
示例6: elf_ph_sane
static int elf_ph_sane(Elf_Phdr *phdr)
{
if (rounddown((uintptr_t)phdr, sizeof(Elf_Addr)) != (uintptr_t)phdr) {
return 0;
}
return 1;
}
示例7: offtab_read_window
static bool
offtab_read_window(struct offtab *offtab, uint32_t blkno, int read_flags)
{
const uint32_t window_start = rounddown(blkno, offtab->ot_window_size);
size_t window_bytes;
off_t window_pos;
assert(offtab->ot_mode == OFFTAB_MODE_READ);
assert(ISSET(read_flags, OFFTAB_READ_SEEK) ||
(lseek(offtab->ot_fd, 0, SEEK_CUR) == offtab->ot_fdpos) ||
((lseek(offtab->ot_fd, 0, SEEK_CUR) == -1) && (errno == ESPIPE)));
offtab_compute_window_position(offtab, window_start,
&window_bytes, &window_pos);
const ssize_t n_read = (ISSET(read_flags, OFFTAB_READ_SEEK)
? pread_block(offtab->ot_fd, offtab->ot_window, window_bytes,
window_pos)
: read_block(offtab->ot_fd, offtab->ot_window, window_bytes));
if (n_read == -1) {
(*offtab->ot_report)("read offset table at %"PRIuMAX,
(uintmax_t)window_pos);
return false;
}
assert(n_read >= 0);
if ((size_t)n_read != window_bytes) {
(*offtab->ot_reportx)("partial read of offset table"
" at %"PRIuMAX": %zu != %zu",
(uintmax_t)window_pos, (size_t)n_read, window_bytes);
return false;
}
offtab->ot_window_start = window_start;
return true;
}
示例8: swiotlb_set_max_segment
void swiotlb_set_max_segment(unsigned int val)
{
if (swiotlb_force == SWIOTLB_FORCE)
max_segment = 1;
else
max_segment = rounddown(val, PAGE_SIZE);
}
示例9: pcm512x_find_sck
static unsigned long pcm512x_find_sck(struct snd_soc_dai *dai,
unsigned long bclk_rate)
{
struct device *dev = dai->dev;
struct snd_soc_codec *codec = dai->codec;
struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
unsigned long sck_rate;
int pow2;
/* 64 MHz <= pll_rate <= 100 MHz, VREF mode */
/* 16 MHz <= sck_rate <= 25 MHz, VREF mode */
/* select sck_rate as a multiple of bclk_rate but still with
* as many factors of 2 as possible, as that makes it easier
* to find a fast DAC rate
*/
pow2 = 1 << fls((pcm512x_pll_max(pcm512x) - 16000000) / bclk_rate);
for (; pow2; pow2 >>= 1) {
sck_rate = rounddown(pcm512x_pll_max(pcm512x),
bclk_rate * pow2);
if (sck_rate >= 16000000)
break;
}
if (!pow2) {
dev_err(dev, "Impossible to generate a suitable SCK\n");
return 0;
}
dev_dbg(dev, "sck_rate %lu\n", sck_rate);
return sck_rate;
}
示例10: ath10k_bmi_fast_download
int ath10k_bmi_fast_download(struct ath10k *ar,
u32 address, const void *buffer, u32 length)
{
u8 trailer[4] = {};
u32 head_len = rounddown(length, 4);
u32 trailer_len = length - head_len;
int ret;
ret = ath10k_bmi_lz_stream_start(ar, address);
if (ret)
return ret;
/* copy the last word into a zero padded buffer */
if (trailer_len > 0)
memcpy(trailer, buffer + head_len, trailer_len);
ret = ath10k_bmi_lz_data(ar, buffer, head_len);
if (ret)
return ret;
if (trailer_len > 0)
ret = ath10k_bmi_lz_data(ar, trailer, 4);
if (ret != 0)
return ret;
/*
* Close compressed stream and open a new (fake) one.
* This serves mainly to flush Target caches.
*/
ret = ath10k_bmi_lz_stream_start(ar, 0x00);
return ret;
}
示例11: mouse_cut_start
/* a mouse button is pressed, start cut operation */
static void
mouse_cut_start(scr_stat *scp)
{
int i;
int s;
if (scp->status & MOUSE_VISIBLE) {
sc_remove_all_cutmarkings(scp->sc);
if ((scp->mouse_pos == scp->mouse_cut_start) &&
(scp->mouse_pos == scp->mouse_cut_end)) {
cut_buffer[0] = '\0';
return;
} else if (skip_spc_right(scp, scp->mouse_pos) >= scp->xsize) {
/* if the pointer is on trailing blank chars, mark towards eol */
i = skip_spc_left(scp, scp->mouse_pos) + 1;
s = spltty();
scp->mouse_cut_start =
rounddown(scp->mouse_pos, scp->xsize) + i;
scp->mouse_cut_end =
(scp->mouse_pos / scp->xsize + 1) * scp->xsize - 1;
splx(s);
cut_buffer[0] = '\r';
} else {
s = spltty();
scp->mouse_cut_start = scp->mouse_pos;
scp->mouse_cut_end = scp->mouse_cut_start;
splx(s);
cut_buffer[0] = sc_vtb_getc(&scp->vtb, scp->mouse_cut_start);
}
cut_buffer[1] = '\0';
scp->status |= MOUSE_CUTTING;
mark_all(scp); /* this is probably overkill XXX */
}
}
示例12: mouse_cut_word
/* copy a word under the mouse pointer */
static void
mouse_cut_word(scr_stat *scp)
{
int start;
int end;
int sol;
int eol;
int c;
int j;
int len;
/*
* Because we don't have locale information in the kernel,
* we only distinguish space char and non-space chars. Punctuation
* chars, symbols and other regular chars are all treated alike
* unless user specified SC_CUT_SEPCHARS in his kernel config file.
*/
if (scp->status & MOUSE_VISIBLE) {
sol = rounddown(scp->mouse_pos, scp->xsize);
eol = sol + scp->xsize;
c = sc_vtb_getc(&scp->vtb, scp->mouse_pos);
if (IS_SEP_CHAR(c)) {
/* blank space */
for (j = scp->mouse_pos; j >= sol; --j) {
c = sc_vtb_getc(&scp->vtb, j);
if (!IS_SEP_CHAR(c))
break;
}
start = ++j;
for (j = scp->mouse_pos; j < eol; ++j) {
c = sc_vtb_getc(&scp->vtb, j);
if (!IS_SEP_CHAR(c))
break;
}
end = j - 1;
} else {
/* non-space word */
for (j = scp->mouse_pos; j >= sol; --j) {
c = sc_vtb_getc(&scp->vtb, j);
if (IS_SEP_CHAR(c))
break;
}
start = ++j;
for (j = scp->mouse_pos; j < eol; ++j) {
c = sc_vtb_getc(&scp->vtb, j);
if (IS_SEP_CHAR(c))
break;
}
end = j - 1;
}
/* copy the found word */
mouse_do_cut(scp, start, end);
len = strlen(cut_buffer);
if (cut_buffer[len - 1] == '\r')
cut_buffer[len - 1] = '\0';
}
}
示例13: tscm_hwdep_read_queue
static long tscm_hwdep_read_queue(struct snd_tscm *tscm, char __user *buf,
long remained, loff_t *offset)
{
char __user *pos = buf;
unsigned int type = SNDRV_FIREWIRE_EVENT_TASCAM_CONTROL;
struct snd_firewire_tascam_change *entries = tscm->queue;
long count;
// At least, one control event can be copied.
if (remained < sizeof(type) + sizeof(*entries)) {
spin_unlock_irq(&tscm->lock);
return -EINVAL;
}
// Copy the type field later.
count = sizeof(type);
remained -= sizeof(type);
pos += sizeof(type);
while (true) {
unsigned int head_pos;
unsigned int tail_pos;
unsigned int length;
if (tscm->pull_pos == tscm->push_pos)
break;
else if (tscm->pull_pos < tscm->push_pos)
tail_pos = tscm->push_pos;
else
tail_pos = SND_TSCM_QUEUE_COUNT;
head_pos = tscm->pull_pos;
length = (tail_pos - head_pos) * sizeof(*entries);
if (remained < length)
length = rounddown(remained, sizeof(*entries));
if (length == 0)
break;
spin_unlock_irq(&tscm->lock);
if (copy_to_user(pos, &entries[head_pos], length))
return -EFAULT;
spin_lock_irq(&tscm->lock);
tscm->pull_pos = tail_pos % SND_TSCM_QUEUE_COUNT;
count += length;
remained -= length;
pos += length;
}
spin_unlock_irq(&tscm->lock);
if (copy_to_user(buf, &type, sizeof(type)))
return -EFAULT;
return count;
}
示例14: kfd_doorbell_init
/* Doorbell calculations for device init. */
void kfd_doorbell_init(struct kfd_dev *kfd)
{
size_t doorbell_start_offset;
size_t doorbell_aperture_size;
size_t doorbell_process_limit;
/*
* We start with calculations in bytes because the input data might
* only be byte-aligned.
* Only after we have done the rounding can we assume any alignment.
*/
doorbell_start_offset =
roundup(kfd->shared_resources.doorbell_start_offset,
doorbell_process_allocation());
doorbell_aperture_size =
rounddown(kfd->shared_resources.doorbell_aperture_size,
doorbell_process_allocation());
if (doorbell_aperture_size > doorbell_start_offset)
doorbell_process_limit =
(doorbell_aperture_size - doorbell_start_offset) /
doorbell_process_allocation();
else
doorbell_process_limit = 0;
kfd->doorbell_base = kfd->shared_resources.doorbell_physical_address +
doorbell_start_offset;
kfd->doorbell_id_offset = doorbell_start_offset / sizeof(u32);
kfd->doorbell_process_limit = doorbell_process_limit - 1;
kfd->doorbell_kernel_ptr = ioremap(kfd->doorbell_base,
doorbell_process_allocation());
BUG_ON(!kfd->doorbell_kernel_ptr);
pr_debug("kfd: doorbell initialization:\n");
pr_debug("kfd: doorbell base == 0x%08lX\n",
(uintptr_t)kfd->doorbell_base);
pr_debug("kfd: doorbell_id_offset == 0x%08lX\n",
kfd->doorbell_id_offset);
pr_debug("kfd: doorbell_process_limit == 0x%08lX\n",
doorbell_process_limit);
pr_debug("kfd: doorbell_kernel_offset == 0x%08lX\n",
(uintptr_t)kfd->doorbell_base);
pr_debug("kfd: doorbell aperture size == 0x%08lX\n",
kfd->shared_resources.doorbell_aperture_size);
pr_debug("kfd: doorbell kernel address == 0x%08lX\n",
(uintptr_t)kfd->doorbell_kernel_ptr);
}
示例15: smsi2c_ts_feed
int smsi2c_ts_feed(void *args, unsigned char * ts_buffer, int size)
{
struct smscore_device_t *coredev = (struct smscore_device_t *)args;
struct smscore_buffer_t *cb;
struct SmsMsgHdr_S *phdr;
int len = 0;
int quotient, residue;
int ts_buf_size_188align;
sms_debug("%s: buffer:0x%p, size:%d\n", __func__, ts_buffer, size);
if (!size || !args)
return 0;
#define TS_PACKET_SIZE 188
ts_buf_size_188align = rounddown((MAX_I2C_BUF_SIZE - sizeof(struct SmsMsgHdr_S)), TS_PACKET_SIZE);
quotient = size / ts_buf_size_188align;
residue = size % ts_buf_size_188align;
for (; quotient > 0; quotient--) {
cb = smscore_getbuffer(coredev);
if (!cb) {
sms_err("Unable to allocate data buffer!\n");
goto exit;
}
phdr = (struct SmsMsgHdr_S *)cb->p;
memset(cb->p, 0, (int)sizeof(struct SmsMsgHdr_S));
SMS_INIT_MSG_EX(phdr, MSG_SMS_DAB_CHANNEL, HIF_TASK, 1, ts_buf_size_188align + sizeof(struct SmsMsgHdr_S));
memcpy((u8*)(phdr+1),ts_buffer, ts_buf_size_188align);
cb->offset = 0;
cb->size = ts_buf_size_188align + sizeof(struct SmsMsgHdr_S);
smscore_onresponse(coredev, cb);
ts_buffer += ts_buf_size_188align;
len += ts_buf_size_188align;
}
if (residue) {
cb = smscore_getbuffer(coredev);
if (!cb) {
sms_err("Unable to allocate data buffer!\n");
goto exit;
}
phdr = (struct SmsMsgHdr_S *)cb->p;
memset(cb->p, 0, (int)sizeof(struct SmsMsgHdr_S));
SMS_INIT_MSG_EX(phdr, MSG_SMS_DAB_CHANNEL, HIF_TASK, 1, residue + sizeof(struct SmsMsgHdr_S));
memcpy((u8*)(phdr+1),ts_buffer, residue);
cb->offset = 0;
cb->size = residue + sizeof(struct SmsMsgHdr_S);
smscore_onresponse(coredev, cb);
ts_buffer += residue;
len += residue;
}
exit:
return len;
}