git subrepo pull (merge) --force deps/libchdr
[pcsx_rearmed.git] / deps / libchdr / deps / zstd-1.5.5 / CONTRIBUTING.md
1 # Contributing to Zstandard
2 We want to make contributing to this project as easy and transparent as
3 possible.
4
5 ## Our Development Process
6 New versions are being developed in the "dev" branch,
7 or in their own feature branch.
8 When they are deemed ready for a release, they are merged into "release".
9
10 As a consequence, all contributions must stage first through "dev"
11 or their own feature branch.
12
13 ## Pull Requests
14 We actively welcome your pull requests.
15
16 1. Fork the repo and create your branch from `dev`.
17 2. If you've added code that should be tested, add tests.
18 3. If you've changed APIs, update the documentation.
19 4. Ensure the test suite passes.
20 5. Make sure your code lints.
21 6. If you haven't already, complete the Contributor License Agreement ("CLA").
22
23 ## Contributor License Agreement ("CLA")
24 In order to accept your pull request, we need you to submit a CLA. You only need
25 to do this once to work on any of Facebook's open source projects.
26
27 Complete your CLA here: <https://code.facebook.com/cla>
28
29 ## Workflow
30 Zstd uses a branch-based workflow for making changes to the codebase. Typically, zstd
31 will use a new branch per sizable topic. For smaller changes, it is okay to lump multiple
32 related changes into a branch.
33
34 Our contribution process works in three main stages:
35 1. Local development
36     * Update:
37         * Checkout your fork of zstd if you have not already
38         ```
39         git checkout https://github.com/<username>/zstd
40         cd zstd
41         ```
42         * Update your local dev branch
43         ```
44         git pull https://github.com/facebook/zstd dev
45         git push origin dev
46         ```
47     * Topic and development:
48         * Make a new branch on your fork about the topic you're developing for
49         ```
50         # branch names should be concise but sufficiently informative
51         git checkout -b <branch-name>
52         git push origin <branch-name>
53         ```
54         * Make commits and push
55         ```
56         # make some changes =
57         git add -u && git commit -m <message>
58         git push origin <branch-name>
59         ```
60         * Note: run local tests to ensure that your changes didn't break existing functionality
61             * Quick check
62             ```
63             make shortest
64             ```
65             * Longer check
66             ```
67             make test
68             ```
69 2. Code Review and CI tests
70     * Ensure CI tests pass:
71         * Before sharing anything to the community, create a pull request in your own fork against the dev branch
72         and make sure that all GitHub Actions CI tests pass. See the Continuous Integration section below for more information.
73         * Ensure that static analysis passes on your development machine. See the Static Analysis section
74         below to see how to do this.
75     * Create a pull request:
76         * When you are ready to share you changes to the community, create a pull request from your branch
77         to facebook:dev. You can do this very easily by clicking 'Create Pull Request' on your fork's home
78         page.
79         * From there, select the branch where you made changes as your source branch and facebook:dev
80         as the destination.
81         * Examine the diff presented between the two branches to make sure there is nothing unexpected.
82     * Write a good pull request description:
83         * While there is no strict template that our contributors follow, we would like them to
84         sufficiently summarize and motivate the changes they are proposing. We recommend all pull requests,
85         at least indirectly, address the following points.
86             * Is this pull request important and why?
87             * Is it addressing an issue? If so, what issue? (provide links for convenience please)
88             * Is this a new feature? If so, why is it useful and/or necessary?
89             * Are there background references and documents that reviewers should be aware of to properly assess this change?
90         * Note: make sure to point out any design and architectural decisions that you made and the rationale behind them.
91         * Note: if you have been working with a specific user and would like them to review your work, make sure you mention them using (@<username>)
92     * Submit the pull request and iterate with feedback.
93 3. Merge and Release
94     * Getting approval:
95         * You will have to iterate on your changes with feedback from other collaborators to reach a point
96         where your pull request can be safely merged.
97         * To avoid too many comments on style and convention, make sure that you have a
98         look at our style section below before creating a pull request.
99         * Eventually, someone from the zstd team will approve your pull request and not long after merge it into
100         the dev branch.
101     * Housekeeping:
102         * Most PRs are linked with one or more Github issues. If this is the case for your PR, make sure
103         the corresponding issue is mentioned. If your change 'fixes' or completely addresses the
104         issue at hand, then please indicate this by requesting that an issue be closed by commenting.
105         * Just because your changes have been merged does not mean the topic or larger issue is complete. Remember
106         that the change must make it to an official zstd release for it to be meaningful. We recommend
107         that contributors track the activity on their pull request and corresponding issue(s) page(s) until
108         their change makes it to the next release of zstd. Users will often discover bugs in your code or
109         suggest ways to refine and improve your initial changes even after the pull request is merged.
110
111 ## Static Analysis
112 Static analysis is a process for examining the correctness or validity of a program without actually
113 executing it. It usually helps us find many simple bugs. Zstd uses clang's `scan-build` tool for
114 static analysis. You can install it by following the instructions for your OS on https://clang-analyzer.llvm.org/scan-build.
115
116 Once installed, you can ensure that our static analysis tests pass on your local development machine
117 by running:
118 ```
119 make staticAnalyze
120 ```
121
122 In general, you can use `scan-build` to static analyze any build script. For example, to static analyze
123 just `contrib/largeNbDicts` and nothing else, you can run:
124
125 ```
126 scan-build make -C contrib/largeNbDicts largeNbDicts
127 ```
128
129 ### Pitfalls of static analysis
130 `scan-build` is part of our regular CI suite. Other static analyzers are not.
131
132 It can be useful to look at additional static analyzers once in a while (and we do), but it's not a good idea to multiply the nb of analyzers run continuously at each commit and PR. The reasons are :
133
134 - Static analyzers are full of false positive. The signal to noise ratio is actually pretty low.
135 - A good CI policy is "zero-warning tolerance". That means that all issues must be solved, including false positives. This quickly becomes a tedious workload.
136 - Multiple static analyzers will feature multiple kind of false positives, sometimes applying to the same code but in different ways leading to :
137    + tortuous code, trying to please multiple constraints, hurting readability and therefore maintenance. Sometimes, such complexity introduce other more subtle bugs, that are just out of scope of the analyzers.
138    + sometimes, these constraints are mutually exclusive : if one try to solve one, the other static analyzer will complain, they can't be both happy at the same time.
139 - As if that was not enough, the list of false positives change with each version. It's hard enough to follow one static analyzer, but multiple ones with their own update agenda, this quickly becomes a massive velocity reducer.
140
141 This is different from running a static analyzer once in a while, looking at the output, and __cherry picking__ a few warnings that seem helpful, either because they detected a genuine risk of bug, or because it helps expressing the code in a way which is more readable or more difficult to misuse. These kinds of reports can be useful, and are accepted.
142
143 ## Continuous Integration
144 CI tests run every time a pull request (PR) is created or updated. The exact tests
145 that get run will depend on the destination branch you specify. Some tests take
146 longer to run than others. Currently, our CI is set up to run a short
147 series of tests when creating a PR to the dev branch and a longer series of tests
148 when creating a PR to the release branch. You can look in the configuration files
149 of the respective CI platform for more information on what gets run when.
150
151 Most people will just want to create a PR with the destination set to their local dev
152 branch of zstd. You can then find the status of the tests on the PR's page. You can also
153 re-run tests and cancel running tests from the PR page or from the respective CI's dashboard.
154
155 Almost all of zstd's CI runs on GitHub Actions (configured at `.github/workflows`), which will automatically run on PRs to your
156 own fork. A small number of tests run on other services (e.g. Travis CI, Circle CI, Appveyor).
157 These require work to set up on your local fork, and (at least for Travis CI) cost money.
158 Therefore, if the PR on your local fork passes GitHub Actions, feel free to submit a PR
159 against the main repo.
160
161 ### Third-party CI
162 A small number of tests cannot run on GitHub Actions, or have yet to be migrated.
163 For these, we use a variety of third-party services (listed below). It is not necessary to set
164 these up on your fork in order to contribute to zstd; however, we do link to instructions for those
165 who want earlier signal.
166
167 | Service   | Purpose                                                                                                    | Setup Links                                                                                                                                            | Config Path            |
168 |-----------|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|
169 | Travis CI | Used for testing on non-x86 architectures such as PowerPC                                                  | https://docs.travis-ci.com/user/tutorial/#to-get-started-with-travis-ci-using-github <br> https://github.com/marketplace/travis-ci                     | `.travis.yml`          |
170 | AppVeyor  | Used for some Windows testing (e.g. cygwin, mingw)                                                         | https://www.appveyor.com/blog/2018/10/02/github-apps-integration/ <br> https://github.com/marketplace/appveyor                                         | `appveyor.yml`         |
171 | Cirrus CI | Used for testing on FreeBSD                                                                                | https://github.com/marketplace/cirrus-ci/                                                                                                              | `.cirrus.yml`          |
172 | Circle CI | Historically was used to provide faster signal,<br/> but we may be able to migrate these to Github Actions | https://circleci.com/docs/2.0/getting-started/#setting-up-circleci <br> https://youtu.be/Js3hMUsSZ2c <br> https://circleci.com/docs/2.0/enable-checks/ | `.circleci/config.yml` |
173
174 Note: the instructions linked above mostly cover how to set up a repository with CI from scratch. 
175 The general idea should be the same for setting up CI on your fork of zstd, but you may have to 
176 follow slightly different steps. In particular, please ignore any instructions related to setting up
177 config files (since zstd already has configs for each of these services).
178
179 ## Performance
180 Performance is extremely important for zstd and we only merge pull requests whose performance
181 landscape and corresponding trade-offs have been adequately analyzed, reproduced, and presented.
182 This high bar for performance means that every PR which has the potential to
183 impact performance takes a very long time for us to properly review. That being said, we
184 always welcome contributions to improve performance (or worsen performance for the trade-off of
185 something else). Please keep the following in mind before submitting a performance related PR:
186
187 1. Zstd isn't as old as gzip but it has been around for time now and its evolution is
188 very well documented via past Github issues and pull requests. It may be the case that your
189 particular performance optimization has already been considered in the past. Please take some
190 time to search through old issues and pull requests using keywords specific to your
191 would-be PR. Of course, just because a topic has already been discussed (and perhaps rejected
192 on some grounds) in the past, doesn't mean it isn't worth bringing up again. But even in that case,
193 it will be helpful for you to have context from that topic's history before contributing.
194 2. The distinction between noise and actual performance gains can unfortunately be very subtle
195 especially when microbenchmarking extremely small wins or losses. The only remedy to getting
196 something subtle merged is extensive benchmarking. You will be doing us a great favor if you
197 take the time to run extensive, long-duration, and potentially cross-(os, platform, process, etc)
198 benchmarks on your end before submitting a PR. Of course, you will not be able to benchmark
199 your changes on every single processor and os out there (and neither will we) but do that best
200 you can:) We've added some things to think about when benchmarking below in the Benchmarking
201 Performance section which might be helpful for you.
202 3. Optimizing performance for a certain OS, processor vendor, compiler, or network system is a perfectly
203 legitimate thing to do as long as it does not harm the overall performance health of Zstd.
204 This is a hard balance to strike but please keep in mind other aspects of Zstd when
205 submitting changes that are clang-specific, windows-specific, etc.
206
207 ## Benchmarking Performance
208 Performance microbenchmarking is a tricky subject but also essential for Zstd. We value empirical
209 testing over theoretical speculation. This guide it not perfect but for most scenarios, it
210 is a good place to start.
211
212 ### Stability
213 Unfortunately, the most important aspect in being able to benchmark reliably is to have a stable
214 benchmarking machine. A virtual machine, a machine with shared resources, or your laptop
215 will typically not be stable enough to obtain reliable benchmark results. If you can get your
216 hands on a desktop, this is usually a better scenario.
217
218 Of course, benchmarking can be done on non-hyper-stable machines as well. You will just have to
219 do a little more work to ensure that you are in fact measuring the changes you've made not and
220 noise. Here are some things you can do to make your benchmarks more stable:
221
222 1. The most simple thing you can do to drastically improve the stability of your benchmark is
223 to run it multiple times and then aggregate the results of those runs. As a general rule of
224 thumb, the smaller the change you are trying to measure, the more samples of benchmark runs
225 you will have to aggregate over to get reliable results. Here are some additional things to keep in
226 mind when running multiple trials:
227     * How you aggregate your samples are important. You might be tempted to use the mean of your
228     results. While this is certainly going to be a more stable number than a raw single sample
229     benchmark number, you might have more luck by taking the median. The mean is not robust to
230     outliers whereas the median is. Better still, you could simply take the fastest speed your
231     benchmark achieved on each run since that is likely the fastest your process will be
232     capable of running your code. In our experience, this (aggregating by just taking the sample
233     with the fastest running time) has been the most stable approach.
234     * The more samples you have, the more stable your benchmarks should be. You can verify
235     your improved stability by looking at the size of your confidence intervals as you
236     increase your sample count. These should get smaller and smaller. Eventually hopefully
237     smaller than the performance win you are expecting.
238     * Most processors will take some time to get `hot` when running anything. The observations
239     you collect during that time period will very different from the true performance number. Having
240     a very large number of sample will help alleviate this problem slightly but you can also
241     address is directly by simply not including the first `n` iterations of your benchmark in
242     your aggregations. You can determine `n` by simply looking at the results from each iteration
243     and then hand picking a good threshold after which the variance in results seems to stabilize.
244 2. You cannot really get reliable benchmarks if your host machine is simultaneously running
245 another cpu/memory-intensive application in the background. If you are running benchmarks on your
246 personal laptop for instance, you should close all applications (including your code editor and
247 browser) before running your benchmarks. You might also have invisible background applications
248 running. You can see what these are by looking at either Activity Monitor on Mac or Task Manager
249 on Windows. You will get more stable benchmark results of you end those processes as well.
250     * If you have multiple cores, you can even run your benchmark on a reserved core to prevent
251     pollution from other OS and user processes. There are a number of ways to do this depending
252     on your OS:
253         * On linux boxes, you have use https://github.com/lpechacek/cpuset.
254         * On Windows, you can "Set Processor Affinity" using https://www.thewindowsclub.com/processor-affinity-windows
255         * On Mac, you can try to use their dedicated affinity API https://developer.apple.com/library/archive/releasenotes/Performance/RN-AffinityAPI/#//apple_ref/doc/uid/TP40006635-CH1-DontLinkElementID_2
256 3. To benchmark, you will likely end up writing a separate c/c++ program that will link libzstd.
257 Dynamically linking your library will introduce some added variation (not a large amount but
258 definitely some). Statically linking libzstd will be more stable. Static libraries should
259 be enabled by default when building zstd.
260 4. Use a profiler with a good high resolution timer. See the section below on profiling for
261 details on this.
262 5. Disable frequency scaling, turbo boost and address space randomization (this will vary by OS)
263 6. Try to avoid storage. On some systems you can use tmpfs. Putting the program, inputs and outputs on
264 tmpfs avoids touching a real storage system, which can have a pretty big variability.
265
266 Also check our LLVM's guide on benchmarking here: https://llvm.org/docs/Benchmarking.html
267
268 ### Zstd benchmark
269 The fastest signal you can get regarding your performance changes is via the in-build zstd cli
270 bench option. You can run Zstd as you typically would for your scenario using some set of options
271 and then additionally also specify the `-b#` option. Doing this will run our benchmarking pipeline
272 for that options you have just provided. If you want to look at the internals of how this
273 benchmarking script works, you can check out programs/benchzstd.c
274
275 For example: say you have made a change that you believe improves the speed of zstd level 1. The
276 very first thing you should use to assess whether you actually achieved any sort of improvement
277 is `zstd -b`. You might try to do something like this. Note: you can use the `-i` option to
278 specify a running time for your benchmark in seconds (default is 3 seconds).
279 Usually, the longer the running time, the more stable your results will be.
280
281 ```
282 $ git checkout <commit-before-your-change>
283 $ make && cp zstd zstd-old
284 $ git checkout <commit-after-your-change>
285 $ make && cp zstd zstd-new
286 $ zstd-old -i5 -b1 <your-test-data>
287  1<your-test-data>         :      8990 ->      3992 (2.252), 302.6 MB/s , 626.4 MB/s
288 $ zstd-new -i5 -b1 <your-test-data>
289  1<your-test-data>         :      8990 ->      3992 (2.252), 302.8 MB/s , 628.4 MB/s
290 ```
291
292 Unless your performance win is large enough to be visible despite the intrinsic noise
293 on your computer, benchzstd alone will likely not be enough to validate the impact of your
294 changes. For example, the results of the example above indicate that effectively nothing
295 changed but there could be a small <3% improvement that the noise on the host machine
296 obscured. So unless you see a large performance win (10-15% consistently) using just
297 this method of evaluation will not be sufficient.
298
299 ### Profiling
300 There are a number of great profilers out there. We're going to briefly mention how you can
301 profile your code using `instruments` on mac, `perf` on linux and `visual studio profiler`
302 on Windows.
303
304 Say you have an idea for a change that you think will provide some good performance gains
305 for level 1 compression on Zstd. Typically this means, you have identified a section of
306 code that you think can be made to run faster.
307
308 The first thing you will want to do is make sure that the piece of code is actually taking up
309 a notable amount of time to run. It is usually not worth optimizing something which accounts for less than
310 0.0001% of the total running time. Luckily, there are tools to help with this.
311 Profilers will let you see how much time your code spends inside a particular function.
312 If your target code snippet is only part of a function, it might be worth trying to
313 isolate that snippet by moving it to its own function (this is usually not necessary but
314 might be).
315
316 Most profilers (including the profilers discussed below) will generate a call graph of
317 functions for you. Your goal will be to find your function of interest in this call graph
318 and then inspect the time spent inside of it. You might also want to look at the annotated
319 assembly which most profilers will provide you with.
320
321 #### Instruments
322 We will once again consider the scenario where you think you've identified a piece of code
323 whose performance can be improved upon. Follow these steps to profile your code using
324 Instruments.
325
326 1. Open Instruments
327 2. Select `Time Profiler` from the list of standard templates
328 3. Close all other applications except for your instruments window and your terminal
329 4. Run your benchmarking script from your terminal window
330     * You will want a benchmark that runs for at least a few seconds (5 seconds will
331     usually be long enough). This way the profiler will have something to work with
332     and you will have ample time to attach your profiler to this process:)
333     * I will just use benchzstd as my benchmarmking script for this example:
334 ```
335 $ zstd -b1 -i5 <my-data> # this will run for 5 seconds
336 ```
337 5. Once you run your benchmarking script, switch back over to instruments and attach your
338 process to the time profiler. You can do this by:
339     * Clicking on the `All Processes` drop down in the top left of the toolbar.
340     * Selecting your process from the dropdown. In my case, it is just going to be labeled
341     `zstd`
342     * Hitting the bright red record circle button on the top left of the toolbar
343 6. You profiler will now start collecting metrics from your benchmarking script. Once
344 you think you have collected enough samples (usually this is the case after 3 seconds of
345 recording), stop your profiler.
346 7. Make sure that in toolbar of the bottom window, `profile` is selected.
347 8. You should be able to see your call graph.
348     * If you don't see the call graph or an incomplete call graph, make sure you have compiled
349     zstd and your benchmarking script using debug flags. On mac and linux, this just means
350     you will have to supply the `-g` flag alone with your build script. You might also
351     have to provide the `-fno-omit-frame-pointer` flag
352 9. Dig down the graph to find your function call and then inspect it by double clicking
353 the list item. You will be able to see the annotated source code and the assembly side by
354 side.
355
356 #### Perf
357
358 This wiki has a pretty detailed tutorial on getting started working with perf so we'll
359 leave you to check that out of you're getting started:
360
361 https://perf.wiki.kernel.org/index.php/Tutorial
362
363 Some general notes on perf:
364 * Use `perf stat -r # <bench-program>` to quickly get some relevant timing and
365 counter statistics. Perf uses a high resolution timer and this is likely one
366 of the first things your team will run when assessing your PR.
367 * Perf has a long list of hardware counters that can be viewed with `perf --list`.
368 When measuring optimizations, something worth trying is to make sure the hardware
369 counters you expect to be impacted by your change are in fact being so. For example,
370 if you expect the L1 cache misses to decrease with your change, you can look at the
371 counter `L1-dcache-load-misses`
372 * Perf hardware counters will not work on a virtual machine.
373
374 #### Visual Studio
375
376 TODO
377
378 ## Issues
379 We use GitHub issues to track public bugs. Please ensure your description is
380 clear and has sufficient instructions to be able to reproduce the issue.
381
382 Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
383 disclosure of security bugs. In those cases, please go through the process
384 outlined on that page and do not file a public issue.
385
386 ## Coding Style
387 It's a pretty long topic, which is difficult to summarize in a single paragraph.
388 As a rule of thumbs, try to imitate the coding style of
389 similar lines of codes around your contribution.
390 The following is a non-exhaustive list of rules employed in zstd code base:
391
392 ### C90
393 This code base is following strict C90 standard,
394 with 2 extensions : 64-bit `long long` types, and variadic macros.
395 This rule is applied strictly to code within `lib/` and `programs/`.
396 Sub-project in `contrib/` are allowed to use other conventions.
397
398 ### C++ direct compatibility : symbol mangling
399 All public symbol declarations must be wrapped in `extern “C” { … }`,
400 so that this project can be compiled as C++98 code,
401 and linked into C++ applications.
402
403 ### Minimal Frugal
404 This design requirement is fundamental to preserve the portability of the code base.
405 #### Dependencies
406 - Reduce dependencies to the minimum possible level.
407   Any dependency should be considered “bad” by default,
408   and only tolerated because it provides a service in a better way than can be achieved locally.
409   The only external dependencies this repository tolerates are
410   standard C libraries, and in rare cases, system level headers.
411 - Within `lib/`, this policy is even more drastic.
412   The only external dependencies allowed are `<assert.h>`, `<stdlib.h>`, `<string.h>`,
413   and even then, not directly.
414   In particular, no function shall ever allocate on heap directly,
415   and must use instead `ZSTD_malloc()` and equivalent.
416   Other accepted non-symbol headers are `<stddef.h>` and `<limits.h>`.
417 - Within the project, there is a strict hierarchy of dependencies that must be respected.
418   `programs/` is allowed to depend on `lib/`, but only its public API.
419   Within `lib/`, `lib/common` doesn't depend on any other directory.
420   `lib/compress` and `lib/decompress` shall not depend on each other.
421   `lib/dictBuilder` can depend on `lib/common` and `lib/compress`, but not `lib/decompress`.
422 #### Resources
423 - Functions in `lib/` must use very little stack space,
424   several dozens of bytes max.
425   Everything larger must use the heap allocator,
426   or require a scratch buffer to be emplaced manually.
427
428 ### Naming
429 * All public symbols are prefixed with `ZSTD_`
430   + private symbols, with a scope limited to their own unit, are free of this restriction.
431     However, since `libzstd` source code can be amalgamated,
432     each symbol name must attempt to be (and remain) unique.
433     Avoid too generic names that could become ground for future collisions.
434     This generally implies usage of some form of prefix.
435 * For symbols (functions and variables), naming convention is `PREFIX_camelCase`.
436   + In some advanced cases, one can also find :
437     - `PREFIX_prefix2_camelCase`
438     - `PREFIX_camelCase_extendedQualifier`
439 * Multi-words names generally consist of an action followed by object:
440   - for example : `ZSTD_createCCtx()`
441 * Prefer positive actions
442   - `goBackward` rather than `notGoForward`
443 * Type names (`struct`, etc.) follow similar convention,
444   except that they are allowed and even invited to start by an Uppercase letter.
445   Example : `ZSTD_CCtx`, `ZSTD_CDict`
446 * Macro names are all Capital letters.
447   The same composition rules (`PREFIX_NAME_QUALIFIER`) apply.
448 * File names are all lowercase letters.
449   The convention is `snake_case`.
450   File names **must** be unique across the entire code base,
451   even when they stand in clearly separated directories.
452
453 ### Qualifiers
454 * This code base is `const` friendly, if not `const` fanatical.
455   Any variable that can be `const` (aka. read-only) **must** be `const`.
456   Any pointer which content will not be modified must be `const`.
457   This property is then controlled at compiler level.
458   `const` variables are an important signal to readers that this variable isn't modified.
459   Conversely, non-const variables are a signal to readers to watch out for modifications later on in the function.
460 * If a function must be inlined, mention it explicitly,
461   using project's own portable macros, such as `FORCE_INLINE_ATTR`,
462   defined in `lib/common/compiler.h`.
463
464 ### Debugging
465 * **Assertions** are welcome, and should be used very liberally,
466   to control any condition the code expects for its correct execution.
467   These assertion checks will be run in debug builds, and disabled in production.
468 * For traces, this project provides its own debug macros,
469   in particular `DEBUGLOG(level, ...)`, defined in `lib/common/debug.h`.
470
471 ### Code documentation
472 * Avoid code documentation that merely repeats what the code is already stating.
473   Whenever applicable, prefer employing the code as the primary way to convey explanations.
474   Example 1 : `int nbTokens = n;` instead of `int i = n; /* i is a nb of tokens *./`.
475   Example 2 : `assert(size > 0);` instead of `/* here, size should be positive */`.
476 * At declaration level, the documentation explains how to use the function or variable
477   and when applicable why it's needed, of the scenarios where it can be useful.
478 * At implementation level, the documentation explains the general outline of the algorithm employed,
479   and when applicable why this specific choice was preferred.
480
481 ### General layout
482 * 4 spaces for indentation rather than tabs
483 * Code documentation shall directly precede function declaration or implementation
484 * Function implementations and its code documentation should be preceded and followed by an empty line
485
486
487 ## License
488 By contributing to Zstandard, you agree that your contributions will be licensed
489 under both the [LICENSE](LICENSE) file and the [COPYING](COPYING) file in the root directory of this source tree.