GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
divide.h
Go to the documentation of this file.
1// Copyright 2016 The Draco Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15#ifndef DRACO_CORE_DIVIDE_H_
16#define DRACO_CORE_DIVIDE_H_
17// An implementation of the divide by multiply algorithm
18// https://gmplib.org/~tege/divcnst-pldi94.pdf
19// This file is based off libvpx's divide.h.
20
21#include <stdint.h>
22
23#include <climits>
24
25namespace draco {
26
28 unsigned mult;
29 unsigned shift;
30};
31
32extern const struct fastdiv_elem vp10_fastdiv_tab[256];
33
34static inline unsigned fastdiv(unsigned x, int y) {
35 unsigned t =
36 ((uint64_t)x * vp10_fastdiv_tab[y].mult) >> (sizeof(x) * CHAR_BIT);
37 return (t + x) >> vp10_fastdiv_tab[y].shift;
38}
39
40} // namespace draco
41
42#endif // DRACO_CORE_DIVIDE_H_
Definition attribute_octahedron_transform.cc:21
const struct fastdiv_elem vp10_fastdiv_tab[256]
Definition divide.cc:21
Definition divide.h:27
unsigned shift
Definition divide.h:29
unsigned mult
Definition divide.h:28