file-type

GCC 优化选项详解:-O、-Ofast与-Os

MD文件

下载需积分: 5 | 8KB | 更新于2024-08-30 | 133 浏览量 | 0 下载量 举报 收藏
download 立即下载
"print-level-options.md" 在编程和编译过程中,优化级别是决定程序性能的关键因素之一。`print-level-options.md` 文件讨论了 GCC 编译器在优化代码时可用的不同选项,这些选项可以影响程序的执行效率、大小以及速度。通过调整这些选项,开发者可以根据需求平衡代码的性能与生成的二进制文件大小。 ### 1. 优化级别选项 - `-O<number>`:这是GCC的基本优化级别设置,`<number>` 可以是0、1、2、3或s。-O0表示无优化,-O1是轻度优化,-O2是常规优化,-O3是更高程度的优化,而-Os则侧重于减小目标代码的大小。 - `-Ofast`:这是比-O3更激进的优化,它启用了一些可能改变语义的优化,例如放宽对浮点运算标准的遵守。 ### 2. 其他特定优化选项 - `-falign-functions`、`-falign-jumps`、`-falign-labels` 和 `-falign-loops`:这些选项用于控制函数、跳转、标签和循环的对齐,可以提高性能但可能会增加代码大小。 - `-fasynchronous-unwind-tables`:当异常处理发生时,这个选项支持异步回溯,以快速恢复调用栈。 - `-fbranch-count-reg` 和 `-fbranch-probabilities`:这两个选项帮助编译器了解分支的概率,从而进行更智能的指令调度。 - `-fcrossjumping`:允许编译器跨越函数来消除冗余代码。 - `-fdata-sections`:每个全局变量或静态变量都放在自己的数据段中,便于链接器删除未使用的变量。 - `-fdelete-null-pointer-checks`:在某些情况下,编译器会删除对空指针的检查,假设这是安全的。 - `-fexpensive-optimizations`:启用一些可能延长编译时间但能显著提高代码性能的优化。 ### 3. 内存管理优化 - `-fcaller-saves`:让调用者保存被调用函数使用的寄存器,以防止因函数调用而丢失信息。 - `-fcommon`:处理未初始化的全局变量,如果它们在多个翻译单元中声明但未定义。 - `-fconserve-stack`:尽可能地减少栈的使用。 ### 4. 代码生成优化 - `-finline-functions` 和 `-finline-functions-called-once`:鼓励或强制内联函数以减少函数调用开销。 - `-fmerge-all-constants` 和 `-fmerge-constants`:合并常量,减少存储需求。 - `-freorder-blocks-and-partition` 和 `-freorder-blocks`:重新排列基本块以改善指令调度。 ### 5. 其他特性 - `-fno-strict-aliasing`:禁用严格的别名规则,有时会导致优化问题。 - `-funroll-loops`:展开循环以减少迭代次数,但可能导致代码膨胀。 理解并熟练运用这些优化选项是提升程序性能的关键。在实际项目中,开发者需要根据具体需求和目标平台选择合适的优化策略。例如,对于嵌入式系统,可能更关心代码大小,因此 `-Os` 或者禁用特定的增大代码大小的选项是明智的选择。而在高性能计算中,可能需要 `-O3` 或 `-Ofast` 来最大化性能。

相关推荐

filetype

D:\miniconda3\envs\pyopenjtalk_test_env\lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:82: SetuptoolsDeprecationWarning: `project.license` as a TOML table is deprecated !! ******************************************************************************** Please use a simple string containing a SPDX expression for `project.license`. You can also use `project.license-files`. (Both options available on setuptools>=77.0.0). By 2026-Feb-18, you need to update your project and remove deprecated calls or your builds will no longer be supported. See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! corresp(dist, value, root_dir) D:\miniconda3\envs\pyopenjtalk_test_env\lib\site-packages\setuptools\config\_apply_pyprojecttoml.py:61: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: MIT License See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! dist._finalize_license_expression() D:\miniconda3\envs\pyopenjtalk_test_env\lib\site-packages\setuptools\dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: MIT License See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! self._finalize_license_expression() running bdist_wheel running build running build_py creating build\lib.win32-cpython-39\pyopenjtalk copying pyopenjtalk\utils.py -> build\lib.win32-cpython-39\pyopenjtalk copying pyopenjtalk\version.py -> build\lib.win32-cpython-39\pyopenjtalk copying pyopenjtalk\__init__.py -> build\lib.win32-cpython-39\pyopenjtalk running egg_info writing pyopenjtalk.egg-info\PKG-INFO writing dependency_links to pyopenjtalk.egg-info\dependency_links.txt writing requirements to pyopenjtalk.egg-info\requires.txt writing top-level names to pyopenjtalk.egg-info\top_level.txt reading manifest file 'pyopenjtalk.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no previously-included files found matching '.gitignore' warning: no previously-included files found matching '.gitmodules' warning: no previously-included files found matching '.travis.yml' warning: no previously-included files found matching 'tox.ini' no previously-included directories found matching '.github\*' no previously-included directories found matching 'docs\**' adding license file 'LICENSE.md' writing manifest file 'pyopenjtalk.egg-info\SOURCES.txt' creating build\lib.win32-cpython-39\pyopenjtalk\htsvoice copying pyopenjtalk\htsvoice\LICENSE_mei_normal.htsvoice -> build\lib.win32-cpython-39\pyopenjtalk\htsvoice copying pyopenjtalk\htsvoice\README.md -> build\lib.win32-cpython-39\pyopenjtalk\htsvoice copying pyopenjtalk\htsvoice\mei_normal.htsvoice -> build\lib.win32-cpython-39\pyopenjtalk\htsvoice running build_ext Compiling pyopenjtalk\openjtalk.pyx because it changed. [1/1] Cythonizing pyopenjtalk\openjtalk.pyx building 'pyopenjtalk.openjtalk' extension error: Unable to find a compatible Visual Studio installation.

ppcust
  • 粉丝: 38
上传资源 快速赚钱