diff options
Diffstat (limited to 'extern/draco/draco/src/draco/core/divide.h')
-rw-r--r-- | extern/draco/draco/src/draco/core/divide.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/extern/draco/draco/src/draco/core/divide.h b/extern/draco/draco/src/draco/core/divide.h new file mode 100644 index 00000000000..7e3838a008c --- /dev/null +++ b/extern/draco/draco/src/draco/core/divide.h @@ -0,0 +1,42 @@ +// Copyright 2016 The Draco Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +#ifndef DRACO_CORE_DIVIDE_H_ +#define DRACO_CORE_DIVIDE_H_ +// An implementation of the divide by multiply algorithm +// https://gmplib.org/~tege/divcnst-pldi94.pdf +// This file is based off libvpx's divide.h. + +#include <stdint.h> + +#include <climits> + +namespace draco { + +struct fastdiv_elem { + unsigned mult; + unsigned shift; +}; + +extern const struct fastdiv_elem vp10_fastdiv_tab[256]; + +static inline unsigned fastdiv(unsigned x, int y) { + unsigned t = + ((uint64_t)x * vp10_fastdiv_tab[y].mult) >> (sizeof(x) * CHAR_BIT); + return (t + x) >> vp10_fastdiv_tab[y].shift; +} + +} // namespace draco + +#endif // DRACO_CORE_DIVIDE_H_ |