Hello all,
Can anyone help me convert this tiny C program that calls the Neon "vcvt_f32_f16" instruction, e.g. converting to FPC assembly?
My OpenGL code uses GL_INT_2_10_10_10_REV datatype for normals which is not supported on the M1. I can use GL_FLOAT (float32), but that is wasteful. Therefore, I would like to use GL_HALF (float16). Included is a simple C program which calls the Neon SIMD instruction. My Pascal uses scalar code but the results appear different. Perhaps this reflects that Arm supports two half-precision (16-bit) floating-point scalar data types:
The IEEE 754-2008 __fp16 data type, defined in the Arm C Language Extensions.
The _Float16 data type, defined in the C11 extension ISO/IEC TS 18661-3:2015
(the attached file "f16.inc" should be renamed "f16.c", extension changed to allow upload).
$gcc f16.c -o f16; ./f16
f32: 32.012 64.094 12.096 3.14159274
f16: 0x00000020 0x00000040 0x0000000c 0x00000003
f32: 32 64.125 12.0938 3.14062500
$fpc f16.pas; ./f16
Free Pascal Compiler version 3.3.1 [2021/01/01] for aarch64
Copyright (c) 1993-2020 by Florian Klaempfl and others
Target OS: Darwin for AArch64
Compiling f16.pas
Assembling f16
Linking f16
200 lines compiled, 0.5 sec
f32: 32.0120010375977 64.0940017700195 12.0959997177124 3.14159274101257
f16: 0x5000 0x5402 0x4A0C 0x4248
f32: 32 64.125 12.09375 3.140625