Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
70561ed1
Commit
70561ed1
authored
Jan 12, 2022
by
Junekey Jeon
Committed by
Victor Zverovich
Jan 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minimize the usage of built-in 128-bit ints
It usually generates slower code than manual handling.
parent
cdf1a3b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
35 deletions
+24
-35
include/fmt/format-inl.h
include/fmt/format-inl.h
+24
-35
No files found.
include/fmt/format-inl.h
View file @
70561ed1
...
...
@@ -789,48 +789,36 @@ FMT_INLINE FMT_CONSTEXPR20 digits::result grisu_gen_digits(
struct
uint128_wrapper
{
uint128_wrapper
()
=
default
;
#if FMT_USE_INT128
uint128_t
internal_
;
constexpr
uint128_wrapper
(
uint64_t
high
,
uint64_t
low
)
FMT_NOEXCEPT
:
internal_
{
static_cast
<
uint128_t
>
(
low
)
|
(
static_cast
<
uint128_t
>
(
high
)
<<
64
)}
{}
constexpr
uint128_wrapper
(
uint128_t
u
)
:
internal_
{
u
}
{}
constexpr
uint64_t
high
()
const
FMT_NOEXCEPT
{
return
uint64_t
(
internal_
>>
64
);
}
constexpr
uint64_t
low
()
const
FMT_NOEXCEPT
{
return
uint64_t
(
internal_
);
}
uint128_wrapper
&
operator
+=
(
uint64_t
n
)
FMT_NOEXCEPT
{
internal_
+=
n
;
return
*
this
;
}
#else
uint64_t
high_
;
uint64_t
low_
;
constexpr
uint128_wrapper
(
uint64_t
high
,
uint64_t
low
)
FMT_NOEXCEPT
:
high_
{
high
},
low_
{
low
}
{}
constexpr
uint64_t
high
()
const
FMT_NOEXCEPT
{
return
high_
;
}
constexpr
uint64_t
low
()
const
FMT_NOEXCEPT
{
return
low_
;
}
uint128_wrapper
&
operator
+=
(
uint64_t
n
)
FMT_NOEXCEPT
{
# if defined(_MSC_VER) && defined(_M_X64)
unsigned
char
carry
=
_addcarry_u64
(
0
,
low_
,
n
,
&
low_
);
constexpr
uint128_wrapper
(
uint64_t
high
,
uint64_t
low
)
noexcept
:
high_
{
high
},
low_
{
low
}
{}
constexpr
uint64_t
high
()
const
noexcept
{
return
high_
;
}
constexpr
uint64_t
low
()
const
noexcept
{
return
low_
;
}
uint128_wrapper
&
operator
+=
(
uint64_t
n
)
&
noexcept
{
#if FMT_HAS_BUILTIN(__builtin_addcll)
unsigned
long
long
carry
;
low_
=
__builtin_addcll
(
low_
,
n
,
0
,
&
carry
);
high_
=
__builtin_addcll
(
high_
,
0
,
carry
,
&
carry
);
#elif FMT_HAS_BUILTIN(__builtin_ia32_addcarryx_u64)
unsigned
long
long
result
;
auto
carry
=
__builtin_ia32_addcarryx_u64
(
0
,
low_
,
n
,
&
result
);
low_
=
result
;
__builtin_ia32_addcarryx_u64
(
carry
,
high_
,
0
,
&
result
);
high_
=
result
;
#elif defined(_MSC_VER) && defined(_M_X64)
auto
carry
=
_addcarry_u64
(
0
,
low_
,
n
,
&
low_
);
_addcarry_u64
(
carry
,
high_
,
0
,
&
high_
);
return
*
this
;
# else
uint64_t
sum
=
low_
+
n
;
#else
auto
sum
=
low_
+
n
;
high_
+=
(
sum
<
low_
?
1
:
0
);
low_
=
sum
;
#endif
return
*
this
;
# endif
}
#endif
};
// Implementation of Dragonbox algorithm: https://github.com/jk-jeon/dragonbox.
...
...
@@ -838,7 +826,8 @@ namespace dragonbox {
// Computes 128-bit result of multiplication of two 64-bit unsigned integers.
inline
uint128_wrapper
umul128
(
uint64_t
x
,
uint64_t
y
)
FMT_NOEXCEPT
{
#if FMT_USE_INT128
return
static_cast
<
uint128_t
>
(
x
)
*
static_cast
<
uint128_t
>
(
y
);
auto
p
=
static_cast
<
uint128_t
>
(
x
)
*
static_cast
<
uint128_t
>
(
y
);
return
{
static_cast
<
uint64_t
>
(
p
>>
64
),
static_cast
<
uint64_t
>
(
p
)};
#elif defined(_MSC_VER) && defined(_M_X64)
uint128_wrapper
result
;
result
.
low_
=
_umul128
(
x
,
y
,
&
result
.
high_
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment