MeshLib C++ Docs
Loading...
Searching...
No Matches
MRInt64Mul128.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRFastInt128.h"
5#include <MRPch/MRBindingMacros.h>
6#include <cstdint>
7
8#if defined _MSC_VER && !defined __clang__
9#include <intrin.h>
10#endif
11
12namespace MR
13{
14
17
21class MR_BIND_IGNORE Int64Mul128
22{
23public:
24 Int64Mul128() noexcept = default;
25 constexpr Int64Mul128( std::int64_t v ) noexcept : v_( v ) { }
26 [[nodiscard]] constexpr explicit operator std::int64_t() const noexcept { return v_; }
27
28 [[nodiscard]] friend constexpr std::int64_t operator +( Int64Mul128 a ) noexcept { return a.v_; }
29 [[nodiscard]] friend constexpr std::int64_t operator -( Int64Mul128 a ) noexcept { return -a.v_; }
30
31 [[nodiscard]] friend constexpr std::int64_t operator +( Int64Mul128 a, Int64Mul128 b ) noexcept { return a.v_ + b.v_; }
32 [[nodiscard]] friend constexpr std::int64_t operator -( Int64Mul128 a, Int64Mul128 b ) noexcept { return a.v_ - b.v_; }
33 [[nodiscard]] friend constexpr std::int64_t operator /( Int64Mul128 a, Int64Mul128 b ) noexcept { return a.v_ / b.v_; }
34
35 [[nodiscard]] friend FastInt128 operator *( Int64Mul128 a, Int64Mul128 b ) noexcept
36 {
37#if defined _MSC_VER && !defined __clang__ && defined _M_X64
38 std::int64_t hi = 0;
39 const auto lo = _mul128( a.v_, b.v_, &hi );
40 return FastInt128( std::uint64_t( lo ), std::uint64_t( hi ) );
41#elif defined _MSC_VER && !defined __clang__ && defined _M_ARM64
42 const auto hi = __mulh( a.v_, b.v_ );
43 return FastInt128( std::uint64_t( a.v_ ) * std::uint64_t( b.v_ ), std::uint64_t( hi ) );
44#else
46 return FastInt128( a.v_ ) * b.v_;
47#endif
48 }
49
50 [[nodiscard]] friend constexpr bool operator ==( Int64Mul128 a, Int64Mul128 b ) noexcept { return a.v_ == b.v_; }
51 [[nodiscard]] friend constexpr auto operator <=>( Int64Mul128 a, Int64Mul128 b ) noexcept { return a.v_ <=> b.v_; }
52
53private:
54 std::int64_t v_;
55};
56
58#if !defined MR_PARSING_FOR_ANY_BINDINGS && !defined MR_COMPILING_ANY_BINDINGS
61#endif
62
64
65}
constexpr bool operator==(ImVec2 a, ImVec2 b)
Definition MRImGuiVectorOperators.h:117
constexpr A operator-(A a)
Definition MRImGuiVectorOperators.h:98
constexpr A operator+(A a)
Operators.
Definition MRImGuiVectorOperators.h:97
constexpr auto operator*(A a, B b)
Definition MRImGuiVectorOperators.h:107
constexpr auto operator/(A a, B b)
Definition MRImGuiVectorOperators.h:110
Int64Mul128() noexcept=default
Vector2< Int64Mul128 > Vector2i64mul
no bindings for the same reason as for Vector3i128fast
Definition MRInt64Mul128.h:59
Vector3< Int64Mul128 > Vector3i64mul
Definition MRInt64Mul128.h:60
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
__int128_t FastInt128
Definition MRFastInt128.h:22
Definition MRVector2.h:29
Definition MRVector3.h:33