Coverage Report

Created: 2026-09-28 06:47

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