Coverage Report

Created: 2026-05-16 07:22

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