openMSX
Multiply32.hh
Go to the documentation of this file.
1 #ifndef MULTIPLY32_HH
2 #define MULTIPLY32_HH
3 
4 #include <cstdint>
5 
6 namespace openmsx {
7 
8 template<typename Pixel> class PixelOperations;
9 
14 template<typename Pixel> class Multiply32;
15 
16 template<> class Multiply32<uint32_t>
17 {
18 public:
20 
21  inline void setFactor32(unsigned f)
22  {
23  factor = f;
24  }
25 
26  inline uint32_t mul32(uint32_t p) const
27  {
28  return ((((p & 0x00FF00FF) * factor) & 0xFF00FF00) >> 8)
29  | ((((p >> 8) & 0x00FF00FF) * factor) & 0xFF00FF00);
30  }
31 
32  inline uint32_t conv32(uint32_t p) const
33  {
34  return p;
35  }
36 
37 private:
38  unsigned factor;
39 };
40 
41 template<> class Multiply32<uint16_t>
42 {
43  // Note that 0 <= n < 32; on x86 this doesn't matter but on PPC it does.
44  inline uint32_t rotRight(uint32_t a, unsigned n) const
45  {
46  return (a >> n) | (a << (32 - n));
47  }
48 
49 public:
50  explicit Multiply32(const PixelOperations<uint16_t>& pixelOps);
51 
52  void setFactor32(unsigned factor);
53 
54  inline uint32_t mul32(uint16_t p) const
55  {
56  return tab[p];
57  }
58 
59  inline uint16_t conv32(uint32_t p) const
60  {
61  return (rotRight(p, Rshift3) & Rmask1) |
62  (rotRight(p, Gshift3) & Gmask1) |
63  (rotRight(p, Bshift3) & Bmask1);
64  }
65 
66 private:
67  uint32_t tab[0x10000];
68  unsigned factor;
69  unsigned Rshift1, Gshift1, Bshift1;
70  unsigned Rshift2, Gshift2, Bshift2;
71  unsigned Rshift3, Gshift3, Bshift3;
72  uint16_t Rmask1, Gmask1, Bmask1;
73  uint16_t Rmask2, Gmask2, Bmask2;
74 };
75 
76 } // namespace openmsx
77 
78 #endif
Helper class to perform &#39;pixel x scalar&#39; calculations.
Definition: Multiply32.hh:14
uint32_t mul32(uint16_t p) const
Definition: Multiply32.hh:54
void setFactor32(unsigned f)
Definition: Multiply32.hh:21
uint32_t conv32(uint32_t p) const
Definition: Multiply32.hh:32
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void format(SectorAccessibleDisk &disk, bool dos1)
Format the given disk (= a single partition).
uint32_t mul32(uint32_t p) const
Definition: Multiply32.hh:26
uint16_t conv32(uint32_t p) const
Definition: Multiply32.hh:59