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
0651e459
Commit
0651e459
authored
Sep 23, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor tweaks to get_cached_power
parent
6c025520
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
33 deletions
+28
-33
include/fmt/format-inl.h
include/fmt/format-inl.h
+28
-33
No files found.
include/fmt/format-inl.h
View file @
0651e459
...
@@ -1934,6 +1934,7 @@ template <class T> struct cache_accessor;
...
@@ -1934,6 +1934,7 @@ template <class T> struct cache_accessor;
template
<
>
struct
cache_accessor
<
float
>
{
template
<
>
struct
cache_accessor
<
float
>
{
using
carrier_uint
=
float_info
<
float
>::
carrier_uint
;
using
carrier_uint
=
float_info
<
float
>::
carrier_uint
;
using
cache_entry_type
=
uint64_t
;
using
cache_entry_type
=
uint64_t
;
static
uint64_t
get_cached_power
(
int
k
)
FMT_NOEXCEPT
{
static
uint64_t
get_cached_power
(
int
k
)
FMT_NOEXCEPT
{
FMT_ASSERT
(
k
>=
float_info
<
float
>::
min_k
&&
k
<=
float_info
<
float
>::
max_k
,
FMT_ASSERT
(
k
>=
float_info
<
float
>::
min_k
&&
k
<=
float_info
<
float
>::
max_k
,
"k is out of range"
);
"k is out of range"
);
...
@@ -1986,6 +1987,7 @@ template <> struct cache_accessor<float> {
...
@@ -1986,6 +1987,7 @@ template <> struct cache_accessor<float> {
template
<
>
struct
cache_accessor
<
double
>
{
template
<
>
struct
cache_accessor
<
double
>
{
using
carrier_uint
=
float_info
<
double
>::
carrier_uint
;
using
carrier_uint
=
float_info
<
double
>::
carrier_uint
;
using
cache_entry_type
=
uint128_wrapper
;
using
cache_entry_type
=
uint128_wrapper
;
static
uint128_wrapper
get_cached_power
(
int
k
)
FMT_NOEXCEPT
{
static
uint128_wrapper
get_cached_power
(
int
k
)
FMT_NOEXCEPT
{
FMT_ASSERT
(
k
>=
float_info
<
double
>::
min_k
&&
k
<=
float_info
<
double
>::
max_k
,
FMT_ASSERT
(
k
>=
float_info
<
double
>::
min_k
&&
k
<=
float_info
<
double
>::
max_k
,
"k is out of range"
);
"k is out of range"
);
...
@@ -1996,53 +1998,46 @@ template <> struct cache_accessor<double> {
...
@@ -1996,53 +1998,46 @@ template <> struct cache_accessor<double> {
#else
#else
static
const
int
compression_ratio
=
27
;
static
const
int
compression_ratio
=
27
;
// Compute base index
// Compute base index
.
int
cache_index
=
(
k
-
float_info
<
double
>::
min_k
)
/
compression_ratio
;
int
cache_index
=
(
k
-
float_info
<
double
>::
min_k
)
/
compression_ratio
;
int
kb
=
cache_index
*
compression_ratio
+
float_info
<
double
>::
min_k
;
int
kb
=
cache_index
*
compression_ratio
+
float_info
<
double
>::
min_k
;
int
offset
=
k
-
kb
;
int
offset
=
k
-
kb
;
// Get base cache
// Get base cache
.
uint128_wrapper
base_cache
=
uint128_wrapper
base_cache
=
data
::
dragonbox_pow10_significands_128
[
cache_index
];
data
::
dragonbox_pow10_significands_128
[
cache_index
];
if
(
offset
==
0
)
return
base_cache
;
if
(
offset
==
0
)
{
// Compute the required amount of bit-shift.
return
base_cache
;
int
alpha
=
floor_log2_pow10
(
kb
+
offset
)
-
floor_log2_pow10
(
kb
)
-
offset
;
}
else
{
FMT_ASSERT
(
alpha
>
0
&&
alpha
<
64
,
"shifting error detected"
);
// Compute the required amount of bit-shift
int
alpha
=
floor_log2_pow10
(
kb
+
offset
)
-
floor_log2_pow10
(
kb
)
-
offset
;
FMT_ASSERT
(
alpha
>
0
&&
alpha
<
64
,
"shifting error detected"
);
// Try to recover the real cache
uint64_t
pow5
=
data
::
powers_of_5_64
[
offset
];
uint128_wrapper
recovered_cache
=
umul128
(
base_cache
.
high
(),
pow5
);
uint128_wrapper
middle_low
=
umul128
(
base_cache
.
low
()
-
(
kb
<
0
?
1
:
0
),
pow5
);
recovered_cache
+=
middle_low
.
high
();
// Try to recover the real cache.
uint64_t
pow5
=
data
::
powers_of_5_64
[
offset
];
uint128_wrapper
recovered_cache
=
umul128
(
base_cache
.
high
(),
pow5
);
uint128_wrapper
middle_low
=
umul128
(
base_cache
.
low
()
-
(
kb
<
0
?
1
:
0
),
pow5
);
uint64_t
high_to_middle
=
recovered_cache
.
high
()
<<
(
64
-
alpha
);
recovered_cache
+=
middle_low
.
high
();
uint64_t
middle_to_low
=
recovered_cache
.
low
()
<<
(
64
-
alpha
);
recovered_cache
=
uint64_t
high_to_middle
=
recovered_cache
.
high
()
<<
(
64
-
alpha
);
uint128_wrapper
{(
recovered_cache
.
low
()
>>
alpha
)
|
high_to_middle
,
uint64_t
middle_to_low
=
recovered_cache
.
low
()
<<
(
64
-
alpha
);
((
middle_low
.
low
()
>>
alpha
)
|
middle_to_low
)};
if
(
kb
<
0
)
{
recovered_cache
=
recovered_cache
+=
1
;
uint128_wrapper
{(
recovered_cache
.
low
()
>>
alpha
)
|
high_to_middle
,
}
((
middle_low
.
low
()
>>
alpha
)
|
middle_to_low
)};
// Get error
if
(
kb
<
0
)
recovered_cache
+=
1
;
int
error_idx
=
(
k
-
float_info
<
double
>::
min_k
)
/
16
;
uint32_t
error
=
(
data
::
dragonbox_pow10_recovery_errors
[
error_idx
]
>>
((
k
-
float_info
<
double
>::
min_k
)
%
16
)
*
2
)
&
0x3
;
// Add the error back
// Get error.
FMT_ASSERT
(
recovered_cache
.
low
()
+
error
>=
recovered_cache
.
low
(),
""
);
int
error_idx
=
(
k
-
float_info
<
double
>::
min_k
)
/
16
;
recovered_cache
=
{
recovered_cache
.
high
(),
recovered_cache
.
low
()
+
error
};
uint32_t
error
=
(
data
::
dragonbox_pow10_recovery_errors
[
error_idx
]
>>
((
k
-
float_info
<
double
>::
min_k
)
%
16
)
*
2
)
&
0x3
;
return
recovered_cache
;
// Add the error back.
}
FMT_ASSERT
(
recovered_cache
.
low
()
+
error
>=
recovered_cache
.
low
(),
""
);
return
{
recovered_cache
.
high
(),
recovered_cache
.
low
()
+
error
};
#endif
#endif
}
}
...
...
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