如何在x86_64的gcc上启用__fp16类型 [英] How to enable __fp16 type on gcc for x86_64

查看:911
本文介绍了如何在x86_64的gcc上启用__fp16类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

__fp16浮点数据类型是对C标准的众所周知的扩展,特别是在ARM处理器上使用的C标准.我想在我的x86_64处理器上运行它们的IEEE版本.虽然我知道它们通常不具备这种功能,但我可以使用无符号短"存储(它们具有相同的对齐要求和存储空间)和(硬件)浮点运算来模拟它们.

The __fp16 floating point data-type is a well known extension to the C standard used notably on ARM processors. I would like to run the IEEE version of them on my x86_64 processor. While I know they typically do not have that, I would be fine with emulating them with "unsigned short" storage (they have the same alignment requirement and storage space), and (hardware) float arithmetic.

是否可以在gcc中请求?

Is there a way to request that in gcc?

我认为四舍五入可能有点不正确",但这对我来说是可以的.

I assume the rounding might be slightly "incorrect", but that is ok to me.

如果这也可以在C ++中工作,那将是理想的选择.

If this were to work in C++ too that would be ideal.

推荐答案

在gcc(自gcc 8.2.0起)中,我没有找到一种方法.

I did not find a way to do so in gcc (as of gcc 8.2.0).

对于clang,在6.0.0中,以下选项显示出一些成功:

As for clang, in 6.0.0 the following options showed some success:

clang -cc1 -fnative-half-type -fallow-half-arguments-and-returns

选项-fnative-half-type启用__fp16类型的使用(而不是促使它们浮动).虽然选项-fallow-half-arguments-and-returns允许按值传递__fp16,但该API是非标准的API,请注意不要混合使用不同的编译器.

The option -fnative-half-type enable the use of __fp16 type (instead of promoting them to float). While the option -fallow-half-arguments-and-returns allows to pass __fp16 by value, the API being non-standard be careful not to mix different compilers.

话虽如此,它不提供使用__fp16类型的数学函数(它将提升它们到floatdouble或从floatdouble升级).

That being said, it does not provide math functions using __fp16 types (it will promote them to/from float or double).

对于我的用例来说就足够了.

It was sufficient for my use case.

这篇关于如何在x86_64的gcc上启用__fp16类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆