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
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}
Int64Mul128() noexcept=default
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRBitSet.h:477
bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
__int128_t FastInt128
Definition MRFastInt128.h:25
Color operator/(const Color &b, float a)
Definition MRColor.h:129
Color operator*(float a, const Color &b)
Definition MRColor.h:119
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:13
Color operator+(const Color &a, const Color &b)
Definition MRColor.h:109
Vector2< Int64Mul128 > Vector2i64mul
no bindings for the same reason as for Vector3i128fast
Definition MRInt64Mul128.h:59
Vector3< Int64Mul128 > Vector3i64mul
Definition MRInt64Mul128.h:60
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRVector2.h:29
Definition MRVector3.h:33