1275 Commits

Author SHA1 Message Date
Benjamin Kramer
c4e9a43773 [libc] Fix a constexpr violation from b4e552999de518a1d006c7b84f94491beeb4092c
In msan mode this calls __msan_unpoison, which isn't constexpr.
2023-10-25 13:36:17 +02:00
michaelrj-google
b4e552999d
[libc] Fix printf long double inf, bitcast in msan (#70067)
These bugs were found with the new printf long double fuzzing. The long
double inf vs nan bug was introduced when we changed to
get_explicit_exponent. The bitcast msan issue hadn't come up previously,
but isn't a real bug, just a poisoning confusion.
2023-10-24 15:41:54 -07:00
Dmitry Vyukov
f364a7a8b4
[libc] Speed up memmove overlapping check (#70017)
Use a check that requries fewer instructions and cheaper.
Current code:
```
   1b704:       48 39 f7                cmp    %rsi,%rdi
   1b707:       48 89 f0                mov    %rsi,%rax
   1b70a:       48 0f 47 c7             cmova  %rdi,%rax
   1b70e:       48 89 f9                mov    %rdi,%rcx
   1b711:       48 0f 47 ce             cmova  %rsi,%rcx
   1b715:       48 01 d1                add    %rdx,%rcx
   1b718:       48 39 c1                cmp    %rax,%rcx
```
New code:
```
   1b704:       48 89 f8                mov    %rdi,%rax
   1b707:       48 29 f0                sub    %rsi,%rax
   1b70a:       48 89 c1                mov    %rax,%rcx
   1b70d:       48 f7 d9                neg    %rcx
   1b710:       48 0f 48 c8             cmovs  %rax,%rcx
   1b714:       48 39 d1                cmp    %rdx,%rcx
```
```
                 │  baseline   │              disjoint              │
                 │   sec/op    │   sec/op     vs base               │
memmove/Google_A   3.910n ± 0%   3.861n ± 1%  -1.26% (p=0.000 n=50)
```
```
            │  baseline   │              disjoint               │
            │   sec/op    │   sec/op     vs base                │
memmove/1     2.724n ± 3%   2.441n ± 0%  -10.37% (n=50)
memmove/2     2.878n ± 0%   2.713n ± 0%   -5.73% (n=50)
memmove/3     2.835n ± 0%   2.593n ± 0%   -8.54% (n=50)
memmove/4     3.032n ± 0%   2.776n ± 0%   -8.45% (p=0.000 n=50)
memmove/5     2.833n ± 0%   2.600n ± 0%   -8.20% (p=0.000 n=50)
memmove/6     2.758n ± 0%   2.744n ± 0%   -0.52% (p=0.000 n=50)
memmove/7     2.762n ± 0%   2.744n ± 0%   -0.63% (p=0.000 n=50)
memmove/8     2.763n ± 0%   2.750n ± 0%   -0.46% (p=0.000 n=50)
memmove/9     3.182n ± 0%   3.269n ± 0%   +2.75% (p=0.000 n=50)
memmove/10    3.185n ± 0%   3.270n ± 0%   +2.64% (p=0.000 n=50)
memmove/11    3.188n ± 0%   3.277n ± 0%   +2.79% (p=0.000 n=50)
memmove/12    3.190n ± 0%   3.279n ± 0%   +2.82% (p=0.000 n=50)
memmove/13    3.194n ± 0%   3.281n ± 0%   +2.73% (p=0.000 n=50)
memmove/14    3.197n ± 0%   3.285n ± 0%   +2.77% (p=0.000 n=50)
memmove/15    3.198n ± 0%   3.282n ± 0%   +2.62% (p=0.000 n=50)
memmove/16    3.201n ± 0%   3.284n ± 0%   +2.61% (p=0.000 n=50)
memmove/17    3.564n ± 0%   3.320n ± 0%   -6.86% (p=0.000 n=50)
memmove/18    3.572n ± 0%   3.313n ± 0%   -7.25% (p=0.000 n=50)
memmove/19    3.572n ± 0%   3.325n ± 0%   -6.94% (p=0.000 n=50)
memmove/20    3.575n ± 0%   3.319n ± 0%   -7.15% (p=0.000 n=50)
memmove/21    3.578n ± 0%   3.327n ± 0%   -7.03% (p=0.000 n=50)
memmove/22    3.581n ± 0%   3.330n ± 0%   -7.01% (p=0.000 n=50)
memmove/23    3.582n ± 0%   3.354n ± 1%   -6.37% (p=0.000 n=50)
memmove/24    3.587n ± 0%   3.347n ± 1%   -6.71% (p=0.000 n=50)
memmove/25    3.591n ± 0%   3.320n ± 0%   -7.55% (p=0.000 n=50)
memmove/26    3.593n ± 0%   3.348n ± 0%   -6.82% (p=0.000 n=50)
memmove/27    3.596n ± 0%   3.346n ± 0%   -6.94% (p=0.000 n=50)
memmove/28    3.597n ± 0%   3.357n ± 0%   -6.67% (p=0.000 n=50)
memmove/29    3.601n ± 0%   3.340n ± 0%   -7.23% (p=0.000 n=50)
memmove/30    3.602n ± 0%   3.345n ± 0%   -7.12% (p=0.000 n=50)
memmove/31    3.608n ± 0%   3.357n ± 0%   -6.94% (p=0.000 n=50)
memmove/32    3.605n ± 0%   3.352n ± 0%   -7.01% (p=0.000 n=50)
memmove/33    4.128n ± 1%   3.829n ± 0%   -7.23% (p=0.000 n=50)
memmove/34    4.149n ± 0%   3.836n ± 0%   -7.54% (p=0.000 n=50)
memmove/35    4.134n ± 0%   3.839n ± 0%   -7.15% (n=50)
memmove/36    4.151n ± 0%   3.842n ± 0%   -7.45% (n=50)
memmove/37    4.152n ± 0%   3.841n ± 0%   -7.49% (p=0.000 n=50)
memmove/38    4.159n ± 0%   3.844n ± 0%   -7.58% (p=0.000 n=50)
memmove/39    4.165n ± 0%   3.841n ± 0%   -7.78% (p=0.000 n=50)
memmove/40    4.162n ± 0%   3.837n ± 0%   -7.81% (p=0.000 n=50)
memmove/41    4.161n ± 0%   3.845n ± 0%   -7.58% (p=0.000 n=50)
memmove/42    4.164n ± 0%   3.851n ± 0%   -7.53% (p=0.000 n=50)
memmove/43    4.165n ± 0%   3.843n ± 0%   -7.74% (p=0.000 n=50)
memmove/44    4.175n ± 0%   3.847n ± 0%   -7.83% (p=0.000 n=50)
memmove/45    4.170n ± 0%   3.849n ± 0%   -7.70% (p=0.000 n=50)
memmove/46    4.175n ± 0%   3.850n ± 0%   -7.79% (p=0.000 n=50)
memmove/47    4.180n ± 0%   3.851n ± 0%   -7.87% (p=0.000 n=50)
memmove/48    4.178n ± 0%   3.852n ± 0%   -7.81% (p=0.000 n=50)
memmove/49    4.175n ± 0%   3.851n ± 0%   -7.76% (n=50)
memmove/50    4.178n ± 0%   3.855n ± 0%   -7.73% (p=0.000 n=50)
memmove/51    4.190n ± 0%   3.859n ± 0%   -7.91% (p=0.000 n=50)
memmove/52    4.188n ± 0%   3.859n ± 0%   -7.84% (p=0.000 n=50)
memmove/53    4.191n ± 0%   3.863n ± 0%   -7.82% (p=0.000 n=50)
memmove/54    4.192n ± 0%   3.860n ± 0%   -7.91% (p=0.000 n=50)
memmove/55    4.192n ± 0%   3.869n ± 0%   -7.70% (p=0.000 n=50)
memmove/56    4.204n ± 0%   3.866n ± 0%   -8.05% (p=0.000 n=50)
memmove/57    4.198n ± 0%   3.864n ± 0%   -7.95% (p=0.000 n=50)
memmove/58    4.202n ± 0%   3.865n ± 0%   -8.02% (p=0.000 n=50)
memmove/59    4.208n ± 0%   3.868n ± 0%   -8.09% (p=0.000 n=50)
memmove/60    4.205n ± 0%   3.873n ± 0%   -7.89% (p=0.000 n=50)
memmove/61    4.212n ± 0%   3.872n ± 0%   -8.08% (p=0.000 n=50)
memmove/62    4.214n ± 0%   3.870n ± 0%   -8.16% (p=0.000 n=50)
memmove/63    4.215n ± 0%   3.877n ± 0%   -8.02% (p=0.000 n=50)
memmove/64    4.217n ± 0%   3.881n ± 0%   -7.99% (p=0.000 n=50)
memmove/65    4.990n ± 0%   4.683n ± 0%   -6.15% (p=0.000 n=50)
memmove/66    5.022n ± 0%   4.719n ± 0%   -6.03% (p=0.000 n=50)
memmove/67    5.030n ± 0%   4.725n ± 0%   -6.07% (p=0.000 n=50)
memmove/68    5.035n ± 0%   4.724n ± 0%   -6.18% (p=0.000 n=50)
memmove/69    5.030n ± 0%   4.725n ± 0%   -6.07% (p=0.000 n=50)
memmove/70    5.040n ± 0%   4.728n ± 0%   -6.19% (p=0.000 n=50)
memmove/71    5.053n ± 0%   4.728n ± 0%   -6.43% (p=0.000 n=50)
memmove/72    5.050n ± 0%   4.732n ± 0%   -6.29% (p=0.000 n=50)
memmove/73    5.049n ± 0%   4.733n ± 0%   -6.24% (p=0.000 n=50)
memmove/74    5.054n ± 0%   4.734n ± 0%   -6.34% (p=0.000 n=50)
memmove/75    5.063n ± 0%   4.736n ± 0%   -6.46% (p=0.000 n=50)
memmove/76    5.046n ± 0%   4.741n ± 0%   -6.04% (p=0.000 n=50)
memmove/77    5.057n ± 0%   4.741n ± 0%   -6.25% (p=0.000 n=50)
memmove/78    5.077n ± 0%   4.739n ± 0%   -6.65% (p=0.000 n=50)
memmove/79    5.074n ± 0%   4.746n ± 0%   -6.46% (p=0.000 n=50)
memmove/80    5.085n ± 0%   4.747n ± 0%   -6.65% (p=0.000 n=50)
memmove/81    5.077n ± 0%   4.735n ± 0%   -6.74% (p=0.000 n=50)
memmove/82    5.087n ± 0%   4.747n ± 0%   -6.68% (p=0.000 n=50)
memmove/83    5.087n ± 0%   4.754n ± 0%   -6.56% (p=0.000 n=50)
memmove/84    5.096n ± 0%   4.753n ± 0%   -6.73% (p=0.000 n=50)
memmove/85    5.082n ± 0%   4.749n ± 0%   -6.55% (p=0.000 n=50)
memmove/86    5.103n ± 0%   4.752n ± 0%   -6.87% (p=0.000 n=50)
memmove/87    5.096n ± 0%   4.760n ± 0%   -6.61% (p=0.000 n=50)
memmove/88    5.099n ± 0%   4.765n ± 0%   -6.55% (p=0.000 n=50)
memmove/89    5.104n ± 0%   4.757n ± 0%   -6.79% (p=0.000 n=50)
memmove/90    5.117n ± 0%   4.767n ± 0%   -6.84% (p=0.000 n=50)
memmove/91    5.100n ± 0%   4.766n ± 0%   -6.54% (p=0.000 n=50)
memmove/92    5.103n ± 0%   4.763n ± 0%   -6.67% (p=0.000 n=50)
memmove/93    5.115n ± 0%   4.772n ± 0%   -6.71% (p=0.000 n=50)
memmove/94    5.117n ± 0%   4.769n ± 0%   -6.80% (p=0.000 n=50)
memmove/95    5.131n ± 0%   4.775n ± 0%   -6.94% (p=0.000 n=50)
memmove/96    5.129n ± 0%   4.772n ± 0%   -6.97% (p=0.000 n=50)
memmove/97    5.130n ± 0%   4.764n ± 0%   -7.13% (p=0.000 n=50)
memmove/98    5.134n ± 0%   4.780n ± 0%   -6.89% (p=0.000 n=50)
memmove/99    5.141n ± 0%   4.780n ± 0%   -7.03% (p=0.000 n=50)
memmove/100   5.141n ± 0%   4.780n ± 0%   -7.02% (p=0.000 n=50)
memmove/101   5.150n ± 0%   4.782n ± 0%   -7.14% (p=0.000 n=50)
memmove/102   5.150n ± 0%   4.790n ± 0%   -6.99% (p=0.000 n=50)
memmove/103   5.156n ± 0%   4.788n ± 0%   -7.14% (n=50)
memmove/104   5.157n ± 0%   4.793n ± 0%   -7.05% (p=0.000 n=50)
memmove/105   5.147n ± 0%   4.791n ± 0%   -6.90% (p=0.000 n=50)
memmove/106   5.167n ± 0%   4.793n ± 0%   -7.23% (p=0.000 n=50)
memmove/107   5.165n ± 0%   4.801n ± 0%   -7.06% (p=0.000 n=50)
memmove/108   5.173n ± 0%   4.800n ± 0%   -7.21% (p=0.000 n=50)
memmove/109   5.173n ± 0%   4.797n ± 0%   -7.27% (p=0.000 n=50)
memmove/110   5.171n ± 0%   4.808n ± 0%   -7.01% (p=0.000 n=50)
memmove/111   5.180n ± 0%   4.799n ± 0%   -7.36% (p=0.000 n=50)
memmove/112   5.185n ± 0%   4.812n ± 0%   -7.19% (p=0.000 n=50)
memmove/113   5.187n ± 0%   4.797n ± 0%   -7.53% (p=0.000 n=50)
memmove/114   5.183n ± 0%   4.809n ± 0%   -7.21% (n=50)
memmove/115   5.193n ± 0%   4.811n ± 0%   -7.36% (p=0.000 n=50)
memmove/116   5.196n ± 0%   4.815n ± 0%   -7.32% (p=0.000 n=50)
memmove/117   5.199n ± 0%   4.816n ± 0%   -7.37% (p=0.000 n=50)
memmove/118   5.198n ± 0%   4.811n ± 0%   -7.45% (p=0.000 n=50)
memmove/119   5.203n ± 0%   4.818n ± 0%   -7.40% (p=0.000 n=50)
memmove/120   5.195n ± 0%   4.823n ± 0%   -7.16% (p=0.000 n=50)
memmove/121   5.203n ± 0%   4.812n ± 0%   -7.51% (p=0.000 n=50)
memmove/122   5.204n ± 0%   4.818n ± 0%   -7.42% (n=50)
memmove/123   5.202n ± 0%   4.822n ± 0%   -7.31% (p=0.000 n=50)
memmove/124   5.216n ± 0%   4.823n ± 0%   -7.54% (p=0.000 n=50)
memmove/125   5.227n ± 0%   4.823n ± 0%   -7.72% (p=0.000 n=50)
memmove/126   5.235n ± 0%   4.830n ± 0%   -7.74% (p=0.000 n=50)
memmove/127   5.237n ± 0%   4.833n ± 0%   -7.72% (p=0.000 n=50)
memmove/128   5.241n ± 0%   4.832n ± 0%   -7.81% (p=0.000 n=50)
memmove/129   6.460n ± 0%   5.858n ± 0%   -9.31% (p=0.000 n=50)
memmove/130   7.539n ± 0%   6.634n ± 0%  -12.00% (p=0.000 n=50)
memmove/131   7.542n ± 0%   6.623n ± 0%  -12.18% (p=0.000 n=50)
memmove/132   7.527n ± 0%   6.667n ± 1%  -11.43% (p=0.000 n=50)
memmove/133   7.521n ± 0%   6.631n ± 0%  -11.83% (p=0.000 n=50)
memmove/134   7.531n ± 0%   6.642n ± 0%  -11.81% (p=0.000 n=50)
memmove/135   7.541n ± 0%   6.692n ± 1%  -11.25% (p=0.000 n=50)
memmove/136   7.549n ± 0%   6.657n ± 0%  -11.81% (p=0.000 n=50)
memmove/137   7.544n ± 0%   6.646n ± 0%  -11.90% (p=0.000 n=50)
memmove/138   7.557n ± 0%   6.673n ± 1%  -11.70% (p=0.000 n=50)
memmove/139   7.545n ± 0%   6.654n ± 0%  -11.81% (n=50)
memmove/140   7.559n ± 0%   6.680n ± 1%  -11.63% (p=0.000 n=50)
memmove/141   7.560n ± 0%   6.664n ± 0%  -11.85% (p=0.000 n=50)
memmove/142   7.556n ± 0%   6.679n ± 0%  -11.62% (p=0.000 n=50)
memmove/143   7.570n ± 0%   6.683n ± 1%  -11.71% (p=0.000 n=50)
memmove/144   7.586n ± 0%   6.683n ± 0%  -11.91% (p=0.000 n=50)
memmove/145   7.593n ± 0%   6.665n ± 0%  -12.22% (p=0.000 n=50)
memmove/146   7.591n ± 0%   6.665n ± 0%  -12.20% (p=0.000 n=50)
memmove/147   7.598n ± 0%   6.665n ± 0%  -12.27% (p=0.000 n=50)
memmove/148   7.598n ± 0%   6.670n ± 0%  -12.21% (p=0.000 n=50)
memmove/149   7.593n ± 0%   6.691n ± 0%  -11.88% (p=0.000 n=50)
memmove/150   7.625n ± 0%   6.713n ± 1%  -11.97% (p=0.000 n=50)
memmove/151   7.603n ± 0%   6.710n ± 1%  -11.74% (p=0.000 n=50)
memmove/152   7.613n ± 0%   6.701n ± 1%  -11.97% (p=0.000 n=50)
memmove/153   7.595n ± 0%   6.710n ± 0%  -11.65% (p=0.000 n=50)
memmove/154   7.614n ± 0%   6.721n ± 0%  -11.74% (p=0.000 n=50)
memmove/155   7.615n ± 0%   6.709n ± 0%  -11.89% (p=0.000 n=50)
memmove/156   7.613n ± 0%   6.693n ± 0%  -12.08% (p=0.000 n=50)
memmove/157   7.628n ± 0%   6.708n ± 0%  -12.05% (p=0.000 n=50)
memmove/158   7.629n ± 0%   6.706n ± 0%  -12.10% (p=0.000 n=50)
memmove/159   7.639n ± 0%   6.724n ± 0%  -11.98% (p=0.000 n=50)
memmove/160   7.619n ± 0%   6.702n ± 0%  -12.04% (p=0.000 n=50)
memmove/161   7.653n ± 0%   6.698n ± 0%  -12.49% (p=0.000 n=50)
memmove/162   8.104n ± 0%   7.140n ± 1%  -11.89% (p=0.000 n=50)
memmove/163   8.141n ± 0%   7.187n ± 1%  -11.72% (p=0.000 n=50)
memmove/164   8.154n ± 0%   7.107n ± 0%  -12.84% (p=0.000 n=50)
memmove/165   8.143n ± 0%   7.117n ± 0%  -12.59% (p=0.000 n=50)
memmove/166   8.176n ± 0%   7.110n ± 0%  -13.04% (p=0.000 n=50)
memmove/167   8.194n ± 0%   7.168n ± 1%  -12.52% (p=0.000 n=50)
memmove/168   8.214n ± 0%   7.188n ± 1%  -12.50% (p=0.000 n=50)
memmove/169   8.220n ± 0%   7.242n ± 1%  -11.90% (p=0.000 n=50)
memmove/170   8.228n ± 0%   7.244n ± 1%  -11.96% (p=0.000 n=50)
memmove/171   8.263n ± 0%   7.184n ± 0%  -13.06% (p=0.000 n=50)
memmove/172   8.259n ± 0%   7.325n ± 1%  -11.31% (p=0.000 n=50)
memmove/173   8.271n ± 0%   7.225n ± 0%  -12.65% (p=0.000 n=50)
memmove/174   8.284n ± 0%   7.287n ± 1%  -12.04% (p=0.000 n=50)
memmove/175   8.289n ± 0%   7.282n ± 1%  -12.15% (p=0.000 n=50)
memmove/176   8.309n ± 0%   7.328n ± 1%  -11.81% (p=0.000 n=50)
memmove/177   8.317n ± 0%   7.264n ± 1%  -12.67% (p=0.000 n=50)
memmove/178   8.302n ± 0%   7.342n ± 1%  -11.57% (p=0.000 n=50)
memmove/179   8.309n ± 0%   7.357n ± 1%  -11.45% (p=0.000 n=50)
memmove/180   8.304n ± 0%   7.318n ± 1%  -11.87% (p=0.000 n=50)
memmove/181   8.312n ± 0%   7.363n ± 1%  -11.42% (p=0.000 n=50)
memmove/182   8.315n ± 0%   7.320n ± 1%  -11.96% (p=0.000 n=50)
memmove/183   8.330n ± 0%   7.286n ± 1%  -12.53% (p=0.000 n=50)
memmove/184   8.310n ± 0%   7.324n ± 1%  -11.86% (p=0.000 n=50)
memmove/185   8.303n ± 0%   7.267n ± 1%  -12.47% (p=0.000 n=50)
memmove/186   8.287n ± 0%   7.312n ± 1%  -11.76% (p=0.000 n=50)
memmove/187   8.298n ± 0%   7.395n ± 2%  -10.88% (p=0.000 n=50)
memmove/188   8.296n ± 0%   7.339n ± 1%  -11.54% (p=0.000 n=50)
memmove/189   8.306n ± 0%   7.299n ± 1%  -12.12% (p=0.000 n=50)
memmove/190   8.281n ± 0%   7.309n ± 1%  -11.74% (p=0.000 n=50)
memmove/191   8.299n ± 0%   7.282n ± 1%  -12.26% (p=0.000 n=50)
memmove/192   8.281n ± 0%   7.335n ± 1%  -11.41% (p=0.000 n=50)
memmove/193   8.299n ± 0%   7.325n ± 1%  -11.74% (p=0.000 n=50)
memmove/194   8.641n ± 0%   8.034n ± 0%   -7.02% (p=0.000 n=50)
memmove/195   8.667n ± 0%   8.073n ± 0%   -6.85% (p=0.000 n=50)
memmove/196   8.666n ± 0%   8.030n ± 0%   -7.34% (p=0.000 n=50)
memmove/197   8.660n ± 0%   8.096n ± 1%   -6.51% (p=0.000 n=50)
memmove/198   8.688n ± 0%   8.047n ± 0%   -7.39% (p=0.000 n=50)
memmove/199   8.678n ± 0%   8.061n ± 0%   -7.11% (p=0.000 n=50)
memmove/200   8.669n ± 0%   8.034n ± 0%   -7.32% (p=0.000 n=50)
memmove/201   8.692n ± 0%   8.061n ± 0%   -7.26% (p=0.000 n=50)
memmove/202   8.668n ± 0%   8.060n ± 0%   -7.02% (p=0.000 n=50)
memmove/203   8.687n ± 0%   8.066n ± 0%   -7.15% (p=0.000 n=50)
memmove/204   8.699n ± 0%   8.076n ± 0%   -7.16% (p=0.000 n=50)
memmove/205   8.676n ± 0%   8.085n ± 0%   -6.82% (p=0.000 n=50)
memmove/206   8.684n ± 0%   8.101n ± 1%   -6.71% (p=0.000 n=50)
memmove/207   8.725n ± 0%   8.099n ± 0%   -7.18% (p=0.000 n=50)
memmove/208   8.674n ± 0%   8.073n ± 0%   -6.92% (p=0.000 n=50)
memmove/209   8.697n ± 0%   8.088n ± 0%   -7.01% (p=0.000 n=50)
memmove/210   8.733n ± 0%   8.076n ± 0%   -7.53% (p=0.000 n=50)
memmove/211   8.732n ± 0%   8.104n ± 0%   -7.19% (p=0.000 n=50)
memmove/212   8.730n ± 0%   8.091n ± 0%   -7.32% (p=0.000 n=50)
memmove/213   8.728n ± 0%   8.100n ± 0%   -7.19% (p=0.000 n=50)
memmove/214   8.744n ± 1%   8.081n ± 1%   -7.57% (p=0.000 n=50)
memmove/215   8.734n ± 0%   8.150n ± 0%   -6.68% (p=0.000 n=50)
memmove/216   8.748n ± 0%   8.116n ± 0%   -7.23% (p=0.000 n=50)
memmove/217   8.751n ± 0%   8.129n ± 1%   -7.11% (p=0.000 n=50)
memmove/218   8.747n ± 0%   8.114n ± 0%   -7.23% (p=0.000 n=50)
memmove/219   8.733n ± 0%   8.159n ± 0%   -6.57% (p=0.000 n=50)
memmove/220   8.764n ± 0%   8.145n ± 0%   -7.06% (p=0.000 n=50)
memmove/221   8.764n ± 0%   8.142n ± 0%   -7.10% (p=0.000 n=50)
memmove/222   8.775n ± 0%   8.152n ± 0%   -7.10% (p=0.000 n=50)
memmove/223   8.771n ± 0%   8.143n ± 0%   -7.16% (p=0.000 n=50)
memmove/224   8.778n ± 0%   8.175n ± 1%   -6.87% (p=0.000 n=50)
memmove/225   8.794n ± 0%   8.138n ± 0%   -7.45% (p=0.000 n=50)
memmove/226   10.13n ± 0%   10.06n ± 0%   -0.71% (p=0.000 n=50)
memmove/227   10.14n ± 0%   10.08n ± 0%   -0.53% (p=0.000 n=50)
memmove/228   10.13n ± 0%   10.08n ± 0%   -0.56% (p=0.000 n=50)
memmove/229   10.17n ± 0%   10.11n ± 0%   -0.56% (p=0.000 n=50)
memmove/230   10.17n ± 0%   10.13n ± 0%   -0.38% (p=0.003 n=50)
memmove/231   10.16n ± 0%   10.12n ± 0%   -0.41% (p=0.001 n=50)
memmove/232   10.19n ± 0%   10.12n ± 0%   -0.67% (p=0.000 n=50)
memmove/233   10.21n ± 0%   10.14n ± 0%   -0.71% (p=0.000 n=50)
memmove/234   10.24n ± 0%   10.16n ± 0%   -0.79% (p=0.000 n=50)
memmove/235   10.24n ± 0%   10.16n ± 0%   -0.76% (p=0.000 n=50)
memmove/236   10.25n ± 0%   10.16n ± 0%   -0.81% (p=0.000 n=50)
memmove/237   10.24n ± 0%   10.17n ± 0%   -0.69% (p=0.000 n=50)
memmove/238   10.27n ± 0%   10.19n ± 0%   -0.79% (p=0.000 n=50)
memmove/239   10.29n ± 0%   10.19n ± 0%   -0.90% (p=0.000 n=50)
memmove/240   10.30n ± 0%   10.20n ± 0%   -0.95% (p=0.000 n=50)
memmove/241   10.29n ± 0%   10.20n ± 0%   -0.91% (p=0.000 n=50)
memmove/242   10.30n ± 0%   10.22n ± 0%   -0.80% (p=0.000 n=50)
memmove/243   10.32n ± 0%   10.23n ± 0%   -0.87% (p=0.000 n=50)
memmove/244   10.32n ± 0%   10.24n ± 0%   -0.74% (p=0.000 n=50)
memmove/245   10.33n ± 0%   10.23n ± 0%   -0.97% (p=0.000 n=50)
memmove/246   10.33n ± 0%   10.24n ± 0%   -0.92% (p=0.000 n=50)
memmove/247   10.31n ± 0%   10.24n ± 0%   -0.69% (p=0.000 n=50)
memmove/248   10.32n ± 0%   10.26n ± 0%   -0.55% (p=0.000 n=50)
memmove/249   10.33n ± 0%   10.28n ± 0%   -0.52% (p=0.000 n=50)
memmove/250   10.34n ± 0%   10.27n ± 0%   -0.66% (p=0.000 n=50)
memmove/251   10.32n ± 0%   10.27n ± 0%   -0.45% (p=0.000 n=50)
memmove/252   10.34n ± 0%   10.30n ± 0%   -0.39% (p=0.005 n=50)
memmove/253   10.33n ± 0%   10.27n ± 0%   -0.57% (p=0.000 n=50)
memmove/254   10.33n ± 0%   10.27n ± 0%   -0.54% (p=0.000 n=50)
memmove/255   10.34n ± 0%   10.29n ± 0%   -0.50% (p=0.002 n=50)
memmove/256   10.36n ± 0%   10.31n ± 0%   -0.44% (p=0.006 n=50)
memmove/257   10.33n ± 0%   10.29n ± 0%   -0.36% (p=0.004 n=50)
geomean       6.142n        5.696n        -7.26%
```
2023-10-24 16:05:27 +02:00
Anton Rydahl
e774482c4c
Fixed typo in GPU libm device library warning (#69752)
Correcting a small typo in the error message when the CUDA device libraries are not detected.
2023-10-20 12:17:26 -07:00
Joseph Huber
630037ede4
[libc] Partially implement 'rand' for the GPU (#66167)
Summary:
This patch partially implements the `rand` function on the GPU. This is
partial because the GPU currently doesn't support thread local storage
or static initializers. To implement this on the GPU. I use 1/8th of the
local / shared memory quota to treak the shared memory as thread local
storage. This is done by simply allocating enough storage for each
thread in the block and indexing into this based off of the thread id.
The downside to this is that it does not initialize `srand` correctly to
be `1` as the standard says, it is also wasteful. In the future we
should figure out a way to support TLS on the GPU so that this can be
completely common and less resource intensive.
2023-10-19 17:01:43 -04:00
Joseph Huber
a39215768b
[libc] Rework the 'fgets' implementation on the GPU (#69635)
Summary:
The `fgets` function as implemented is not functional currently when
called with multiple threads. This is because we rely on reapeatedly
polling the character to detect EOF. This doesn't work when there are
multiple threads that may with to poll the characters. this patch pulls
out the logic into a standalone RPC call to handle this in a single
operation such that calling it from multiple threads functions as
expected. It also makes it less slow because we no longer make N RPC
calls for N characters.
2023-10-19 17:00:01 -04:00
Anton Rydahl
c73ad025b1
[libc][libm][GPU] Add missing vendor entrypoints to the GPU version of libm (#66034)
This patch populates the GPU version of `libm` with missing vendor entrypoints. The vendor math entrypoints are disabled by default but can be enabled with the CMake option `LIBC_GPU_VENDOR_MATH=ON`.
2023-10-19 12:24:50 -07:00
alfredfo
f350532099
[libc] Fix accidental LIBC_NAMESPACE_clock_freq (#69620)
See-also: https://github.com/llvm/llvm-project/pull/69548
2023-10-19 19:39:02 +02:00
lntue
3fd5113cba
[libc][math][NFC] Remove global scope constants declaration in math tests (#69558)
Clean up usage of `DECLARE_SPECIAL_CONSTANTS` in global scope.
2023-10-19 10:30:11 -04:00
alfredfo
d404130134
[libc] Fix accidental LIBC_NAMESPACE_syscall definition (#69548)
Building helloworld.c currently errors with "undefined symbol:
__llvm_libc_syscall"

See: https://github.com/llvm/llvm-project/pull/67032
2023-10-19 11:22:16 +02:00
Joseph Huber
ddc30ff802
[libc] Implement the 'ungetc' function on the GPU (#69248)
Summary:
This function follows closely with the pattern of all the other
functions. That is, making a new opcode and forwarding the call to the
host. However, this also required modifying the test somewhat. It seems
that not all `libc` implementations follow the same error rules as are
tested here, and it is not explicit in the standard, so we simply
disable these EOF checks when targeting the GPU.
2023-10-17 13:02:31 -05:00
michaelrj-google
8a47ad4b67
[libc] Add simple long double to printf float fuzz (#68449)
Recent testing has uncovered some hard-to-find bugs in printf's long
double support. This patch adds an extra long double path to the fuzzer
with minimal extra effort. While a more thorough long double fuzzer
would be useful, it would need to handle the non-standard cases of 80
bit long doubles such as unnormal and pseudo-denormal numbers. For that
reason, a standalone long double fuzzer is left for future development.
2023-10-16 13:32:34 -07:00
Samira Bazuzi
b5c2fa14ea
[libc] Mark operator== const to avoid ambiguity in C++20. (#68805)
C++20 will automatically generate an operator== with reversed operand
order, which is ambiguous with the written operator== when one argument
is marked const and the other isn't.

This operator currently triggers -Wambiguous-reversed-operator at usage
site libc/test/UnitTest/PrintfMatcher.cpp:28.
2023-10-11 23:59:13 -04:00
Joseph Huber
9bcf9dc98a [libc] Fix missing warp sync for the NVPTX assert
Summary:
The implementation of `assert` has an if statement so that only the
first thread in the warp prints the assertion. On modern NVPTX
architecture, this can be printed out of order with the abort call. This
would lead to only a portion of the message being printed and then
exiting the program. By adding a mandatory warp sync we force the full
string to be printed before we continue to the abort.
2023-10-10 12:50:37 -05:00
Joseph Huber
fa23a2396b
[libc] Fix linking of AMDGPU device runtime control constants for math (#65676)
Summary:
Currently, `libc` temporarily provides math by linking against existing
vendor implementations. To use the AMDGPU DeviceRTL we need to define a
handful of control constants that alter behaviour for architecture
specific things. Previously these were marked `extern const` because
they must be present when we link-in the vendor bitcode library.
However, this causes linker errors if more than one math function was
used.

This patch fixes the issue by marking these functions as used and inline
on top of being external. This means that they are linkable, but it
gives us `linkonce_odr` semantics. The downside is that these globals
won't be optimized out, but it allows us to perform constant propagation
on them unlike using `weak`.
2023-10-06 21:50:35 -05:00
Joseph Huber
4cb6c1c7cb
[libc] Enable missing memory tests on the GPU (#68111)
Summary:
There were a few tests that weren't enabled on the GPU. This is because
the logic caused them to be skipped as we don't use CPU featured on the
host. This also disables the logic making multiple versions of the
memory functions.
2023-10-06 08:27:36 -05:00
michaelrj-google
bfcfc2a6d4
[libc] Fix typo in long double negative block (#68243)
The long double version of float to string's get_negative_block had a
bug in table mode. In table mode, one of the tables is named
"MIN_BLOCK_2" and it stores the number of blocks that are all zeroes
before the digits start for a given index. The check for long doubles
was incorrectly "block_index <= MIN_BLOCK_2[idx]" when it should be
"block_index < MIN_BLOCK_2[idx]" (without the equal sign). This bug
caused an off-by-one error for some long double values. This patch fixes
the bug and adds tests to ensure it doesn't regress.
2023-10-04 13:00:48 -07:00
Joseph Huber
452fa6b86d
[libc] Change the GPU to use builtin memory functions (#68003)
Summary:
The GPU build is special in the sense that we always know that
up-to-date `clang` is always going to be the compiler. This allows us to
rely directly on builtins, which allow us to push a lot of this
complexity into the backend. Backend implementations are favored on
the GPU because it allows us to do a lot more target specific
optimizations. This patch changes over the common memory functions to
use builtin versions when building for AMDGPU or NVPTX.
2023-10-04 07:02:55 -05:00
Mikhail R. Gadelha
8fc87f54a8
[libc][NFC] Couple of small warning fixes (#67847)
This patch fixes a couple of warnings when compiling with gcc 13:

* CPP/type_traits_test.cpp: 'apply' overrides a member function but is
not marked 'override'
* UnitTest/LibcTest.cpp:98: control reaches end of non-void function
* MPFRWrapper/MPFRUtils.cpp:75: control reaches end of non-void function
* smoke/FrexpTest.h:92: backslash-newline at end of file
* __support/float_to_string.h:118: comparison of unsigned expression in ‘>= 0’ is always true
* test/src/__support/CPP/bitset_test.cpp:197: comparison of unsigned expression in ‘>= 0’ is always true

---------

Signed-off-by: Mikhail R. Gadelha <mikhail@igalia.com>
2023-10-02 19:29:26 -04:00
lntue
da28593d71
[libc][math] Implement double precision expm1 function correctly rounded for all rounding modes. (#67048)
Implementing expm1 function for double precision based on exp function
algorithm:

- Reduced x = log2(e) * (hi + mid1 + mid2) + lo, where:
  * hi is an integer
  * mid1 * 2^-6 is an integer
  * mid2 * 2^-12 is an integer
  * |lo| < 2^-13 + 2^-30
- Then exp(x) - 1 = 2^hi * 2^mid1 * 2^mid2 * exp(lo) - 1 ~ 2^hi *
(2^mid1 * 2^mid2 * (1 + lo * P(lo)) - 2^(-hi) )
- We evaluate fast pass with P(lo) is a degree-3 Taylor polynomial of
(e^lo - 1) / lo in double precision
- If the Ziv accuracy test fails, we use degree-6 Taylor polynomial of
(e^lo - 1) / lo in double double precision
- If the Ziv accuracy test still fails, we re-evaluate everything in
128-bit precision.
2023-09-28 16:43:15 -04:00
Joseph Huber
1a5d3b6cda
[libc] Scan the ports more fairly in the RPC server (#66680)
Summary:
Currently, we use the RPC server to respond to different ports which
each contain a request from some client thread wishing to do work on the
server. This scan starts at zero and continues until its checked all
ports at which point it resets. If we find an active port, we service it
and then restart the search.

This is bad for two reasons. First, it means that we will always bias
the lower ports. If a thread grabs a high port it will be stuck for a
very long time until all the other work is done. Second, it means that
the `handle_server` function can technically run indefinitely as long as
the client is always pushing new work. Because the OpenMP implementation
uses the user thread to service the kernel, this means that it could be
stalled with another asyncrhonous device's kernels.

This patch addresses this by making the server restart at the next port
over. This means we will always do a full scan of the ports before
quitting.
2023-09-26 16:09:48 -05:00
Joseph Huber
2b7227db1e [libc] Fix RPC server global after mass replace of __llvm_libc
Summary:
This variable needs a reserved name starting with `__`. It was
mistakenly changed with a mass replace. It happened to work because the
tests still picked up the associated symbol, but it just became a bad
name because it's not reserved anymore.
2023-09-26 14:28:48 -05:00
Siva Chandra
f2c9fe452f
[libc][NFC] Fix delete operator linkage names after switch to LIBC_NAMESPACE. (#67475)
The name __llvm_libc was mass-replaced with LIBC_NAMESPACE which ended
up changing the "__llvm_libc" prefix of the delete operator linkage names to
"LIBC_NAMESPACE". This change corrects it by changing the namespace prefix
to "__llvm_libc_<version info>".
2023-09-26 11:53:14 -07:00
Siva Chandra
3bfd6a7521
[libc][NFC] Add compile options only to the header libraries which use them. (#67447)
Other libraries dependent on these libraries will automatically inherit
those compile options. This change in particular affects the compile
option "-DLIBC_COPT_STDIO_USE_SYSTEM_FILE".
2023-09-26 09:20:00 -07:00
Mikhail R. Gadelha
e3087c4b8c [libc] Start to refactor riscv platform abstraction to support both 32 and 64 bits versions
This patch enables the compilation of libc for rv32 by unifying the
current rv64 and rv32 implementation into a single rv implementation.

We updated the cmake file to match the new riscv32 arch and force
LIBC_TARGET_ARCHITECTURE to be "riscv" whenever we find "riscv32" or
"riscv64". This is required as LIBC_TARGET_ARCHITECTURE is used in the
path for several platform specific implementations.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D148797
2023-09-26 12:32:25 -03:00
Siva Chandra
599eadec28
[libc] Propagate printf config options from a single config header library. (#66979)
printf_core.parser is not yet updated to use the printf config options. It
does not use them currently anyway and the corresponding parser_test
should be updated to respect the config options.
2023-09-26 08:16:31 -07:00
Joseph Huber
1b8c8155cc [libc][Obvious] Fix incorrect filepath for ftell.h header
Summary:
The previous patch moved the location of this CMake line but didn't
update the header. Fix it.
2023-09-26 10:02:20 -05:00
Joseph Huber
7ac8e26fc7
[libc] Implement fseek, fflush, and ftell on the GPU (#67160)
Summary:
This patch adds the necessary entrypoints to handle the `fseek`,
`fflush`, and `ftell` functions. These are all very straightfoward, we
simply make RPC calls to the associated function on the other end.
Implementing it this way allows us to more or less borrow the state of
the stream from the server as we intentionally maintain no internal
state on the GPU device. However, this does not implement the `errno`
functinality so that must be ignored.
2023-09-26 09:46:46 -05:00
Guillaume Chatelet
b6bc9d72f6
[libc] Mass replace enclosing namespace (#67032)
This is step 4 of
https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-09-26 11:45:04 +02:00
michaelrj-google
23552fe220
[libc] Acquire the lock for scanf files (#67357)
When creating the new scanf reader design, I forgot to add back the
calls to flockfile and funlockfile in vfscanf_internal. This patch fixes
that, and also changes the system file version to use the normal
variants since ungetc_unlocked isn't always available.
2023-09-25 15:00:03 -07:00
Joseph Huber
791b279924
[libc] Change the puts implementation on the GPU (#67189)
Summary:
Normally, the implementation of `puts` simply writes a second newline
charcter after printing the first string. However, because the GPU does
everything in batches of the SIMT group size, this will end up with very
poor output where you get the strings printed and then 1-64 newline
characters all in a row. Optimizations like to turn `printf` calls into
`puts` so it's a good idea to make this produce the expected output.

The least invasive way I could do this was to add a new opcode. It's a
little bloated, but it avoids an unneccessary and slow send operation to
configure this.
2023-09-25 11:17:22 -05:00
michaelrj-google
a5a008ff4f
[libc] Refactor scanf reader to match printf (#66023)
In a previous patch, the printf writer was rewritten to use a single
writer class with a buffer and a callback hook. This patch refactors
scanf's reader to match conceptually.
2023-09-22 12:50:02 -07:00
Joseph Huber
e0be78be42
[libc] Template the printf / scanf parser class (#66277)
Summary:
The parser class for stdio currently accepts different argument
providers. In-tree this is only used for a fuzzer test, however, the
proposed implementation of the GPU handling of printf / scanf will
require custom argument handlers. This makes the current approach of
using a preprocessor macro messier. This path proposed folding this
logic into a template instantiation. The downside to this is that
because the implementation of the parser class is placed into an
implementation file we need to manually instantiate the needed templates
which will slightly bloat binary size. Alternatively we could remove the
implementation file, or key off of the `libc` external packaging macro
so it is not present in the installed version.
2023-09-21 17:02:26 -05:00
Joseph Huber
f548d19fc8
[libc] Fix and simplify the implementation of 'fread' on the GPU (#66948)
Summary:
Previously, the `fread` operation was wrong in cases when we read less
data than was requested. That is, if we tried to read N bytes while the
file was in EOF, it would still copy N bytes of garbage. This is fixed
by only copying over the sizes we got from locally opening it rather
than just using the provided size.

Additionally, this patch simplifies the interface. The output functions
have special variants for writing to stdout / stderr. This is primarily
an optimization for these common cases so we can avoid sending the
stream as an argument which has a high delay. Because for input, we
already need to start with a `send` to tell the server how much data to
read, it costs us nothing to send the file along with it so this is
redundant. Re-use the file encoding scheme from the other
implementations, the one that stores the stream type in the LSBs of the
FILE pointer.
2023-09-21 14:28:06 -05:00
michaelrj-google
5bd34e0a55
[libc] Fix Off By One Errors In Printf Long Double (#66957)
Two major off-by-one errors are fixed in this patch. The first is in
float_to_string.h with length_for_num, which wasn't accounting for the
implicit leading bit when calculating the length of a number, causing
a missing digit on 80 bit float max. The other off-by-one is the
ryu_long_double_constants.h (a.k.a the Mega Table) not having any
entries for the last POW10_OFFSET in POW10_SPLIT. This was also found on
80 bit float max. Finally, the integer calculation mode was using a
slightly too short integer, again on 80 bit float max, not accounting
for the mantissa width. All of these are fixed in this patch.
2023-09-21 11:43:29 -07:00
Joseph Huber
59896c168a
[libc] Remove the 'rpc_reset' routine from the RPC implementation (#66700)
Summary:
This patch removes the `rpc_reset` function. This was previously used to
initialize the RPC client on the device by setting up the pointers to
communicate with the server. The purpose of this was to make it easier
to initialize the device for testing. However, this prevented us from
enforcing an invariant that the buffers are all read-only from the
client side.

The expected way to initialize the server is now to copy it from the
host runtime. This will allow us to maintain that the RPC client is in
the constant address space on the GPU, potentially through inference,
and improving caching behaviour.
2023-09-21 11:07:09 -05:00
Guillaume Chatelet
270547f3bf
[libc][clang-tidy] Add llvm-header-guard to get consistant naming and prevent file copy/paste issues. (#66477) 2023-09-21 11:14:47 +02:00
Joseph Huber
3641d18557 [libc][Obvious] Fix incorrect RPC opcode for clearerr
Summary:
This was mistakenly using the opcode for `ferror` which wasn't noticed
because tests using this weren't yet activated. This patch fixes this
mistake.
2023-09-20 11:54:35 -05:00
michaelrj-google
d37496e75a
[libc] Fix printf config not working (#66834)
The list of printf copts available in config.json wasn't working because
the printf_core subdirectory was included before the printf_copts
variable was defined, making it effectively nothing for the printf
internals. Additionally, the tests weren't respecting the flags so they
would cause the tests to fail. This patch reorders the cmake in src and
adds flag handling in test.
2023-09-19 15:36:14 -07:00
Tue Ly
84c899b235 [libc][math] Extract non-MPFR math tests into libc-math-smoke-tests.
Extract non-MPFR math tests into libc-math-smoke-tests.

Reviewed By: sivachandra, jhuber6

Differential Revision: https://reviews.llvm.org/D159477
2023-09-19 12:10:21 -04:00
Guillaume Chatelet
2dbdc9fc85
[libc] Add invoke / invoke_result type traits (#65750) 2023-09-15 11:15:41 +02:00
Joseph Huber
bbe7eb92b4 [libc][Obvious] Fix missing entrypoints after moving to generic
Summary:
The previous patch moved the implementations of these to generic/ and
accidentally did not add the unlocked variants. This patch fixes that
2023-09-14 15:59:08 -05:00
Joseph Huber
a1be5d69df
[libc] Implement more input functions on the GPU (#66288)
Summary:
This patch implements the `fgets`, `getc`, `fgetc`, and `getchar`
functions on the GPU. Their implementations are straightforward enough.
One thing worth noting is that the implementation of `fgets` will be
extremely slow due to the high latency to read a single char. A faster
solution would be to make a new RPC call to call `fgets` (due to the
special rule that newline or null breaks the stream). But this is left
out because performance isn't the primary concern here.
2023-09-14 15:39:29 -05:00
Alex Brachet
2ad7a06cb1
[libc] Fix some warnings (#66366)
Some compilers will warn about dangling else and missleading lack of
parentheses.
2023-09-14 08:47:21 -04:00
Guillaume Chatelet
aee8f8784a
[libc][utils] cpp::always_false to enable static_assert(false) (#66209) 2023-09-14 10:28:43 +02:00
Siva Chandra
17114f8b19
[libc] Remove common_libc_tuners.cmake and move options into config.json. (#66226)
The name has been changed to adhere to the config option naming format.
The necessary build changes to use the new option have also been made.
2023-09-13 22:17:00 -07:00
Michael Jones
3fb63c2921 [libc] simplify printf float writing
The two decimal float printing styles are similar, but different in how
they end. For simplicity of writing I initially gave them different
"write_last_block" functions. This patch unifies them into one function.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D158036
2023-09-13 13:53:29 -07:00
michaelrj-google
380eb46b13
[libc] Move long double table option to new config (#66151)
This patch adds the long double table option for printf into the new
configuration scheme. This allows it to be set for most targets but
unset for baremetal.
2023-09-13 10:43:05 -07:00
Mikhail R. Gadelha
75398f28eb [libc] Make time_t 64 bits long on all platforms but arm32
This patch changes the size of time_t to be an int64_t. This still
follows the POSIX standard which only requires time_t to be an integer.

Making time_t a 64-bit integer also fixes two cases in 32 bits platforms
that use SYS_clock_nanosleep_time64 and SYS_clock_gettime64, as the name
of these calls implies, they require a 64-bit time_t. For instance, in rv32,
the 32-bit version of these syscalls is not available.

We also follow glibc here, where time_t is still a 32-bit integer in
arm32.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D159125
2023-09-13 10:49:39 -03:00
Joseph Huber
ef169f5707
[libc] Improve the implementation of the rand() function (#66131)
Summary:
This patch improves the implementation of the standard `rand()` function
by implementing it in terms of the xorshift64star pRNG as described in
https://en.wikipedia.org/wiki/Xorshift#xorshift*. This is a good,
general purpose random number generator that is sufficient for most
applications that do not require an extremely long period. This patch
also correctly initializes the seed to be `1` as described by the
standard. We also increase the `RAND_MAX` value to be `INT_MAX` as the
standard only specifies that it can be larger than 32768.
2023-09-12 16:52:20 -05:00