1 | /** |
---|---|
2 | * Copyright (c) 2018-present, Facebook, Inc. |
3 | * All rights reserved. |
4 | * |
5 | * This source code is licensed under the BSD-style license found in the |
6 | * LICENSE file in the root directory of this source tree. |
7 | */ |
8 | |
9 | #include "gloo/types.h" |
10 | |
11 | #include <stdexcept> |
12 | #include <string> |
13 | |
14 | namespace gloo { |
15 | |
16 | Slot Slot::build(uint8_t prefix, uint32_t tag) { |
17 | uint64_t u64prefix = ((uint64_t)prefix) << 56; |
18 | uint64_t u64tag = (((uint64_t)tag) & 0xffffffff) << 24; |
19 | return Slot(u64prefix | u64tag, 0); |
20 | } |
21 | |
22 | Slot Slot::operator+(uint8_t i) const { |
23 | // Maximum of 8 bits for use in a single collective operation. |
24 | // To avoid conflicts between them, raise if it overflows. |
25 | auto delta = delta_ + i; |
26 | if (delta > 0xff) { |
27 | throw std::runtime_error( |
28 | "Slot overflow: delta "+ std::to_string(delta) + " > 0xff"); |
29 | } |
30 | |
31 | return Slot(base_, delta); |
32 | } |
33 | |
34 | } // namespace gloo |
35 |