Commit 08b941fc by FritzFlorian

Traded cas field uses platform independent data type.

The cas size could exceed an unsigned long, so we use the correct cas_integer type for the traded_cas_field representations.
parent f8ab8e0a
Pipeline #1417 failed with stages
in 37 seconds
...@@ -18,62 +18,63 @@ struct traded_cas_field { ...@@ -18,62 +18,63 @@ struct traded_cas_field {
"As traded objects are usually cache aligned, we need big enough cache lines."); "As traded objects are usually cache aligned, we need big enough cache lines.");
// Base size of our CAS integer/pointer // Base size of our CAS integer/pointer
static constexpr unsigned long CAS_SIZE = base::system_details::CAS_SIZE; static constexpr base::system_details::cas_integer CAS_SIZE = base::system_details::CAS_SIZE;
// States of the integer (tag indicating current content) // States of the integer (tag indicating current content)
static constexpr unsigned long EMPTY_TAG = 0x0lu; static constexpr base::system_details::cas_integer EMPTY_TAG = 0x0lu;
static constexpr unsigned long STAMP_TAG = 0x1lu; static constexpr base::system_details::cas_integer STAMP_TAG = 0x1lu;
static constexpr unsigned long TRADE_TAG = 0x2lu; static constexpr base::system_details::cas_integer TRADE_TAG = 0x2lu;
// Bitmasks and shifts for cas_integer_, two variants: // Bitmasks and shifts for cas_integer_, two variants:
// cas_integer_ = traded object | tag // cas_integer_ = traded object | tag
// cas_integer_ = stamp | id | tag // cas_integer_ = stamp | id | tag
static constexpr unsigned long TAG_SIZE = 2ul; static constexpr base::system_details::cas_integer TAG_SIZE = 2ul;
static constexpr unsigned long TAG_BITS = ~((~0x0ul) << TAG_SIZE); static constexpr base::system_details::cas_integer TAG_BITS = ~((~0x0ul) << TAG_SIZE);
static constexpr unsigned long TRADED_OBJECT_SIZE = CAS_SIZE - TAG_SIZE; static constexpr base::system_details::cas_integer TRADED_OBJECT_SIZE = CAS_SIZE - TAG_SIZE;
static constexpr unsigned long TRADED_OBJECT_SHIFT = TAG_SIZE; static constexpr base::system_details::cas_integer TRADED_OBJECT_SHIFT = TAG_SIZE;
static constexpr unsigned long TRADE_OBJECT_BITS = ~((~0x0ul) << TRADED_OBJECT_SIZE) << TRADED_OBJECT_SHIFT; static constexpr base::system_details::cas_integer
TRADE_OBJECT_BITS = ~((~0x0ul) << TRADED_OBJECT_SIZE) << TRADED_OBJECT_SHIFT;
static constexpr unsigned long ID_SIZE = 10ul; // Up to 1024 cores static constexpr base::system_details::cas_integer ID_SIZE = 10ul; // Up to 1024 cores
static constexpr unsigned long ID_SHIFT = TAG_SIZE; static constexpr base::system_details::cas_integer ID_SHIFT = TAG_SIZE;
static constexpr unsigned long ID_BITS = ~((~0x0ul) << ID_SIZE) << ID_SHIFT; static constexpr base::system_details::cas_integer ID_BITS = ~((~0x0ul) << ID_SIZE) << ID_SHIFT;
static constexpr unsigned long STAMP_SIZE = CAS_SIZE - TAG_SIZE - ID_SIZE; static constexpr base::system_details::cas_integer STAMP_SIZE = CAS_SIZE - TAG_SIZE - ID_SIZE;
static constexpr unsigned long STAMP_SHIFT = TAG_SIZE + ID_SIZE; static constexpr base::system_details::cas_integer STAMP_SHIFT = TAG_SIZE + ID_SIZE;
static constexpr unsigned long STAMP_BITS = ~((~0x0ul) << STAMP_SIZE) << STAMP_SHIFT; static constexpr base::system_details::cas_integer STAMP_BITS = ~((~0x0ul) << STAMP_SIZE) << STAMP_SHIFT;
public: public:
void fill_with_stamp(unsigned long stamp, unsigned long deque_id) { void fill_with_stamp(base::system_details::cas_integer stamp, base::system_details::cas_integer deque_id) {
cas_integer_ = (((stamp << STAMP_SHIFT) & STAMP_BITS) | ((deque_id << ID_SHIFT) & ID_BITS) | STAMP_TAG); cas_integer_ = (((stamp << STAMP_SHIFT) & STAMP_BITS) | ((deque_id << ID_SHIFT) & ID_BITS) | STAMP_TAG);
} }
unsigned long get_stamp() { base::system_details::cas_integer get_stamp() {
PLS_ASSERT(is_filled_with_stamp(), "Must only read out the tag when the traded field contains one."); PLS_ASSERT(is_filled_with_stamp(), "Must only read out the tag when the traded field contains one.");
return (((unsigned long) cas_integer_) & STAMP_BITS) >> STAMP_SHIFT; return (((base::system_details::cas_integer) cas_integer_) & STAMP_BITS) >> STAMP_SHIFT;
} }
unsigned long get_deque_id() { base::system_details::cas_integer get_deque_id() {
PLS_ASSERT(is_filled_with_stamp(), "Must only read out the tag when the traded field contains one."); PLS_ASSERT(is_filled_with_stamp(), "Must only read out the tag when the traded field contains one.");
return (((unsigned long) cas_integer_) & ID_BITS) >> ID_SHIFT; return (((base::system_details::cas_integer) cas_integer_) & ID_BITS) >> ID_SHIFT;
} }
bool is_filled_with_stamp() { bool is_filled_with_stamp() {
return (((unsigned long) cas_integer_) & TAG_BITS) == STAMP_TAG; return (((base::system_details::cas_integer) cas_integer_) & TAG_BITS) == STAMP_TAG;
} }
void fill_with_trade_object(task *new_task) { void fill_with_trade_object(task *new_task) {
PLS_ASSERT((((unsigned long) new_task) & TAG_BITS) == 0, PLS_ASSERT((((base::system_details::cas_integer) new_task) & TAG_BITS) == 0,
"Must only store aligned objects in this data structure (last bits are needed for tag bit)"); "Must only store aligned objects in this data structure (last bits are needed for tag bit)");
cas_integer_ = (((unsigned long) new_task) | TRADE_TAG); cas_integer_ = (((base::system_details::cas_integer) new_task) | TRADE_TAG);
} }
task *get_trade_object() { task *get_trade_object() {
PLS_ASSERT(is_filled_with_object(), "Must only read out the object when the traded field contains one."); PLS_ASSERT(is_filled_with_object(), "Must only read out the object when the traded field contains one.");
return reinterpret_cast<task *>(((unsigned long) cas_integer_) & TRADE_OBJECT_BITS); return reinterpret_cast<task *>(((base::system_details::cas_integer) cas_integer_) & TRADE_OBJECT_BITS);
} }
bool is_filled_with_object() { bool is_filled_with_object() {
return (((unsigned long) cas_integer_) & TAG_BITS) == TRADE_TAG; return (((base::system_details::cas_integer) cas_integer_) & TAG_BITS) == TRADE_TAG;
} }
bool is_empty() { bool is_empty() {
return (((unsigned long) cas_integer_) & TAG_BITS) == EMPTY_TAG; return (((base::system_details::cas_integer) cas_integer_) & TAG_BITS) == EMPTY_TAG;
} }
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment