openMSX
Multiply32.cc
Go to the documentation of this file.
1 #include "Multiply32.hh"
2 #include "PixelOperations.hh"
3 #include <cstring>
4 
5 namespace openmsx {
6 
7 // class Multiply32<uint32_t>
8 
10 {
11  // nothing
12 }
13 
14 
15 // class Multiply32<uint16_t>
16 
17 // gcc can optimize these rotate functions to just one instruction.
18 // We don't really need a rotate, but we do need a shift over a positive or
19 // negative (not known at compile time) distance, rotate handles this just fine.
20 // Note that 0 <= n < 32; on x86 this doesn't matter but on PPC it does.
21 static inline uint32_t rotLeft(uint32_t a, unsigned n)
22 {
23  return (a << n) | (a >> (32 - n));
24 }
25 
27 {
28  Rmask1 = pixelOps.getRmask();
29  Gmask1 = pixelOps.getGmask();
30  Bmask1 = pixelOps.getBmask();
31 
32  Rshift1 = ((2 + pixelOps.getRloss()) - pixelOps.getRshift()) & 31;
33  Gshift1 = ((2 + pixelOps.getGloss()) - pixelOps.getGshift()) & 31;
34  Bshift1 = ((2 + pixelOps.getBloss()) - pixelOps.getBshift()) & 31;
35 
36  Rmask2 = ((1 << (2 + pixelOps.getRloss())) - 1) <<
37  (10 + pixelOps.getRshift() - 2 * (2 + pixelOps.getRloss()));
38  Gmask2 = ((1 << (2 + pixelOps.getGloss())) - 1) <<
39  (10 + pixelOps.getGshift() - 2 * (2 + pixelOps.getGloss()));
40  Bmask2 = ((1 << (2 + pixelOps.getBloss())) - 1) <<
41  (10 + pixelOps.getBshift() - 2 * (2 + pixelOps.getBloss()));
42 
43  Rshift2 = (2 * (2 + pixelOps.getRloss()) - pixelOps.getRshift() - 10) & 31;
44  Gshift2 = (2 * (2 + pixelOps.getGloss()) - pixelOps.getGshift() - 10) & 31;
45  Bshift2 = (2 * (2 + pixelOps.getBloss()) - pixelOps.getBshift() - 10) & 31;
46 
47  Rshift3 = (Rshift1 + 0) & 31;
48  Gshift3 = (Gshift1 + 10) & 31;
49  Bshift3 = (Bshift1 + 20) & 31;
50 
51  factor = 0;
52  memset(tab, 0, sizeof(tab));
53 }
54 
56 {
57  if (factor == f) {
58  return;
59  }
60  factor = f;
61 
62  for (unsigned p = 0; p < 0x10000; ++p) {
63  uint32_t r = rotLeft((p & Rmask1), Rshift1) |
64  rotLeft((p & Rmask2), Rshift2);
65  uint32_t g = rotLeft((p & Gmask1), Gshift1) |
66  rotLeft((p & Gmask2), Gshift2);
67  uint32_t b = rotLeft((p & Bmask1), Bshift1) |
68  rotLeft((p & Bmask2), Bshift2);
69  tab[p] = (((r * factor) >> 8) << 0) |
70  (((g * factor) >> 8) << 10) |
71  (((b * factor) >> 8) << 20);
72  }
73 }
74 
75 } // namespace openmsx
openmsx::PixelOpBase::getGshift
int getGshift() const
Definition: PixelOperations.hh:27
openmsx::PixelOpBase::getRloss
int getRloss() const
Definition: PixelOperations.hh:30
openmsx::PixelOpBase::getBshift
int getBshift() const
Definition: PixelOperations.hh:28
openmsx::PixelOperations
Definition: PixelOperations.hh:143
openmsx::PixelOpBase::getBmask
int getBmask() const
Definition: PixelOperations.hh:24
Multiply32.hh
openmsx::PixelOpBase::getGmask
int getGmask() const
Definition: PixelOperations.hh:23
openmsx::PixelOpBase::getRshift
int getRshift() const
Definition: PixelOperations.hh:26
g
int g
Definition: ScopedAssign_test.cc:20
PixelOperations.hh
openmsx::PixelOpBase::getBloss
int getBloss() const
Definition: PixelOperations.hh:32
openmsx::Multiply32
Helper class to perform 'pixel x scalar' calculations.
Definition: Multiply32.hh:14
openmsx::PixelOpBase::getGloss
int getGloss() const
Definition: PixelOperations.hh:31
openmsx::PixelOpBase::getRmask
int getRmask() const
Definition: PixelOperations.hh:22
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5