Coverage Report

Created: 2026-06-07 07:20

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
476k
                               uint32_t* JXL_RESTRICT out) {
45
476k
  const HWY_FULL(uint32_t) du;
46
476k
  const HWY_FULL(float) df;
47
476k
  const auto kZero = Zero(du);
48
476k
  const auto kSplit = Set(du, 1 << E);
49
476k
  const auto kExpOffset = Set(du, 127);
50
476k
  const auto kEBOffset = Set(du, 127 + M + L);
51
476k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
476k
  const auto kMulN = Set(du, 1 << (M + L));
53
476k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
476k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
476k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
476k
  constexpr size_t kLargeShiftVal = 10;
57
476k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
476k
  auto extra_bits = kZero;
60
476k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
60.4M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
59.9M
    const auto val = LoadU(du, values + i);
63
59.9M
    const auto is_large = Gt(val, kLargeThreshold);
64
59.9M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
59.9M
    const auto not_literal = Ge(val, kSplit);
66
59.9M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
59.9M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
59.9M
    const auto l = And(val, kMaskL);
69
59.9M
    const auto exp = ShiftRight<23>(b);
70
59.9M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
59.9M
    const auto n = Sub(exp_fixed, kExpOffset);
72
59.9M
    const auto eb = Sub(exp_fixed, kEBOffset);
73
59.9M
    const auto m = ShiftRight<23 - M - L>(b);
74
59.9M
    const auto a = Add(kBase, Mul(n, kMulN));
75
59.9M
    const auto d = And(m, kMaskM);
76
59.9M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
59.9M
    const auto c = Or(a, l);
78
59.9M
    extra_bits = Add(extra_bits, eb_fixed);
79
59.9M
    const auto t = Or(c, d);
80
59.9M
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
59.9M
    Store(t_fixed, du, out + i);
82
59.9M
  }
83
476k
  if (last_full < len) {
84
410k
    const auto stop = Set(du, len);
85
410k
    const auto fence = Iota(du, last_full);
86
410k
    const auto take = Lt(fence, stop);
87
410k
    const auto val = LoadU(du, values + last_full);
88
410k
    const auto is_large = Gt(val, kLargeThreshold);
89
410k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
410k
    const auto not_literal = Ge(val, kSplit);
91
410k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
410k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
410k
    const auto l = And(val, kMaskL);
94
410k
    const auto exp = ShiftRight<23>(b);
95
410k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
410k
    const auto n = Sub(exp_fixed, kExpOffset);
97
410k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
410k
    const auto m = ShiftRight<23 - M - L>(b);
99
410k
    const auto a = Add(kBase, Mul(n, kMulN));
100
410k
    const auto d = And(m, kMaskM);
101
410k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
410k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
410k
    const auto c = Or(a, l);
104
410k
    extra_bits = Add(extra_bits, eb_masked);
105
410k
    const auto t = Or(c, d);
106
410k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
410k
    Store(t_fixed, du, out + last_full);
108
410k
  }
109
476k
  return GetLane(SumOfLanes(du, extra_bits));
110
476k
}
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
80.7k
                               uint32_t* JXL_RESTRICT out) {
45
80.7k
  const HWY_FULL(uint32_t) du;
46
80.7k
  const HWY_FULL(float) df;
47
80.7k
  const auto kZero = Zero(du);
48
80.7k
  const auto kSplit = Set(du, 1 << E);
49
80.7k
  const auto kExpOffset = Set(du, 127);
50
80.7k
  const auto kEBOffset = Set(du, 127 + M + L);
51
80.7k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
80.7k
  const auto kMulN = Set(du, 1 << (M + L));
53
80.7k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
80.7k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
80.7k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
80.7k
  constexpr size_t kLargeShiftVal = 10;
57
80.7k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
80.7k
  auto extra_bits = kZero;
60
80.7k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
11.2M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
11.2M
    const auto val = LoadU(du, values + i);
63
11.2M
    const auto is_large = Gt(val, kLargeThreshold);
64
11.2M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
11.2M
    const auto not_literal = Ge(val, kSplit);
66
11.2M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
11.2M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
11.2M
    const auto l = And(val, kMaskL);
69
11.2M
    const auto exp = ShiftRight<23>(b);
70
11.2M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
11.2M
    const auto n = Sub(exp_fixed, kExpOffset);
72
11.2M
    const auto eb = Sub(exp_fixed, kEBOffset);
73
11.2M
    const auto m = ShiftRight<23 - M - L>(b);
74
11.2M
    const auto a = Add(kBase, Mul(n, kMulN));
75
11.2M
    const auto d = And(m, kMaskM);
76
11.2M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
11.2M
    const auto c = Or(a, l);
78
11.2M
    extra_bits = Add(extra_bits, eb_fixed);
79
11.2M
    const auto t = Or(c, d);
80
11.2M
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
11.2M
    Store(t_fixed, du, out + i);
82
11.2M
  }
83
80.7k
  if (last_full < len) {
84
69.9k
    const auto stop = Set(du, len);
85
69.9k
    const auto fence = Iota(du, last_full);
86
69.9k
    const auto take = Lt(fence, stop);
87
69.9k
    const auto val = LoadU(du, values + last_full);
88
69.9k
    const auto is_large = Gt(val, kLargeThreshold);
89
69.9k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
69.9k
    const auto not_literal = Ge(val, kSplit);
91
69.9k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
69.9k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
69.9k
    const auto l = And(val, kMaskL);
94
69.9k
    const auto exp = ShiftRight<23>(b);
95
69.9k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
69.9k
    const auto n = Sub(exp_fixed, kExpOffset);
97
69.9k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
69.9k
    const auto m = ShiftRight<23 - M - L>(b);
99
69.9k
    const auto a = Add(kBase, Mul(n, kMulN));
100
69.9k
    const auto d = And(m, kMaskM);
101
69.9k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
69.9k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
69.9k
    const auto c = Or(a, l);
104
69.9k
    extra_bits = Add(extra_bits, eb_masked);
105
69.9k
    const auto t = Or(c, d);
106
69.9k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
69.9k
    Store(t_fixed, du, out + last_full);
108
69.9k
  }
109
80.7k
  return GetLane(SumOfLanes(du, extra_bits));
110
80.7k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<2ul, 0ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
80.1k
                               uint32_t* JXL_RESTRICT out) {
45
80.1k
  const HWY_FULL(uint32_t) du;
46
80.1k
  const HWY_FULL(float) df;
47
80.1k
  const auto kZero = Zero(du);
48
80.1k
  const auto kSplit = Set(du, 1 << E);
49
80.1k
  const auto kExpOffset = Set(du, 127);
50
80.1k
  const auto kEBOffset = Set(du, 127 + M + L);
51
80.1k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
80.1k
  const auto kMulN = Set(du, 1 << (M + L));
53
80.1k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
80.1k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
80.1k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
80.1k
  constexpr size_t kLargeShiftVal = 10;
57
80.1k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
80.1k
  auto extra_bits = kZero;
60
80.1k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
11.2M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
11.2M
    const auto val = LoadU(du, values + i);
63
11.2M
    const auto is_large = Gt(val, kLargeThreshold);
64
11.2M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
11.2M
    const auto not_literal = Ge(val, kSplit);
66
11.2M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
11.2M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
11.2M
    const auto l = And(val, kMaskL);
69
11.2M
    const auto exp = ShiftRight<23>(b);
70
11.2M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
11.2M
    const auto n = Sub(exp_fixed, kExpOffset);
72
11.2M
    const auto eb = Sub(exp_fixed, kEBOffset);
73
11.2M
    const auto m = ShiftRight<23 - M - L>(b);
74
11.2M
    const auto a = Add(kBase, Mul(n, kMulN));
75
11.2M
    const auto d = And(m, kMaskM);
76
11.2M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
11.2M
    const auto c = Or(a, l);
78
11.2M
    extra_bits = Add(extra_bits, eb_fixed);
79
11.2M
    const auto t = Or(c, d);
80
11.2M
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
11.2M
    Store(t_fixed, du, out + i);
82
11.2M
  }
83
80.1k
  if (last_full < len) {
84
69.4k
    const auto stop = Set(du, len);
85
69.4k
    const auto fence = Iota(du, last_full);
86
69.4k
    const auto take = Lt(fence, stop);
87
69.4k
    const auto val = LoadU(du, values + last_full);
88
69.4k
    const auto is_large = Gt(val, kLargeThreshold);
89
69.4k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
69.4k
    const auto not_literal = Ge(val, kSplit);
91
69.4k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
69.4k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
69.4k
    const auto l = And(val, kMaskL);
94
69.4k
    const auto exp = ShiftRight<23>(b);
95
69.4k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
69.4k
    const auto n = Sub(exp_fixed, kExpOffset);
97
69.4k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
69.4k
    const auto m = ShiftRight<23 - M - L>(b);
99
69.4k
    const auto a = Add(kBase, Mul(n, kMulN));
100
69.4k
    const auto d = And(m, kMaskM);
101
69.4k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
69.4k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
69.4k
    const auto c = Or(a, l);
104
69.4k
    extra_bits = Add(extra_bits, eb_masked);
105
69.4k
    const auto t = Or(c, d);
106
69.4k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
69.4k
    Store(t_fixed, du, out + last_full);
108
69.4k
  }
109
80.1k
  return GetLane(SumOfLanes(du, extra_bits));
110
80.1k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
80.1k
                               uint32_t* JXL_RESTRICT out) {
45
80.1k
  const HWY_FULL(uint32_t) du;
46
80.1k
  const HWY_FULL(float) df;
47
80.1k
  const auto kZero = Zero(du);
48
80.1k
  const auto kSplit = Set(du, 1 << E);
49
80.1k
  const auto kExpOffset = Set(du, 127);
50
80.1k
  const auto kEBOffset = Set(du, 127 + M + L);
51
80.1k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
80.1k
  const auto kMulN = Set(du, 1 << (M + L));
53
80.1k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
80.1k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
80.1k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
80.1k
  constexpr size_t kLargeShiftVal = 10;
57
80.1k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
80.1k
  auto extra_bits = kZero;
60
80.1k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
11.2M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
11.2M
    const auto val = LoadU(du, values + i);
63
11.2M
    const auto is_large = Gt(val, kLargeThreshold);
64
11.2M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
11.2M
    const auto not_literal = Ge(val, kSplit);
66
11.2M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
11.2M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
11.2M
    const auto l = And(val, kMaskL);
69
11.2M
    const auto exp = ShiftRight<23>(b);
70
11.2M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
11.2M
    const auto n = Sub(exp_fixed, kExpOffset);
72
11.2M
    const auto eb = Sub(exp_fixed, kEBOffset);
73
11.2M
    const auto m = ShiftRight<23 - M - L>(b);
74
11.2M
    const auto a = Add(kBase, Mul(n, kMulN));
75
11.2M
    const auto d = And(m, kMaskM);
76
11.2M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
11.2M
    const auto c = Or(a, l);
78
11.2M
    extra_bits = Add(extra_bits, eb_fixed);
79
11.2M
    const auto t = Or(c, d);
80
11.2M
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
11.2M
    Store(t_fixed, du, out + i);
82
11.2M
  }
83
80.1k
  if (last_full < len) {
84
69.4k
    const auto stop = Set(du, len);
85
69.4k
    const auto fence = Iota(du, last_full);
86
69.4k
    const auto take = Lt(fence, stop);
87
69.4k
    const auto val = LoadU(du, values + last_full);
88
69.4k
    const auto is_large = Gt(val, kLargeThreshold);
89
69.4k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
69.4k
    const auto not_literal = Ge(val, kSplit);
91
69.4k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
69.4k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
69.4k
    const auto l = And(val, kMaskL);
94
69.4k
    const auto exp = ShiftRight<23>(b);
95
69.4k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
69.4k
    const auto n = Sub(exp_fixed, kExpOffset);
97
69.4k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
69.4k
    const auto m = ShiftRight<23 - M - L>(b);
99
69.4k
    const auto a = Add(kBase, Mul(n, kMulN));
100
69.4k
    const auto d = And(m, kMaskM);
101
69.4k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
69.4k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
69.4k
    const auto c = Or(a, l);
104
69.4k
    extra_bits = Add(extra_bits, eb_masked);
105
69.4k
    const auto t = Or(c, d);
106
69.4k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
69.4k
    Store(t_fixed, du, out + last_full);
108
69.4k
  }
109
80.1k
  return GetLane(SumOfLanes(du, extra_bits));
110
80.1k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
80.1k
                               uint32_t* JXL_RESTRICT out) {
45
80.1k
  const HWY_FULL(uint32_t) du;
46
80.1k
  const HWY_FULL(float) df;
47
80.1k
  const auto kZero = Zero(du);
48
80.1k
  const auto kSplit = Set(du, 1 << E);
49
80.1k
  const auto kExpOffset = Set(du, 127);
50
80.1k
  const auto kEBOffset = Set(du, 127 + M + L);
51
80.1k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
80.1k
  const auto kMulN = Set(du, 1 << (M + L));
53
80.1k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
80.1k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
80.1k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
80.1k
  constexpr size_t kLargeShiftVal = 10;
57
80.1k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
80.1k
  auto extra_bits = kZero;
60
80.1k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
11.2M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
11.2M
    const auto val = LoadU(du, values + i);
63
11.2M
    const auto is_large = Gt(val, kLargeThreshold);
64
11.2M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
11.2M
    const auto not_literal = Ge(val, kSplit);
66
11.2M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
11.2M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
11.2M
    const auto l = And(val, kMaskL);
69
11.2M
    const auto exp = ShiftRight<23>(b);
70
11.2M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
11.2M
    const auto n = Sub(exp_fixed, kExpOffset);
72
11.2M
    const auto eb = Sub(exp_fixed, kEBOffset);
73
11.2M
    const auto m = ShiftRight<23 - M - L>(b);
74
11.2M
    const auto a = Add(kBase, Mul(n, kMulN));
75
11.2M
    const auto d = And(m, kMaskM);
76
11.2M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
11.2M
    const auto c = Or(a, l);
78
11.2M
    extra_bits = Add(extra_bits, eb_fixed);
79
11.2M
    const auto t = Or(c, d);
80
11.2M
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
11.2M
    Store(t_fixed, du, out + i);
82
11.2M
  }
83
80.1k
  if (last_full < len) {
84
69.4k
    const auto stop = Set(du, len);
85
69.4k
    const auto fence = Iota(du, last_full);
86
69.4k
    const auto take = Lt(fence, stop);
87
69.4k
    const auto val = LoadU(du, values + last_full);
88
69.4k
    const auto is_large = Gt(val, kLargeThreshold);
89
69.4k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
69.4k
    const auto not_literal = Ge(val, kSplit);
91
69.4k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
69.4k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
69.4k
    const auto l = And(val, kMaskL);
94
69.4k
    const auto exp = ShiftRight<23>(b);
95
69.4k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
69.4k
    const auto n = Sub(exp_fixed, kExpOffset);
97
69.4k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
69.4k
    const auto m = ShiftRight<23 - M - L>(b);
99
69.4k
    const auto a = Add(kBase, Mul(n, kMulN));
100
69.4k
    const auto d = And(m, kMaskM);
101
69.4k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
69.4k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
69.4k
    const auto c = Or(a, l);
104
69.4k
    extra_bits = Add(extra_bits, eb_masked);
105
69.4k
    const auto t = Or(c, d);
106
69.4k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
69.4k
    Store(t_fixed, du, out + last_full);
108
69.4k
  }
109
80.1k
  return GetLane(SumOfLanes(du, extra_bits));
110
80.1k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.87k
    const auto stop = Set(du, len);
85
5.87k
    const auto fence = Iota(du, last_full);
86
5.87k
    const auto take = Lt(fence, stop);
87
5.87k
    const auto val = LoadU(du, values + last_full);
88
5.87k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.87k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.87k
    const auto not_literal = Ge(val, kSplit);
91
5.87k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.87k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.87k
    const auto l = And(val, kMaskL);
94
5.87k
    const auto exp = ShiftRight<23>(b);
95
5.87k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.87k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.87k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.87k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.87k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.87k
    const auto d = And(m, kMaskM);
101
5.87k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.87k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.87k
    const auto c = Or(a, l);
104
5.87k
    extra_bits = Add(extra_bits, eb_masked);
105
5.87k
    const auto t = Or(c, d);
106
5.87k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.87k
    Store(t_fixed, du, out + last_full);
108
5.87k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.87k
    const auto stop = Set(du, len);
85
5.87k
    const auto fence = Iota(du, last_full);
86
5.87k
    const auto take = Lt(fence, stop);
87
5.87k
    const auto val = LoadU(du, values + last_full);
88
5.87k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.87k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.87k
    const auto not_literal = Ge(val, kSplit);
91
5.87k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.87k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.87k
    const auto l = And(val, kMaskL);
94
5.87k
    const auto exp = ShiftRight<23>(b);
95
5.87k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.87k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.87k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.87k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.87k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.87k
    const auto d = And(m, kMaskM);
101
5.87k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.87k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.87k
    const auto c = Or(a, l);
104
5.87k
    extra_bits = Add(extra_bits, eb_masked);
105
5.87k
    const auto t = Or(c, d);
106
5.87k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.87k
    Store(t_fixed, du, out + last_full);
108
5.87k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 1ul, 5ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.97k
                               uint32_t* JXL_RESTRICT out) {
45
5.97k
  const HWY_FULL(uint32_t) du;
46
5.97k
  const HWY_FULL(float) df;
47
5.97k
  const auto kZero = Zero(du);
48
5.97k
  const auto kSplit = Set(du, 1 << E);
49
5.97k
  const auto kExpOffset = Set(du, 127);
50
5.97k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.97k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.97k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.97k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.97k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.97k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.97k
  constexpr size_t kLargeShiftVal = 10;
57
5.97k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.97k
  auto extra_bits = kZero;
60
5.97k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
376k
  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.97k
  if (last_full < len) {
84
5.10k
    const auto stop = Set(du, len);
85
5.10k
    const auto fence = Iota(du, last_full);
86
5.10k
    const auto take = Lt(fence, stop);
87
5.10k
    const auto val = LoadU(du, values + last_full);
88
5.10k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.10k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.10k
    const auto not_literal = Ge(val, kSplit);
91
5.10k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.10k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.10k
    const auto l = And(val, kMaskL);
94
5.10k
    const auto exp = ShiftRight<23>(b);
95
5.10k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.10k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.10k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.10k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.10k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.10k
    const auto d = And(m, kMaskM);
101
5.10k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.10k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.10k
    const auto c = Or(a, l);
104
5.10k
    extra_bits = Add(extra_bits, eb_masked);
105
5.10k
    const auto t = Or(c, d);
106
5.10k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.10k
    Store(t_fixed, du, out + last_full);
108
5.10k
  }
109
5.97k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.97k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 2ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.97k
                               uint32_t* JXL_RESTRICT out) {
45
5.97k
  const HWY_FULL(uint32_t) du;
46
5.97k
  const HWY_FULL(float) df;
47
5.97k
  const auto kZero = Zero(du);
48
5.97k
  const auto kSplit = Set(du, 1 << E);
49
5.97k
  const auto kExpOffset = Set(du, 127);
50
5.97k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.97k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.97k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.97k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.97k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.97k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.97k
  constexpr size_t kLargeShiftVal = 10;
57
5.97k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.97k
  auto extra_bits = kZero;
60
5.97k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
376k
  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.97k
  if (last_full < len) {
84
5.10k
    const auto stop = Set(du, len);
85
5.10k
    const auto fence = Iota(du, last_full);
86
5.10k
    const auto take = Lt(fence, stop);
87
5.10k
    const auto val = LoadU(du, values + last_full);
88
5.10k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.10k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.10k
    const auto not_literal = Ge(val, kSplit);
91
5.10k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.10k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.10k
    const auto l = And(val, kMaskL);
94
5.10k
    const auto exp = ShiftRight<23>(b);
95
5.10k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.10k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.10k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.10k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.10k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.10k
    const auto d = And(m, kMaskM);
101
5.10k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.10k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.10k
    const auto c = Or(a, l);
104
5.10k
    extra_bits = Add(extra_bits, eb_masked);
105
5.10k
    const auto t = Or(c, d);
106
5.10k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.10k
    Store(t_fixed, du, out + last_full);
108
5.10k
  }
109
5.97k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.97k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<7ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
6.92k
                               uint32_t* JXL_RESTRICT out) {
45
6.92k
  const HWY_FULL(uint32_t) du;
46
6.92k
  const HWY_FULL(float) df;
47
6.92k
  const auto kZero = Zero(du);
48
6.92k
  const auto kSplit = Set(du, 1 << E);
49
6.92k
  const auto kExpOffset = Set(du, 127);
50
6.92k
  const auto kEBOffset = Set(du, 127 + M + L);
51
6.92k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
6.92k
  const auto kMulN = Set(du, 1 << (M + L));
53
6.92k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
6.92k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
6.92k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
6.92k
  constexpr size_t kLargeShiftVal = 10;
57
6.92k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
6.92k
  auto extra_bits = kZero;
60
6.92k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
753k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
746k
    const auto val = LoadU(du, values + i);
63
746k
    const auto is_large = Gt(val, kLargeThreshold);
64
746k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
746k
    const auto not_literal = Ge(val, kSplit);
66
746k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
746k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
746k
    const auto l = And(val, kMaskL);
69
746k
    const auto exp = ShiftRight<23>(b);
70
746k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
746k
    const auto n = Sub(exp_fixed, kExpOffset);
72
746k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
746k
    const auto m = ShiftRight<23 - M - L>(b);
74
746k
    const auto a = Add(kBase, Mul(n, kMulN));
75
746k
    const auto d = And(m, kMaskM);
76
746k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
746k
    const auto c = Or(a, l);
78
746k
    extra_bits = Add(extra_bits, eb_fixed);
79
746k
    const auto t = Or(c, d);
80
746k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
746k
    Store(t_fixed, du, out + i);
82
746k
  }
83
6.92k
  if (last_full < len) {
84
5.88k
    const auto stop = Set(du, len);
85
5.88k
    const auto fence = Iota(du, last_full);
86
5.88k
    const auto take = Lt(fence, stop);
87
5.88k
    const auto val = LoadU(du, values + last_full);
88
5.88k
    const auto is_large = Gt(val, kLargeThreshold);
89
5.88k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
5.88k
    const auto not_literal = Ge(val, kSplit);
91
5.88k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
5.88k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
5.88k
    const auto l = And(val, kMaskL);
94
5.88k
    const auto exp = ShiftRight<23>(b);
95
5.88k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
5.88k
    const auto n = Sub(exp_fixed, kExpOffset);
97
5.88k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
5.88k
    const auto m = ShiftRight<23 - M - L>(b);
99
5.88k
    const auto a = Add(kBase, Mul(n, kMulN));
100
5.88k
    const auto d = And(m, kMaskM);
101
5.88k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
5.88k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
5.88k
    const auto c = Or(a, l);
104
5.88k
    extra_bits = Add(extra_bits, eb_masked);
105
5.88k
    const auto t = Or(c, d);
106
5.88k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
5.88k
    Store(t_fixed, du, out + last_full);
108
5.88k
  }
109
6.92k
  return GetLane(SumOfLanes(du, extra_bits));
110
6.92k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<8ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.15k
                               uint32_t* JXL_RESTRICT out) {
45
5.15k
  const HWY_FULL(uint32_t) du;
46
5.15k
  const HWY_FULL(float) df;
47
5.15k
  const auto kZero = Zero(du);
48
5.15k
  const auto kSplit = Set(du, 1 << E);
49
5.15k
  const auto kExpOffset = Set(du, 127);
50
5.15k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.15k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.15k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.15k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.15k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.15k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.15k
  constexpr size_t kLargeShiftVal = 10;
57
5.15k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.15k
  auto extra_bits = kZero;
60
5.15k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
345k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
339k
    const auto val = LoadU(du, values + i);
63
339k
    const auto is_large = Gt(val, kLargeThreshold);
64
339k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
339k
    const auto not_literal = Ge(val, kSplit);
66
339k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
339k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
339k
    const auto l = And(val, kMaskL);
69
339k
    const auto exp = ShiftRight<23>(b);
70
339k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
339k
    const auto n = Sub(exp_fixed, kExpOffset);
72
339k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
339k
    const auto m = ShiftRight<23 - M - L>(b);
74
339k
    const auto a = Add(kBase, Mul(n, kMulN));
75
339k
    const auto d = And(m, kMaskM);
76
339k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
339k
    const auto c = Or(a, l);
78
339k
    extra_bits = Add(extra_bits, eb_fixed);
79
339k
    const auto t = Or(c, d);
80
339k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
339k
    Store(t_fixed, du, out + i);
82
339k
  }
83
5.15k
  if (last_full < len) {
84
4.35k
    const auto stop = Set(du, len);
85
4.35k
    const auto fence = Iota(du, last_full);
86
4.35k
    const auto take = Lt(fence, stop);
87
4.35k
    const auto val = LoadU(du, values + last_full);
88
4.35k
    const auto is_large = Gt(val, kLargeThreshold);
89
4.35k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
4.35k
    const auto not_literal = Ge(val, kSplit);
91
4.35k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
4.35k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
4.35k
    const auto l = And(val, kMaskL);
94
4.35k
    const auto exp = ShiftRight<23>(b);
95
4.35k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
4.35k
    const auto n = Sub(exp_fixed, kExpOffset);
97
4.35k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
4.35k
    const auto m = ShiftRight<23 - M - L>(b);
99
4.35k
    const auto a = Add(kBase, Mul(n, kMulN));
100
4.35k
    const auto d = And(m, kMaskM);
101
4.35k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
4.35k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
4.35k
    const auto c = Or(a, l);
104
4.35k
    extra_bits = Add(extra_bits, eb_masked);
105
4.35k
    const auto t = Or(c, d);
106
4.35k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
4.35k
    Store(t_fixed, du, out + last_full);
108
4.35k
  }
109
5.15k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.15k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<9ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.15k
                               uint32_t* JXL_RESTRICT out) {
45
5.15k
  const HWY_FULL(uint32_t) du;
46
5.15k
  const HWY_FULL(float) df;
47
5.15k
  const auto kZero = Zero(du);
48
5.15k
  const auto kSplit = Set(du, 1 << E);
49
5.15k
  const auto kExpOffset = Set(du, 127);
50
5.15k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.15k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.15k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.15k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.15k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.15k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.15k
  constexpr size_t kLargeShiftVal = 10;
57
5.15k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.15k
  auto extra_bits = kZero;
60
5.15k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
345k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
339k
    const auto val = LoadU(du, values + i);
63
339k
    const auto is_large = Gt(val, kLargeThreshold);
64
339k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
339k
    const auto not_literal = Ge(val, kSplit);
66
339k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
339k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
339k
    const auto l = And(val, kMaskL);
69
339k
    const auto exp = ShiftRight<23>(b);
70
339k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
339k
    const auto n = Sub(exp_fixed, kExpOffset);
72
339k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
339k
    const auto m = ShiftRight<23 - M - L>(b);
74
339k
    const auto a = Add(kBase, Mul(n, kMulN));
75
339k
    const auto d = And(m, kMaskM);
76
339k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
339k
    const auto c = Or(a, l);
78
339k
    extra_bits = Add(extra_bits, eb_fixed);
79
339k
    const auto t = Or(c, d);
80
339k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
339k
    Store(t_fixed, du, out + i);
82
339k
  }
83
5.15k
  if (last_full < len) {
84
4.35k
    const auto stop = Set(du, len);
85
4.35k
    const auto fence = Iota(du, last_full);
86
4.35k
    const auto take = Lt(fence, stop);
87
4.35k
    const auto val = LoadU(du, values + last_full);
88
4.35k
    const auto is_large = Gt(val, kLargeThreshold);
89
4.35k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
4.35k
    const auto not_literal = Ge(val, kSplit);
91
4.35k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
4.35k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
4.35k
    const auto l = And(val, kMaskL);
94
4.35k
    const auto exp = ShiftRight<23>(b);
95
4.35k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
4.35k
    const auto n = Sub(exp_fixed, kExpOffset);
97
4.35k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
4.35k
    const auto m = ShiftRight<23 - M - L>(b);
99
4.35k
    const auto a = Add(kBase, Mul(n, kMulN));
100
4.35k
    const auto d = And(m, kMaskM);
101
4.35k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
4.35k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
4.35k
    const auto c = Or(a, l);
104
4.35k
    extra_bits = Add(extra_bits, eb_masked);
105
4.35k
    const auto t = Or(c, d);
106
4.35k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
4.35k
    Store(t_fixed, du, out + last_full);
108
4.35k
  }
109
5.15k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.15k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<10ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.15k
                               uint32_t* JXL_RESTRICT out) {
45
5.15k
  const HWY_FULL(uint32_t) du;
46
5.15k
  const HWY_FULL(float) df;
47
5.15k
  const auto kZero = Zero(du);
48
5.15k
  const auto kSplit = Set(du, 1 << E);
49
5.15k
  const auto kExpOffset = Set(du, 127);
50
5.15k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.15k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.15k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.15k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.15k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.15k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.15k
  constexpr size_t kLargeShiftVal = 10;
57
5.15k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.15k
  auto extra_bits = kZero;
60
5.15k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
345k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
339k
    const auto val = LoadU(du, values + i);
63
339k
    const auto is_large = Gt(val, kLargeThreshold);
64
339k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
339k
    const auto not_literal = Ge(val, kSplit);
66
339k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
339k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
339k
    const auto l = And(val, kMaskL);
69
339k
    const auto exp = ShiftRight<23>(b);
70
339k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
339k
    const auto n = Sub(exp_fixed, kExpOffset);
72
339k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
339k
    const auto m = ShiftRight<23 - M - L>(b);
74
339k
    const auto a = Add(kBase, Mul(n, kMulN));
75
339k
    const auto d = And(m, kMaskM);
76
339k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
339k
    const auto c = Or(a, l);
78
339k
    extra_bits = Add(extra_bits, eb_fixed);
79
339k
    const auto t = Or(c, d);
80
339k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
339k
    Store(t_fixed, du, out + i);
82
339k
  }
83
5.15k
  if (last_full < len) {
84
4.35k
    const auto stop = Set(du, len);
85
4.35k
    const auto fence = Iota(du, last_full);
86
4.35k
    const auto take = Lt(fence, stop);
87
4.35k
    const auto val = LoadU(du, values + last_full);
88
4.35k
    const auto is_large = Gt(val, kLargeThreshold);
89
4.35k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
4.35k
    const auto not_literal = Ge(val, kSplit);
91
4.35k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
4.35k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
4.35k
    const auto l = And(val, kMaskL);
94
4.35k
    const auto exp = ShiftRight<23>(b);
95
4.35k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
4.35k
    const auto n = Sub(exp_fixed, kExpOffset);
97
4.35k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
4.35k
    const auto m = ShiftRight<23 - M - L>(b);
99
4.35k
    const auto a = Add(kBase, Mul(n, kMulN));
100
4.35k
    const auto d = And(m, kMaskM);
101
4.35k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
4.35k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
4.35k
    const auto c = Or(a, l);
104
4.35k
    extra_bits = Add(extra_bits, eb_masked);
105
4.35k
    const auto t = Or(c, d);
106
4.35k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
4.35k
    Store(t_fixed, du, out + last_full);
108
4.35k
  }
109
5.15k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.15k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<11ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.15k
                               uint32_t* JXL_RESTRICT out) {
45
5.15k
  const HWY_FULL(uint32_t) du;
46
5.15k
  const HWY_FULL(float) df;
47
5.15k
  const auto kZero = Zero(du);
48
5.15k
  const auto kSplit = Set(du, 1 << E);
49
5.15k
  const auto kExpOffset = Set(du, 127);
50
5.15k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.15k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.15k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.15k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.15k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.15k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.15k
  constexpr size_t kLargeShiftVal = 10;
57
5.15k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.15k
  auto extra_bits = kZero;
60
5.15k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
345k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
339k
    const auto val = LoadU(du, values + i);
63
339k
    const auto is_large = Gt(val, kLargeThreshold);
64
339k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
339k
    const auto not_literal = Ge(val, kSplit);
66
339k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
339k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
339k
    const auto l = And(val, kMaskL);
69
339k
    const auto exp = ShiftRight<23>(b);
70
339k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
339k
    const auto n = Sub(exp_fixed, kExpOffset);
72
339k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
339k
    const auto m = ShiftRight<23 - M - L>(b);
74
339k
    const auto a = Add(kBase, Mul(n, kMulN));
75
339k
    const auto d = And(m, kMaskM);
76
339k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
339k
    const auto c = Or(a, l);
78
339k
    extra_bits = Add(extra_bits, eb_fixed);
79
339k
    const auto t = Or(c, d);
80
339k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
339k
    Store(t_fixed, du, out + i);
82
339k
  }
83
5.15k
  if (last_full < len) {
84
4.35k
    const auto stop = Set(du, len);
85
4.35k
    const auto fence = Iota(du, last_full);
86
4.35k
    const auto take = Lt(fence, stop);
87
4.35k
    const auto val = LoadU(du, values + last_full);
88
4.35k
    const auto is_large = Gt(val, kLargeThreshold);
89
4.35k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
4.35k
    const auto not_literal = Ge(val, kSplit);
91
4.35k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
4.35k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
4.35k
    const auto l = And(val, kMaskL);
94
4.35k
    const auto exp = ShiftRight<23>(b);
95
4.35k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
4.35k
    const auto n = Sub(exp_fixed, kExpOffset);
97
4.35k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
4.35k
    const auto m = ShiftRight<23 - M - L>(b);
99
4.35k
    const auto a = Add(kBase, Mul(n, kMulN));
100
4.35k
    const auto d = And(m, kMaskM);
101
4.35k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
4.35k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
4.35k
    const auto c = Or(a, l);
104
4.35k
    extra_bits = Add(extra_bits, eb_masked);
105
4.35k
    const auto t = Or(c, d);
106
4.35k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
4.35k
    Store(t_fixed, du, out + last_full);
108
4.35k
  }
109
5.15k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.15k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<12ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
44
5.15k
                               uint32_t* JXL_RESTRICT out) {
45
5.15k
  const HWY_FULL(uint32_t) du;
46
5.15k
  const HWY_FULL(float) df;
47
5.15k
  const auto kZero = Zero(du);
48
5.15k
  const auto kSplit = Set(du, 1 << E);
49
5.15k
  const auto kExpOffset = Set(du, 127);
50
5.15k
  const auto kEBOffset = Set(du, 127 + M + L);
51
5.15k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
52
5.15k
  const auto kMulN = Set(du, 1 << (M + L));
53
5.15k
  const auto kMaskL = Set(du, (1 << L) - 1);
54
5.15k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
55
5.15k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
56
5.15k
  constexpr size_t kLargeShiftVal = 10;
57
5.15k
  const auto kLargeShift = Set(du, kLargeShiftVal);
58
59
5.15k
  auto extra_bits = kZero;
60
5.15k
  size_t last_full = Lanes(du) * (len / Lanes(du));
61
345k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
62
339k
    const auto val = LoadU(du, values + i);
63
339k
    const auto is_large = Gt(val, kLargeThreshold);
64
339k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
65
339k
    const auto not_literal = Ge(val, kSplit);
66
339k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
67
339k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
68
339k
    const auto l = And(val, kMaskL);
69
339k
    const auto exp = ShiftRight<23>(b);
70
339k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
71
339k
    const auto n = Sub(exp_fixed, kExpOffset);
72
339k
    const auto eb = Sub(exp_fixed, kEBOffset);
73
339k
    const auto m = ShiftRight<23 - M - L>(b);
74
339k
    const auto a = Add(kBase, Mul(n, kMulN));
75
339k
    const auto d = And(m, kMaskM);
76
339k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
77
339k
    const auto c = Or(a, l);
78
339k
    extra_bits = Add(extra_bits, eb_fixed);
79
339k
    const auto t = Or(c, d);
80
339k
    const auto t_fixed = IfThenElse(not_literal, t, val);
81
339k
    Store(t_fixed, du, out + i);
82
339k
  }
83
5.15k
  if (last_full < len) {
84
4.35k
    const auto stop = Set(du, len);
85
4.35k
    const auto fence = Iota(du, last_full);
86
4.35k
    const auto take = Lt(fence, stop);
87
4.35k
    const auto val = LoadU(du, values + last_full);
88
4.35k
    const auto is_large = Gt(val, kLargeThreshold);
89
4.35k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
90
4.35k
    const auto not_literal = Ge(val, kSplit);
91
4.35k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
92
4.35k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
93
4.35k
    const auto l = And(val, kMaskL);
94
4.35k
    const auto exp = ShiftRight<23>(b);
95
4.35k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
96
4.35k
    const auto n = Sub(exp_fixed, kExpOffset);
97
4.35k
    const auto eb = Sub(exp_fixed, kEBOffset);
98
4.35k
    const auto m = ShiftRight<23 - M - L>(b);
99
4.35k
    const auto a = Add(kBase, Mul(n, kMulN));
100
4.35k
    const auto d = And(m, kMaskM);
101
4.35k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
102
4.35k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
103
4.35k
    const auto c = Or(a, l);
104
4.35k
    extra_bits = Add(extra_bits, eb_masked);
105
4.35k
    const auto t = Or(c, d);
106
4.35k
    const auto t_fixed = IfThenElse(not_literal, t, val);
107
4.35k
    Store(t_fixed, du, out + last_full);
108
4.35k
  }
109
5.15k
  return GetLane(SumOfLanes(du, extra_bits));
110
5.15k
}
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
476k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
114
476k
  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
476k
  if (cfg.split_exponent == 0) {
127
80.7k
    return EstimateTokenCostImpl<0, 0, 0>(values, len, out);
128
395k
  } else if (cfg.split_exponent == 2) {
129
80.1k
    JXL_DASSERT((cfg.msb_in_token == 0) && (cfg.lsb_in_token == 1));
130
80.1k
    return EstimateTokenCostImpl<2, 0, 1>(values, len, out);
131
315k
  } else if (cfg.split_exponent == 3) {
132
27.7k
    if (cfg.msb_in_token == 1) {
133
13.8k
      if (cfg.lsb_in_token == 0) {
134
6.92k
        return EstimateTokenCostImpl<3, 1, 0>(values, len, out);
135
6.92k
      } else {
136
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 2);
137
6.92k
        return EstimateTokenCostImpl<3, 1, 2>(values, len, out);
138
6.92k
      }
139
13.8k
    } else {
140
13.8k
      JXL_DASSERT(cfg.msb_in_token == 2);
141
13.8k
      if (cfg.lsb_in_token == 0) {
142
6.92k
        return EstimateTokenCostImpl<3, 2, 0>(values, len, out);
143
6.92k
      } else {
144
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 1);
145
6.92k
        return EstimateTokenCostImpl<3, 2, 1>(values, len, out);
146
6.92k
      }
147
13.8k
    }
148
288k
  } else if (cfg.split_exponent == 4) {
149
188k
    if (cfg.msb_in_token == 1) {
150
94.0k
      if (cfg.lsb_in_token == 0) {
151
6.92k
        return EstimateTokenCostImpl<4, 1, 0>(values, len, out);
152
87.0k
      } else if (cfg.lsb_in_token == 2) {
153
80.1k
        return EstimateTokenCostImpl<4, 1, 2>(values, len, out);
154
80.1k
      } else {
155
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 3);
156
6.92k
        return EstimateTokenCostImpl<4, 1, 3>(values, len, out);
157
6.92k
      }
158
94.0k
    } else {
159
94.0k
      JXL_DASSERT(cfg.msb_in_token == 2);
160
94.0k
      if (cfg.lsb_in_token == 0) {
161
80.1k
        return EstimateTokenCostImpl<4, 2, 0>(values, len, out);
162
80.1k
      } else if (cfg.lsb_in_token == 1) {
163
6.92k
        return EstimateTokenCostImpl<4, 2, 1>(values, len, out);
164
6.92k
      } else {
165
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 2);
166
6.92k
        return EstimateTokenCostImpl<4, 2, 2>(values, len, out);
167
6.92k
      }
168
94.0k
    }
169
188k
  } else if (cfg.split_exponent == 5) {
170
48.4k
    if (cfg.msb_in_token == 1) {
171
20.7k
      if (cfg.lsb_in_token == 0) {
172
6.92k
        return EstimateTokenCostImpl<5, 1, 0>(values, len, out);
173
13.8k
      } else if (cfg.lsb_in_token == 2) {
174
6.92k
        return EstimateTokenCostImpl<5, 1, 2>(values, len, out);
175
6.92k
      } else {
176
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 4);
177
6.92k
        return EstimateTokenCostImpl<5, 1, 4>(values, len, out);
178
6.92k
      }
179
27.7k
    } else {
180
27.7k
      JXL_DASSERT(cfg.msb_in_token == 2);
181
27.7k
      if (cfg.lsb_in_token == 0) {
182
6.92k
        return EstimateTokenCostImpl<5, 2, 0>(values, len, out);
183
20.7k
      } else if (cfg.lsb_in_token == 1) {
184
6.92k
        return EstimateTokenCostImpl<5, 2, 1>(values, len, out);
185
13.8k
      } else if (cfg.lsb_in_token == 2) {
186
6.92k
        return EstimateTokenCostImpl<5, 2, 2>(values, len, out);
187
6.92k
      } else {
188
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 3);
189
6.92k
        return EstimateTokenCostImpl<5, 2, 3>(values, len, out);
190
6.92k
      }
191
27.7k
    }
192
51.6k
  } else if (cfg.split_exponent == 6) {
193
18.8k
    if (cfg.msb_in_token == 0) {
194
6.92k
      JXL_DASSERT(cfg.lsb_in_token == 0);
195
6.92k
      return EstimateTokenCostImpl<6, 0, 0>(values, len, out);
196
11.9k
    } else if (cfg.msb_in_token == 1) {
197
5.97k
      JXL_DASSERT(cfg.lsb_in_token == 5);
198
5.97k
      return EstimateTokenCostImpl<6, 1, 5>(values, len, out);
199
5.97k
    } else {
200
5.97k
      JXL_DASSERT(cfg.msb_in_token == 2);
201
5.97k
      JXL_DASSERT(cfg.lsb_in_token == 4);
202
5.97k
      return EstimateTokenCostImpl<6, 2, 4>(values, len, out);
203
5.97k
    }
204
32.7k
  } else if (cfg.split_exponent >= 7 && cfg.split_exponent <= 12) {
205
32.7k
    JXL_DASSERT(cfg.msb_in_token == 0);
206
32.7k
    JXL_DASSERT(cfg.lsb_in_token == 0);
207
32.7k
    if (cfg.split_exponent == 7) {
208
6.92k
      return EstimateTokenCostImpl<7, 0, 0>(values, len, out);
209
25.7k
    } else if (cfg.split_exponent == 8) {
210
5.15k
      return EstimateTokenCostImpl<8, 0, 0>(values, len, out);
211
20.6k
    } else if (cfg.split_exponent == 9) {
212
5.15k
      return EstimateTokenCostImpl<9, 0, 0>(values, len, out);
213
15.4k
    } else if (cfg.split_exponent == 10) {
214
5.15k
      return EstimateTokenCostImpl<10, 0, 0>(values, len, out);
215
10.3k
    } else if (cfg.split_exponent == 11) {
216
5.15k
      return EstimateTokenCostImpl<11, 0, 0>(values, len, out);
217
5.15k
    } else {
218
5.15k
      return EstimateTokenCostImpl<12, 0, 0>(values, len, out);
219
5.15k
    }
220
32.7k
  } else {
221
0
    JXL_DASSERT(false);
222
0
  }
223
0
  return ~0;
224
476k
#endif
225
476k
}
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
476k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
114
476k
  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
476k
  if (cfg.split_exponent == 0) {
127
80.7k
    return EstimateTokenCostImpl<0, 0, 0>(values, len, out);
128
395k
  } else if (cfg.split_exponent == 2) {
129
80.1k
    JXL_DASSERT((cfg.msb_in_token == 0) && (cfg.lsb_in_token == 1));
130
80.1k
    return EstimateTokenCostImpl<2, 0, 1>(values, len, out);
131
315k
  } else if (cfg.split_exponent == 3) {
132
27.7k
    if (cfg.msb_in_token == 1) {
133
13.8k
      if (cfg.lsb_in_token == 0) {
134
6.92k
        return EstimateTokenCostImpl<3, 1, 0>(values, len, out);
135
6.92k
      } else {
136
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 2);
137
6.92k
        return EstimateTokenCostImpl<3, 1, 2>(values, len, out);
138
6.92k
      }
139
13.8k
    } else {
140
13.8k
      JXL_DASSERT(cfg.msb_in_token == 2);
141
13.8k
      if (cfg.lsb_in_token == 0) {
142
6.92k
        return EstimateTokenCostImpl<3, 2, 0>(values, len, out);
143
6.92k
      } else {
144
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 1);
145
6.92k
        return EstimateTokenCostImpl<3, 2, 1>(values, len, out);
146
6.92k
      }
147
13.8k
    }
148
288k
  } else if (cfg.split_exponent == 4) {
149
188k
    if (cfg.msb_in_token == 1) {
150
94.0k
      if (cfg.lsb_in_token == 0) {
151
6.92k
        return EstimateTokenCostImpl<4, 1, 0>(values, len, out);
152
87.0k
      } else if (cfg.lsb_in_token == 2) {
153
80.1k
        return EstimateTokenCostImpl<4, 1, 2>(values, len, out);
154
80.1k
      } else {
155
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 3);
156
6.92k
        return EstimateTokenCostImpl<4, 1, 3>(values, len, out);
157
6.92k
      }
158
94.0k
    } else {
159
94.0k
      JXL_DASSERT(cfg.msb_in_token == 2);
160
94.0k
      if (cfg.lsb_in_token == 0) {
161
80.1k
        return EstimateTokenCostImpl<4, 2, 0>(values, len, out);
162
80.1k
      } else if (cfg.lsb_in_token == 1) {
163
6.92k
        return EstimateTokenCostImpl<4, 2, 1>(values, len, out);
164
6.92k
      } else {
165
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 2);
166
6.92k
        return EstimateTokenCostImpl<4, 2, 2>(values, len, out);
167
6.92k
      }
168
94.0k
    }
169
188k
  } else if (cfg.split_exponent == 5) {
170
48.4k
    if (cfg.msb_in_token == 1) {
171
20.7k
      if (cfg.lsb_in_token == 0) {
172
6.92k
        return EstimateTokenCostImpl<5, 1, 0>(values, len, out);
173
13.8k
      } else if (cfg.lsb_in_token == 2) {
174
6.92k
        return EstimateTokenCostImpl<5, 1, 2>(values, len, out);
175
6.92k
      } else {
176
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 4);
177
6.92k
        return EstimateTokenCostImpl<5, 1, 4>(values, len, out);
178
6.92k
      }
179
27.7k
    } else {
180
27.7k
      JXL_DASSERT(cfg.msb_in_token == 2);
181
27.7k
      if (cfg.lsb_in_token == 0) {
182
6.92k
        return EstimateTokenCostImpl<5, 2, 0>(values, len, out);
183
20.7k
      } else if (cfg.lsb_in_token == 1) {
184
6.92k
        return EstimateTokenCostImpl<5, 2, 1>(values, len, out);
185
13.8k
      } else if (cfg.lsb_in_token == 2) {
186
6.92k
        return EstimateTokenCostImpl<5, 2, 2>(values, len, out);
187
6.92k
      } else {
188
6.92k
        JXL_DASSERT(cfg.lsb_in_token == 3);
189
6.92k
        return EstimateTokenCostImpl<5, 2, 3>(values, len, out);
190
6.92k
      }
191
27.7k
    }
192
51.6k
  } else if (cfg.split_exponent == 6) {
193
18.8k
    if (cfg.msb_in_token == 0) {
194
6.92k
      JXL_DASSERT(cfg.lsb_in_token == 0);
195
6.92k
      return EstimateTokenCostImpl<6, 0, 0>(values, len, out);
196
11.9k
    } else if (cfg.msb_in_token == 1) {
197
5.97k
      JXL_DASSERT(cfg.lsb_in_token == 5);
198
5.97k
      return EstimateTokenCostImpl<6, 1, 5>(values, len, out);
199
5.97k
    } else {
200
5.97k
      JXL_DASSERT(cfg.msb_in_token == 2);
201
5.97k
      JXL_DASSERT(cfg.lsb_in_token == 4);
202
5.97k
      return EstimateTokenCostImpl<6, 2, 4>(values, len, out);
203
5.97k
    }
204
32.7k
  } else if (cfg.split_exponent >= 7 && cfg.split_exponent <= 12) {
205
32.7k
    JXL_DASSERT(cfg.msb_in_token == 0);
206
32.7k
    JXL_DASSERT(cfg.lsb_in_token == 0);
207
32.7k
    if (cfg.split_exponent == 7) {
208
6.92k
      return EstimateTokenCostImpl<7, 0, 0>(values, len, out);
209
25.7k
    } else if (cfg.split_exponent == 8) {
210
5.15k
      return EstimateTokenCostImpl<8, 0, 0>(values, len, out);
211
20.6k
    } else if (cfg.split_exponent == 9) {
212
5.15k
      return EstimateTokenCostImpl<9, 0, 0>(values, len, out);
213
15.4k
    } else if (cfg.split_exponent == 10) {
214
5.15k
      return EstimateTokenCostImpl<10, 0, 0>(values, len, out);
215
10.3k
    } else if (cfg.split_exponent == 11) {
216
5.15k
      return EstimateTokenCostImpl<11, 0, 0>(values, len, out);
217
5.15k
    } else {
218
5.15k
      return EstimateTokenCostImpl<12, 0, 0>(values, len, out);
219
5.15k
    }
220
32.7k
  } else {
221
0
    JXL_DASSERT(false);
222
0
  }
223
0
  return ~0;
224
476k
#endif
225
476k
}
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
476k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
239
476k
  JXL_DASSERT(cfg.lsb_in_token + cfg.msb_in_token <= cfg.split_exponent);
240
476k
  return HWY_DYNAMIC_DISPATCH(EstimateTokenCost)(values, len, cfg, tokens);
241
476k
}
242
243
}  // namespace jxl
244
#endif