Coverage Report

Created: 2025-10-12 07:48

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