openMSX
Multiply32.hh
Go to the documentation of this file.
1#ifndef MULTIPLY32_HH
2#define MULTIPLY32_HH
3
4#include <array>
5#include <bit>
6#include <concepts>
7#include <cstdint>
8
9namespace openmsx {
10
11template<std::unsigned_integral Pixel> class PixelOperations;
12
17template<std::unsigned_integral Pixel> class Multiply32;
18
19template<> class Multiply32<uint32_t>
20{
21public:
22 explicit Multiply32(const PixelOperations<uint32_t>& /*format*/) {
23 // nothing
24 }
25
26 inline void setFactor32(unsigned f)
27 {
28 factor = f;
29 }
30
31 [[nodiscard]] inline uint32_t mul32(uint32_t p) const
32 {
33 return ((((p & 0x00FF00FF) * factor) & 0xFF00FF00) >> 8)
34 | ((((p >> 8) & 0x00FF00FF) * factor) & 0xFF00FF00);
35 }
36
37 [[nodiscard]] inline uint32_t conv32(uint32_t p) const
38 {
39 return p;
40 }
41
42private:
43 unsigned factor = 0;
44};
45
46template<> class Multiply32<uint16_t>
47{
48public:
49 explicit Multiply32(const PixelOperations<uint16_t>& pixelOps);
50
51 void setFactor32(unsigned factor);
52
53 [[nodiscard]] inline uint32_t mul32(uint16_t p) const
54 {
55 return tab[p];
56 }
57
58 [[nodiscard]] inline uint16_t conv32(uint32_t p) const
59 {
60 return (std::rotr(p, Rshift3) & Rmask1) |
61 (std::rotr(p, Gshift3) & Gmask1) |
62 (std::rotr(p, Bshift3) & Bmask1);
63 }
64
65private:
66 std::array<uint32_t, 0x10000> tab = {}; // fill with zero
67 unsigned factor = 0;
68 int Rshift1, Gshift1, Bshift1;
69 int Rshift2, Gshift2, Bshift2;
70 int Rshift3, Gshift3, Bshift3;
71 uint16_t Rmask1, Gmask1, Bmask1;
72 uint16_t Rmask2, Gmask2, Bmask2;
73};
74
75} // namespace openmsx
76
77#endif
uint16_t conv32(uint32_t p) const
Definition: Multiply32.hh:58
uint32_t mul32(uint16_t p) const
Definition: Multiply32.hh:53
uint32_t mul32(uint32_t p) const
Definition: Multiply32.hh:31
uint32_t conv32(uint32_t p) const
Definition: Multiply32.hh:37
void setFactor32(unsigned f)
Definition: Multiply32.hh:26
Multiply32(const PixelOperations< uint32_t > &)
Definition: Multiply32.hh:22
Helper class to perform 'pixel x scalar' calculations.
Definition: Multiply32.hh:17
This file implemented 3 utility functions:
Definition: Autofire.cc:9