Coverage Report

Created: 2025-12-13 07:57

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