Permalink
Browse files

Unrolled_3 and Unrolled_4 removed from e1.cpp; test code removed

  • Loading branch information...
pzemtsov committed May 12, 2014
1 parent 7a67fe7 commit ed29557be68e178600e7f2139330bcbdd724fe9f
Showing with 1 addition and 257 deletions.
  1. +0 −105 e1-2.cpp
  2. +0 −95 e1-3.cpp
  3. +1 −57 e1.cpp
View
105 e1-2.cpp
@@ -1,105 +0,0 @@
-/** The simplified version of e1.cpp, only used for resolving performance instability issue
- (see article "The mystery of an unstable performance").
- Contains simplified versions of Dst_First_1 and Dst_First_2
- */
-
-#include <cassert>
-#include <cstdlib>
-#include <cstring>
-#include <iostream>
-#include <typeinfo>
-
-#include "timer.h"
-#include "mymacros.h"
-
-typedef unsigned char byte;
-
-static const unsigned NUM_TIMESLOTS = 32;
-static const unsigned DST_SIZE = 64;
-static const unsigned SRC_SIZE = NUM_TIMESLOTS * DST_SIZE;
-static const unsigned ITERATIONS = 1000000;
-static const unsigned REPETITIONS = 2;
-
-using namespace std;
-
-class Demux
-{
-public:
- virtual void demux (const byte * src, unsigned src_length, byte ** dst) const = 0;
-};
-
-class Dst_First_1 : public Demux
-{
-public:
- void demux (const byte * src, unsigned src_length, byte ** dst) const
- {
- for (unsigned dst_num = 0; dst_num < NUM_TIMESLOTS; ++ dst_num) {
- for (unsigned dst_pos = 0; dst_pos < src_length / NUM_TIMESLOTS; ++ dst_pos) {
- dst [dst_num][dst_pos] = src [dst_pos * NUM_TIMESLOTS + dst_num];
- }
- }
- }
-};
-
-class Dst_First_3 : public Demux
-{
-public:
- void demux (const byte * src, unsigned src_length, byte ** dst) const
- {
- for (unsigned dst_num = 0; dst_num < NUM_TIMESLOTS; ++ dst_num) {
- for (unsigned dst_pos = 0; dst_pos < DST_SIZE; ++ dst_pos) {
- dst [dst_num][dst_pos] = src [dst_pos * NUM_TIMESLOTS + dst_num];
- }
- }
- }
-};
-
-
-byte * generate ()
-{
- byte * buf = new byte [SRC_SIZE];
- srand (0);
- for (unsigned i = 0; i < SRC_SIZE; i++) buf[i] = (byte) (rand () % 256);
- return buf;
-}
-
-byte ** allocate_dst ()
-{
- byte ** result = new byte * [NUM_TIMESLOTS];
- for (unsigned i = 0; i < NUM_TIMESLOTS; i++) {
- result [i] = new byte [DST_SIZE];
- }
- return result;
-}
-
-void delete_dst (byte ** dst)
-{
- for (unsigned i = 0; i < NUM_TIMESLOTS; i++) {
- delete dst [i];
- }
- delete dst;
-}
-
-byte * src;
-byte ** dst;
-
-void measure (const Demux & demux)
-{
- uint64_t t0 = currentTimeMillis ();
- for (int i = 0; i < ITERATIONS; i++) {
- demux.demux (src, SRC_SIZE, dst);
- }
- uint64_t t = currentTimeMillis () - t0;
- cout << typeid (demux).name() << ": " << t << endl;
-}
-
-int main (void)
-{
- src = generate ();
- dst = allocate_dst ();
-
- measure (Dst_First_1 ());
- measure (Dst_First_3 ());
-
- return 0;
-}
View
@@ -1,95 +0,0 @@
-/** The simplified version of e2.cpp, only used for resolving performance instability issue
- (see article "The mystery of an unstable performance").
- Contains several copies of Dst_First_1
- */
-
-#include <cassert>
-#include <cstdlib>
-#include <cstring>
-#include <iostream>
-#include <typeinfo>
-
-#include "timer.h"
-#include "mymacros.h"
-
-typedef unsigned char byte;
-
-static const unsigned NUM_TIMESLOTS = 32;
-static const unsigned DST_SIZE = 64;
-static const unsigned SRC_SIZE = NUM_TIMESLOTS * DST_SIZE;
-static const unsigned ITERATIONS = 1000000;
-static const unsigned REPETITIONS = 2;
-
-using namespace std;
-
-class Demux
-{
-public:
- virtual void demux (const byte * src, unsigned src_length, byte ** dst) const = 0;
-};
-
-template<int N> class Dst_First_1 : public Demux
-{
-public:
- void demux (const byte * src, unsigned src_length, byte ** dst) const
- {
- for (unsigned dst_num = 0; dst_num < NUM_TIMESLOTS; ++ dst_num) {
- for (unsigned dst_pos = 0; dst_pos < src_length / NUM_TIMESLOTS; ++ dst_pos) {
- dst [dst_num][dst_pos] = src [dst_pos * NUM_TIMESLOTS + dst_num];
- }
- }
- }
-};
-
-byte * generate ()
-{
- byte * buf = new byte [SRC_SIZE];
- srand (0);
- for (unsigned i = 0; i < SRC_SIZE; i++) buf[i] = (byte) (rand () % 256);
- return buf;
-}
-
-byte ** allocate_dst ()
-{
- byte ** result = new byte * [NUM_TIMESLOTS];
- for (unsigned i = 0; i < NUM_TIMESLOTS; i++) {
- result [i] = new byte [DST_SIZE];
- }
- return result;
-}
-
-void delete_dst (byte ** dst)
-{
- for (unsigned i = 0; i < NUM_TIMESLOTS; i++) {
- delete dst [i];
- }
- delete dst;
-}
-
-byte * src;
-byte ** dst;
-
-void measure (const Demux & demux)
-{
- uint64_t t0 = currentTimeMillis ();
- for (int i = 0; i < ITERATIONS; i++) {
- demux.demux (src, SRC_SIZE, dst);
- }
- uint64_t t = currentTimeMillis () - t0;
- cout << typeid (demux).name() << ": " << t << endl;
-}
-
-int main (void)
-{
- src = generate ();
- dst = allocate_dst ();
-
- measure (Dst_First_1<0> ());
- measure (Dst_First_1<1> ());
- measure (Dst_First_1<2> ());
- measure (Dst_First_1<3> ());
- measure (Dst_First_1<4> ());
- measure (Dst_First_1<5> ());
-
- return 0;
-}
View
58 e1.cpp
@@ -3,6 +3,7 @@
Revision 3: Used generic multipliers in unrolled versions
Revision 4: Used different version of generic multipliers in unrolled versions
Revision 5: Replaced test code to run just once
+ Revision 6: Removed Unrolled_3 and Unrolled_4
*/
#include <cassert>
@@ -242,61 +243,6 @@ class Unrolled_2_Full : public Demux
}
};
-class Unrolled_3 : public Demux
-{
-public:
- void demux (const byte * src, unsigned src_length, byte ** dst) const
- {
- assert (src_length % NUM_TIMESLOTS == 0);
-
-#define CALL_DEMUX(i) demux_##i (src, dst[i])
- DUP_32 (CALL_DEMUX);
-#undef CALL_DEMUX
- }
-
-private:
-
-#define DEF_DEMUX(i) \
- inline void demux_##i (const byte * src, byte * d) const\
- {\
- MOVE_BYTES_64 (i);\
- }
-
- DEF_DEMUX ( 0) DEF_DEMUX ( 1) DEF_DEMUX ( 2) DEF_DEMUX ( 3)
- DEF_DEMUX ( 4) DEF_DEMUX ( 5) DEF_DEMUX ( 6) DEF_DEMUX ( 7)
- DEF_DEMUX ( 8) DEF_DEMUX ( 9) DEF_DEMUX (10) DEF_DEMUX (11)
- DEF_DEMUX (12) DEF_DEMUX (13) DEF_DEMUX (14) DEF_DEMUX (15)
- DEF_DEMUX (16) DEF_DEMUX (17) DEF_DEMUX (18) DEF_DEMUX (19)
- DEF_DEMUX (20) DEF_DEMUX (21) DEF_DEMUX (22) DEF_DEMUX (23)
- DEF_DEMUX (24) DEF_DEMUX (25) DEF_DEMUX (26) DEF_DEMUX (27)
- DEF_DEMUX (28) DEF_DEMUX (29) DEF_DEMUX (30) DEF_DEMUX (31)
-#undef DEF_DEMUX
-};
-
-class Unrolled_4 : public Demux
-{
-public:
- void demux (const byte * src, unsigned src_length, byte ** dst) const
- {
- assert (NUM_TIMESLOTS == 32);
- assert (DST_SIZE == 64);
- assert (src_length == NUM_TIMESLOTS * DST_SIZE);
-
-#define DEMUX(i) demux_0 (src, dst[i], i)
-
- DUP_32 (DEMUX);
-
-#undef DEMUX
- }
-
-private:
- inline void demux_0 (const byte * src, byte * d, unsigned i) const
- {
- MOVE_BYTES_64 (i);
- }
-
-};
-
byte * generate ()
{
byte * buf = new byte [SRC_SIZE];
@@ -374,8 +320,6 @@ int main (void)
measure (Unrolled_1_8 ());
measure (Unrolled_1_16 ());
measure (Unrolled_2_Full ());
- measure (Unrolled_3 ());
- measure (Unrolled_4 ());
return 0;
}

0 comments on commit ed29557

Please sign in to comment.