CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
Cordic Class Reference

#include <Cordic.h>

Public Member Functions

 Cordic (const uint32_t &aPhiScale, const uint32_t &aMagnitudeBits, const uint32_t &aSteps)
 
int32_t IntegerizeMagnitude (const double &aMagnitude)
 
double NormalizeMagnitude (const uint32_t &aMagnitude)
 
double NormalizePhi (const uint32_t &aPhi)
 
void operator() (int32_t aX, int32_t aY, int32_t &aPhi, uint32_t &aMagnitude)
 
virtual ~Cordic ()
 

Private Member Functions

uint32_t tower (const double &aRadians)
 

Private Attributes

uint32_t mMagnitudeBits
 
uint64_t mMagnitudeRenormalization
 
uint32_t mMagnitudeScale
 
uint32_t mPhiScale
 
const double mPi
 
std::vector< uint32_t > mRotations
 
uint32_t mSteps
 

Detailed Description

Definition at line 7 of file Cordic.h.

Constructor & Destructor Documentation

Cordic::Cordic ( const uint32_t &  aPhiScale,
const uint32_t &  aMagnitudeBits,
const uint32_t &  aSteps 
)

Definition at line 9 of file Cordic.cc.

References mMagnitudeRenormalization, mMagnitudeScale, mRotations, mSteps, funct::pow(), mathSSE::sqrt(), and tower().

10  : mPhiScale(aPhiScale),
11  mMagnitudeScale(1 << aMagnitudeBits),
12  mMagnitudeBits(aMagnitudeBits),
13  mSteps(aSteps),
14  mPi(3.1415926535897932384626433832795) {
15  mRotations.reserve(mSteps);
16 
17  double lValue(1.0);
18 
19  for (uint32_t lStep(0); lStep != mSteps; ++lStep) {
20  lValue /= sqrt(1.0 + pow(4.0, -double(lStep)));
21  mRotations.push_back(tower(atan(pow(2.0, -double(lStep)))));
22  }
23  mMagnitudeRenormalization = uint32_t(round(mMagnitudeScale * lValue));
24 }
uint32_t mMagnitudeBits
Definition: Cordic.h:24
uint32_t mPhiScale
Definition: Cordic.h:22
T sqrt(T t)
Definition: SSEVec.h:19
const double mPi
Definition: Cordic.h:29
uint32_t mSteps
Definition: Cordic.h:25
uint32_t tower(const double &aRadians)
Definition: Cordic.cc:34
uint64_t mMagnitudeRenormalization
Definition: Cordic.h:26
uint32_t mMagnitudeScale
Definition: Cordic.h:23
std::vector< uint32_t > mRotations
Definition: Cordic.h:27
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
Cordic::~Cordic ( )
virtual

Definition at line 26 of file Cordic.cc.

26 {}

Member Function Documentation

int32_t Cordic::IntegerizeMagnitude ( const double &  aMagnitude)

Definition at line 32 of file Cordic.cc.

References mMagnitudeScale.

32 { return int32_t(aMagnitude * mMagnitudeScale); }
uint32_t mMagnitudeScale
Definition: Cordic.h:23
double Cordic::NormalizeMagnitude ( const uint32_t &  aMagnitude)

Definition at line 30 of file Cordic.cc.

References mMagnitudeScale.

30 { return double(aMagnitude) / double(mMagnitudeScale); }
uint32_t mMagnitudeScale
Definition: Cordic.h:23
double Cordic::NormalizePhi ( const uint32_t &  aPhi)

Definition at line 28 of file Cordic.cc.

References mPhiScale.

28 { return double(aPhi) / double(mPhiScale); }
uint32_t mPhiScale
Definition: Cordic.h:22
void Cordic::operator() ( int32_t  aX,
int32_t  aY,
int32_t &  aPhi,
uint32_t &  aMagnitude 
)

Definition at line 36 of file Cordic.cc.

References mMagnitudeBits, mMagnitudeRenormalization, mPi, mRotations, mSteps, tower(), testProducerWithPsetDescEmpty_cfi::x1, and testProducerWithPsetDescEmpty_cfi::x2.

36  {
37  bool lSign(true);
38 
39  switch (((aY >= 0) ? 0x0 : 0x2) | ((aX >= 0) ? 0x0 : 0x1)) {
40  case 0:
41  aPhi = tower(mPi);
42  break;
43  case 1:
44  aPhi = tower(2 * mPi);
45  lSign = false;
46  aX = -aX;
47  break;
48  case 2:
49  aPhi = tower(mPi);
50  lSign = false;
51  aY = -aY;
52  break;
53  case 3:
54  aPhi = 0;
55  aX = -aX;
56  aY = -aY;
57  break;
58  default:
59  throw 0;
60  }
61 
62  for (uint32_t lStep(0); lStep != mSteps; ++lStep) {
63  if ((aY < 0) == lSign) {
64  aPhi -= mRotations[lStep];
65  } else {
66  aPhi += mRotations[lStep];
67  }
68 
69  int32_t lX(aX), lY(aY);
70  if (lY < 0) {
71  aX = lX - (lY >> lStep);
72  aY = lY + (lX >> lStep);
73  } else {
74  aX = lX + (lY >> lStep);
75  aY = lY - (lX >> lStep);
76  }
77  }
78 
79  aMagnitude = (aX * mMagnitudeRenormalization) >> mMagnitudeBits;
80 }
uint32_t mMagnitudeBits
Definition: Cordic.h:24
const double mPi
Definition: Cordic.h:29
uint32_t mSteps
Definition: Cordic.h:25
uint32_t tower(const double &aRadians)
Definition: Cordic.cc:34
uint64_t mMagnitudeRenormalization
Definition: Cordic.h:26
std::vector< uint32_t > mRotations
Definition: Cordic.h:27
uint32_t Cordic::tower ( const double &  aRadians)
private

Definition at line 34 of file Cordic.cc.

References mPhiScale, and mPi.

Referenced by Cordic(), and operator()().

34 { return uint32_t(round(mPhiScale * 0.5 * aRadians / mPi)); }
uint32_t mPhiScale
Definition: Cordic.h:22
const double mPi
Definition: Cordic.h:29

Member Data Documentation

uint32_t Cordic::mMagnitudeBits
private

Definition at line 24 of file Cordic.h.

Referenced by operator()().

uint64_t Cordic::mMagnitudeRenormalization
private

Definition at line 26 of file Cordic.h.

Referenced by Cordic(), and operator()().

uint32_t Cordic::mMagnitudeScale
private

Definition at line 23 of file Cordic.h.

Referenced by Cordic(), IntegerizeMagnitude(), and NormalizeMagnitude().

uint32_t Cordic::mPhiScale
private

Definition at line 22 of file Cordic.h.

Referenced by NormalizePhi(), and tower().

const double Cordic::mPi
private

Definition at line 29 of file Cordic.h.

Referenced by operator()(), and tower().

std::vector<uint32_t> Cordic::mRotations
private

Definition at line 27 of file Cordic.h.

Referenced by Cordic(), and operator()().

uint32_t Cordic::mSteps
private

Definition at line 25 of file Cordic.h.

Referenced by Cordic(), and operator()().