alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
MultiplyAndSplit64to32.hpp
Go to the documentation of this file.
1/* Copyright 2023 Jiří Vyskočil, Bernhard Manfred Gruber, Jan Stephan
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
8
9#include <cstdint>
10
11namespace alpaka::rand
12{
13 /// Get high 32 bits of a 64-bit number
14 ALPAKA_FN_HOST_ACC inline constexpr auto high32Bits(std::uint64_t const x) -> std::uint32_t
15 {
16 return static_cast<std::uint32_t>(x >> 32);
17 }
18
19 /// Get low 32 bits of a 64-bit number
20 ALPAKA_FN_HOST_ACC inline constexpr auto low32Bits(std::uint64_t const x) -> std::uint32_t
21 {
22 return static_cast<std::uint32_t>(x & 0xffff'ffff);
23 }
24
25 /** Multiply two 64-bit numbers and split the result into high and low 32 bits, also known as "mulhilo32"
26 *
27 * @param a first 64-bit multiplier
28 * @param b second 64-bit multiplier
29 * @param resultHigh high 32 bits of the product a*b
30 * @param resultLow low 32 bits of the product a*b
31 */
32 // TODO: See single-instruction implementations in original Philox source code
34 std::uint64_t const a,
35 std::uint64_t const b,
36 std::uint32_t& resultHigh,
37 std::uint32_t& resultLow)
38 {
39 std::uint64_t res64 = a * b;
40 resultHigh = high32Bits(res64);
41 resultLow = low32Bits(res64);
42 }
43} // namespace alpaka::rand
#define ALPAKA_FN_HOST_ACC
Definition Common.hpp:39
ALPAKA_FN_HOST_ACC constexpr void multiplyAndSplit64to32(std::uint64_t const a, std::uint64_t const b, std::uint32_t &resultHigh, std::uint32_t &resultLow)
ALPAKA_FN_HOST_ACC constexpr auto high32Bits(std::uint64_t const x) -> std::uint32_t
Get high 32 bits of a 64-bit number.
ALPAKA_FN_HOST_ACC constexpr auto low32Bits(std::uint64_t const x) -> std::uint32_t
Get low 32 bits of a 64-bit number.