Nebula
Loading...
Searching...
No Matches
round.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "core/types.h"
13
14//------------------------------------------------------------------------------
15namespace Util
16{
17class Round
18{
19public:
21 static uint RoundUp2(uint val);
23 static uint RoundUp4(uint val);
25 static uint RoundUp8(uint val);
27 static uint RoundUp16(uint val);
29 static uint RoundUp32(uint val);
31 static uint RoundUp(uint val, uint boundary);
32};
33
34//------------------------------------------------------------------------------
37__forceinline uint
39{
40 return ((uint)val + (2 - 1)) & ~(2 - 1);
41}
42
43//------------------------------------------------------------------------------
46__forceinline uint
48{
49 return ((uint)val + (4 - 1)) & ~(4 - 1);
50}
51
52//------------------------------------------------------------------------------
55__forceinline uint
57{
58 return ((uint)val + (8 - 1)) & ~(8 - 1);
59}
60
61//------------------------------------------------------------------------------
64__forceinline uint
66{
67 return ((uint)val + (16 - 1)) & ~(16 - 1);
68}
69
70//------------------------------------------------------------------------------
73__forceinline uint
75{
76 return ((uint)val + (32 - 1)) & ~(32 - 1);
77}
78
79//------------------------------------------------------------------------------
82__forceinline uint
83Round::RoundUp(uint val, uint boundary)
84{
85 n_assert(0 != boundary);
86 return (((val - 1) / boundary) + 1) * boundary;
87}
88
89} // namespace Util
90//------------------------------------------------------------------------------
Definition round.h:18
static uint RoundUp(uint val, uint boundary)
generic roundup
Definition round.h:83
static uint RoundUp8(uint val)
round up to nearest 8 bytes boundary
Definition round.h:56
static uint RoundUp32(uint val)
round up to nearest 32 bytes boundary
Definition round.h:74
static uint RoundUp2(uint val)
round up to nearest 2 bytes boundary
Definition round.h:38
static uint RoundUp16(uint val)
round up to nearest 16 bytes boundary
Definition round.h:65
static uint RoundUp4(uint val)
round up to nearest 4 bytes boundary
Definition round.h:47
#define n_assert(exp)
Definition debug.h:50
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
unsigned int uint
Definition types.h:31