1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
3
4 extern "C" void abort (void);
5
6 typedef int int32;
7 typedef unsigned int uint32;
8 typedef unsigned long long uint64;
9 typedef short int16;
10
11 class Tp {
12 public:
13 Tp(int, const int segment, const int index) __attribute__((noinline));
14
15 inline bool operator==(const Tp& other) const;
16 inline bool operator!=(const Tp& other) const;
GetType()17 int GetType() const { return type_; }
GetSegment()18 int GetSegment() const { return segment_; }
GetIndex()19 int GetIndex() const { return index_; }
20 private:
21 inline static bool IsValidSegment(const int segment);
22 static const int kSegmentBits = 28;
23 static const int kTypeBits = 4;
24 static const int kMaxSegment = (1 << kSegmentBits) - 1;
25
26 union {
27
28 struct {
29 int32 index_;
30 uint32 segment_ : kSegmentBits;
31 uint32 type_ : kTypeBits;
32 };
33 struct {
34 int32 dummy_;
35 uint32 type_and_segment_;
36 };
37 uint64 value_;
38 };
39 };
40
Tp(int t,const int segment,const int index)41 Tp::Tp(int t, const int segment, const int index)
42 : index_(index), segment_(segment), type_(t) {}
43
44 inline bool Tp::operator==(const Tp& other) const {
45 return value_ == other.value_;
46 }
47 inline bool Tp::operator!=(const Tp& other) const {
48 return value_ != other.value_;
49 }
50
51 class Range {
52 public:
53 inline Range(const Tp& position, const int count) __attribute__((always_inline));
54 inline Tp GetBeginTokenPosition() const;
55 inline Tp GetEndTokenPosition() const;
56 private:
57 Tp position_;
58 int count_;
59 int16 begin_index_;
60 int16 end_index_;
61 };
62
Range(const Tp & position,const int count)63 inline Range::Range(const Tp& position,
64 const int count)
65 : position_(position), count_(count), begin_index_(0), end_index_(0)
66 { }
67
GetBeginTokenPosition()68 inline Tp Range::GetBeginTokenPosition() const {
69 return position_;
70 }
GetEndTokenPosition()71 inline Tp Range::GetEndTokenPosition() const {
72 return Tp(position_.GetType(), position_.GetSegment(),
73 position_.GetIndex() + count_);
74 }
75
main()76 int main ()
77 {
78 Range range(Tp(0, 0, 3), 0);
79 if (!(range.GetBeginTokenPosition() == Tp(0, 0, 3)))
80 abort ();
81
82 if (!(range.GetEndTokenPosition() == Tp(0, 0, 3)))
83 abort();
84
85 return 0;
86 }
87