Coverage Report

Created: 2026-11-12 07:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/jxl/enc_ans_simd.cc
Line
Count
Source
1
// Copyright (c) the JPEG XL Project Authors. All rights reserved.
2
//
3
// Use of this source code is governed by a BSD-style
4
// license that can be found in the LICENSE file.
5
6
#include "lib/jxl/enc_ans_simd.h"
7
8
#include <cstdint>
9
10
#include "lib/jxl/base/compiler_specific.h"
11
#include "lib/jxl/base/status.h"
12
#include "lib/jxl/dec_ans.h"
13
#include "lib/jxl/memory_manager_internal.h"
14
15
#undef HWY_TARGET_INCLUDE
16
#define HWY_TARGET_INCLUDE "lib/jxl/enc_ans_simd.cc"
17
#include <hwy/foreach_target.h>
18
#include <hwy/highway.h>
19
20
HWY_BEFORE_NAMESPACE();
21
namespace jxl {
22
namespace HWY_NAMESPACE {
23
24
// These templates are not found via ADL.
25
using hwy::HWY_NAMESPACE::Add;
26
using hwy::HWY_NAMESPACE::And;
27
using hwy::HWY_NAMESPACE::Ge;
28
using hwy::HWY_NAMESPACE::GetLane;
29
using hwy::HWY_NAMESPACE::Gt;
30
using hwy::HWY_NAMESPACE::IfThenElse;
31
using hwy::HWY_NAMESPACE::IfThenElseZero;
32
using hwy::HWY_NAMESPACE::Iota;
33
using hwy::HWY_NAMESPACE::LoadU;
34
using hwy::HWY_NAMESPACE::Lt;
35
using hwy::HWY_NAMESPACE::Mul;
36
using hwy::HWY_NAMESPACE::Or;
37
using hwy::HWY_NAMESPACE::Set;
38
using hwy::HWY_NAMESPACE::ShiftRight;
39
using hwy::HWY_NAMESPACE::Store;
40
using hwy::HWY_NAMESPACE::Sub;
41
using hwy::HWY_NAMESPACE::Zero;
42
43
template <size_t E, size_t M, size_t L>
44
uint32_t EstimateTokenCostImpl(uint32_t* JXL_RESTRICT values, size_t len,
45
487k
                               uint32_t* JXL_RESTRICT out) {
46
487k
  const HWY_FULL(uint32_t) du;
47
487k
  const HWY_FULL(float) df;
48
487k
  const auto kZero = Zero(du);
49
487k
  const auto kSplit = Set(du, 1 << E);
50
487k
  const auto kExpOffset = Set(du, 127);
51
487k
  const auto kEBOffset = Set(du, 127 + M + L);
52
487k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
487k
  const auto kMulN = Set(du, 1 << (M + L));
54
487k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
487k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
487k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
487k
  constexpr size_t kLargeShiftVal = 10;
58
487k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
487k
  auto extra_bits = kZero;
61
487k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
62.2M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
61.7M
    const auto val = LoadU(du, values + i);
64
61.7M
    const auto is_large = Gt(val, kLargeThreshold);
65
61.7M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
61.7M
    const auto not_literal = Ge(val, kSplit);
67
61.7M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
61.7M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
61.7M
    const auto l = And(val, kMaskL);
70
61.7M
    const auto exp = ShiftRight<23>(b);
71
61.7M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
61.7M
    const auto n = Sub(exp_fixed, kExpOffset);
73
61.7M
    const auto eb = Sub(exp_fixed, kEBOffset);
74
61.7M
    const auto m = ShiftRight<23 - M - L>(b);
75
61.7M
    const auto a = Add(kBase, Mul(n, kMulN));
76
61.7M
    const auto d = And(m, kMaskM);
77
61.7M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
61.7M
    const auto c = Or(a, l);
79
61.7M
    extra_bits = Add(extra_bits, eb_fixed);
80
61.7M
    const auto t = Or(c, d);
81
61.7M
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
61.7M
    Store(t_fixed, du, out + i);
83
61.7M
  }
84
487k
  if (last_full < len) {
85
419k
    const auto stop = Set(du, len);
86
419k
    const auto fence = Iota(du, last_full);
87
419k
    const auto take = Lt(fence, stop);
88
419k
    const auto val = LoadU(du, values + last_full);
89
419k
    const auto is_large = Gt(val, kLargeThreshold);
90
419k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
419k
    const auto not_literal = Ge(val, kSplit);
92
419k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
419k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
419k
    const auto l = And(val, kMaskL);
95
419k
    const auto exp = ShiftRight<23>(b);
96
419k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
419k
    const auto n = Sub(exp_fixed, kExpOffset);
98
419k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
419k
    const auto m = ShiftRight<23 - M - L>(b);
100
419k
    const auto a = Add(kBase, Mul(n, kMulN));
101
419k
    const auto d = And(m, kMaskM);
102
419k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
419k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
419k
    const auto c = Or(a, l);
105
419k
    extra_bits = Add(extra_bits, eb_masked);
106
419k
    const auto t = Or(c, d);
107
419k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
419k
    Store(t_fixed, du, out + last_full);
109
419k
  }
110
487k
  return GetLane(SumOfLanes(du, extra_bits));
111
487k
}
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<0ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<2ul, 0ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<3ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<3ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<3ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<3ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 1ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 1ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 2ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<6ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<6ul, 1ul, 5ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<6ul, 2ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<7ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<8ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<9ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<10ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<11ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<12ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<0ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
80.9k
                               uint32_t* JXL_RESTRICT out) {
46
80.9k
  const HWY_FULL(uint32_t) du;
47
80.9k
  const HWY_FULL(float) df;
48
80.9k
  const auto kZero = Zero(du);
49
80.9k
  const auto kSplit = Set(du, 1 << E);
50
80.9k
  const auto kExpOffset = Set(du, 127);
51
80.9k
  const auto kEBOffset = Set(du, 127 + M + L);
52
80.9k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
80.9k
  const auto kMulN = Set(du, 1 << (M + L));
54
80.9k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
80.9k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
80.9k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
80.9k
  constexpr size_t kLargeShiftVal = 10;
58
80.9k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
80.9k
  auto extra_bits = kZero;
61
80.9k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
11.9M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
11.9M
    const auto val = LoadU(du, values + i);
64
11.9M
    const auto is_large = Gt(val, kLargeThreshold);
65
11.9M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
11.9M
    const auto not_literal = Ge(val, kSplit);
67
11.9M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
11.9M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
11.9M
    const auto l = And(val, kMaskL);
70
11.9M
    const auto exp = ShiftRight<23>(b);
71
11.9M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
11.9M
    const auto n = Sub(exp_fixed, kExpOffset);
73
11.9M
    const auto eb = Sub(exp_fixed, kEBOffset);
74
11.9M
    const auto m = ShiftRight<23 - M - L>(b);
75
11.9M
    const auto a = Add(kBase, Mul(n, kMulN));
76
11.9M
    const auto d = And(m, kMaskM);
77
11.9M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
11.9M
    const auto c = Or(a, l);
79
11.9M
    extra_bits = Add(extra_bits, eb_fixed);
80
11.9M
    const auto t = Or(c, d);
81
11.9M
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
11.9M
    Store(t_fixed, du, out + i);
83
11.9M
  }
84
80.9k
  if (last_full < len) {
85
70.0k
    const auto stop = Set(du, len);
86
70.0k
    const auto fence = Iota(du, last_full);
87
70.0k
    const auto take = Lt(fence, stop);
88
70.0k
    const auto val = LoadU(du, values + last_full);
89
70.0k
    const auto is_large = Gt(val, kLargeThreshold);
90
70.0k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
70.0k
    const auto not_literal = Ge(val, kSplit);
92
70.0k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
70.0k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
70.0k
    const auto l = And(val, kMaskL);
95
70.0k
    const auto exp = ShiftRight<23>(b);
96
70.0k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
70.0k
    const auto n = Sub(exp_fixed, kExpOffset);
98
70.0k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
70.0k
    const auto m = ShiftRight<23 - M - L>(b);
100
70.0k
    const auto a = Add(kBase, Mul(n, kMulN));
101
70.0k
    const auto d = And(m, kMaskM);
102
70.0k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
70.0k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
70.0k
    const auto c = Or(a, l);
105
70.0k
    extra_bits = Add(extra_bits, eb_masked);
106
70.0k
    const auto t = Or(c, d);
107
70.0k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
70.0k
    Store(t_fixed, du, out + last_full);
109
70.0k
  }
110
80.9k
  return GetLane(SumOfLanes(du, extra_bits));
111
80.9k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<2ul, 0ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
80.0k
                               uint32_t* JXL_RESTRICT out) {
46
80.0k
  const HWY_FULL(uint32_t) du;
47
80.0k
  const HWY_FULL(float) df;
48
80.0k
  const auto kZero = Zero(du);
49
80.0k
  const auto kSplit = Set(du, 1 << E);
50
80.0k
  const auto kExpOffset = Set(du, 127);
51
80.0k
  const auto kEBOffset = Set(du, 127 + M + L);
52
80.0k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
80.0k
  const auto kMulN = Set(du, 1 << (M + L));
54
80.0k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
80.0k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
80.0k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
80.0k
  constexpr size_t kLargeShiftVal = 10;
58
80.0k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
80.0k
  auto extra_bits = kZero;
61
80.0k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
11.9M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
11.9M
    const auto val = LoadU(du, values + i);
64
11.9M
    const auto is_large = Gt(val, kLargeThreshold);
65
11.9M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
11.9M
    const auto not_literal = Ge(val, kSplit);
67
11.9M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
11.9M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
11.9M
    const auto l = And(val, kMaskL);
70
11.9M
    const auto exp = ShiftRight<23>(b);
71
11.9M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
11.9M
    const auto n = Sub(exp_fixed, kExpOffset);
73
11.9M
    const auto eb = Sub(exp_fixed, kEBOffset);
74
11.9M
    const auto m = ShiftRight<23 - M - L>(b);
75
11.9M
    const auto a = Add(kBase, Mul(n, kMulN));
76
11.9M
    const auto d = And(m, kMaskM);
77
11.9M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
11.9M
    const auto c = Or(a, l);
79
11.9M
    extra_bits = Add(extra_bits, eb_fixed);
80
11.9M
    const auto t = Or(c, d);
81
11.9M
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
11.9M
    Store(t_fixed, du, out + i);
83
11.9M
  }
84
80.0k
  if (last_full < len) {
85
69.3k
    const auto stop = Set(du, len);
86
69.3k
    const auto fence = Iota(du, last_full);
87
69.3k
    const auto take = Lt(fence, stop);
88
69.3k
    const auto val = LoadU(du, values + last_full);
89
69.3k
    const auto is_large = Gt(val, kLargeThreshold);
90
69.3k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
69.3k
    const auto not_literal = Ge(val, kSplit);
92
69.3k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
69.3k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
69.3k
    const auto l = And(val, kMaskL);
95
69.3k
    const auto exp = ShiftRight<23>(b);
96
69.3k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
69.3k
    const auto n = Sub(exp_fixed, kExpOffset);
98
69.3k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
69.3k
    const auto m = ShiftRight<23 - M - L>(b);
100
69.3k
    const auto a = Add(kBase, Mul(n, kMulN));
101
69.3k
    const auto d = And(m, kMaskM);
102
69.3k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
69.3k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
69.3k
    const auto c = Or(a, l);
105
69.3k
    extra_bits = Add(extra_bits, eb_masked);
106
69.3k
    const auto t = Or(c, d);
107
69.3k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
69.3k
    Store(t_fixed, du, out + last_full);
109
69.3k
  }
110
80.0k
  return GetLane(SumOfLanes(du, extra_bits));
111
80.0k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
80.0k
                               uint32_t* JXL_RESTRICT out) {
46
80.0k
  const HWY_FULL(uint32_t) du;
47
80.0k
  const HWY_FULL(float) df;
48
80.0k
  const auto kZero = Zero(du);
49
80.0k
  const auto kSplit = Set(du, 1 << E);
50
80.0k
  const auto kExpOffset = Set(du, 127);
51
80.0k
  const auto kEBOffset = Set(du, 127 + M + L);
52
80.0k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
80.0k
  const auto kMulN = Set(du, 1 << (M + L));
54
80.0k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
80.0k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
80.0k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
80.0k
  constexpr size_t kLargeShiftVal = 10;
58
80.0k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
80.0k
  auto extra_bits = kZero;
61
80.0k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
11.9M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
11.9M
    const auto val = LoadU(du, values + i);
64
11.9M
    const auto is_large = Gt(val, kLargeThreshold);
65
11.9M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
11.9M
    const auto not_literal = Ge(val, kSplit);
67
11.9M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
11.9M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
11.9M
    const auto l = And(val, kMaskL);
70
11.9M
    const auto exp = ShiftRight<23>(b);
71
11.9M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
11.9M
    const auto n = Sub(exp_fixed, kExpOffset);
73
11.9M
    const auto eb = Sub(exp_fixed, kEBOffset);
74
11.9M
    const auto m = ShiftRight<23 - M - L>(b);
75
11.9M
    const auto a = Add(kBase, Mul(n, kMulN));
76
11.9M
    const auto d = And(m, kMaskM);
77
11.9M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
11.9M
    const auto c = Or(a, l);
79
11.9M
    extra_bits = Add(extra_bits, eb_fixed);
80
11.9M
    const auto t = Or(c, d);
81
11.9M
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
11.9M
    Store(t_fixed, du, out + i);
83
11.9M
  }
84
80.0k
  if (last_full < len) {
85
69.3k
    const auto stop = Set(du, len);
86
69.3k
    const auto fence = Iota(du, last_full);
87
69.3k
    const auto take = Lt(fence, stop);
88
69.3k
    const auto val = LoadU(du, values + last_full);
89
69.3k
    const auto is_large = Gt(val, kLargeThreshold);
90
69.3k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
69.3k
    const auto not_literal = Ge(val, kSplit);
92
69.3k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
69.3k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
69.3k
    const auto l = And(val, kMaskL);
95
69.3k
    const auto exp = ShiftRight<23>(b);
96
69.3k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
69.3k
    const auto n = Sub(exp_fixed, kExpOffset);
98
69.3k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
69.3k
    const auto m = ShiftRight<23 - M - L>(b);
100
69.3k
    const auto a = Add(kBase, Mul(n, kMulN));
101
69.3k
    const auto d = And(m, kMaskM);
102
69.3k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
69.3k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
69.3k
    const auto c = Or(a, l);
105
69.3k
    extra_bits = Add(extra_bits, eb_masked);
106
69.3k
    const auto t = Or(c, d);
107
69.3k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
69.3k
    Store(t_fixed, du, out + last_full);
109
69.3k
  }
110
80.0k
  return GetLane(SumOfLanes(du, extra_bits));
111
80.0k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
80.0k
                               uint32_t* JXL_RESTRICT out) {
46
80.0k
  const HWY_FULL(uint32_t) du;
47
80.0k
  const HWY_FULL(float) df;
48
80.0k
  const auto kZero = Zero(du);
49
80.0k
  const auto kSplit = Set(du, 1 << E);
50
80.0k
  const auto kExpOffset = Set(du, 127);
51
80.0k
  const auto kEBOffset = Set(du, 127 + M + L);
52
80.0k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
80.0k
  const auto kMulN = Set(du, 1 << (M + L));
54
80.0k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
80.0k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
80.0k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
80.0k
  constexpr size_t kLargeShiftVal = 10;
58
80.0k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
80.0k
  auto extra_bits = kZero;
61
80.0k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
11.9M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
11.9M
    const auto val = LoadU(du, values + i);
64
11.9M
    const auto is_large = Gt(val, kLargeThreshold);
65
11.9M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
11.9M
    const auto not_literal = Ge(val, kSplit);
67
11.9M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
11.9M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
11.9M
    const auto l = And(val, kMaskL);
70
11.9M
    const auto exp = ShiftRight<23>(b);
71
11.9M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
11.9M
    const auto n = Sub(exp_fixed, kExpOffset);
73
11.9M
    const auto eb = Sub(exp_fixed, kEBOffset);
74
11.9M
    const auto m = ShiftRight<23 - M - L>(b);
75
11.9M
    const auto a = Add(kBase, Mul(n, kMulN));
76
11.9M
    const auto d = And(m, kMaskM);
77
11.9M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
11.9M
    const auto c = Or(a, l);
79
11.9M
    extra_bits = Add(extra_bits, eb_fixed);
80
11.9M
    const auto t = Or(c, d);
81
11.9M
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
11.9M
    Store(t_fixed, du, out + i);
83
11.9M
  }
84
80.0k
  if (last_full < len) {
85
69.3k
    const auto stop = Set(du, len);
86
69.3k
    const auto fence = Iota(du, last_full);
87
69.3k
    const auto take = Lt(fence, stop);
88
69.3k
    const auto val = LoadU(du, values + last_full);
89
69.3k
    const auto is_large = Gt(val, kLargeThreshold);
90
69.3k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
69.3k
    const auto not_literal = Ge(val, kSplit);
92
69.3k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
69.3k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
69.3k
    const auto l = And(val, kMaskL);
95
69.3k
    const auto exp = ShiftRight<23>(b);
96
69.3k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
69.3k
    const auto n = Sub(exp_fixed, kExpOffset);
98
69.3k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
69.3k
    const auto m = ShiftRight<23 - M - L>(b);
100
69.3k
    const auto a = Add(kBase, Mul(n, kMulN));
101
69.3k
    const auto d = And(m, kMaskM);
102
69.3k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
69.3k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
69.3k
    const auto c = Or(a, l);
105
69.3k
    extra_bits = Add(extra_bits, eb_masked);
106
69.3k
    const auto t = Or(c, d);
107
69.3k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
69.3k
    Store(t_fixed, du, out + last_full);
109
69.3k
  }
110
80.0k
  return GetLane(SumOfLanes(du, extra_bits));
111
80.0k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.36k
                               uint32_t* JXL_RESTRICT out) {
46
7.36k
  const HWY_FULL(uint32_t) du;
47
7.36k
  const HWY_FULL(float) df;
48
7.36k
  const auto kZero = Zero(du);
49
7.36k
  const auto kSplit = Set(du, 1 << E);
50
7.36k
  const auto kExpOffset = Set(du, 127);
51
7.36k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.36k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.36k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.36k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.36k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.36k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.36k
  constexpr size_t kLargeShiftVal = 10;
58
7.36k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.36k
  auto extra_bits = kZero;
61
7.36k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
690k
    const auto val = LoadU(du, values + i);
64
690k
    const auto is_large = Gt(val, kLargeThreshold);
65
690k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
690k
    const auto not_literal = Ge(val, kSplit);
67
690k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
690k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
690k
    const auto l = And(val, kMaskL);
70
690k
    const auto exp = ShiftRight<23>(b);
71
690k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
690k
    const auto n = Sub(exp_fixed, kExpOffset);
73
690k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
690k
    const auto m = ShiftRight<23 - M - L>(b);
75
690k
    const auto a = Add(kBase, Mul(n, kMulN));
76
690k
    const auto d = And(m, kMaskM);
77
690k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
690k
    const auto c = Or(a, l);
79
690k
    extra_bits = Add(extra_bits, eb_fixed);
80
690k
    const auto t = Or(c, d);
81
690k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
690k
    Store(t_fixed, du, out + i);
83
690k
  }
84
7.36k
  if (last_full < len) {
85
6.27k
    const auto stop = Set(du, len);
86
6.27k
    const auto fence = Iota(du, last_full);
87
6.27k
    const auto take = Lt(fence, stop);
88
6.27k
    const auto val = LoadU(du, values + last_full);
89
6.27k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.27k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.27k
    const auto not_literal = Ge(val, kSplit);
92
6.27k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.27k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.27k
    const auto l = And(val, kMaskL);
95
6.27k
    const auto exp = ShiftRight<23>(b);
96
6.27k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.27k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.27k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.27k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.27k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.27k
    const auto d = And(m, kMaskM);
102
6.27k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.27k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.27k
    const auto c = Or(a, l);
105
6.27k
    extra_bits = Add(extra_bits, eb_masked);
106
6.27k
    const auto t = Or(c, d);
107
6.27k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.27k
    Store(t_fixed, du, out + last_full);
109
6.27k
  }
110
7.36k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.36k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.36k
                               uint32_t* JXL_RESTRICT out) {
46
7.36k
  const HWY_FULL(uint32_t) du;
47
7.36k
  const HWY_FULL(float) df;
48
7.36k
  const auto kZero = Zero(du);
49
7.36k
  const auto kSplit = Set(du, 1 << E);
50
7.36k
  const auto kExpOffset = Set(du, 127);
51
7.36k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.36k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.36k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.36k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.36k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.36k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.36k
  constexpr size_t kLargeShiftVal = 10;
58
7.36k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.36k
  auto extra_bits = kZero;
61
7.36k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
690k
    const auto val = LoadU(du, values + i);
64
690k
    const auto is_large = Gt(val, kLargeThreshold);
65
690k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
690k
    const auto not_literal = Ge(val, kSplit);
67
690k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
690k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
690k
    const auto l = And(val, kMaskL);
70
690k
    const auto exp = ShiftRight<23>(b);
71
690k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
690k
    const auto n = Sub(exp_fixed, kExpOffset);
73
690k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
690k
    const auto m = ShiftRight<23 - M - L>(b);
75
690k
    const auto a = Add(kBase, Mul(n, kMulN));
76
690k
    const auto d = And(m, kMaskM);
77
690k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
690k
    const auto c = Or(a, l);
79
690k
    extra_bits = Add(extra_bits, eb_fixed);
80
690k
    const auto t = Or(c, d);
81
690k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
690k
    Store(t_fixed, du, out + i);
83
690k
  }
84
7.36k
  if (last_full < len) {
85
6.27k
    const auto stop = Set(du, len);
86
6.27k
    const auto fence = Iota(du, last_full);
87
6.27k
    const auto take = Lt(fence, stop);
88
6.27k
    const auto val = LoadU(du, values + last_full);
89
6.27k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.27k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.27k
    const auto not_literal = Ge(val, kSplit);
92
6.27k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.27k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.27k
    const auto l = And(val, kMaskL);
95
6.27k
    const auto exp = ShiftRight<23>(b);
96
6.27k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.27k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.27k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.27k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.27k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.27k
    const auto d = And(m, kMaskM);
102
6.27k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.27k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.27k
    const auto c = Or(a, l);
105
6.27k
    extra_bits = Add(extra_bits, eb_masked);
106
6.27k
    const auto t = Or(c, d);
107
6.27k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.27k
    Store(t_fixed, du, out + last_full);
109
6.27k
  }
110
7.36k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.36k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 1ul, 5ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
6.46k
                               uint32_t* JXL_RESTRICT out) {
46
6.46k
  const HWY_FULL(uint32_t) du;
47
6.46k
  const HWY_FULL(float) df;
48
6.46k
  const auto kZero = Zero(du);
49
6.46k
  const auto kSplit = Set(du, 1 << E);
50
6.46k
  const auto kExpOffset = Set(du, 127);
51
6.46k
  const auto kEBOffset = Set(du, 127 + M + L);
52
6.46k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
6.46k
  const auto kMulN = Set(du, 1 << (M + L));
54
6.46k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
6.46k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
6.46k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
6.46k
  constexpr size_t kLargeShiftVal = 10;
58
6.46k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
6.46k
  auto extra_bits = kZero;
61
6.46k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
366k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
359k
    const auto val = LoadU(du, values + i);
64
359k
    const auto is_large = Gt(val, kLargeThreshold);
65
359k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
359k
    const auto not_literal = Ge(val, kSplit);
67
359k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
359k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
359k
    const auto l = And(val, kMaskL);
70
359k
    const auto exp = ShiftRight<23>(b);
71
359k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
359k
    const auto n = Sub(exp_fixed, kExpOffset);
73
359k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
359k
    const auto m = ShiftRight<23 - M - L>(b);
75
359k
    const auto a = Add(kBase, Mul(n, kMulN));
76
359k
    const auto d = And(m, kMaskM);
77
359k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
359k
    const auto c = Or(a, l);
79
359k
    extra_bits = Add(extra_bits, eb_fixed);
80
359k
    const auto t = Or(c, d);
81
359k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
359k
    Store(t_fixed, du, out + i);
83
359k
  }
84
6.46k
  if (last_full < len) {
85
5.53k
    const auto stop = Set(du, len);
86
5.53k
    const auto fence = Iota(du, last_full);
87
5.53k
    const auto take = Lt(fence, stop);
88
5.53k
    const auto val = LoadU(du, values + last_full);
89
5.53k
    const auto is_large = Gt(val, kLargeThreshold);
90
5.53k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
5.53k
    const auto not_literal = Ge(val, kSplit);
92
5.53k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
5.53k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
5.53k
    const auto l = And(val, kMaskL);
95
5.53k
    const auto exp = ShiftRight<23>(b);
96
5.53k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
5.53k
    const auto n = Sub(exp_fixed, kExpOffset);
98
5.53k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
5.53k
    const auto m = ShiftRight<23 - M - L>(b);
100
5.53k
    const auto a = Add(kBase, Mul(n, kMulN));
101
5.53k
    const auto d = And(m, kMaskM);
102
5.53k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
5.53k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
5.53k
    const auto c = Or(a, l);
105
5.53k
    extra_bits = Add(extra_bits, eb_masked);
106
5.53k
    const auto t = Or(c, d);
107
5.53k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
5.53k
    Store(t_fixed, du, out + last_full);
109
5.53k
  }
110
6.46k
  return GetLane(SumOfLanes(du, extra_bits));
111
6.46k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 2ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
6.46k
                               uint32_t* JXL_RESTRICT out) {
46
6.46k
  const HWY_FULL(uint32_t) du;
47
6.46k
  const HWY_FULL(float) df;
48
6.46k
  const auto kZero = Zero(du);
49
6.46k
  const auto kSplit = Set(du, 1 << E);
50
6.46k
  const auto kExpOffset = Set(du, 127);
51
6.46k
  const auto kEBOffset = Set(du, 127 + M + L);
52
6.46k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
6.46k
  const auto kMulN = Set(du, 1 << (M + L));
54
6.46k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
6.46k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
6.46k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
6.46k
  constexpr size_t kLargeShiftVal = 10;
58
6.46k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
6.46k
  auto extra_bits = kZero;
61
6.46k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
366k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
359k
    const auto val = LoadU(du, values + i);
64
359k
    const auto is_large = Gt(val, kLargeThreshold);
65
359k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
359k
    const auto not_literal = Ge(val, kSplit);
67
359k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
359k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
359k
    const auto l = And(val, kMaskL);
70
359k
    const auto exp = ShiftRight<23>(b);
71
359k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
359k
    const auto n = Sub(exp_fixed, kExpOffset);
73
359k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
359k
    const auto m = ShiftRight<23 - M - L>(b);
75
359k
    const auto a = Add(kBase, Mul(n, kMulN));
76
359k
    const auto d = And(m, kMaskM);
77
359k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
359k
    const auto c = Or(a, l);
79
359k
    extra_bits = Add(extra_bits, eb_fixed);
80
359k
    const auto t = Or(c, d);
81
359k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
359k
    Store(t_fixed, du, out + i);
83
359k
  }
84
6.46k
  if (last_full < len) {
85
5.53k
    const auto stop = Set(du, len);
86
5.53k
    const auto fence = Iota(du, last_full);
87
5.53k
    const auto take = Lt(fence, stop);
88
5.53k
    const auto val = LoadU(du, values + last_full);
89
5.53k
    const auto is_large = Gt(val, kLargeThreshold);
90
5.53k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
5.53k
    const auto not_literal = Ge(val, kSplit);
92
5.53k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
5.53k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
5.53k
    const auto l = And(val, kMaskL);
95
5.53k
    const auto exp = ShiftRight<23>(b);
96
5.53k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
5.53k
    const auto n = Sub(exp_fixed, kExpOffset);
98
5.53k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
5.53k
    const auto m = ShiftRight<23 - M - L>(b);
100
5.53k
    const auto a = Add(kBase, Mul(n, kMulN));
101
5.53k
    const auto d = And(m, kMaskM);
102
5.53k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
5.53k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
5.53k
    const auto c = Or(a, l);
105
5.53k
    extra_bits = Add(extra_bits, eb_masked);
106
5.53k
    const auto t = Or(c, d);
107
5.53k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
5.53k
    Store(t_fixed, du, out + last_full);
109
5.53k
  }
110
6.46k
  return GetLane(SumOfLanes(du, extra_bits));
111
6.46k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<7ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.37k
                               uint32_t* JXL_RESTRICT out) {
46
7.37k
  const HWY_FULL(uint32_t) du;
47
7.37k
  const HWY_FULL(float) df;
48
7.37k
  const auto kZero = Zero(du);
49
7.37k
  const auto kSplit = Set(du, 1 << E);
50
7.37k
  const auto kExpOffset = Set(du, 127);
51
7.37k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.37k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.37k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.37k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.37k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.37k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.37k
  constexpr size_t kLargeShiftVal = 10;
58
7.37k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.37k
  auto extra_bits = kZero;
61
7.37k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
698k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
691k
    const auto val = LoadU(du, values + i);
64
691k
    const auto is_large = Gt(val, kLargeThreshold);
65
691k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
691k
    const auto not_literal = Ge(val, kSplit);
67
691k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
691k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
691k
    const auto l = And(val, kMaskL);
70
691k
    const auto exp = ShiftRight<23>(b);
71
691k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
691k
    const auto n = Sub(exp_fixed, kExpOffset);
73
691k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
691k
    const auto m = ShiftRight<23 - M - L>(b);
75
691k
    const auto a = Add(kBase, Mul(n, kMulN));
76
691k
    const auto d = And(m, kMaskM);
77
691k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
691k
    const auto c = Or(a, l);
79
691k
    extra_bits = Add(extra_bits, eb_fixed);
80
691k
    const auto t = Or(c, d);
81
691k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
691k
    Store(t_fixed, du, out + i);
83
691k
  }
84
7.37k
  if (last_full < len) {
85
6.28k
    const auto stop = Set(du, len);
86
6.28k
    const auto fence = Iota(du, last_full);
87
6.28k
    const auto take = Lt(fence, stop);
88
6.28k
    const auto val = LoadU(du, values + last_full);
89
6.28k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.28k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.28k
    const auto not_literal = Ge(val, kSplit);
92
6.28k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.28k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.28k
    const auto l = And(val, kMaskL);
95
6.28k
    const auto exp = ShiftRight<23>(b);
96
6.28k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.28k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.28k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.28k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.28k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.28k
    const auto d = And(m, kMaskM);
102
6.28k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.28k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.28k
    const auto c = Or(a, l);
105
6.28k
    extra_bits = Add(extra_bits, eb_masked);
106
6.28k
    const auto t = Or(c, d);
107
6.28k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.28k
    Store(t_fixed, du, out + last_full);
109
6.28k
  }
110
7.37k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.37k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<8ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
5.56k
                               uint32_t* JXL_RESTRICT out) {
46
5.56k
  const HWY_FULL(uint32_t) du;
47
5.56k
  const HWY_FULL(float) df;
48
5.56k
  const auto kZero = Zero(du);
49
5.56k
  const auto kSplit = Set(du, 1 << E);
50
5.56k
  const auto kExpOffset = Set(du, 127);
51
5.56k
  const auto kEBOffset = Set(du, 127 + M + L);
52
5.56k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
5.56k
  const auto kMulN = Set(du, 1 << (M + L));
54
5.56k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
5.56k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
5.56k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
5.56k
  constexpr size_t kLargeShiftVal = 10;
58
5.56k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
5.56k
  auto extra_bits = kZero;
61
5.56k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
333k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
328k
    const auto val = LoadU(du, values + i);
64
328k
    const auto is_large = Gt(val, kLargeThreshold);
65
328k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
328k
    const auto not_literal = Ge(val, kSplit);
67
328k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
328k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
328k
    const auto l = And(val, kMaskL);
70
328k
    const auto exp = ShiftRight<23>(b);
71
328k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
328k
    const auto n = Sub(exp_fixed, kExpOffset);
73
328k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
328k
    const auto m = ShiftRight<23 - M - L>(b);
75
328k
    const auto a = Add(kBase, Mul(n, kMulN));
76
328k
    const auto d = And(m, kMaskM);
77
328k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
328k
    const auto c = Or(a, l);
79
328k
    extra_bits = Add(extra_bits, eb_fixed);
80
328k
    const auto t = Or(c, d);
81
328k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
328k
    Store(t_fixed, du, out + i);
83
328k
  }
84
5.56k
  if (last_full < len) {
85
4.72k
    const auto stop = Set(du, len);
86
4.72k
    const auto fence = Iota(du, last_full);
87
4.72k
    const auto take = Lt(fence, stop);
88
4.72k
    const auto val = LoadU(du, values + last_full);
89
4.72k
    const auto is_large = Gt(val, kLargeThreshold);
90
4.72k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
4.72k
    const auto not_literal = Ge(val, kSplit);
92
4.72k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
4.72k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
4.72k
    const auto l = And(val, kMaskL);
95
4.72k
    const auto exp = ShiftRight<23>(b);
96
4.72k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
4.72k
    const auto n = Sub(exp_fixed, kExpOffset);
98
4.72k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
4.72k
    const auto m = ShiftRight<23 - M - L>(b);
100
4.72k
    const auto a = Add(kBase, Mul(n, kMulN));
101
4.72k
    const auto d = And(m, kMaskM);
102
4.72k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
4.72k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
4.72k
    const auto c = Or(a, l);
105
4.72k
    extra_bits = Add(extra_bits, eb_masked);
106
4.72k
    const auto t = Or(c, d);
107
4.72k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
4.72k
    Store(t_fixed, du, out + last_full);
109
4.72k
  }
110
5.56k
  return GetLane(SumOfLanes(du, extra_bits));
111
5.56k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<9ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
5.56k
                               uint32_t* JXL_RESTRICT out) {
46
5.56k
  const HWY_FULL(uint32_t) du;
47
5.56k
  const HWY_FULL(float) df;
48
5.56k
  const auto kZero = Zero(du);
49
5.56k
  const auto kSplit = Set(du, 1 << E);
50
5.56k
  const auto kExpOffset = Set(du, 127);
51
5.56k
  const auto kEBOffset = Set(du, 127 + M + L);
52
5.56k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
5.56k
  const auto kMulN = Set(du, 1 << (M + L));
54
5.56k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
5.56k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
5.56k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
5.56k
  constexpr size_t kLargeShiftVal = 10;
58
5.56k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
5.56k
  auto extra_bits = kZero;
61
5.56k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
333k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
328k
    const auto val = LoadU(du, values + i);
64
328k
    const auto is_large = Gt(val, kLargeThreshold);
65
328k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
328k
    const auto not_literal = Ge(val, kSplit);
67
328k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
328k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
328k
    const auto l = And(val, kMaskL);
70
328k
    const auto exp = ShiftRight<23>(b);
71
328k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
328k
    const auto n = Sub(exp_fixed, kExpOffset);
73
328k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
328k
    const auto m = ShiftRight<23 - M - L>(b);
75
328k
    const auto a = Add(kBase, Mul(n, kMulN));
76
328k
    const auto d = And(m, kMaskM);
77
328k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
328k
    const auto c = Or(a, l);
79
328k
    extra_bits = Add(extra_bits, eb_fixed);
80
328k
    const auto t = Or(c, d);
81
328k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
328k
    Store(t_fixed, du, out + i);
83
328k
  }
84
5.56k
  if (last_full < len) {
85
4.72k
    const auto stop = Set(du, len);
86
4.72k
    const auto fence = Iota(du, last_full);
87
4.72k
    const auto take = Lt(fence, stop);
88
4.72k
    const auto val = LoadU(du, values + last_full);
89
4.72k
    const auto is_large = Gt(val, kLargeThreshold);
90
4.72k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
4.72k
    const auto not_literal = Ge(val, kSplit);
92
4.72k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
4.72k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
4.72k
    const auto l = And(val, kMaskL);
95
4.72k
    const auto exp = ShiftRight<23>(b);
96
4.72k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
4.72k
    const auto n = Sub(exp_fixed, kExpOffset);
98
4.72k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
4.72k
    const auto m = ShiftRight<23 - M - L>(b);
100
4.72k
    const auto a = Add(kBase, Mul(n, kMulN));
101
4.72k
    const auto d = And(m, kMaskM);
102
4.72k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
4.72k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
4.72k
    const auto c = Or(a, l);
105
4.72k
    extra_bits = Add(extra_bits, eb_masked);
106
4.72k
    const auto t = Or(c, d);
107
4.72k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
4.72k
    Store(t_fixed, du, out + last_full);
109
4.72k
  }
110
5.56k
  return GetLane(SumOfLanes(du, extra_bits));
111
5.56k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<10ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
5.56k
                               uint32_t* JXL_RESTRICT out) {
46
5.56k
  const HWY_FULL(uint32_t) du;
47
5.56k
  const HWY_FULL(float) df;
48
5.56k
  const auto kZero = Zero(du);
49
5.56k
  const auto kSplit = Set(du, 1 << E);
50
5.56k
  const auto kExpOffset = Set(du, 127);
51
5.56k
  const auto kEBOffset = Set(du, 127 + M + L);
52
5.56k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
5.56k
  const auto kMulN = Set(du, 1 << (M + L));
54
5.56k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
5.56k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
5.56k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
5.56k
  constexpr size_t kLargeShiftVal = 10;
58
5.56k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
5.56k
  auto extra_bits = kZero;
61
5.56k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
333k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
328k
    const auto val = LoadU(du, values + i);
64
328k
    const auto is_large = Gt(val, kLargeThreshold);
65
328k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
328k
    const auto not_literal = Ge(val, kSplit);
67
328k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
328k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
328k
    const auto l = And(val, kMaskL);
70
328k
    const auto exp = ShiftRight<23>(b);
71
328k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
328k
    const auto n = Sub(exp_fixed, kExpOffset);
73
328k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
328k
    const auto m = ShiftRight<23 - M - L>(b);
75
328k
    const auto a = Add(kBase, Mul(n, kMulN));
76
328k
    const auto d = And(m, kMaskM);
77
328k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
328k
    const auto c = Or(a, l);
79
328k
    extra_bits = Add(extra_bits, eb_fixed);
80
328k
    const auto t = Or(c, d);
81
328k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
328k
    Store(t_fixed, du, out + i);
83
328k
  }
84
5.56k
  if (last_full < len) {
85
4.72k
    const auto stop = Set(du, len);
86
4.72k
    const auto fence = Iota(du, last_full);
87
4.72k
    const auto take = Lt(fence, stop);
88
4.72k
    const auto val = LoadU(du, values + last_full);
89
4.72k
    const auto is_large = Gt(val, kLargeThreshold);
90
4.72k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
4.72k
    const auto not_literal = Ge(val, kSplit);
92
4.72k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
4.72k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
4.72k
    const auto l = And(val, kMaskL);
95
4.72k
    const auto exp = ShiftRight<23>(b);
96
4.72k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
4.72k
    const auto n = Sub(exp_fixed, kExpOffset);
98
4.72k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
4.72k
    const auto m = ShiftRight<23 - M - L>(b);
100
4.72k
    const auto a = Add(kBase, Mul(n, kMulN));
101
4.72k
    const auto d = And(m, kMaskM);
102
4.72k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
4.72k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
4.72k
    const auto c = Or(a, l);
105
4.72k
    extra_bits = Add(extra_bits, eb_masked);
106
4.72k
    const auto t = Or(c, d);
107
4.72k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
4.72k
    Store(t_fixed, du, out + last_full);
109
4.72k
  }
110
5.56k
  return GetLane(SumOfLanes(du, extra_bits));
111
5.56k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<11ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
5.56k
                               uint32_t* JXL_RESTRICT out) {
46
5.56k
  const HWY_FULL(uint32_t) du;
47
5.56k
  const HWY_FULL(float) df;
48
5.56k
  const auto kZero = Zero(du);
49
5.56k
  const auto kSplit = Set(du, 1 << E);
50
5.56k
  const auto kExpOffset = Set(du, 127);
51
5.56k
  const auto kEBOffset = Set(du, 127 + M + L);
52
5.56k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
5.56k
  const auto kMulN = Set(du, 1 << (M + L));
54
5.56k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
5.56k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
5.56k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
5.56k
  constexpr size_t kLargeShiftVal = 10;
58
5.56k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
5.56k
  auto extra_bits = kZero;
61
5.56k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
333k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
328k
    const auto val = LoadU(du, values + i);
64
328k
    const auto is_large = Gt(val, kLargeThreshold);
65
328k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
328k
    const auto not_literal = Ge(val, kSplit);
67
328k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
328k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
328k
    const auto l = And(val, kMaskL);
70
328k
    const auto exp = ShiftRight<23>(b);
71
328k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
328k
    const auto n = Sub(exp_fixed, kExpOffset);
73
328k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
328k
    const auto m = ShiftRight<23 - M - L>(b);
75
328k
    const auto a = Add(kBase, Mul(n, kMulN));
76
328k
    const auto d = And(m, kMaskM);
77
328k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
328k
    const auto c = Or(a, l);
79
328k
    extra_bits = Add(extra_bits, eb_fixed);
80
328k
    const auto t = Or(c, d);
81
328k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
328k
    Store(t_fixed, du, out + i);
83
328k
  }
84
5.56k
  if (last_full < len) {
85
4.72k
    const auto stop = Set(du, len);
86
4.72k
    const auto fence = Iota(du, last_full);
87
4.72k
    const auto take = Lt(fence, stop);
88
4.72k
    const auto val = LoadU(du, values + last_full);
89
4.72k
    const auto is_large = Gt(val, kLargeThreshold);
90
4.72k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
4.72k
    const auto not_literal = Ge(val, kSplit);
92
4.72k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
4.72k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
4.72k
    const auto l = And(val, kMaskL);
95
4.72k
    const auto exp = ShiftRight<23>(b);
96
4.72k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
4.72k
    const auto n = Sub(exp_fixed, kExpOffset);
98
4.72k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
4.72k
    const auto m = ShiftRight<23 - M - L>(b);
100
4.72k
    const auto a = Add(kBase, Mul(n, kMulN));
101
4.72k
    const auto d = And(m, kMaskM);
102
4.72k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
4.72k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
4.72k
    const auto c = Or(a, l);
105
4.72k
    extra_bits = Add(extra_bits, eb_masked);
106
4.72k
    const auto t = Or(c, d);
107
4.72k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
4.72k
    Store(t_fixed, du, out + last_full);
109
4.72k
  }
110
5.56k
  return GetLane(SumOfLanes(du, extra_bits));
111
5.56k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<12ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
5.56k
                               uint32_t* JXL_RESTRICT out) {
46
5.56k
  const HWY_FULL(uint32_t) du;
47
5.56k
  const HWY_FULL(float) df;
48
5.56k
  const auto kZero = Zero(du);
49
5.56k
  const auto kSplit = Set(du, 1 << E);
50
5.56k
  const auto kExpOffset = Set(du, 127);
51
5.56k
  const auto kEBOffset = Set(du, 127 + M + L);
52
5.56k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
5.56k
  const auto kMulN = Set(du, 1 << (M + L));
54
5.56k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
5.56k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
5.56k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
5.56k
  constexpr size_t kLargeShiftVal = 10;
58
5.56k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
5.56k
  auto extra_bits = kZero;
61
5.56k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
333k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
328k
    const auto val = LoadU(du, values + i);
64
328k
    const auto is_large = Gt(val, kLargeThreshold);
65
328k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
328k
    const auto not_literal = Ge(val, kSplit);
67
328k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
328k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
328k
    const auto l = And(val, kMaskL);
70
328k
    const auto exp = ShiftRight<23>(b);
71
328k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
328k
    const auto n = Sub(exp_fixed, kExpOffset);
73
328k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
328k
    const auto m = ShiftRight<23 - M - L>(b);
75
328k
    const auto a = Add(kBase, Mul(n, kMulN));
76
328k
    const auto d = And(m, kMaskM);
77
328k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
328k
    const auto c = Or(a, l);
79
328k
    extra_bits = Add(extra_bits, eb_fixed);
80
328k
    const auto t = Or(c, d);
81
328k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
328k
    Store(t_fixed, du, out + i);
83
328k
  }
84
5.56k
  if (last_full < len) {
85
4.72k
    const auto stop = Set(du, len);
86
4.72k
    const auto fence = Iota(du, last_full);
87
4.72k
    const auto take = Lt(fence, stop);
88
4.72k
    const auto val = LoadU(du, values + last_full);
89
4.72k
    const auto is_large = Gt(val, kLargeThreshold);
90
4.72k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
4.72k
    const auto not_literal = Ge(val, kSplit);
92
4.72k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
4.72k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
4.72k
    const auto l = And(val, kMaskL);
95
4.72k
    const auto exp = ShiftRight<23>(b);
96
4.72k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
4.72k
    const auto n = Sub(exp_fixed, kExpOffset);
98
4.72k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
4.72k
    const auto m = ShiftRight<23 - M - L>(b);
100
4.72k
    const auto a = Add(kBase, Mul(n, kMulN));
101
4.72k
    const auto d = And(m, kMaskM);
102
4.72k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
4.72k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
4.72k
    const auto c = Or(a, l);
105
4.72k
    extra_bits = Add(extra_bits, eb_masked);
106
4.72k
    const auto t = Or(c, d);
107
4.72k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
4.72k
    Store(t_fixed, du, out + last_full);
109
4.72k
  }
110
5.56k
  return GetLane(SumOfLanes(du, extra_bits));
111
5.56k
}
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<0ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<2ul, 0ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<3ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<3ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<3ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<3ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<4ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<4ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<4ul, 1ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<4ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<4ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<4ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<5ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<5ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<5ul, 1ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<5ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<5ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<5ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<5ul, 2ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<6ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<6ul, 1ul, 5ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<6ul, 2ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<7ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<8ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<9ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<10ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<11ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE2::EstimateTokenCostImpl<12ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
112
113
uint32_t EstimateTokenCost(uint32_t* JXL_RESTRICT values, size_t len,
114
487k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
115
487k
  uint32_t* JXL_RESTRICT out = tokens.address<uint32_t>();
116
#if HWY_TARGET == HWY_SCALAR
117
  uint32_t extra_bits = 0;
118
  for (size_t i = 0; i < len; ++i) {
119
    uint32_t v = values[i];
120
    uint32_t tok, nbits, bits;
121
    cfg.Encode(v, &tok, &nbits, &bits);
122
    extra_bits += nbits;
123
    out[i] = tok;
124
  }
125
  return extra_bits;
126
#else
127
487k
  if (cfg.split_exponent == 0) {
128
80.9k
    return EstimateTokenCostImpl<0, 0, 0>(values, len, out);
129
406k
  } else if (cfg.split_exponent == 2) {
130
80.0k
    JXL_DASSERT((cfg.msb_in_token == 0) && (cfg.lsb_in_token == 1));
131
80.0k
    return EstimateTokenCostImpl<2, 0, 1>(values, len, out);
132
326k
  } else if (cfg.split_exponent == 3) {
133
29.4k
    if (cfg.msb_in_token == 1) {
134
14.7k
      if (cfg.lsb_in_token == 0) {
135
7.37k
        return EstimateTokenCostImpl<3, 1, 0>(values, len, out);
136
7.37k
      } else {
137
7.37k
        JXL_DASSERT(cfg.lsb_in_token == 2);
138
7.37k
        return EstimateTokenCostImpl<3, 1, 2>(values, len, out);
139
7.37k
      }
140
14.7k
    } else {
141
14.7k
      JXL_DASSERT(cfg.msb_in_token == 2);
142
14.7k
      if (cfg.lsb_in_token == 0) {
143
7.37k
        return EstimateTokenCostImpl<3, 2, 0>(values, len, out);
144
7.37k
      } else {
145
7.37k
        JXL_DASSERT(cfg.lsb_in_token == 1);
146
7.37k
        return EstimateTokenCostImpl<3, 2, 1>(values, len, out);
147
7.37k
      }
148
14.7k
    }
149
296k
  } else if (cfg.split_exponent == 4) {
150
189k
    if (cfg.msb_in_token == 1) {
151
94.8k
      if (cfg.lsb_in_token == 0) {
152
7.37k
        return EstimateTokenCostImpl<4, 1, 0>(values, len, out);
153
87.4k
      } else if (cfg.lsb_in_token == 2) {
154
80.0k
        return EstimateTokenCostImpl<4, 1, 2>(values, len, out);
155
80.0k
      } else {
156
7.37k
        JXL_DASSERT(cfg.lsb_in_token == 3);
157
7.37k
        return EstimateTokenCostImpl<4, 1, 3>(values, len, out);
158
7.37k
      }
159
94.8k
    } else {
160
94.8k
      JXL_DASSERT(cfg.msb_in_token == 2);
161
94.8k
      if (cfg.lsb_in_token == 0) {
162
80.0k
        return EstimateTokenCostImpl<4, 2, 0>(values, len, out);
163
80.0k
      } else if (cfg.lsb_in_token == 1) {
164
7.37k
        return EstimateTokenCostImpl<4, 2, 1>(values, len, out);
165
7.37k
      } else {
166
7.37k
        JXL_DASSERT(cfg.lsb_in_token == 2);
167
7.37k
        return EstimateTokenCostImpl<4, 2, 2>(values, len, out);
168
7.37k
      }
169
94.8k
    }
170
189k
  } else if (cfg.split_exponent == 5) {
171
51.5k
    if (cfg.msb_in_token == 1) {
172
22.1k
      if (cfg.lsb_in_token == 0) {
173
7.37k
        return EstimateTokenCostImpl<5, 1, 0>(values, len, out);
174
14.7k
      } else if (cfg.lsb_in_token == 2) {
175
7.37k
        return EstimateTokenCostImpl<5, 1, 2>(values, len, out);
176
7.37k
      } else {
177
7.36k
        JXL_DASSERT(cfg.lsb_in_token == 4);
178
7.36k
        return EstimateTokenCostImpl<5, 1, 4>(values, len, out);
179
7.36k
      }
180
29.4k
    } else {
181
29.4k
      JXL_DASSERT(cfg.msb_in_token == 2);
182
29.4k
      if (cfg.lsb_in_token == 0) {
183
7.37k
        return EstimateTokenCostImpl<5, 2, 0>(values, len, out);
184
22.1k
      } else if (cfg.lsb_in_token == 1) {
185
7.37k
        return EstimateTokenCostImpl<5, 2, 1>(values, len, out);
186
14.7k
      } else if (cfg.lsb_in_token == 2) {
187
7.37k
        return EstimateTokenCostImpl<5, 2, 2>(values, len, out);
188
7.37k
      } else {
189
7.36k
        JXL_DASSERT(cfg.lsb_in_token == 3);
190
7.36k
        return EstimateTokenCostImpl<5, 2, 3>(values, len, out);
191
7.36k
      }
192
29.4k
    }
193
55.5k
  } else if (cfg.split_exponent == 6) {
194
20.2k
    if (cfg.msb_in_token == 0) {
195
7.37k
      JXL_DASSERT(cfg.lsb_in_token == 0);
196
7.37k
      return EstimateTokenCostImpl<6, 0, 0>(values, len, out);
197
12.9k
    } else if (cfg.msb_in_token == 1) {
198
6.46k
      JXL_DASSERT(cfg.lsb_in_token == 5);
199
6.46k
      return EstimateTokenCostImpl<6, 1, 5>(values, len, out);
200
6.46k
    } else {
201
6.46k
      JXL_DASSERT(cfg.msb_in_token == 2);
202
6.46k
      JXL_DASSERT(cfg.lsb_in_token == 4);
203
6.46k
      return EstimateTokenCostImpl<6, 2, 4>(values, len, out);
204
6.46k
    }
205
35.2k
  } else if (cfg.split_exponent >= 7 && cfg.split_exponent <= 12) {
206
35.2k
    JXL_DASSERT(cfg.msb_in_token == 0);
207
35.2k
    JXL_DASSERT(cfg.lsb_in_token == 0);
208
35.2k
    if (cfg.split_exponent == 7) {
209
7.37k
      return EstimateTokenCostImpl<7, 0, 0>(values, len, out);
210
27.8k
    } else if (cfg.split_exponent == 8) {
211
5.56k
      return EstimateTokenCostImpl<8, 0, 0>(values, len, out);
212
22.2k
    } else if (cfg.split_exponent == 9) {
213
5.56k
      return EstimateTokenCostImpl<9, 0, 0>(values, len, out);
214
16.7k
    } else if (cfg.split_exponent == 10) {
215
5.56k
      return EstimateTokenCostImpl<10, 0, 0>(values, len, out);
216
11.1k
    } else if (cfg.split_exponent == 11) {
217
5.56k
      return EstimateTokenCostImpl<11, 0, 0>(values, len, out);
218
5.56k
    } else {
219
5.56k
      return EstimateTokenCostImpl<12, 0, 0>(values, len, out);
220
5.56k
    }
221
35.2k
  } else {
222
0
    JXL_DASSERT(false);
223
0
  }
224
0
  return ~0;
225
487k
#endif
226
487k
}
Unexecuted instantiation: jxl::N_SSE4::EstimateTokenCost(unsigned int*, unsigned long, jxl::HybridUintConfig, jxl::AlignedMemory&)
jxl::N_AVX2::EstimateTokenCost(unsigned int*, unsigned long, jxl::HybridUintConfig, jxl::AlignedMemory&)
Line
Count
Source
114
487k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
115
487k
  uint32_t* JXL_RESTRICT out = tokens.address<uint32_t>();
116
#if HWY_TARGET == HWY_SCALAR
117
  uint32_t extra_bits = 0;
118
  for (size_t i = 0; i < len; ++i) {
119
    uint32_t v = values[i];
120
    uint32_t tok, nbits, bits;
121
    cfg.Encode(v, &tok, &nbits, &bits);
122
    extra_bits += nbits;
123
    out[i] = tok;
124
  }
125
  return extra_bits;
126
#else
127
487k
  if (cfg.split_exponent == 0) {
128
80.9k
    return EstimateTokenCostImpl<0, 0, 0>(values, len, out);
129
406k
  } else if (cfg.split_exponent == 2) {
130
80.0k
    JXL_DASSERT((cfg.msb_in_token == 0) && (cfg.lsb_in_token == 1));
131
80.0k
    return EstimateTokenCostImpl<2, 0, 1>(values, len, out);
132
326k
  } else if (cfg.split_exponent == 3) {
133
29.4k
    if (cfg.msb_in_token == 1) {
134
14.7k
      if (cfg.lsb_in_token == 0) {
135
7.37k
        return EstimateTokenCostImpl<3, 1, 0>(values, len, out);
136
7.37k
      } else {
137
7.37k
        JXL_DASSERT(cfg.lsb_in_token == 2);
138
7.37k
        return EstimateTokenCostImpl<3, 1, 2>(values, len, out);
139
7.37k
      }
140
14.7k
    } else {
141
14.7k
      JXL_DASSERT(cfg.msb_in_token == 2);
142
14.7k
      if (cfg.lsb_in_token == 0) {
143
7.37k
        return EstimateTokenCostImpl<3, 2, 0>(values, len, out);
144
7.37k
      } else {
145
7.37k
        JXL_DASSERT(cfg.lsb_in_token == 1);
146
7.37k
        return EstimateTokenCostImpl<3, 2, 1>(values, len, out);
147
7.37k
      }
148
14.7k
    }
149
296k
  } else if (cfg.split_exponent == 4) {
150
189k
    if (cfg.msb_in_token == 1) {
151
94.8k
      if (cfg.lsb_in_token == 0) {
152
7.37k
        return EstimateTokenCostImpl<4, 1, 0>(values, len, out);
153
87.4k
      } else if (cfg.lsb_in_token == 2) {
154
80.0k
        return EstimateTokenCostImpl<4, 1, 2>(values, len, out);
155
80.0k
      } else {
156
7.37k
        JXL_DASSERT(cfg.lsb_in_token == 3);
157
7.37k
        return EstimateTokenCostImpl<4, 1, 3>(values, len, out);
158
7.37k
      }
159
94.8k
    } else {
160
94.8k
      JXL_DASSERT(cfg.msb_in_token == 2);
161
94.8k
      if (cfg.lsb_in_token == 0) {
162
80.0k
        return EstimateTokenCostImpl<4, 2, 0>(values, len, out);
163
80.0k
      } else if (cfg.lsb_in_token == 1) {
164
7.37k
        return EstimateTokenCostImpl<4, 2, 1>(values, len, out);
165
7.37k
      } else {
166
7.37k
        JXL_DASSERT(cfg.lsb_in_token == 2);
167
7.37k
        return EstimateTokenCostImpl<4, 2, 2>(values, len, out);
168
7.37k
      }
169
94.8k
    }
170
189k
  } else if (cfg.split_exponent == 5) {
171
51.5k
    if (cfg.msb_in_token == 1) {
172
22.1k
      if (cfg.lsb_in_token == 0) {
173
7.37k
        return EstimateTokenCostImpl<5, 1, 0>(values, len, out);
174
14.7k
      } else if (cfg.lsb_in_token == 2) {
175
7.37k
        return EstimateTokenCostImpl<5, 1, 2>(values, len, out);
176
7.37k
      } else {
177
7.36k
        JXL_DASSERT(cfg.lsb_in_token == 4);
178
7.36k
        return EstimateTokenCostImpl<5, 1, 4>(values, len, out);
179
7.36k
      }
180
29.4k
    } else {
181
29.4k
      JXL_DASSERT(cfg.msb_in_token == 2);
182
29.4k
      if (cfg.lsb_in_token == 0) {
183
7.37k
        return EstimateTokenCostImpl<5, 2, 0>(values, len, out);
184
22.1k
      } else if (cfg.lsb_in_token == 1) {
185
7.37k
        return EstimateTokenCostImpl<5, 2, 1>(values, len, out);
186
14.7k
      } else if (cfg.lsb_in_token == 2) {
187
7.37k
        return EstimateTokenCostImpl<5, 2, 2>(values, len, out);
188
7.37k
      } else {
189
7.36k
        JXL_DASSERT(cfg.lsb_in_token == 3);
190
7.36k
        return EstimateTokenCostImpl<5, 2, 3>(values, len, out);
191
7.36k
      }
192
29.4k
    }
193
55.5k
  } else if (cfg.split_exponent == 6) {
194
20.2k
    if (cfg.msb_in_token == 0) {
195
7.37k
      JXL_DASSERT(cfg.lsb_in_token == 0);
196
7.37k
      return EstimateTokenCostImpl<6, 0, 0>(values, len, out);
197
12.9k
    } else if (cfg.msb_in_token == 1) {
198
6.46k
      JXL_DASSERT(cfg.lsb_in_token == 5);
199
6.46k
      return EstimateTokenCostImpl<6, 1, 5>(values, len, out);
200
6.46k
    } else {
201
6.46k
      JXL_DASSERT(cfg.msb_in_token == 2);
202
6.46k
      JXL_DASSERT(cfg.lsb_in_token == 4);
203
6.46k
      return EstimateTokenCostImpl<6, 2, 4>(values, len, out);
204
6.46k
    }
205
35.2k
  } else if (cfg.split_exponent >= 7 && cfg.split_exponent <= 12) {
206
35.2k
    JXL_DASSERT(cfg.msb_in_token == 0);
207
35.2k
    JXL_DASSERT(cfg.lsb_in_token == 0);
208
35.2k
    if (cfg.split_exponent == 7) {
209
7.37k
      return EstimateTokenCostImpl<7, 0, 0>(values, len, out);
210
27.8k
    } else if (cfg.split_exponent == 8) {
211
5.56k
      return EstimateTokenCostImpl<8, 0, 0>(values, len, out);
212
22.2k
    } else if (cfg.split_exponent == 9) {
213
5.56k
      return EstimateTokenCostImpl<9, 0, 0>(values, len, out);
214
16.7k
    } else if (cfg.split_exponent == 10) {
215
5.56k
      return EstimateTokenCostImpl<10, 0, 0>(values, len, out);
216
11.1k
    } else if (cfg.split_exponent == 11) {
217
5.56k
      return EstimateTokenCostImpl<11, 0, 0>(values, len, out);
218
5.56k
    } else {
219
5.56k
      return EstimateTokenCostImpl<12, 0, 0>(values, len, out);
220
5.56k
    }
221
35.2k
  } else {
222
0
    JXL_DASSERT(false);
223
0
  }
224
0
  return ~0;
225
487k
#endif
226
487k
}
Unexecuted instantiation: jxl::N_SSE2::EstimateTokenCost(unsigned int*, unsigned long, jxl::HybridUintConfig, jxl::AlignedMemory&)
227
228
// NOLINTNEXTLINE(google-readability-namespace-comments)
229
}  // namespace HWY_NAMESPACE
230
}  // namespace jxl
231
HWY_AFTER_NAMESPACE();
232
233
#if HWY_ONCE
234
namespace jxl {
235
236
HWY_EXPORT(EstimateTokenCost);
237
238
uint32_t EstimateTokenCost(uint32_t* JXL_RESTRICT values, size_t len,
239
487k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
240
487k
  JXL_DASSERT(cfg.lsb_in_token + cfg.msb_in_token <= cfg.split_exponent);
241
487k
  return HWY_DYNAMIC_DISPATCH(EstimateTokenCost)(values, len, cfg, tokens);
242
487k
}
243
244
}  // namespace jxl
245
#endif