Coverage Report

Created: 2026-09-13 07:02

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
523k
                               uint32_t* JXL_RESTRICT out) {
46
523k
  const HWY_FULL(uint32_t) du;
47
523k
  const HWY_FULL(float) df;
48
523k
  const auto kZero = Zero(du);
49
523k
  const auto kSplit = Set(du, 1 << E);
50
523k
  const auto kExpOffset = Set(du, 127);
51
523k
  const auto kEBOffset = Set(du, 127 + M + L);
52
523k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
523k
  const auto kMulN = Set(du, 1 << (M + L));
54
523k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
523k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
523k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
523k
  constexpr size_t kLargeShiftVal = 10;
58
523k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
523k
  auto extra_bits = kZero;
61
523k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
68.2M
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
67.6M
    const auto val = LoadU(du, values + i);
64
67.6M
    const auto is_large = Gt(val, kLargeThreshold);
65
67.6M
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
67.6M
    const auto not_literal = Ge(val, kSplit);
67
67.6M
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
67.6M
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
67.6M
    const auto l = And(val, kMaskL);
70
67.6M
    const auto exp = ShiftRight<23>(b);
71
67.6M
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
67.6M
    const auto n = Sub(exp_fixed, kExpOffset);
73
67.6M
    const auto eb = Sub(exp_fixed, kEBOffset);
74
67.6M
    const auto m = ShiftRight<23 - M - L>(b);
75
67.6M
    const auto a = Add(kBase, Mul(n, kMulN));
76
67.6M
    const auto d = And(m, kMaskM);
77
67.6M
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
67.6M
    const auto c = Or(a, l);
79
67.6M
    extra_bits = Add(extra_bits, eb_fixed);
80
67.6M
    const auto t = Or(c, d);
81
67.6M
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
67.6M
    Store(t_fixed, du, out + i);
83
67.6M
  }
84
523k
  if (last_full < len) {
85
450k
    const auto stop = Set(du, len);
86
450k
    const auto fence = Iota(du, last_full);
87
450k
    const auto take = Lt(fence, stop);
88
450k
    const auto val = LoadU(du, values + last_full);
89
450k
    const auto is_large = Gt(val, kLargeThreshold);
90
450k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
450k
    const auto not_literal = Ge(val, kSplit);
92
450k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
450k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
450k
    const auto l = And(val, kMaskL);
95
450k
    const auto exp = ShiftRight<23>(b);
96
450k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
450k
    const auto n = Sub(exp_fixed, kExpOffset);
98
450k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
450k
    const auto m = ShiftRight<23 - M - L>(b);
100
450k
    const auto a = Add(kBase, Mul(n, kMulN));
101
450k
    const auto d = And(m, kMaskM);
102
450k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
450k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
450k
    const auto c = Or(a, l);
105
450k
    extra_bits = Add(extra_bits, eb_masked);
106
450k
    const auto t = Or(c, d);
107
450k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
450k
    Store(t_fixed, du, out + last_full);
109
450k
  }
110
523k
  return GetLane(SumOfLanes(du, extra_bits));
111
523k
}
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<0ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<2ul, 0ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<3ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<3ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<3ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<3ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 1ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<4ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 1ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<5ul, 2ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<6ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<6ul, 1ul, 5ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<6ul, 2ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<7ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<8ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<9ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<10ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<11ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Unexecuted instantiation: unsigned int jxl::N_SSE4::EstimateTokenCostImpl<12ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<0ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
88.1k
                               uint32_t* JXL_RESTRICT out) {
46
88.1k
  const HWY_FULL(uint32_t) du;
47
88.1k
  const HWY_FULL(float) df;
48
88.1k
  const auto kZero = Zero(du);
49
88.1k
  const auto kSplit = Set(du, 1 << E);
50
88.1k
  const auto kExpOffset = Set(du, 127);
51
88.1k
  const auto kEBOffset = Set(du, 127 + M + L);
52
88.1k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
88.1k
  const auto kMulN = Set(du, 1 << (M + L));
54
88.1k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
88.1k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
88.1k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
88.1k
  constexpr size_t kLargeShiftVal = 10;
58
88.1k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
88.1k
  auto extra_bits = kZero;
61
88.1k
  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
88.1k
  if (last_full < len) {
85
76.3k
    const auto stop = Set(du, len);
86
76.3k
    const auto fence = Iota(du, last_full);
87
76.3k
    const auto take = Lt(fence, stop);
88
76.3k
    const auto val = LoadU(du, values + last_full);
89
76.3k
    const auto is_large = Gt(val, kLargeThreshold);
90
76.3k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
76.3k
    const auto not_literal = Ge(val, kSplit);
92
76.3k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
76.3k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
76.3k
    const auto l = And(val, kMaskL);
95
76.3k
    const auto exp = ShiftRight<23>(b);
96
76.3k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
76.3k
    const auto n = Sub(exp_fixed, kExpOffset);
98
76.3k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
76.3k
    const auto m = ShiftRight<23 - M - L>(b);
100
76.3k
    const auto a = Add(kBase, Mul(n, kMulN));
101
76.3k
    const auto d = And(m, kMaskM);
102
76.3k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
76.3k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
76.3k
    const auto c = Or(a, l);
105
76.3k
    extra_bits = Add(extra_bits, eb_masked);
106
76.3k
    const auto t = Or(c, d);
107
76.3k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
76.3k
    Store(t_fixed, du, out + last_full);
109
76.3k
  }
110
88.1k
  return GetLane(SumOfLanes(du, extra_bits));
111
88.1k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<2ul, 0ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
87.4k
                               uint32_t* JXL_RESTRICT out) {
46
87.4k
  const HWY_FULL(uint32_t) du;
47
87.4k
  const HWY_FULL(float) df;
48
87.4k
  const auto kZero = Zero(du);
49
87.4k
  const auto kSplit = Set(du, 1 << E);
50
87.4k
  const auto kExpOffset = Set(du, 127);
51
87.4k
  const auto kEBOffset = Set(du, 127 + M + L);
52
87.4k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
87.4k
  const auto kMulN = Set(du, 1 << (M + L));
54
87.4k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
87.4k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
87.4k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
87.4k
  constexpr size_t kLargeShiftVal = 10;
58
87.4k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
87.4k
  auto extra_bits = kZero;
61
87.4k
  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.4k
  if (last_full < len) {
85
75.7k
    const auto stop = Set(du, len);
86
75.7k
    const auto fence = Iota(du, last_full);
87
75.7k
    const auto take = Lt(fence, stop);
88
75.7k
    const auto val = LoadU(du, values + last_full);
89
75.7k
    const auto is_large = Gt(val, kLargeThreshold);
90
75.7k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
75.7k
    const auto not_literal = Ge(val, kSplit);
92
75.7k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
75.7k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
75.7k
    const auto l = And(val, kMaskL);
95
75.7k
    const auto exp = ShiftRight<23>(b);
96
75.7k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
75.7k
    const auto n = Sub(exp_fixed, kExpOffset);
98
75.7k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
75.7k
    const auto m = ShiftRight<23 - M - L>(b);
100
75.7k
    const auto a = Add(kBase, Mul(n, kMulN));
101
75.7k
    const auto d = And(m, kMaskM);
102
75.7k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
75.7k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
75.7k
    const auto c = Or(a, l);
105
75.7k
    extra_bits = Add(extra_bits, eb_masked);
106
75.7k
    const auto t = Or(c, d);
107
75.7k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
75.7k
    Store(t_fixed, du, out + last_full);
109
75.7k
  }
110
87.4k
  return GetLane(SumOfLanes(du, extra_bits));
111
87.4k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<3ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
87.4k
                               uint32_t* JXL_RESTRICT out) {
46
87.4k
  const HWY_FULL(uint32_t) du;
47
87.4k
  const HWY_FULL(float) df;
48
87.4k
  const auto kZero = Zero(du);
49
87.4k
  const auto kSplit = Set(du, 1 << E);
50
87.4k
  const auto kExpOffset = Set(du, 127);
51
87.4k
  const auto kEBOffset = Set(du, 127 + M + L);
52
87.4k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
87.4k
  const auto kMulN = Set(du, 1 << (M + L));
54
87.4k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
87.4k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
87.4k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
87.4k
  constexpr size_t kLargeShiftVal = 10;
58
87.4k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
87.4k
  auto extra_bits = kZero;
61
87.4k
  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.4k
  if (last_full < len) {
85
75.7k
    const auto stop = Set(du, len);
86
75.7k
    const auto fence = Iota(du, last_full);
87
75.7k
    const auto take = Lt(fence, stop);
88
75.7k
    const auto val = LoadU(du, values + last_full);
89
75.7k
    const auto is_large = Gt(val, kLargeThreshold);
90
75.7k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
75.7k
    const auto not_literal = Ge(val, kSplit);
92
75.7k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
75.7k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
75.7k
    const auto l = And(val, kMaskL);
95
75.7k
    const auto exp = ShiftRight<23>(b);
96
75.7k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
75.7k
    const auto n = Sub(exp_fixed, kExpOffset);
98
75.7k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
75.7k
    const auto m = ShiftRight<23 - M - L>(b);
100
75.7k
    const auto a = Add(kBase, Mul(n, kMulN));
101
75.7k
    const auto d = And(m, kMaskM);
102
75.7k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
75.7k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
75.7k
    const auto c = Or(a, l);
105
75.7k
    extra_bits = Add(extra_bits, eb_masked);
106
75.7k
    const auto t = Or(c, d);
107
75.7k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
75.7k
    Store(t_fixed, du, out + last_full);
109
75.7k
  }
110
87.4k
  return GetLane(SumOfLanes(du, extra_bits));
111
87.4k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 1ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
87.4k
                               uint32_t* JXL_RESTRICT out) {
46
87.4k
  const HWY_FULL(uint32_t) du;
47
87.4k
  const HWY_FULL(float) df;
48
87.4k
  const auto kZero = Zero(du);
49
87.4k
  const auto kSplit = Set(du, 1 << E);
50
87.4k
  const auto kExpOffset = Set(du, 127);
51
87.4k
  const auto kEBOffset = Set(du, 127 + M + L);
52
87.4k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
87.4k
  const auto kMulN = Set(du, 1 << (M + L));
54
87.4k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
87.4k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
87.4k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
87.4k
  constexpr size_t kLargeShiftVal = 10;
58
87.4k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
87.4k
  auto extra_bits = kZero;
61
87.4k
  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.4k
  if (last_full < len) {
85
75.7k
    const auto stop = Set(du, len);
86
75.7k
    const auto fence = Iota(du, last_full);
87
75.7k
    const auto take = Lt(fence, stop);
88
75.7k
    const auto val = LoadU(du, values + last_full);
89
75.7k
    const auto is_large = Gt(val, kLargeThreshold);
90
75.7k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
75.7k
    const auto not_literal = Ge(val, kSplit);
92
75.7k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
75.7k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
75.7k
    const auto l = And(val, kMaskL);
95
75.7k
    const auto exp = ShiftRight<23>(b);
96
75.7k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
75.7k
    const auto n = Sub(exp_fixed, kExpOffset);
98
75.7k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
75.7k
    const auto m = ShiftRight<23 - M - L>(b);
100
75.7k
    const auto a = Add(kBase, Mul(n, kMulN));
101
75.7k
    const auto d = And(m, kMaskM);
102
75.7k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
75.7k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
75.7k
    const auto c = Or(a, l);
105
75.7k
    extra_bits = Add(extra_bits, eb_masked);
106
75.7k
    const auto t = Or(c, d);
107
75.7k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
75.7k
    Store(t_fixed, du, out + last_full);
109
75.7k
  }
110
87.4k
  return GetLane(SumOfLanes(du, extra_bits));
111
87.4k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<4ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 1ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.51k
    const auto stop = Set(du, len);
86
6.51k
    const auto fence = Iota(du, last_full);
87
6.51k
    const auto take = Lt(fence, stop);
88
6.51k
    const auto val = LoadU(du, values + last_full);
89
6.51k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.51k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.51k
    const auto not_literal = Ge(val, kSplit);
92
6.51k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.51k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.51k
    const auto l = And(val, kMaskL);
95
6.51k
    const auto exp = ShiftRight<23>(b);
96
6.51k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.51k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.51k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.51k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.51k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.51k
    const auto d = And(m, kMaskM);
102
6.51k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.51k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.51k
    const auto c = Or(a, l);
105
6.51k
    extra_bits = Add(extra_bits, eb_masked);
106
6.51k
    const auto t = Or(c, d);
107
6.51k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.51k
    Store(t_fixed, du, out + last_full);
109
6.51k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 1ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 2ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<5ul, 2ul, 3ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.51k
    const auto stop = Set(du, len);
86
6.51k
    const auto fence = Iota(du, last_full);
87
6.51k
    const auto take = Lt(fence, stop);
88
6.51k
    const auto val = LoadU(du, values + last_full);
89
6.51k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.51k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.51k
    const auto not_literal = Ge(val, kSplit);
92
6.51k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.51k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.51k
    const auto l = And(val, kMaskL);
95
6.51k
    const auto exp = ShiftRight<23>(b);
96
6.51k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.51k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.51k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.51k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.51k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.51k
    const auto d = And(m, kMaskM);
102
6.51k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.51k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.51k
    const auto c = Or(a, l);
105
6.51k
    extra_bits = Add(extra_bits, eb_masked);
106
6.51k
    const auto t = Or(c, d);
107
6.51k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.51k
    Store(t_fixed, du, out + last_full);
109
6.51k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 1ul, 5ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
6.66k
                               uint32_t* JXL_RESTRICT out) {
46
6.66k
  const HWY_FULL(uint32_t) du;
47
6.66k
  const HWY_FULL(float) df;
48
6.66k
  const auto kZero = Zero(du);
49
6.66k
  const auto kSplit = Set(du, 1 << E);
50
6.66k
  const auto kExpOffset = Set(du, 127);
51
6.66k
  const auto kEBOffset = Set(du, 127 + M + L);
52
6.66k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
6.66k
  const auto kMulN = Set(du, 1 << (M + L));
54
6.66k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
6.66k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
6.66k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
6.66k
  constexpr size_t kLargeShiftVal = 10;
58
6.66k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
6.66k
  auto extra_bits = kZero;
61
6.66k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
399k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
393k
    const auto val = LoadU(du, values + i);
64
393k
    const auto is_large = Gt(val, kLargeThreshold);
65
393k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
393k
    const auto not_literal = Ge(val, kSplit);
67
393k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
393k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
393k
    const auto l = And(val, kMaskL);
70
393k
    const auto exp = ShiftRight<23>(b);
71
393k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
393k
    const auto n = Sub(exp_fixed, kExpOffset);
73
393k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
393k
    const auto m = ShiftRight<23 - M - L>(b);
75
393k
    const auto a = Add(kBase, Mul(n, kMulN));
76
393k
    const auto d = And(m, kMaskM);
77
393k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
393k
    const auto c = Or(a, l);
79
393k
    extra_bits = Add(extra_bits, eb_fixed);
80
393k
    const auto t = Or(c, d);
81
393k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
393k
    Store(t_fixed, du, out + i);
83
393k
  }
84
6.66k
  if (last_full < len) {
85
5.69k
    const auto stop = Set(du, len);
86
5.69k
    const auto fence = Iota(du, last_full);
87
5.69k
    const auto take = Lt(fence, stop);
88
5.69k
    const auto val = LoadU(du, values + last_full);
89
5.69k
    const auto is_large = Gt(val, kLargeThreshold);
90
5.69k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
5.69k
    const auto not_literal = Ge(val, kSplit);
92
5.69k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
5.69k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
5.69k
    const auto l = And(val, kMaskL);
95
5.69k
    const auto exp = ShiftRight<23>(b);
96
5.69k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
5.69k
    const auto n = Sub(exp_fixed, kExpOffset);
98
5.69k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
5.69k
    const auto m = ShiftRight<23 - M - L>(b);
100
5.69k
    const auto a = Add(kBase, Mul(n, kMulN));
101
5.69k
    const auto d = And(m, kMaskM);
102
5.69k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
5.69k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
5.69k
    const auto c = Or(a, l);
105
5.69k
    extra_bits = Add(extra_bits, eb_masked);
106
5.69k
    const auto t = Or(c, d);
107
5.69k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
5.69k
    Store(t_fixed, du, out + last_full);
109
5.69k
  }
110
6.66k
  return GetLane(SumOfLanes(du, extra_bits));
111
6.66k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<6ul, 2ul, 4ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
6.66k
                               uint32_t* JXL_RESTRICT out) {
46
6.66k
  const HWY_FULL(uint32_t) du;
47
6.66k
  const HWY_FULL(float) df;
48
6.66k
  const auto kZero = Zero(du);
49
6.66k
  const auto kSplit = Set(du, 1 << E);
50
6.66k
  const auto kExpOffset = Set(du, 127);
51
6.66k
  const auto kEBOffset = Set(du, 127 + M + L);
52
6.66k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
6.66k
  const auto kMulN = Set(du, 1 << (M + L));
54
6.66k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
6.66k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
6.66k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
6.66k
  constexpr size_t kLargeShiftVal = 10;
58
6.66k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
6.66k
  auto extra_bits = kZero;
61
6.66k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
399k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
393k
    const auto val = LoadU(du, values + i);
64
393k
    const auto is_large = Gt(val, kLargeThreshold);
65
393k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
393k
    const auto not_literal = Ge(val, kSplit);
67
393k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
393k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
393k
    const auto l = And(val, kMaskL);
70
393k
    const auto exp = ShiftRight<23>(b);
71
393k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
393k
    const auto n = Sub(exp_fixed, kExpOffset);
73
393k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
393k
    const auto m = ShiftRight<23 - M - L>(b);
75
393k
    const auto a = Add(kBase, Mul(n, kMulN));
76
393k
    const auto d = And(m, kMaskM);
77
393k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
393k
    const auto c = Or(a, l);
79
393k
    extra_bits = Add(extra_bits, eb_fixed);
80
393k
    const auto t = Or(c, d);
81
393k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
393k
    Store(t_fixed, du, out + i);
83
393k
  }
84
6.66k
  if (last_full < len) {
85
5.69k
    const auto stop = Set(du, len);
86
5.69k
    const auto fence = Iota(du, last_full);
87
5.69k
    const auto take = Lt(fence, stop);
88
5.69k
    const auto val = LoadU(du, values + last_full);
89
5.69k
    const auto is_large = Gt(val, kLargeThreshold);
90
5.69k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
5.69k
    const auto not_literal = Ge(val, kSplit);
92
5.69k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
5.69k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
5.69k
    const auto l = And(val, kMaskL);
95
5.69k
    const auto exp = ShiftRight<23>(b);
96
5.69k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
5.69k
    const auto n = Sub(exp_fixed, kExpOffset);
98
5.69k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
5.69k
    const auto m = ShiftRight<23 - M - L>(b);
100
5.69k
    const auto a = Add(kBase, Mul(n, kMulN));
101
5.69k
    const auto d = And(m, kMaskM);
102
5.69k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
5.69k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
5.69k
    const auto c = Or(a, l);
105
5.69k
    extra_bits = Add(extra_bits, eb_masked);
106
5.69k
    const auto t = Or(c, d);
107
5.69k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
5.69k
    Store(t_fixed, du, out + last_full);
109
5.69k
  }
110
6.66k
  return GetLane(SumOfLanes(du, extra_bits));
111
6.66k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<7ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
7.68k
                               uint32_t* JXL_RESTRICT out) {
46
7.68k
  const HWY_FULL(uint32_t) du;
47
7.68k
  const HWY_FULL(float) df;
48
7.68k
  const auto kZero = Zero(du);
49
7.68k
  const auto kSplit = Set(du, 1 << E);
50
7.68k
  const auto kExpOffset = Set(du, 127);
51
7.68k
  const auto kEBOffset = Set(du, 127 + M + L);
52
7.68k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
7.68k
  const auto kMulN = Set(du, 1 << (M + L));
54
7.68k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
7.68k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
7.68k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
7.68k
  constexpr size_t kLargeShiftVal = 10;
58
7.68k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
7.68k
  auto extra_bits = kZero;
61
7.68k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
783k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
776k
    const auto val = LoadU(du, values + i);
64
776k
    const auto is_large = Gt(val, kLargeThreshold);
65
776k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
776k
    const auto not_literal = Ge(val, kSplit);
67
776k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
776k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
776k
    const auto l = And(val, kMaskL);
70
776k
    const auto exp = ShiftRight<23>(b);
71
776k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
776k
    const auto n = Sub(exp_fixed, kExpOffset);
73
776k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
776k
    const auto m = ShiftRight<23 - M - L>(b);
75
776k
    const auto a = Add(kBase, Mul(n, kMulN));
76
776k
    const auto d = And(m, kMaskM);
77
776k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
776k
    const auto c = Or(a, l);
79
776k
    extra_bits = Add(extra_bits, eb_fixed);
80
776k
    const auto t = Or(c, d);
81
776k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
776k
    Store(t_fixed, du, out + i);
83
776k
  }
84
7.68k
  if (last_full < len) {
85
6.52k
    const auto stop = Set(du, len);
86
6.52k
    const auto fence = Iota(du, last_full);
87
6.52k
    const auto take = Lt(fence, stop);
88
6.52k
    const auto val = LoadU(du, values + last_full);
89
6.52k
    const auto is_large = Gt(val, kLargeThreshold);
90
6.52k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
6.52k
    const auto not_literal = Ge(val, kSplit);
92
6.52k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
6.52k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
6.52k
    const auto l = And(val, kMaskL);
95
6.52k
    const auto exp = ShiftRight<23>(b);
96
6.52k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
6.52k
    const auto n = Sub(exp_fixed, kExpOffset);
98
6.52k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
6.52k
    const auto m = ShiftRight<23 - M - L>(b);
100
6.52k
    const auto a = Add(kBase, Mul(n, kMulN));
101
6.52k
    const auto d = And(m, kMaskM);
102
6.52k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
6.52k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
6.52k
    const auto c = Or(a, l);
105
6.52k
    extra_bits = Add(extra_bits, eb_masked);
106
6.52k
    const auto t = Or(c, d);
107
6.52k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
6.52k
    Store(t_fixed, du, out + last_full);
109
6.52k
  }
110
7.68k
  return GetLane(SumOfLanes(du, extra_bits));
111
7.68k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<8ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
5.74k
                               uint32_t* JXL_RESTRICT out) {
46
5.74k
  const HWY_FULL(uint32_t) du;
47
5.74k
  const HWY_FULL(float) df;
48
5.74k
  const auto kZero = Zero(du);
49
5.74k
  const auto kSplit = Set(du, 1 << E);
50
5.74k
  const auto kExpOffset = Set(du, 127);
51
5.74k
  const auto kEBOffset = Set(du, 127 + M + L);
52
5.74k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
5.74k
  const auto kMulN = Set(du, 1 << (M + L));
54
5.74k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
5.74k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
5.74k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
5.74k
  constexpr size_t kLargeShiftVal = 10;
58
5.74k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
5.74k
  auto extra_bits = kZero;
61
5.74k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
365k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
359k
    const auto val = LoadU(du, values + i);
64
359k
    const auto is_large = Gt(val, kLargeThreshold);
65
359k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
359k
    const auto not_literal = Ge(val, kSplit);
67
359k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
359k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
359k
    const auto l = And(val, kMaskL);
70
359k
    const auto exp = ShiftRight<23>(b);
71
359k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
359k
    const auto n = Sub(exp_fixed, kExpOffset);
73
359k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
359k
    const auto m = ShiftRight<23 - M - L>(b);
75
359k
    const auto a = Add(kBase, Mul(n, kMulN));
76
359k
    const auto d = And(m, kMaskM);
77
359k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
359k
    const auto c = Or(a, l);
79
359k
    extra_bits = Add(extra_bits, eb_fixed);
80
359k
    const auto t = Or(c, d);
81
359k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
359k
    Store(t_fixed, du, out + i);
83
359k
  }
84
5.74k
  if (last_full < len) {
85
4.86k
    const auto stop = Set(du, len);
86
4.86k
    const auto fence = Iota(du, last_full);
87
4.86k
    const auto take = Lt(fence, stop);
88
4.86k
    const auto val = LoadU(du, values + last_full);
89
4.86k
    const auto is_large = Gt(val, kLargeThreshold);
90
4.86k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
4.86k
    const auto not_literal = Ge(val, kSplit);
92
4.86k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
4.86k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
4.86k
    const auto l = And(val, kMaskL);
95
4.86k
    const auto exp = ShiftRight<23>(b);
96
4.86k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
4.86k
    const auto n = Sub(exp_fixed, kExpOffset);
98
4.86k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
4.86k
    const auto m = ShiftRight<23 - M - L>(b);
100
4.86k
    const auto a = Add(kBase, Mul(n, kMulN));
101
4.86k
    const auto d = And(m, kMaskM);
102
4.86k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
4.86k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
4.86k
    const auto c = Or(a, l);
105
4.86k
    extra_bits = Add(extra_bits, eb_masked);
106
4.86k
    const auto t = Or(c, d);
107
4.86k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
4.86k
    Store(t_fixed, du, out + last_full);
109
4.86k
  }
110
5.74k
  return GetLane(SumOfLanes(du, extra_bits));
111
5.74k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<9ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
5.74k
                               uint32_t* JXL_RESTRICT out) {
46
5.74k
  const HWY_FULL(uint32_t) du;
47
5.74k
  const HWY_FULL(float) df;
48
5.74k
  const auto kZero = Zero(du);
49
5.74k
  const auto kSplit = Set(du, 1 << E);
50
5.74k
  const auto kExpOffset = Set(du, 127);
51
5.74k
  const auto kEBOffset = Set(du, 127 + M + L);
52
5.74k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
5.74k
  const auto kMulN = Set(du, 1 << (M + L));
54
5.74k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
5.74k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
5.74k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
5.74k
  constexpr size_t kLargeShiftVal = 10;
58
5.74k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
5.74k
  auto extra_bits = kZero;
61
5.74k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
365k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
359k
    const auto val = LoadU(du, values + i);
64
359k
    const auto is_large = Gt(val, kLargeThreshold);
65
359k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
359k
    const auto not_literal = Ge(val, kSplit);
67
359k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
359k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
359k
    const auto l = And(val, kMaskL);
70
359k
    const auto exp = ShiftRight<23>(b);
71
359k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
359k
    const auto n = Sub(exp_fixed, kExpOffset);
73
359k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
359k
    const auto m = ShiftRight<23 - M - L>(b);
75
359k
    const auto a = Add(kBase, Mul(n, kMulN));
76
359k
    const auto d = And(m, kMaskM);
77
359k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
359k
    const auto c = Or(a, l);
79
359k
    extra_bits = Add(extra_bits, eb_fixed);
80
359k
    const auto t = Or(c, d);
81
359k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
359k
    Store(t_fixed, du, out + i);
83
359k
  }
84
5.74k
  if (last_full < len) {
85
4.86k
    const auto stop = Set(du, len);
86
4.86k
    const auto fence = Iota(du, last_full);
87
4.86k
    const auto take = Lt(fence, stop);
88
4.86k
    const auto val = LoadU(du, values + last_full);
89
4.86k
    const auto is_large = Gt(val, kLargeThreshold);
90
4.86k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
4.86k
    const auto not_literal = Ge(val, kSplit);
92
4.86k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
4.86k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
4.86k
    const auto l = And(val, kMaskL);
95
4.86k
    const auto exp = ShiftRight<23>(b);
96
4.86k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
4.86k
    const auto n = Sub(exp_fixed, kExpOffset);
98
4.86k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
4.86k
    const auto m = ShiftRight<23 - M - L>(b);
100
4.86k
    const auto a = Add(kBase, Mul(n, kMulN));
101
4.86k
    const auto d = And(m, kMaskM);
102
4.86k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
4.86k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
4.86k
    const auto c = Or(a, l);
105
4.86k
    extra_bits = Add(extra_bits, eb_masked);
106
4.86k
    const auto t = Or(c, d);
107
4.86k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
4.86k
    Store(t_fixed, du, out + last_full);
109
4.86k
  }
110
5.74k
  return GetLane(SumOfLanes(du, extra_bits));
111
5.74k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<10ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
5.74k
                               uint32_t* JXL_RESTRICT out) {
46
5.74k
  const HWY_FULL(uint32_t) du;
47
5.74k
  const HWY_FULL(float) df;
48
5.74k
  const auto kZero = Zero(du);
49
5.74k
  const auto kSplit = Set(du, 1 << E);
50
5.74k
  const auto kExpOffset = Set(du, 127);
51
5.74k
  const auto kEBOffset = Set(du, 127 + M + L);
52
5.74k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
5.74k
  const auto kMulN = Set(du, 1 << (M + L));
54
5.74k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
5.74k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
5.74k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
5.74k
  constexpr size_t kLargeShiftVal = 10;
58
5.74k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
5.74k
  auto extra_bits = kZero;
61
5.74k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
365k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
359k
    const auto val = LoadU(du, values + i);
64
359k
    const auto is_large = Gt(val, kLargeThreshold);
65
359k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
359k
    const auto not_literal = Ge(val, kSplit);
67
359k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
359k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
359k
    const auto l = And(val, kMaskL);
70
359k
    const auto exp = ShiftRight<23>(b);
71
359k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
359k
    const auto n = Sub(exp_fixed, kExpOffset);
73
359k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
359k
    const auto m = ShiftRight<23 - M - L>(b);
75
359k
    const auto a = Add(kBase, Mul(n, kMulN));
76
359k
    const auto d = And(m, kMaskM);
77
359k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
359k
    const auto c = Or(a, l);
79
359k
    extra_bits = Add(extra_bits, eb_fixed);
80
359k
    const auto t = Or(c, d);
81
359k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
359k
    Store(t_fixed, du, out + i);
83
359k
  }
84
5.74k
  if (last_full < len) {
85
4.86k
    const auto stop = Set(du, len);
86
4.86k
    const auto fence = Iota(du, last_full);
87
4.86k
    const auto take = Lt(fence, stop);
88
4.86k
    const auto val = LoadU(du, values + last_full);
89
4.86k
    const auto is_large = Gt(val, kLargeThreshold);
90
4.86k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
4.86k
    const auto not_literal = Ge(val, kSplit);
92
4.86k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
4.86k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
4.86k
    const auto l = And(val, kMaskL);
95
4.86k
    const auto exp = ShiftRight<23>(b);
96
4.86k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
4.86k
    const auto n = Sub(exp_fixed, kExpOffset);
98
4.86k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
4.86k
    const auto m = ShiftRight<23 - M - L>(b);
100
4.86k
    const auto a = Add(kBase, Mul(n, kMulN));
101
4.86k
    const auto d = And(m, kMaskM);
102
4.86k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
4.86k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
4.86k
    const auto c = Or(a, l);
105
4.86k
    extra_bits = Add(extra_bits, eb_masked);
106
4.86k
    const auto t = Or(c, d);
107
4.86k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
4.86k
    Store(t_fixed, du, out + last_full);
109
4.86k
  }
110
5.74k
  return GetLane(SumOfLanes(du, extra_bits));
111
5.74k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<11ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
5.74k
                               uint32_t* JXL_RESTRICT out) {
46
5.74k
  const HWY_FULL(uint32_t) du;
47
5.74k
  const HWY_FULL(float) df;
48
5.74k
  const auto kZero = Zero(du);
49
5.74k
  const auto kSplit = Set(du, 1 << E);
50
5.74k
  const auto kExpOffset = Set(du, 127);
51
5.74k
  const auto kEBOffset = Set(du, 127 + M + L);
52
5.74k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
5.74k
  const auto kMulN = Set(du, 1 << (M + L));
54
5.74k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
5.74k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
5.74k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
5.74k
  constexpr size_t kLargeShiftVal = 10;
58
5.74k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
5.74k
  auto extra_bits = kZero;
61
5.74k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
365k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
359k
    const auto val = LoadU(du, values + i);
64
359k
    const auto is_large = Gt(val, kLargeThreshold);
65
359k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
359k
    const auto not_literal = Ge(val, kSplit);
67
359k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
359k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
359k
    const auto l = And(val, kMaskL);
70
359k
    const auto exp = ShiftRight<23>(b);
71
359k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
359k
    const auto n = Sub(exp_fixed, kExpOffset);
73
359k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
359k
    const auto m = ShiftRight<23 - M - L>(b);
75
359k
    const auto a = Add(kBase, Mul(n, kMulN));
76
359k
    const auto d = And(m, kMaskM);
77
359k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
359k
    const auto c = Or(a, l);
79
359k
    extra_bits = Add(extra_bits, eb_fixed);
80
359k
    const auto t = Or(c, d);
81
359k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
359k
    Store(t_fixed, du, out + i);
83
359k
  }
84
5.74k
  if (last_full < len) {
85
4.86k
    const auto stop = Set(du, len);
86
4.86k
    const auto fence = Iota(du, last_full);
87
4.86k
    const auto take = Lt(fence, stop);
88
4.86k
    const auto val = LoadU(du, values + last_full);
89
4.86k
    const auto is_large = Gt(val, kLargeThreshold);
90
4.86k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
4.86k
    const auto not_literal = Ge(val, kSplit);
92
4.86k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
4.86k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
4.86k
    const auto l = And(val, kMaskL);
95
4.86k
    const auto exp = ShiftRight<23>(b);
96
4.86k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
4.86k
    const auto n = Sub(exp_fixed, kExpOffset);
98
4.86k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
4.86k
    const auto m = ShiftRight<23 - M - L>(b);
100
4.86k
    const auto a = Add(kBase, Mul(n, kMulN));
101
4.86k
    const auto d = And(m, kMaskM);
102
4.86k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
4.86k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
4.86k
    const auto c = Or(a, l);
105
4.86k
    extra_bits = Add(extra_bits, eb_masked);
106
4.86k
    const auto t = Or(c, d);
107
4.86k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
4.86k
    Store(t_fixed, du, out + last_full);
109
4.86k
  }
110
5.74k
  return GetLane(SumOfLanes(du, extra_bits));
111
5.74k
}
unsigned int jxl::N_AVX2::EstimateTokenCostImpl<12ul, 0ul, 0ul>(unsigned int*, unsigned long, unsigned int*)
Line
Count
Source
45
5.74k
                               uint32_t* JXL_RESTRICT out) {
46
5.74k
  const HWY_FULL(uint32_t) du;
47
5.74k
  const HWY_FULL(float) df;
48
5.74k
  const auto kZero = Zero(du);
49
5.74k
  const auto kSplit = Set(du, 1 << E);
50
5.74k
  const auto kExpOffset = Set(du, 127);
51
5.74k
  const auto kEBOffset = Set(du, 127 + M + L);
52
5.74k
  const auto kBase = Set(du, static_cast<uint32_t>((1 << E) - (E << (M + L))));
53
5.74k
  const auto kMulN = Set(du, 1 << (M + L));
54
5.74k
  const auto kMaskL = Set(du, (1 << L) - 1);
55
5.74k
  const auto kMaskM = Set(du, ((1 << M) - 1) << L);
56
5.74k
  const auto kLargeThreshold = Set(du, (1 << 22) - 1);
57
5.74k
  constexpr size_t kLargeShiftVal = 10;
58
5.74k
  const auto kLargeShift = Set(du, kLargeShiftVal);
59
60
5.74k
  auto extra_bits = kZero;
61
5.74k
  size_t last_full = Lanes(du) * (len / Lanes(du));
62
365k
  for (size_t i = 0; i < last_full; i += Lanes(du)) {
63
359k
    const auto val = LoadU(du, values + i);
64
359k
    const auto is_large = Gt(val, kLargeThreshold);
65
359k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
66
359k
    const auto not_literal = Ge(val, kSplit);
67
359k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
68
359k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
69
359k
    const auto l = And(val, kMaskL);
70
359k
    const auto exp = ShiftRight<23>(b);
71
359k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
72
359k
    const auto n = Sub(exp_fixed, kExpOffset);
73
359k
    const auto eb = Sub(exp_fixed, kEBOffset);
74
359k
    const auto m = ShiftRight<23 - M - L>(b);
75
359k
    const auto a = Add(kBase, Mul(n, kMulN));
76
359k
    const auto d = And(m, kMaskM);
77
359k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
78
359k
    const auto c = Or(a, l);
79
359k
    extra_bits = Add(extra_bits, eb_fixed);
80
359k
    const auto t = Or(c, d);
81
359k
    const auto t_fixed = IfThenElse(not_literal, t, val);
82
359k
    Store(t_fixed, du, out + i);
83
359k
  }
84
5.74k
  if (last_full < len) {
85
4.86k
    const auto stop = Set(du, len);
86
4.86k
    const auto fence = Iota(du, last_full);
87
4.86k
    const auto take = Lt(fence, stop);
88
4.86k
    const auto val = LoadU(du, values + last_full);
89
4.86k
    const auto is_large = Gt(val, kLargeThreshold);
90
4.86k
    const auto val_shifted = ShiftRight<kLargeShiftVal>(val);
91
4.86k
    const auto not_literal = Ge(val, kSplit);
92
4.86k
    const auto val_fixed = IfThenElse(is_large, val_shifted, val);
93
4.86k
    const auto b = BitCast(du, ConvertTo(df, val_fixed));
94
4.86k
    const auto l = And(val, kMaskL);
95
4.86k
    const auto exp = ShiftRight<23>(b);
96
4.86k
    const auto exp_fixed = IfThenElse(is_large, Add(exp, kLargeShift), exp);
97
4.86k
    const auto n = Sub(exp_fixed, kExpOffset);
98
4.86k
    const auto eb = Sub(exp_fixed, kEBOffset);
99
4.86k
    const auto m = ShiftRight<23 - M - L>(b);
100
4.86k
    const auto a = Add(kBase, Mul(n, kMulN));
101
4.86k
    const auto d = And(m, kMaskM);
102
4.86k
    const auto eb_fixed = IfThenElseZero(not_literal, eb);
103
4.86k
    const auto eb_masked = IfThenElseZero(take, eb_fixed);
104
4.86k
    const auto c = Or(a, l);
105
4.86k
    extra_bits = Add(extra_bits, eb_masked);
106
4.86k
    const auto t = Or(c, d);
107
4.86k
    const auto t_fixed = IfThenElse(not_literal, t, val);
108
4.86k
    Store(t_fixed, du, out + last_full);
109
4.86k
  }
110
5.74k
  return GetLane(SumOfLanes(du, extra_bits));
111
5.74k
}
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
523k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
115
523k
  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
523k
  if (cfg.split_exponent == 0) {
128
88.1k
    return EstimateTokenCostImpl<0, 0, 0>(values, len, out);
129
435k
  } else if (cfg.split_exponent == 2) {
130
87.4k
    JXL_DASSERT((cfg.msb_in_token == 0) && (cfg.lsb_in_token == 1));
131
87.4k
    return EstimateTokenCostImpl<2, 0, 1>(values, len, out);
132
347k
  } else if (cfg.split_exponent == 3) {
133
30.7k
    if (cfg.msb_in_token == 1) {
134
15.3k
      if (cfg.lsb_in_token == 0) {
135
7.68k
        return EstimateTokenCostImpl<3, 1, 0>(values, len, out);
136
7.68k
      } else {
137
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 2);
138
7.68k
        return EstimateTokenCostImpl<3, 1, 2>(values, len, out);
139
7.68k
      }
140
15.3k
    } else {
141
15.3k
      JXL_DASSERT(cfg.msb_in_token == 2);
142
15.3k
      if (cfg.lsb_in_token == 0) {
143
7.68k
        return EstimateTokenCostImpl<3, 2, 0>(values, len, out);
144
7.68k
      } else {
145
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 1);
146
7.68k
        return EstimateTokenCostImpl<3, 2, 1>(values, len, out);
147
7.68k
      }
148
15.3k
    }
149
316k
  } else if (cfg.split_exponent == 4) {
150
205k
    if (cfg.msb_in_token == 1) {
151
102k
      if (cfg.lsb_in_token == 0) {
152
7.68k
        return EstimateTokenCostImpl<4, 1, 0>(values, len, out);
153
95.1k
      } else if (cfg.lsb_in_token == 2) {
154
87.4k
        return EstimateTokenCostImpl<4, 1, 2>(values, len, out);
155
87.4k
      } else {
156
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 3);
157
7.68k
        return EstimateTokenCostImpl<4, 1, 3>(values, len, out);
158
7.68k
      }
159
102k
    } else {
160
102k
      JXL_DASSERT(cfg.msb_in_token == 2);
161
102k
      if (cfg.lsb_in_token == 0) {
162
87.4k
        return EstimateTokenCostImpl<4, 2, 0>(values, len, out);
163
87.4k
      } else if (cfg.lsb_in_token == 1) {
164
7.68k
        return EstimateTokenCostImpl<4, 2, 1>(values, len, out);
165
7.68k
      } else {
166
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 2);
167
7.68k
        return EstimateTokenCostImpl<4, 2, 2>(values, len, out);
168
7.68k
      }
169
102k
    }
170
205k
  } else if (cfg.split_exponent == 5) {
171
53.7k
    if (cfg.msb_in_token == 1) {
172
23.0k
      if (cfg.lsb_in_token == 0) {
173
7.68k
        return EstimateTokenCostImpl<5, 1, 0>(values, len, out);
174
15.3k
      } else if (cfg.lsb_in_token == 2) {
175
7.68k
        return EstimateTokenCostImpl<5, 1, 2>(values, len, out);
176
7.68k
      } else {
177
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 4);
178
7.68k
        return EstimateTokenCostImpl<5, 1, 4>(values, len, out);
179
7.68k
      }
180
30.7k
    } else {
181
30.7k
      JXL_DASSERT(cfg.msb_in_token == 2);
182
30.7k
      if (cfg.lsb_in_token == 0) {
183
7.68k
        return EstimateTokenCostImpl<5, 2, 0>(values, len, out);
184
23.0k
      } else if (cfg.lsb_in_token == 1) {
185
7.68k
        return EstimateTokenCostImpl<5, 2, 1>(values, len, out);
186
15.3k
      } else if (cfg.lsb_in_token == 2) {
187
7.68k
        return EstimateTokenCostImpl<5, 2, 2>(values, len, out);
188
7.68k
      } else {
189
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 3);
190
7.68k
        return EstimateTokenCostImpl<5, 2, 3>(values, len, out);
191
7.68k
      }
192
30.7k
    }
193
57.4k
  } else if (cfg.split_exponent == 6) {
194
21.0k
    if (cfg.msb_in_token == 0) {
195
7.68k
      JXL_DASSERT(cfg.lsb_in_token == 0);
196
7.68k
      return EstimateTokenCostImpl<6, 0, 0>(values, len, out);
197
13.3k
    } else if (cfg.msb_in_token == 1) {
198
6.66k
      JXL_DASSERT(cfg.lsb_in_token == 5);
199
6.66k
      return EstimateTokenCostImpl<6, 1, 5>(values, len, out);
200
6.66k
    } else {
201
6.66k
      JXL_DASSERT(cfg.msb_in_token == 2);
202
6.66k
      JXL_DASSERT(cfg.lsb_in_token == 4);
203
6.66k
      return EstimateTokenCostImpl<6, 2, 4>(values, len, out);
204
6.66k
    }
205
36.4k
  } else if (cfg.split_exponent >= 7 && cfg.split_exponent <= 12) {
206
36.4k
    JXL_DASSERT(cfg.msb_in_token == 0);
207
36.4k
    JXL_DASSERT(cfg.lsb_in_token == 0);
208
36.4k
    if (cfg.split_exponent == 7) {
209
7.68k
      return EstimateTokenCostImpl<7, 0, 0>(values, len, out);
210
28.7k
    } else if (cfg.split_exponent == 8) {
211
5.74k
      return EstimateTokenCostImpl<8, 0, 0>(values, len, out);
212
22.9k
    } else if (cfg.split_exponent == 9) {
213
5.74k
      return EstimateTokenCostImpl<9, 0, 0>(values, len, out);
214
17.2k
    } else if (cfg.split_exponent == 10) {
215
5.74k
      return EstimateTokenCostImpl<10, 0, 0>(values, len, out);
216
11.4k
    } else if (cfg.split_exponent == 11) {
217
5.74k
      return EstimateTokenCostImpl<11, 0, 0>(values, len, out);
218
5.74k
    } else {
219
5.74k
      return EstimateTokenCostImpl<12, 0, 0>(values, len, out);
220
5.74k
    }
221
36.4k
  } else {
222
0
    JXL_DASSERT(false);
223
0
  }
224
0
  return ~0;
225
523k
#endif
226
523k
}
Unexecuted instantiation: jxl::N_SSE4::EstimateTokenCost(unsigned int*, unsigned long, jxl::HybridUintConfig, jxl::AlignedMemory&)
jxl::N_AVX2::EstimateTokenCost(unsigned int*, unsigned long, jxl::HybridUintConfig, jxl::AlignedMemory&)
Line
Count
Source
114
523k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
115
523k
  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
523k
  if (cfg.split_exponent == 0) {
128
88.1k
    return EstimateTokenCostImpl<0, 0, 0>(values, len, out);
129
435k
  } else if (cfg.split_exponent == 2) {
130
87.4k
    JXL_DASSERT((cfg.msb_in_token == 0) && (cfg.lsb_in_token == 1));
131
87.4k
    return EstimateTokenCostImpl<2, 0, 1>(values, len, out);
132
347k
  } else if (cfg.split_exponent == 3) {
133
30.7k
    if (cfg.msb_in_token == 1) {
134
15.3k
      if (cfg.lsb_in_token == 0) {
135
7.68k
        return EstimateTokenCostImpl<3, 1, 0>(values, len, out);
136
7.68k
      } else {
137
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 2);
138
7.68k
        return EstimateTokenCostImpl<3, 1, 2>(values, len, out);
139
7.68k
      }
140
15.3k
    } else {
141
15.3k
      JXL_DASSERT(cfg.msb_in_token == 2);
142
15.3k
      if (cfg.lsb_in_token == 0) {
143
7.68k
        return EstimateTokenCostImpl<3, 2, 0>(values, len, out);
144
7.68k
      } else {
145
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 1);
146
7.68k
        return EstimateTokenCostImpl<3, 2, 1>(values, len, out);
147
7.68k
      }
148
15.3k
    }
149
316k
  } else if (cfg.split_exponent == 4) {
150
205k
    if (cfg.msb_in_token == 1) {
151
102k
      if (cfg.lsb_in_token == 0) {
152
7.68k
        return EstimateTokenCostImpl<4, 1, 0>(values, len, out);
153
95.1k
      } else if (cfg.lsb_in_token == 2) {
154
87.4k
        return EstimateTokenCostImpl<4, 1, 2>(values, len, out);
155
87.4k
      } else {
156
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 3);
157
7.68k
        return EstimateTokenCostImpl<4, 1, 3>(values, len, out);
158
7.68k
      }
159
102k
    } else {
160
102k
      JXL_DASSERT(cfg.msb_in_token == 2);
161
102k
      if (cfg.lsb_in_token == 0) {
162
87.4k
        return EstimateTokenCostImpl<4, 2, 0>(values, len, out);
163
87.4k
      } else if (cfg.lsb_in_token == 1) {
164
7.68k
        return EstimateTokenCostImpl<4, 2, 1>(values, len, out);
165
7.68k
      } else {
166
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 2);
167
7.68k
        return EstimateTokenCostImpl<4, 2, 2>(values, len, out);
168
7.68k
      }
169
102k
    }
170
205k
  } else if (cfg.split_exponent == 5) {
171
53.7k
    if (cfg.msb_in_token == 1) {
172
23.0k
      if (cfg.lsb_in_token == 0) {
173
7.68k
        return EstimateTokenCostImpl<5, 1, 0>(values, len, out);
174
15.3k
      } else if (cfg.lsb_in_token == 2) {
175
7.68k
        return EstimateTokenCostImpl<5, 1, 2>(values, len, out);
176
7.68k
      } else {
177
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 4);
178
7.68k
        return EstimateTokenCostImpl<5, 1, 4>(values, len, out);
179
7.68k
      }
180
30.7k
    } else {
181
30.7k
      JXL_DASSERT(cfg.msb_in_token == 2);
182
30.7k
      if (cfg.lsb_in_token == 0) {
183
7.68k
        return EstimateTokenCostImpl<5, 2, 0>(values, len, out);
184
23.0k
      } else if (cfg.lsb_in_token == 1) {
185
7.68k
        return EstimateTokenCostImpl<5, 2, 1>(values, len, out);
186
15.3k
      } else if (cfg.lsb_in_token == 2) {
187
7.68k
        return EstimateTokenCostImpl<5, 2, 2>(values, len, out);
188
7.68k
      } else {
189
7.68k
        JXL_DASSERT(cfg.lsb_in_token == 3);
190
7.68k
        return EstimateTokenCostImpl<5, 2, 3>(values, len, out);
191
7.68k
      }
192
30.7k
    }
193
57.4k
  } else if (cfg.split_exponent == 6) {
194
21.0k
    if (cfg.msb_in_token == 0) {
195
7.68k
      JXL_DASSERT(cfg.lsb_in_token == 0);
196
7.68k
      return EstimateTokenCostImpl<6, 0, 0>(values, len, out);
197
13.3k
    } else if (cfg.msb_in_token == 1) {
198
6.66k
      JXL_DASSERT(cfg.lsb_in_token == 5);
199
6.66k
      return EstimateTokenCostImpl<6, 1, 5>(values, len, out);
200
6.66k
    } else {
201
6.66k
      JXL_DASSERT(cfg.msb_in_token == 2);
202
6.66k
      JXL_DASSERT(cfg.lsb_in_token == 4);
203
6.66k
      return EstimateTokenCostImpl<6, 2, 4>(values, len, out);
204
6.66k
    }
205
36.4k
  } else if (cfg.split_exponent >= 7 && cfg.split_exponent <= 12) {
206
36.4k
    JXL_DASSERT(cfg.msb_in_token == 0);
207
36.4k
    JXL_DASSERT(cfg.lsb_in_token == 0);
208
36.4k
    if (cfg.split_exponent == 7) {
209
7.68k
      return EstimateTokenCostImpl<7, 0, 0>(values, len, out);
210
28.7k
    } else if (cfg.split_exponent == 8) {
211
5.74k
      return EstimateTokenCostImpl<8, 0, 0>(values, len, out);
212
22.9k
    } else if (cfg.split_exponent == 9) {
213
5.74k
      return EstimateTokenCostImpl<9, 0, 0>(values, len, out);
214
17.2k
    } else if (cfg.split_exponent == 10) {
215
5.74k
      return EstimateTokenCostImpl<10, 0, 0>(values, len, out);
216
11.4k
    } else if (cfg.split_exponent == 11) {
217
5.74k
      return EstimateTokenCostImpl<11, 0, 0>(values, len, out);
218
5.74k
    } else {
219
5.74k
      return EstimateTokenCostImpl<12, 0, 0>(values, len, out);
220
5.74k
    }
221
36.4k
  } else {
222
0
    JXL_DASSERT(false);
223
0
  }
224
0
  return ~0;
225
523k
#endif
226
523k
}
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
523k
                           HybridUintConfig cfg, AlignedMemory& tokens) {
240
523k
  JXL_DASSERT(cfg.lsb_in_token + cfg.msb_in_token <= cfg.split_exponent);
241
523k
  return HWY_DYNAMIC_DISPATCH(EstimateTokenCost)(values, len, cfg, tokens);
242
523k
}
243
244
}  // namespace jxl
245
#endif