2 Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #include <cpu-features.h>
24 #define TUNABLE_NAMESPACE cpu
25 #include <unistd.h> /* Get STDOUT_FILENO for _dl_printf. */
26 #include <elf/dl-tunables.h>
29 /* Data cache size for use in memory and string routines, typically
30 L1 size, rounded to multiple of 256 bytes. */
31 long int __x86_data_cache_size_half attribute_hidden
= 32 * 1024 / 2;
32 long int __x86_data_cache_size attribute_hidden
= 32 * 1024;
33 /* Shared cache size for use in memory and string routines, typically
34 L2 or L3 size, rounded to multiple of 256 bytes. */
35 long int __x86_shared_cache_size_half attribute_hidden
= 1024 * 1024 / 2;
36 long int __x86_shared_cache_size attribute_hidden
= 1024 * 1024;
38 /* Threshold to use non temporal store in memmove. */
39 long int __x86_shared_non_temporal_threshold attribute_hidden
;
41 /* Threshold to use non temporal store in memset. */
42 long int __x86_memset_non_temporal_threshold attribute_hidden
;
44 /* Threshold to use Enhanced REP MOVSB. */
45 long int __x86_rep_movsb_threshold attribute_hidden
= 2048;
47 /* Threshold to use Enhanced REP STOSB. */
48 long int __x86_rep_stosb_threshold attribute_hidden
= 2048;
50 /* Threshold to stop using Enhanced REP MOVSB. */
51 long int __x86_rep_movsb_stop_threshold attribute_hidden
;
53 /* A bit-wise OR of string/memory requirements for optimal performance
54 e.g. X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB. These bits
55 are used at runtime to tune implementation behavior. */
56 int __x86_string_control attribute_hidden
;
61 const struct cpu_features
*cpu_features
= __get_cpu_features ();
62 long int data
= cpu_features
->data_cache_size
;
63 /* Round data cache size to multiple of 256 bytes. */
67 __x86_data_cache_size_half
= data
/ 2;
68 __x86_data_cache_size
= data
;
71 long int shared
= cpu_features
->shared_cache_size
;
72 /* Round shared cache size to multiple of 256 bytes. */
73 shared
= shared
& ~255L;
76 __x86_shared_cache_size_half
= shared
/ 2;
77 __x86_shared_cache_size
= shared
;
80 __x86_shared_non_temporal_threshold
81 = cpu_features
->non_temporal_threshold
;
83 __x86_memset_non_temporal_threshold
84 = cpu_features
->memset_non_temporal_threshold
;
86 __x86_rep_movsb_threshold
= cpu_features
->rep_movsb_threshold
;
87 __x86_rep_stosb_threshold
= cpu_features
->rep_stosb_threshold
;
88 __x86_rep_movsb_stop_threshold
= cpu_features
->rep_movsb_stop_threshold
;
90 if (CPU_FEATURES_ARCH_P (cpu_features
, Avoid_Short_Distance_REP_MOVSB
))
92 |= X86_STRING_CONTROL_AVOID_SHORT_DISTANCE_REP_MOVSB
;