aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2024-02-01 17:59:51 +0000
committerPádraig Brady <P@draigBrady.com>2024-02-05 13:30:45 +0000
commit76604db7d2da0ceb4de4542ebf315b3d6415f972 (patch)
tree84f4241b1c768fb3d56f4ca9357dd2b56163dd1f /tests
parentseq: say why not ‘x += step’ (diff)
downloadcoreutils-76604db7d2da0ceb4de4542ebf315b3d6415f972.tar.gz
coreutils-76604db7d2da0ceb4de4542ebf315b3d6415f972.zip
od: support half precision floating point
Rely on compiler support for _Float16 and __bf16 to support -fH and -fB formats respectively. I.e. IEEE 16 bit, and brain 16 bit floats respectively. Modern GCC and LLVM compilers support both types. clang-sect=half-precision-floating-point https://gcc.gnu.org/onlinedocs/gcc/Half-Precision.html https://clang.llvm.org/docs/LanguageExtensions.html#$clang-sect https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0192r4.html https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html This was tested on: gcc 13, clang 17 x86 (Both types supported) gcc 7 aarch64 (Only -fH supported) gcc 13 ppc(be) (Neither supported. Both will be with GCC 14) * src/od.c: Support -tf2 or -tfH to print IEEE 16 bit floating point, or -tfB to print Brain 16 bit floating point. * configure.ac: Check for _Float16 and __bf16 types. * doc/coreutils.texi (od invocation): Mention the new -f types. * tests/od/od-float.sh: Add test cases. * NEWS: Mention the new feature. Addresses https://bugs.gnu.org/68871
Diffstat (limited to 'tests')
-rwxr-xr-xtests/od/od-float.sh21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/od/od-float.sh b/tests/od/od-float.sh
index 35a6d1249..239b5f10e 100755
--- a/tests/od/od-float.sh
+++ b/tests/od/od-float.sh
@@ -69,4 +69,25 @@ set x $(printf 00000000ff000000 | tr 0f '\000\377' | od -t fL) || fail=1
#*) fail=1;;
#esac
+# Check Half precision IEEE 16 bit float
+if grep '^#define HAVE__FLOAT16 1' "$CONFIG_HEADER" >/dev/null; then
+ for fmt in '-tfH' '-tf2'; do
+ od_out=$(printf '\x3C\x00\x3C\x00' | od --endian=big -An $fmt | tr -d ' ')
+ test "$od_out" = '11' || fail=1
+ done
+else
+ echo "od: this system doesn't provide a 'fH' floating point type" > exp_err
+ returns_ 1 od -tfH /dev/null 2>err || fail=1
+ compare exp_err err || fail=1
+fi
+# Check Half precision Brain 16 bit float
+if grep '^#define HAVE___BF16 1' "$CONFIG_HEADER" >/dev/null; then
+ od_out=$(printf '\x3F\x80\x3F\x80' | od --endian=big -An -tfB | tr -d ' ')
+ test "$od_out" = '11' || fail=1
+else
+ echo "od: this system doesn't provide a 'fB' floating point type" > exp_err
+ returns_ 1 od -tfB /dev/null 2>err || fail=1
+ compare exp_err err || fail=1
+fi
+
Exit $fail