Coverage Report

Created: 2025-11-14 07:32

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/status.h"
11
#include "lib/jxl/dec_ans.h"
12
#include "lib/jxl/memory_manager_internal.h"
13
14
#undef HWY_TARGET_INCLUDE
15
#define HWY_TARGET_INCLUDE "lib/jxl/enc_ans_simd.cc"
16
#include <hwy/foreach_target.h>
17
#include <hwy/highway.h>
18
19
HWY_BEFORE_NAMESPACE();
20
namespace jxl {
21
namespace HWY_NAMESPACE {
22
23
// These templates are not found via ADL.
24
using hwy::HWY_NAMESPACE::Add;
25
using hwy::HWY_NAMESPACE::And;
26
using hwy::HWY_NAMESPACE::Ge;
27
using hwy::HWY_NAMESPACE::GetLane;
28
using hwy::HWY_NAMESPACE::Gt;
29
using hwy::HWY_NAMESPACE::IfThenElse;
30
using hwy::HWY_NAMESPACE::IfThenElseZero;
31
using hwy::HWY_NAMESPACE::Iota;
32
using hwy::HWY_NAMESPACE::LoadU;
33
using hwy::HWY_NAMESPACE::Lt;
34
using hwy::HWY_NAMESPACE::Mul;
35
using hwy::HWY_NAMESPACE::Or;
36
using hwy::HWY_NAMESPACE::Set;
37
using hwy::HWY_NAMESPACE::ShiftRight;
38
using hwy::HWY_NAMESPACE::Store;
39
using hwy::HWY_NAMESPACE::Sub;
40
using hwy::HWY_NAMESPACE::Zero;
41
42
template <size_t E, size_t M, size_t L>
43
uint32_t EstimateTokenCostImpl(uint32_t* JXL_RESTRICT values, size_t len,
44
523k
                               uint32_t* JXL_RESTRICT out) {
45
523k
  const HWY_FULL(uint32_t) du;
46
523k
  const HWY_FULL(float) df;
47
523k
  const auto kZero = Zero(du);
48
523k
  const auto kSplit = Set(du, 1 << E);
49
523k
  const auto kExpOffset = Set(du, 127);
50
523k
  const auto kEBOffset = Set(du, 127 + M + L);
51
523k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
523k
  const auto kMulN = Set(du, 1 << (M + L));
53
523k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
523k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
523k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
523k
  constexpr size_t kLargeShiftVal = 10;
57
523k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
523k
  auto extra_bits = kZero;
60
523k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
73.5M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
73.0M
    const auto val = LoadU(du, values + i);
63
73.0M
    const auto is_large = Gt(val, kLargeThreshold);
64
73.0M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
73.0M
    const auto not_literal = Ge(val, kSplit);
66
73.0M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
73.0M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
73.0M
    const auto l = And(val, kMaskL);
69
73.0M
    const auto exp = ShiftRight<23>(b);
70
73.0M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
73.0M
    const auto n = Sub(exp_fixed, kExpOffset);
72
73.0M
    const auto eb = Sub(exp_fixed, kEBOffset);
73
73.0M
    const auto m = ShiftRight<23 - M - L>(b);
74
73.0M
    const auto a = Add(kBase, Mul(n, kMulN));
75
73.0M
    const auto d = And(m, kMaskM);
76
73.0M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
73.0M
    const auto c = Or(a, l);
78
73.0M
    extra_bits = Add(extra_bits, eb_fixed);
79
73.0M
    const auto t = Or(c, d);
80
73.0M
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
73.0M
    Store(t_fixed, du, out + i);
82
73.0M
  }
83
523k
  if (last_full < len) {
84
449k
    const auto stop = Set(du, len);
85
449k
    const auto fence = Iota(du, last_full);
86
449k
    const auto take = Lt(fence, stop);
87
449k
    const auto val = LoadU(du, values + last_full);
88
449k
    const auto is_large = Gt(val, kLargeThreshold);
89
449k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
449k
    const auto not_literal = Ge(val, kSplit);
91
449k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
449k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
449k
    const auto l = And(val, kMaskL);
94
449k
    const auto exp = ShiftRight<23>(b);
95
449k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
449k
    const auto n = Sub(exp_fixed, kExpOffset);
97
449k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
449k
    const auto m = ShiftRight<23 - M - L>(b);
99
449k
    const auto a = Add(kBase, Mul(n, kMulN));
100
449k
    const auto d = And(m, kMaskM);
101
449k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
449k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
449k
    const auto c = Or(a, l);
104
449k
    extra_bits = Add(extra_bits, eb_masked);
105
449k
    const auto t = Or(c, d);
106
449k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
449k
    Store(t_fixed, du, out + last_full);
108
449k
  }
109
523k
  return GetLane(SumOfLanes(du, extra_bits));
110
523k
}
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
44
87.9k
                               uint32_t* JXL_RESTRICT out) {
45
87.9k
  const HWY_FULL(uint32_t) du;
46
87.9k
  const HWY_FULL(float) df;
47
87.9k
  const auto kZero = Zero(du);
48
87.9k
  const auto kSplit = Set(du, 1 << E);
49
87.9k
  const auto kExpOffset = Set(du, 127);
50
87.9k
  const auto kEBOffset = Set(du, 127 + M + L);
51
87.9k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
87.9k
  const auto kMulN = Set(du, 1 << (M + L));
53
87.9k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
87.9k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
87.9k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
87.9k
  constexpr size_t kLargeShiftVal = 10;
57
87.9k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
87.9k
  auto extra_bits = kZero;
60
87.9k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
14.2M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
14.1M
    const auto val = LoadU(du, values + i);
63
14.1M
    const auto is_large = Gt(val, kLargeThreshold);
64
14.1M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
14.1M
    const auto not_literal = Ge(val, kSplit);
66
14.1M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
14.1M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
14.1M
    const auto l = And(val, kMaskL);
69
14.1M
    const auto exp = ShiftRight<23>(b);
70
14.1M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
14.1M
    const auto n = Sub(exp_fixed, kExpOffset);
72
14.1M
    const auto eb = Sub(exp_fixed, kEBOffset);
73
14.1M
    const auto m = ShiftRight<23 - M - L>(b);
74
14.1M
    const auto a = Add(kBase, Mul(n, kMulN));
75
14.1M
    const auto d = And(m, kMaskM);
76
14.1M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
14.1M
    const auto c = Or(a, l);
78
14.1M
    extra_bits = Add(extra_bits, eb_fixed);
79
14.1M
    const auto t = Or(c, d);
80
14.1M
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
14.1M
    Store(t_fixed, du, out + i);
82
14.1M
  }
83
87.9k
  if (last_full < len) {
84
76.2k
    const auto stop = Set(du, len);
85
76.2k
    const auto fence = Iota(du, last_full);
86
76.2k
    const auto take = Lt(fence, stop);
87
76.2k
    const auto val = LoadU(du, values + last_full);
88
76.2k
    const auto is_large = Gt(val, kLargeThreshold);
89
76.2k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
76.2k
    const auto not_literal = Ge(val, kSplit);
91
76.2k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
76.2k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
76.2k
    const auto l = And(val, kMaskL);
94
76.2k
    const auto exp = ShiftRight<23>(b);
95
76.2k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
76.2k
    const auto n = Sub(exp_fixed, kExpOffset);
97
76.2k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
76.2k
    const auto m = ShiftRight<23 - M - L>(b);
99
76.2k
    const auto a = Add(kBase, Mul(n, kMulN));
100
76.2k
    const auto d = And(m, kMaskM);
101
76.2k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
76.2k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
76.2k
    const auto c = Or(a, l);
104
76.2k
    extra_bits = Add(extra_bits, eb_masked);
105
76.2k
    const auto t = Or(c, d);
106
76.2k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
76.2k
    Store(t_fixed, du, out + last_full);
108
76.2k
  }
109
87.9k
  return GetLane(SumOfLanes(du, extra_bits));
110
87.9k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<2ul, 0ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
87.2k
                               uint32_t* JXL_RESTRICT out) {
45
87.2k
  const HWY_FULL(uint32_t) du;
46
87.2k
  const HWY_FULL(float) df;
47
87.2k
  const auto kZero = Zero(du);
48
87.2k
  const auto kSplit = Set(du, 1 << E);
49
87.2k
  const auto kExpOffset = Set(du, 127);
50
87.2k
  const auto kEBOffset = Set(du, 127 + M + L);
51
87.2k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
87.2k
  const auto kMulN = Set(du, 1 << (M + L));
53
87.2k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
87.2k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
87.2k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
87.2k
  constexpr size_t kLargeShiftVal = 10;
57
87.2k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
87.2k
  auto extra_bits = kZero;
60
87.2k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
14.2M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
14.1M
    const auto val = LoadU(du, values + i);
63
14.1M
    const auto is_large = Gt(val, kLargeThreshold);
64
14.1M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
14.1M
    const auto not_literal = Ge(val, kSplit);
66
14.1M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
14.1M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
14.1M
    const auto l = And(val, kMaskL);
69
14.1M
    const auto exp = ShiftRight<23>(b);
70
14.1M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
14.1M
    const auto n = Sub(exp_fixed, kExpOffset);
72
14.1M
    const auto eb = Sub(exp_fixed, kEBOffset);
73
14.1M
    const auto m = ShiftRight<23 - M - L>(b);
74
14.1M
    const auto a = Add(kBase, Mul(n, kMulN));
75
14.1M
    const auto d = And(m, kMaskM);
76
14.1M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
14.1M
    const auto c = Or(a, l);
78
14.1M
    extra_bits = Add(extra_bits, eb_fixed);
79
14.1M
    const auto t = Or(c, d);
80
14.1M
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
14.1M
    Store(t_fixed, du, out + i);
82
14.1M
  }
83
87.2k
  if (last_full < len) {
84
75.6k
    const auto stop = Set(du, len);
85
75.6k
    const auto fence = Iota(du, last_full);
86
75.6k
    const auto take = Lt(fence, stop);
87
75.6k
    const auto val = LoadU(du, values + last_full);
88
75.6k
    const auto is_large = Gt(val, kLargeThreshold);
89
75.6k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
75.6k
    const auto not_literal = Ge(val, kSplit);
91
75.6k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
75.6k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
75.6k
    const auto l = And(val, kMaskL);
94
75.6k
    const auto exp = ShiftRight<23>(b);
95
75.6k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
75.6k
    const auto n = Sub(exp_fixed, kExpOffset);
97
75.6k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
75.6k
    const auto m = ShiftRight<23 - M - L>(b);
99
75.6k
    const auto a = Add(kBase, Mul(n, kMulN));
100
75.6k
    const auto d = And(m, kMaskM);
101
75.6k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
75.6k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
75.6k
    const auto c = Or(a, l);
104
75.6k
    extra_bits = Add(extra_bits, eb_masked);
105
75.6k
    const auto t = Or(c, d);
106
75.6k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
75.6k
    Store(t_fixed, du, out + last_full);
108
75.6k
  }
109
87.2k
  return GetLane(SumOfLanes(du, extra_bits));
110
87.2k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
87.1k
                               uint32_t* JXL_RESTRICT out) {
45
87.1k
  const HWY_FULL(uint32_t) du;
46
87.1k
  const HWY_FULL(float) df;
47
87.1k
  const auto kZero = Zero(du);
48
87.1k
  const auto kSplit = Set(du, 1 << E);
49
87.1k
  const auto kExpOffset = Set(du, 127);
50
87.1k
  const auto kEBOffset = Set(du, 127 + M + L);
51
87.1k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
87.1k
  const auto kMulN = Set(du, 1 << (M + L));
53
87.1k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
87.1k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
87.1k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
87.1k
  constexpr size_t kLargeShiftVal = 10;
57
87.1k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
87.1k
  auto extra_bits = kZero;
60
87.1k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
14.2M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
14.1M
    const auto val = LoadU(du, values + i);
63
14.1M
    const auto is_large = Gt(val, kLargeThreshold);
64
14.1M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
14.1M
    const auto not_literal = Ge(val, kSplit);
66
14.1M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
14.1M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
14.1M
    const auto l = And(val, kMaskL);
69
14.1M
    const auto exp = ShiftRight<23>(b);
70
14.1M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
14.1M
    const auto n = Sub(exp_fixed, kExpOffset);
72
14.1M
    const auto eb = Sub(exp_fixed, kEBOffset);
73
14.1M
    const auto m = ShiftRight<23 - M - L>(b);
74
14.1M
    const auto a = Add(kBase, Mul(n, kMulN));
75
14.1M
    const auto d = And(m, kMaskM);
76
14.1M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
14.1M
    const auto c = Or(a, l);
78
14.1M
    extra_bits = Add(extra_bits, eb_fixed);
79
14.1M
    const auto t = Or(c, d);
80
14.1M
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
14.1M
    Store(t_fixed, du, out + i);
82
14.1M
  }
83
87.1k
  if (last_full < len) {
84
75.5k
    const auto stop = Set(du, len);
85
75.5k
    const auto fence = Iota(du, last_full);
86
75.5k
    const auto take = Lt(fence, stop);
87
75.5k
    const auto val = LoadU(du, values + last_full);
88
75.5k
    const auto is_large = Gt(val, kLargeThreshold);
89
75.5k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
75.5k
    const auto not_literal = Ge(val, kSplit);
91
75.5k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
75.5k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
75.5k
    const auto l = And(val, kMaskL);
94
75.5k
    const auto exp = ShiftRight<23>(b);
95
75.5k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
75.5k
    const auto n = Sub(exp_fixed, kExpOffset);
97
75.5k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
75.5k
    const auto m = ShiftRight<23 - M - L>(b);
99
75.5k
    const auto a = Add(kBase, Mul(n, kMulN));
100
75.5k
    const auto d = And(m, kMaskM);
101
75.5k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
75.5k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
75.5k
    const auto c = Or(a, l);
104
75.5k
    extra_bits = Add(extra_bits, eb_masked);
105
75.5k
    const auto t = Or(c, d);
106
75.5k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
75.5k
    Store(t_fixed, du, out + last_full);
108
75.5k
  }
109
87.1k
  return GetLane(SumOfLanes(du, extra_bits));
110
87.1k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
87.2k
                               uint32_t* JXL_RESTRICT out) {
45
87.2k
  const HWY_FULL(uint32_t) du;
46
87.2k
  const HWY_FULL(float) df;
47
87.2k
  const auto kZero = Zero(du);
48
87.2k
  const auto kSplit = Set(du, 1 << E);
49
87.2k
  const auto kExpOffset = Set(du, 127);
50
87.2k
  const auto kEBOffset = Set(du, 127 + M + L);
51
87.2k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
87.2k
  const auto kMulN = Set(du, 1 << (M + L));
53
87.2k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
87.2k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
87.2k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
87.2k
  constexpr size_t kLargeShiftVal = 10;
57
87.2k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
87.2k
  auto extra_bits = kZero;
60
87.2k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
14.2M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
14.1M
    const auto val = LoadU(du, values + i);
63
14.1M
    const auto is_large = Gt(val, kLargeThreshold);
64
14.1M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
14.1M
    const auto not_literal = Ge(val, kSplit);
66
14.1M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
14.1M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
14.1M
    const auto l = And(val, kMaskL);
69
14.1M
    const auto exp = ShiftRight<23>(b);
70
14.1M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
14.1M
    const auto n = Sub(exp_fixed, kExpOffset);
72
14.1M
    const auto eb = Sub(exp_fixed, kEBOffset);
73
14.1M
    const auto m = ShiftRight<23 - M - L>(b);
74
14.1M
    const auto a = Add(kBase, Mul(n, kMulN));
75
14.1M
    const auto d = And(m, kMaskM);
76
14.1M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
14.1M
    const auto c = Or(a, l);
78
14.1M
    extra_bits = Add(extra_bits, eb_fixed);
79
14.1M
    const auto t = Or(c, d);
80
14.1M
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
14.1M
    Store(t_fixed, du, out + i);
82
14.1M
  }
83
87.2k
  if (last_full < len) {
84
75.6k
    const auto stop = Set(du, len);
85
75.6k
    const auto fence = Iota(du, last_full);
86
75.6k
    const auto take = Lt(fence, stop);
87
75.6k
    const auto val = LoadU(du, values + last_full);
88
75.6k
    const auto is_large = Gt(val, kLargeThreshold);
89
75.6k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
75.6k
    const auto not_literal = Ge(val, kSplit);
91
75.6k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
75.6k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
75.6k
    const auto l = And(val, kMaskL);
94
75.6k
    const auto exp = ShiftRight<23>(b);
95
75.6k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
75.6k
    const auto n = Sub(exp_fixed, kExpOffset);
97
75.6k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
75.6k
    const auto m = ShiftRight<23 - M - L>(b);
99
75.6k
    const auto a = Add(kBase, Mul(n, kMulN));
100
75.6k
    const auto d = And(m, kMaskM);
101
75.6k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
75.6k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
75.6k
    const auto c = Or(a, l);
104
75.6k
    extra_bits = Add(extra_bits, eb_masked);
105
75.6k
    const auto t = Or(c, d);
106
75.6k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
75.6k
    Store(t_fixed, du, out + last_full);
108
75.6k
  }
109
87.2k
  return GetLane(SumOfLanes(du, extra_bits));
110
87.2k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.75k
                               uint32_t* JXL_RESTRICT out) {
45
7.75k
  const HWY_FULL(uint32_t) du;
46
7.75k
  const HWY_FULL(float) df;
47
7.75k
  const auto kZero = Zero(du);
48
7.75k
  const auto kSplit = Set(du, 1 << E);
49
7.75k
  const auto kExpOffset = Set(du, 127);
50
7.75k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.75k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.75k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.75k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.75k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.75k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.75k
  constexpr size_t kLargeShiftVal = 10;
57
7.75k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.75k
  auto extra_bits = kZero;
60
7.75k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.75k
  if (last_full < len) {
84
6.55k
    const auto stop = Set(du, len);
85
6.55k
    const auto fence = Iota(du, last_full);
86
6.55k
    const auto take = Lt(fence, stop);
87
6.55k
    const auto val = LoadU(du, values + last_full);
88
6.55k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.55k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.55k
    const auto not_literal = Ge(val, kSplit);
91
6.55k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.55k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.55k
    const auto l = And(val, kMaskL);
94
6.55k
    const auto exp = ShiftRight<23>(b);
95
6.55k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.55k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.55k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.55k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.55k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.55k
    const auto d = And(m, kMaskM);
101
6.55k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.55k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.55k
    const auto c = Or(a, l);
104
6.55k
    extra_bits = Add(extra_bits, eb_masked);
105
6.55k
    const auto t = Or(c, d);
106
6.55k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.55k
    Store(t_fixed, du, out + last_full);
108
6.55k
  }
109
7.75k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.75k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.75k
                               uint32_t* JXL_RESTRICT out) {
45
7.75k
  const HWY_FULL(uint32_t) du;
46
7.75k
  const HWY_FULL(float) df;
47
7.75k
  const auto kZero = Zero(du);
48
7.75k
  const auto kSplit = Set(du, 1 << E);
49
7.75k
  const auto kExpOffset = Set(du, 127);
50
7.75k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.75k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.75k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.75k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.75k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.75k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.75k
  constexpr size_t kLargeShiftVal = 10;
57
7.75k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.75k
  auto extra_bits = kZero;
60
7.75k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.75k
  if (last_full < len) {
84
6.55k
    const auto stop = Set(du, len);
85
6.55k
    const auto fence = Iota(du, last_full);
86
6.55k
    const auto take = Lt(fence, stop);
87
6.55k
    const auto val = LoadU(du, values + last_full);
88
6.55k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.55k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.55k
    const auto not_literal = Ge(val, kSplit);
91
6.55k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.55k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.55k
    const auto l = And(val, kMaskL);
94
6.55k
    const auto exp = ShiftRight<23>(b);
95
6.55k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.55k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.55k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.55k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.55k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.55k
    const auto d = And(m, kMaskM);
101
6.55k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.55k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.55k
    const auto c = Or(a, l);
104
6.55k
    extra_bits = Add(extra_bits, eb_masked);
105
6.55k
    const auto t = Or(c, d);
106
6.55k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.55k
    Store(t_fixed, du, out + last_full);
108
6.55k
  }
109
7.75k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.75k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 1ul, 5ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.62k
                               uint32_t* JXL_RESTRICT out) {
45
6.62k
  const HWY_FULL(uint32_t) du;
46
6.62k
  const HWY_FULL(float) df;
47
6.62k
  const auto kZero = Zero(du);
48
6.62k
  const auto kSplit = Set(du, 1 << E);
49
6.62k
  const auto kExpOffset = Set(du, 127);
50
6.62k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.62k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.62k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.62k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.62k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.62k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.62k
  constexpr size_t kLargeShiftVal = 10;
57
6.62k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.62k
  auto extra_bits = kZero;
60
6.62k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
413k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
406k
    const auto val = LoadU(du, values + i);
63
406k
    const auto is_large = Gt(val, kLargeThreshold);
64
406k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
406k
    const auto not_literal = Ge(val, kSplit);
66
406k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
406k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
406k
    const auto l = And(val, kMaskL);
69
406k
    const auto exp = ShiftRight<23>(b);
70
406k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
406k
    const auto n = Sub(exp_fixed, kExpOffset);
72
406k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
406k
    const auto m = ShiftRight<23 - M - L>(b);
74
406k
    const auto a = Add(kBase, Mul(n, kMulN));
75
406k
    const auto d = And(m, kMaskM);
76
406k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
406k
    const auto c = Or(a, l);
78
406k
    extra_bits = Add(extra_bits, eb_fixed);
79
406k
    const auto t = Or(c, d);
80
406k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
406k
    Store(t_fixed, du, out + i);
82
406k
  }
83
6.62k
  if (last_full < len) {
84
5.61k
    const auto stop = Set(du, len);
85
5.61k
    const auto fence = Iota(du, last_full);
86
5.61k
    const auto take = Lt(fence, stop);
87
5.61k
    const auto val = LoadU(du, values + last_full);
88
5.61k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.61k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.61k
    const auto not_literal = Ge(val, kSplit);
91
5.61k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.61k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.61k
    const auto l = And(val, kMaskL);
94
5.61k
    const auto exp = ShiftRight<23>(b);
95
5.61k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.61k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.61k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.61k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.61k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.61k
    const auto d = And(m, kMaskM);
101
5.61k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.61k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.61k
    const auto c = Or(a, l);
104
5.61k
    extra_bits = Add(extra_bits, eb_masked);
105
5.61k
    const auto t = Or(c, d);
106
5.61k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.61k
    Store(t_fixed, du, out + last_full);
108
5.61k
  }
109
6.62k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.62k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 2ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.62k
                               uint32_t* JXL_RESTRICT out) {
45
6.62k
  const HWY_FULL(uint32_t) du;
46
6.62k
  const HWY_FULL(float) df;
47
6.62k
  const auto kZero = Zero(du);
48
6.62k
  const auto kSplit = Set(du, 1 << E);
49
6.62k
  const auto kExpOffset = Set(du, 127);
50
6.62k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.62k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.62k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.62k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.62k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.62k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.62k
  constexpr size_t kLargeShiftVal = 10;
57
6.62k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.62k
  auto extra_bits = kZero;
60
6.62k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
413k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
406k
    const auto val = LoadU(du, values + i);
63
406k
    const auto is_large = Gt(val, kLargeThreshold);
64
406k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
406k
    const auto not_literal = Ge(val, kSplit);
66
406k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
406k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
406k
    const auto l = And(val, kMaskL);
69
406k
    const auto exp = ShiftRight<23>(b);
70
406k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
406k
    const auto n = Sub(exp_fixed, kExpOffset);
72
406k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
406k
    const auto m = ShiftRight<23 - M - L>(b);
74
406k
    const auto a = Add(kBase, Mul(n, kMulN));
75
406k
    const auto d = And(m, kMaskM);
76
406k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
406k
    const auto c = Or(a, l);
78
406k
    extra_bits = Add(extra_bits, eb_fixed);
79
406k
    const auto t = Or(c, d);
80
406k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
406k
    Store(t_fixed, du, out + i);
82
406k
  }
83
6.62k
  if (last_full < len) {
84
5.61k
    const auto stop = Set(du, len);
85
5.61k
    const auto fence = Iota(du, last_full);
86
5.61k
    const auto take = Lt(fence, stop);
87
5.61k
    const auto val = LoadU(du, values + last_full);
88
5.61k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.61k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.61k
    const auto not_literal = Ge(val, kSplit);
91
5.61k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.61k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.61k
    const auto l = And(val, kMaskL);
94
5.61k
    const auto exp = ShiftRight<23>(b);
95
5.61k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.61k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.61k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.61k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.61k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.61k
    const auto d = And(m, kMaskM);
101
5.61k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.61k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.61k
    const auto c = Or(a, l);
104
5.61k
    extra_bits = Add(extra_bits, eb_masked);
105
5.61k
    const auto t = Or(c, d);
106
5.61k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.61k
    Store(t_fixed, du, out + last_full);
108
5.61k
  }
109
6.62k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.62k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<7ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
7.76k
                               uint32_t* JXL_RESTRICT out) {
45
7.76k
  const HWY_FULL(uint32_t) du;
46
7.76k
  const HWY_FULL(float) df;
47
7.76k
  const auto kZero = Zero(du);
48
7.76k
  const auto kSplit = Set(du, 1 << E);
49
7.76k
  const auto kExpOffset = Set(du, 127);
50
7.76k
  const auto kEBOffset = Set(du, 127 + M + L);
51
7.76k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
7.76k
  const auto kMulN = Set(du, 1 << (M + L));
53
7.76k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
7.76k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
7.76k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
7.76k
  constexpr size_t kLargeShiftVal = 10;
57
7.76k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
7.76k
  auto extra_bits = kZero;
60
7.76k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
814k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
806k
    const auto val = LoadU(du, values + i);
63
806k
    const auto is_large = Gt(val, kLargeThreshold);
64
806k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
806k
    const auto not_literal = Ge(val, kSplit);
66
806k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
806k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
806k
    const auto l = And(val, kMaskL);
69
806k
    const auto exp = ShiftRight<23>(b);
70
806k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
806k
    const auto n = Sub(exp_fixed, kExpOffset);
72
806k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
806k
    const auto m = ShiftRight<23 - M - L>(b);
74
806k
    const auto a = Add(kBase, Mul(n, kMulN));
75
806k
    const auto d = And(m, kMaskM);
76
806k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
806k
    const auto c = Or(a, l);
78
806k
    extra_bits = Add(extra_bits, eb_fixed);
79
806k
    const auto t = Or(c, d);
80
806k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
806k
    Store(t_fixed, du, out + i);
82
806k
  }
83
7.76k
  if (last_full < len) {
84
6.56k
    const auto stop = Set(du, len);
85
6.56k
    const auto fence = Iota(du, last_full);
86
6.56k
    const auto take = Lt(fence, stop);
87
6.56k
    const auto val = LoadU(du, values + last_full);
88
6.56k
    const auto is_large = Gt(val, kLargeThreshold);
89
6.56k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
6.56k
    const auto not_literal = Ge(val, kSplit);
91
6.56k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
6.56k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
6.56k
    const auto l = And(val, kMaskL);
94
6.56k
    const auto exp = ShiftRight<23>(b);
95
6.56k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
6.56k
    const auto n = Sub(exp_fixed, kExpOffset);
97
6.56k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
6.56k
    const auto m = ShiftRight<23 - M - L>(b);
99
6.56k
    const auto a = Add(kBase, Mul(n, kMulN));
100
6.56k
    const auto d = And(m, kMaskM);
101
6.56k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
6.56k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
6.56k
    const auto c = Or(a, l);
104
6.56k
    extra_bits = Add(extra_bits, eb_masked);
105
6.56k
    const auto t = Or(c, d);
106
6.56k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
6.56k
    Store(t_fixed, du, out + last_full);
108
6.56k
  }
109
7.76k
  return GetLane(SumOfLanes(du, extra_bits));
110
7.76k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<8ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.70k
                               uint32_t* JXL_RESTRICT out) {
45
5.70k
  const HWY_FULL(uint32_t) du;
46
5.70k
  const HWY_FULL(float) df;
47
5.70k
  const auto kZero = Zero(du);
48
5.70k
  const auto kSplit = Set(du, 1 << E);
49
5.70k
  const auto kExpOffset = Set(du, 127);
50
5.70k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.70k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.70k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.70k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.70k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.70k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.70k
  constexpr size_t kLargeShiftVal = 10;
57
5.70k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.70k
  auto extra_bits = kZero;
60
5.70k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
375k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
370k
    const auto val = LoadU(du, values + i);
63
370k
    const auto is_large = Gt(val, kLargeThreshold);
64
370k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
370k
    const auto not_literal = Ge(val, kSplit);
66
370k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
370k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
370k
    const auto l = And(val, kMaskL);
69
370k
    const auto exp = ShiftRight<23>(b);
70
370k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
370k
    const auto n = Sub(exp_fixed, kExpOffset);
72
370k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
370k
    const auto m = ShiftRight<23 - M - L>(b);
74
370k
    const auto a = Add(kBase, Mul(n, kMulN));
75
370k
    const auto d = And(m, kMaskM);
76
370k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
370k
    const auto c = Or(a, l);
78
370k
    extra_bits = Add(extra_bits, eb_fixed);
79
370k
    const auto t = Or(c, d);
80
370k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
370k
    Store(t_fixed, du, out + i);
82
370k
  }
83
5.70k
  if (last_full < len) {
84
4.77k
    const auto stop = Set(du, len);
85
4.77k
    const auto fence = Iota(du, last_full);
86
4.77k
    const auto take = Lt(fence, stop);
87
4.77k
    const auto val = LoadU(du, values + last_full);
88
4.77k
    const auto is_large = Gt(val, kLargeThreshold);
89
4.77k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
4.77k
    const auto not_literal = Ge(val, kSplit);
91
4.77k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
4.77k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
4.77k
    const auto l = And(val, kMaskL);
94
4.77k
    const auto exp = ShiftRight<23>(b);
95
4.77k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
4.77k
    const auto n = Sub(exp_fixed, kExpOffset);
97
4.77k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
4.77k
    const auto m = ShiftRight<23 - M - L>(b);
99
4.77k
    const auto a = Add(kBase, Mul(n, kMulN));
100
4.77k
    const auto d = And(m, kMaskM);
101
4.77k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
4.77k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
4.77k
    const auto c = Or(a, l);
104
4.77k
    extra_bits = Add(extra_bits, eb_masked);
105
4.77k
    const auto t = Or(c, d);
106
4.77k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
4.77k
    Store(t_fixed, du, out + last_full);
108
4.77k
  }
109
5.70k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.70k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<9ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.70k
                               uint32_t* JXL_RESTRICT out) {
45
5.70k
  const HWY_FULL(uint32_t) du;
46
5.70k
  const HWY_FULL(float) df;
47
5.70k
  const auto kZero = Zero(du);
48
5.70k
  const auto kSplit = Set(du, 1 << E);
49
5.70k
  const auto kExpOffset = Set(du, 127);
50
5.70k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.70k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.70k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.70k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.70k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.70k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.70k
  constexpr size_t kLargeShiftVal = 10;
57
5.70k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.70k
  auto extra_bits = kZero;
60
5.70k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
375k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
370k
    const auto val = LoadU(du, values + i);
63
370k
    const auto is_large = Gt(val, kLargeThreshold);
64
370k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
370k
    const auto not_literal = Ge(val, kSplit);
66
370k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
370k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
370k
    const auto l = And(val, kMaskL);
69
370k
    const auto exp = ShiftRight<23>(b);
70
370k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
370k
    const auto n = Sub(exp_fixed, kExpOffset);
72
370k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
370k
    const auto m = ShiftRight<23 - M - L>(b);
74
370k
    const auto a = Add(kBase, Mul(n, kMulN));
75
370k
    const auto d = And(m, kMaskM);
76
370k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
370k
    const auto c = Or(a, l);
78
370k
    extra_bits = Add(extra_bits, eb_fixed);
79
370k
    const auto t = Or(c, d);
80
370k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
370k
    Store(t_fixed, du, out + i);
82
370k
  }
83
5.70k
  if (last_full < len) {
84
4.77k
    const auto stop = Set(du, len);
85
4.77k
    const auto fence = Iota(du, last_full);
86
4.77k
    const auto take = Lt(fence, stop);
87
4.77k
    const auto val = LoadU(du, values + last_full);
88
4.77k
    const auto is_large = Gt(val, kLargeThreshold);
89
4.77k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
4.77k
    const auto not_literal = Ge(val, kSplit);
91
4.77k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
4.77k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
4.77k
    const auto l = And(val, kMaskL);
94
4.77k
    const auto exp = ShiftRight<23>(b);
95
4.77k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
4.77k
    const auto n = Sub(exp_fixed, kExpOffset);
97
4.77k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
4.77k
    const auto m = ShiftRight<23 - M - L>(b);
99
4.77k
    const auto a = Add(kBase, Mul(n, kMulN));
100
4.77k
    const auto d = And(m, kMaskM);
101
4.77k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
4.77k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
4.77k
    const auto c = Or(a, l);
104
4.77k
    extra_bits = Add(extra_bits, eb_masked);
105
4.77k
    const auto t = Or(c, d);
106
4.77k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
4.77k
    Store(t_fixed, du, out + last_full);
108
4.77k
  }
109
5.70k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.70k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<10ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.70k
                               uint32_t* JXL_RESTRICT out) {
45
5.70k
  const HWY_FULL(uint32_t) du;
46
5.70k
  const HWY_FULL(float) df;
47
5.70k
  const auto kZero = Zero(du);
48
5.70k
  const auto kSplit = Set(du, 1 << E);
49
5.70k
  const auto kExpOffset = Set(du, 127);
50
5.70k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.70k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.70k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.70k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.70k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.70k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.70k
  constexpr size_t kLargeShiftVal = 10;
57
5.70k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.70k
  auto extra_bits = kZero;
60
5.70k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
375k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
370k
    const auto val = LoadU(du, values + i);
63
370k
    const auto is_large = Gt(val, kLargeThreshold);
64
370k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
370k
    const auto not_literal = Ge(val, kSplit);
66
370k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
370k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
370k
    const auto l = And(val, kMaskL);
69
370k
    const auto exp = ShiftRight<23>(b);
70
370k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
370k
    const auto n = Sub(exp_fixed, kExpOffset);
72
370k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
370k
    const auto m = ShiftRight<23 - M - L>(b);
74
370k
    const auto a = Add(kBase, Mul(n, kMulN));
75
370k
    const auto d = And(m, kMaskM);
76
370k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
370k
    const auto c = Or(a, l);
78
370k
    extra_bits = Add(extra_bits, eb_fixed);
79
370k
    const auto t = Or(c, d);
80
370k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
370k
    Store(t_fixed, du, out + i);
82
370k
  }
83
5.70k
  if (last_full < len) {
84
4.77k
    const auto stop = Set(du, len);
85
4.77k
    const auto fence = Iota(du, last_full);
86
4.77k
    const auto take = Lt(fence, stop);
87
4.77k
    const auto val = LoadU(du, values + last_full);
88
4.77k
    const auto is_large = Gt(val, kLargeThreshold);
89
4.77k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
4.77k
    const auto not_literal = Ge(val, kSplit);
91
4.77k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
4.77k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
4.77k
    const auto l = And(val, kMaskL);
94
4.77k
    const auto exp = ShiftRight<23>(b);
95
4.77k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
4.77k
    const auto n = Sub(exp_fixed, kExpOffset);
97
4.77k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
4.77k
    const auto m = ShiftRight<23 - M - L>(b);
99
4.77k
    const auto a = Add(kBase, Mul(n, kMulN));
100
4.77k
    const auto d = And(m, kMaskM);
101
4.77k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
4.77k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
4.77k
    const auto c = Or(a, l);
104
4.77k
    extra_bits = Add(extra_bits, eb_masked);
105
4.77k
    const auto t = Or(c, d);
106
4.77k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
4.77k
    Store(t_fixed, du, out + last_full);
108
4.77k
  }
109
5.70k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.70k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<11ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.70k
                               uint32_t* JXL_RESTRICT out) {
45
5.70k
  const HWY_FULL(uint32_t) du;
46
5.70k
  const HWY_FULL(float) df;
47
5.70k
  const auto kZero = Zero(du);
48
5.70k
  const auto kSplit = Set(du, 1 << E);
49
5.70k
  const auto kExpOffset = Set(du, 127);
50
5.70k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.70k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.70k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.70k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.70k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.70k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.70k
  constexpr size_t kLargeShiftVal = 10;
57
5.70k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.70k
  auto extra_bits = kZero;
60
5.70k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
375k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
370k
    const auto val = LoadU(du, values + i);
63
370k
    const auto is_large = Gt(val, kLargeThreshold);
64
370k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
370k
    const auto not_literal = Ge(val, kSplit);
66
370k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
370k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
370k
    const auto l = And(val, kMaskL);
69
370k
    const auto exp = ShiftRight<23>(b);
70
370k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
370k
    const auto n = Sub(exp_fixed, kExpOffset);
72
370k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
370k
    const auto m = ShiftRight<23 - M - L>(b);
74
370k
    const auto a = Add(kBase, Mul(n, kMulN));
75
370k
    const auto d = And(m, kMaskM);
76
370k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
370k
    const auto c = Or(a, l);
78
370k
    extra_bits = Add(extra_bits, eb_fixed);
79
370k
    const auto t = Or(c, d);
80
370k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
370k
    Store(t_fixed, du, out + i);
82
370k
  }
83
5.70k
  if (last_full < len) {
84
4.77k
    const auto stop = Set(du, len);
85
4.77k
    const auto fence = Iota(du, last_full);
86
4.77k
    const auto take = Lt(fence, stop);
87
4.77k
    const auto val = LoadU(du, values + last_full);
88
4.77k
    const auto is_large = Gt(val, kLargeThreshold);
89
4.77k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
4.77k
    const auto not_literal = Ge(val, kSplit);
91
4.77k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
4.77k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
4.77k
    const auto l = And(val, kMaskL);
94
4.77k
    const auto exp = ShiftRight<23>(b);
95
4.77k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
4.77k
    const auto n = Sub(exp_fixed, kExpOffset);
97
4.77k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
4.77k
    const auto m = ShiftRight<23 - M - L>(b);
99
4.77k
    const auto a = Add(kBase, Mul(n, kMulN));
100
4.77k
    const auto d = And(m, kMaskM);
101
4.77k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
4.77k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
4.77k
    const auto c = Or(a, l);
104
4.77k
    extra_bits = Add(extra_bits, eb_masked);
105
4.77k
    const auto t = Or(c, d);
106
4.77k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
4.77k
    Store(t_fixed, du, out + last_full);
108
4.77k
  }
109
5.70k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.70k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<12ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.70k
                               uint32_t* JXL_RESTRICT out) {
45
5.70k
  const HWY_FULL(uint32_t) du;
46
5.70k
  const HWY_FULL(float) df;
47
5.70k
  const auto kZero = Zero(du);
48
5.70k
  const auto kSplit = Set(du, 1 << E);
49
5.70k
  const auto kExpOffset = Set(du, 127);
50
5.70k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.70k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.70k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.70k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.70k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.70k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.70k
  constexpr size_t kLargeShiftVal = 10;
57
5.70k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.70k
  auto extra_bits = kZero;
60
5.70k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
375k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
370k
    const auto val = LoadU(du, values + i);
63
370k
    const auto is_large = Gt(val, kLargeThreshold);
64
370k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
370k
    const auto not_literal = Ge(val, kSplit);
66
370k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
370k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
370k
    const auto l = And(val, kMaskL);
69
370k
    const auto exp = ShiftRight<23>(b);
70
370k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
370k
    const auto n = Sub(exp_fixed, kExpOffset);
72
370k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
370k
    const auto m = ShiftRight<23 - M - L>(b);
74
370k
    const auto a = Add(kBase, Mul(n, kMulN));
75
370k
    const auto d = And(m, kMaskM);
76
370k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
370k
    const auto c = Or(a, l);
78
370k
    extra_bits = Add(extra_bits, eb_fixed);
79
370k
    const auto t = Or(c, d);
80
370k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
370k
    Store(t_fixed, du, out + i);
82
370k
  }
83
5.70k
  if (last_full < len) {
84
4.77k
    const auto stop = Set(du, len);
85
4.77k
    const auto fence = Iota(du, last_full);
86
4.77k
    const auto take = Lt(fence, stop);
87
4.77k
    const auto val = LoadU(du, values + last_full);
88
4.77k
    const auto is_large = Gt(val, kLargeThreshold);
89
4.77k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
4.77k
    const auto not_literal = Ge(val, kSplit);
91
4.77k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
4.77k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
4.77k
    const auto l = And(val, kMaskL);
94
4.77k
    const auto exp = ShiftRight<23>(b);
95
4.77k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
4.77k
    const auto n = Sub(exp_fixed, kExpOffset);
97
4.77k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
4.77k
    const auto m = ShiftRight<23 - M - L>(b);
99
4.77k
    const auto a = Add(kBase, Mul(n, kMulN));
100
4.77k
    const auto d = And(m, kMaskM);
101
4.77k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
4.77k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
4.77k
    const auto c = Or(a, l);
104
4.77k
    extra_bits = Add(extra_bits, eb_masked);
105
4.77k
    const auto t = Or(c, d);
106
4.77k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
4.77k
    Store(t_fixed, du, out + last_full);
108
4.77k
  }
109
5.70k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.70k
}
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*)
111
112
uint32_t EstimateTokenCost(uint32_t* JXL_RESTRICT values, size_t len,
113
523k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
114
523k
  uint32_t* JXL_RESTRICT out = tokens.address<uint32_t>();
115
#if HWY_TARGET == HWY_SCALAR
116
  uint32_t extra_bits = 0;
117
  for (size_t i = 0; i < len; ++i) {
118
    uint32_t v = values[i];
119
    uint32_t tok, nbits, bits;
120
    cfg.Encode(v, &tok, &nbits, &bits);
121
    extra_bits += nbits;
122
    out[i] = tok;
123
  }
124
  return extra_bits;
125
#else
126
523k
  if (cfg.split_exponent == 0) {
127
87.9k
    return EstimateTokenCostImpl<0, 0, 0>(values, len, out);
128
435k
  } else if (cfg.split_exponent == 2) {
129
87.2k
    JXL_DASSERT((cfg.msb_in_token == 0) && (cfg.lsb_in_token == 1));
130
87.2k
    return EstimateTokenCostImpl<2, 0, 1>(values, len, out);
131
348k
  } else if (cfg.split_exponent == 3) {
132
31.0k
    if (cfg.msb_in_token == 1) {
133
15.5k
      if (cfg.lsb_in_token == 0) {
134
7.76k
        return EstimateTokenCostImpl<3, 1, 0>(values, len, out);
135
7.76k
      } else {
136
7.76k
        JXL_DASSERT(cfg.lsb_in_token == 2);
137
7.76k
        return EstimateTokenCostImpl<3, 1, 2>(values, len, out);
138
7.76k
      }
139
15.5k
    } else {
140
15.5k
      JXL_DASSERT(cfg.msb_in_token == 2);
141
15.5k
      if (cfg.lsb_in_token == 0) {
142
7.76k
        return EstimateTokenCostImpl<3, 2, 0>(values, len, out);
143
7.76k
      } else {
144
7.76k
        JXL_DASSERT(cfg.lsb_in_token == 1);
145
7.76k
        return EstimateTokenCostImpl<3, 2, 1>(values, len, out);
146
7.76k
      }
147
15.5k
    }
148
317k
  } else if (cfg.split_exponent == 4) {
149
205k
    if (cfg.msb_in_token == 1) {
150
102k
      if (cfg.lsb_in_token == 0) {
151
7.76k
        return EstimateTokenCostImpl<4, 1, 0>(values, len, out);
152
94.9k
      } else if (cfg.lsb_in_token == 2) {
153
87.1k
        return EstimateTokenCostImpl<4, 1, 2>(values, len, out);
154
87.1k
      } else {
155
7.76k
        JXL_DASSERT(cfg.lsb_in_token == 3);
156
7.76k
        return EstimateTokenCostImpl<4, 1, 3>(values, len, out);
157
7.76k
      }
158
102k
    } else {
159
102k
      JXL_DASSERT(cfg.msb_in_token == 2);
160
102k
      if (cfg.lsb_in_token == 0) {
161
87.2k
        return EstimateTokenCostImpl<4, 2, 0>(values, len, out);
162
87.2k
      } else if (cfg.lsb_in_token == 1) {
163
7.76k
        return EstimateTokenCostImpl<4, 2, 1>(values, len, out);
164
7.76k
      } else {
165
7.76k
        JXL_DASSERT(cfg.lsb_in_token == 2);
166
7.76k
        return EstimateTokenCostImpl<4, 2, 2>(values, len, out);
167
7.76k
      }
168
102k
    }
169
205k
  } else if (cfg.split_exponent == 5) {
170
54.3k
    if (cfg.msb_in_token == 1) {
171
23.2k
      if (cfg.lsb_in_token == 0) {
172
7.76k
        return EstimateTokenCostImpl<5, 1, 0>(values, len, out);
173
15.5k
      } else if (cfg.lsb_in_token == 2) {
174
7.76k
        return EstimateTokenCostImpl<5, 1, 2>(values, len, out);
175
7.76k
      } else {
176
7.75k
        JXL_DASSERT(cfg.lsb_in_token == 4);
177
7.75k
        return EstimateTokenCostImpl<5, 1, 4>(values, len, out);
178
7.75k
      }
179
31.0k
    } else {
180
31.0k
      JXL_DASSERT(cfg.msb_in_token == 2);
181
31.0k
      if (cfg.lsb_in_token == 0) {
182
7.76k
        return EstimateTokenCostImpl<5, 2, 0>(values, len, out);
183
23.2k
      } else if (cfg.lsb_in_token == 1) {
184
7.76k
        return EstimateTokenCostImpl<5, 2, 1>(values, len, out);
185
15.5k
      } else if (cfg.lsb_in_token == 2) {
186
7.76k
        return EstimateTokenCostImpl<5, 2, 2>(values, len, out);
187
7.76k
      } else {
188
7.75k
        JXL_DASSERT(cfg.lsb_in_token == 3);
189
7.75k
        return EstimateTokenCostImpl<5, 2, 3>(values, len, out);
190
7.75k
      }
191
31.0k
    }
192
57.2k
  } else if (cfg.split_exponent == 6) {
193
21.0k
    if (cfg.msb_in_token == 0) {
194
7.76k
      JXL_DASSERT(cfg.lsb_in_token == 0);
195
7.76k
      return EstimateTokenCostImpl<6, 0, 0>(values, len, out);
196
13.2k
    } else if (cfg.msb_in_token == 1) {
197
6.62k
      JXL_DASSERT(cfg.lsb_in_token == 5);
198
6.62k
      return EstimateTokenCostImpl<6, 1, 5>(values, len, out);
199
6.62k
    } else {
200
6.62k
      JXL_DASSERT(cfg.msb_in_token == 2);
201
6.62k
      JXL_DASSERT(cfg.lsb_in_token == 4);
202
6.62k
      return EstimateTokenCostImpl<6, 2, 4>(values, len, out);
203
6.62k
    }
204
36.2k
  } else if (cfg.split_exponent >= 7 && cfg.split_exponent <= 12) {
205
36.2k
    JXL_DASSERT(cfg.msb_in_token == 0);
206
36.2k
    JXL_DASSERT(cfg.lsb_in_token == 0);
207
36.2k
    if (cfg.split_exponent == 7) {
208
7.76k
      return EstimateTokenCostImpl<7, 0, 0>(values, len, out);
209
28.5k
    } else if (cfg.split_exponent == 8) {
210
5.70k
      return EstimateTokenCostImpl<8, 0, 0>(values, len, out);
211
22.8k
    } else if (cfg.split_exponent == 9) {
212
5.70k
      return EstimateTokenCostImpl<9, 0, 0>(values, len, out);
213
17.1k
    } else if (cfg.split_exponent == 10) {
214
5.70k
      return EstimateTokenCostImpl<10, 0, 0>(values, len, out);
215
11.4k
    } else if (cfg.split_exponent == 11) {
216
5.70k
      return EstimateTokenCostImpl<11, 0, 0>(values, len, out);
217
5.70k
    } else {
218
5.70k
      return EstimateTokenCostImpl<12, 0, 0>(values, len, out);
219
5.70k
    }
220
36.2k
  } else {
221
0
    JXL_DASSERT(false);
222
0
  }
223
0
  return ~0;
224
523k
#endif
225
523k
}
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
113
523k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
114
523k
  uint32_t* JXL_RESTRICT out = tokens.address<uint32_t>();
115
#if HWY_TARGET == HWY_SCALAR
116
  uint32_t extra_bits = 0;
117
  for (size_t i = 0; i < len; ++i) {
118
    uint32_t v = values[i];
119
    uint32_t tok, nbits, bits;
120
    cfg.Encode(v, &tok, &nbits, &bits);
121
    extra_bits += nbits;
122
    out[i] = tok;
123
  }
124
  return extra_bits;
125
#else
126
523k
  if (cfg.split_exponent == 0) {
127
87.9k
    return EstimateTokenCostImpl<0, 0, 0>(values, len, out);
128
435k
  } else if (cfg.split_exponent == 2) {
129
87.2k
    JXL_DASSERT((cfg.msb_in_token == 0) && (cfg.lsb_in_token == 1));
130
87.2k
    return EstimateTokenCostImpl<2, 0, 1>(values, len, out);
131
348k
  } else if (cfg.split_exponent == 3) {
132
31.0k
    if (cfg.msb_in_token == 1) {
133
15.5k
      if (cfg.lsb_in_token == 0) {
134
7.76k
        return EstimateTokenCostImpl<3, 1, 0>(values, len, out);
135
7.76k
      } else {
136
7.76k
        JXL_DASSERT(cfg.lsb_in_token == 2);
137
7.76k
        return EstimateTokenCostImpl<3, 1, 2>(values, len, out);
138
7.76k
      }
139
15.5k
    } else {
140
15.5k
      JXL_DASSERT(cfg.msb_in_token == 2);
141
15.5k
      if (cfg.lsb_in_token == 0) {
142
7.76k
        return EstimateTokenCostImpl<3, 2, 0>(values, len, out);
143
7.76k
      } else {
144
7.76k
        JXL_DASSERT(cfg.lsb_in_token == 1);
145
7.76k
        return EstimateTokenCostImpl<3, 2, 1>(values, len, out);
146
7.76k
      }
147
15.5k
    }
148
317k
  } else if (cfg.split_exponent == 4) {
149
205k
    if (cfg.msb_in_token == 1) {
150
102k
      if (cfg.lsb_in_token == 0) {
151
7.76k
        return EstimateTokenCostImpl<4, 1, 0>(values, len, out);
152
94.9k
      } else if (cfg.lsb_in_token == 2) {
153
87.1k
        return EstimateTokenCostImpl<4, 1, 2>(values, len, out);
154
87.1k
      } else {
155
7.76k
        JXL_DASSERT(cfg.lsb_in_token == 3);
156
7.76k
        return EstimateTokenCostImpl<4, 1, 3>(values, len, out);
157
7.76k
      }
158
102k
    } else {
159
102k
      JXL_DASSERT(cfg.msb_in_token == 2);
160
102k
      if (cfg.lsb_in_token == 0) {
161
87.2k
        return EstimateTokenCostImpl<4, 2, 0>(values, len, out);
162
87.2k
      } else if (cfg.lsb_in_token == 1) {
163
7.76k
        return EstimateTokenCostImpl<4, 2, 1>(values, len, out);
164
7.76k
      } else {
165
7.76k
        JXL_DASSERT(cfg.lsb_in_token == 2);
166
7.76k
        return EstimateTokenCostImpl<4, 2, 2>(values, len, out);
167
7.76k
      }
168
102k
    }
169
205k
  } else if (cfg.split_exponent == 5) {
170
54.3k
    if (cfg.msb_in_token == 1) {
171
23.2k
      if (cfg.lsb_in_token == 0) {
172
7.76k
        return EstimateTokenCostImpl<5, 1, 0>(values, len, out);
173
15.5k
      } else if (cfg.lsb_in_token == 2) {
174
7.76k
        return EstimateTokenCostImpl<5, 1, 2>(values, len, out);
175
7.76k
      } else {
176
7.75k
        JXL_DASSERT(cfg.lsb_in_token == 4);
177
7.75k
        return EstimateTokenCostImpl<5, 1, 4>(values, len, out);
178
7.75k
      }
179
31.0k
    } else {
180
31.0k
      JXL_DASSERT(cfg.msb_in_token == 2);
181
31.0k
      if (cfg.lsb_in_token == 0) {
182
7.76k
        return EstimateTokenCostImpl<5, 2, 0>(values, len, out);
183
23.2k
      } else if (cfg.lsb_in_token == 1) {
184
7.76k
        return EstimateTokenCostImpl<5, 2, 1>(values, len, out);
185
15.5k
      } else if (cfg.lsb_in_token == 2) {
186
7.76k
        return EstimateTokenCostImpl<5, 2, 2>(values, len, out);
187
7.76k
      } else {
188
7.75k
        JXL_DASSERT(cfg.lsb_in_token == 3);
189
7.75k
        return EstimateTokenCostImpl<5, 2, 3>(values, len, out);
190
7.75k
      }
191
31.0k
    }
192
57.2k
  } else if (cfg.split_exponent == 6) {
193
21.0k
    if (cfg.msb_in_token == 0) {
194
7.76k
      JXL_DASSERT(cfg.lsb_in_token == 0);
195
7.76k
      return EstimateTokenCostImpl<6, 0, 0>(values, len, out);
196
13.2k
    } else if (cfg.msb_in_token == 1) {
197
6.62k
      JXL_DASSERT(cfg.lsb_in_token == 5);
198
6.62k
      return EstimateTokenCostImpl<6, 1, 5>(values, len, out);
199
6.62k
    } else {
200
6.62k
      JXL_DASSERT(cfg.msb_in_token == 2);
201
6.62k
      JXL_DASSERT(cfg.lsb_in_token == 4);
202
6.62k
      return EstimateTokenCostImpl<6, 2, 4>(values, len, out);
203
6.62k
    }
204
36.2k
  } else if (cfg.split_exponent >= 7 && cfg.split_exponent <= 12) {
205
36.2k
    JXL_DASSERT(cfg.msb_in_token == 0);
206
36.2k
    JXL_DASSERT(cfg.lsb_in_token == 0);
207
36.2k
    if (cfg.split_exponent == 7) {
208
7.76k
      return EstimateTokenCostImpl<7, 0, 0>(values, len, out);
209
28.5k
    } else if (cfg.split_exponent == 8) {
210
5.70k
      return EstimateTokenCostImpl<8, 0, 0>(values, len, out);
211
22.8k
    } else if (cfg.split_exponent == 9) {
212
5.70k
      return EstimateTokenCostImpl<9, 0, 0>(values, len, out);
213
17.1k
    } else if (cfg.split_exponent == 10) {
214
5.70k
      return EstimateTokenCostImpl<10, 0, 0>(values, len, out);
215
11.4k
    } else if (cfg.split_exponent == 11) {
216
5.70k
      return EstimateTokenCostImpl<11, 0, 0>(values, len, out);
217
5.70k
    } else {
218
5.70k
      return EstimateTokenCostImpl<12, 0, 0>(values, len, out);
219
5.70k
    }
220
36.2k
  } else {
221
0
    JXL_DASSERT(false);
222
0
  }
223
0
  return ~0;
224
523k
#endif
225
523k
}
Unexecuted instantiation: jxl::N_SSE2::EstimateTokenCost(unsigned int*, unsigned long, jxl::HybridUintConfig, jxl::AlignedMemory&)
226
227
// NOLINTNEXTLINE(google-readability-namespace-comments)
228
}  // namespace HWY_NAMESPACE
229
}  // namespace jxl
230
HWY_AFTER_NAMESPACE();
231
232
#if HWY_ONCE
233
namespace jxl {
234
235
HWY_EXPORT(EstimateTokenCost);
236
237
uint32_t EstimateTokenCost(uint32_t* JXL_RESTRICT values, size_t len,
238
523k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
239
523k
  JXL_DASSERT(cfg.lsb_in_token + cfg.msb_in_token <= cfg.split_exponent);
240
523k
  return HWY_DYNAMIC_DISPATCH(EstimateTokenCost)(values, len, cfg, tokens);
241
523k
}
242
243
}  // namespace jxl
244
#endif