De-bootstrap the qfloat16 generator tool

It doesn't really need Qt. So remove the dependency. I've confirmed that
the output is identical to what used to be generated.

This ought to be replaced by a script. Or just committed to Git, since
the generated output is not really supposed to change, ever.

Change-Id: I46363e5b8944459e8c48fffd158bb5d74fb6184c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Thiago Macieira 2019-03-13 20:33:52 -07:00
parent 6492541df3
commit 26e5aa45e1
3 changed files with 44 additions and 56 deletions

View File

@ -129,7 +129,7 @@ QMAKE_QFLOAT16_TABLES_GENERATE = global/qfloat16.h
qtPrepareTool(QMAKE_QFLOAT16_TABLES, qfloat16-tables) qtPrepareTool(QMAKE_QFLOAT16_TABLES, qfloat16-tables)
qfloat16_tables.commands = $$QMAKE_QFLOAT16_TABLES ${QMAKE_FILE_OUT} qfloat16_tables.commands = $$QMAKE_QFLOAT16_TABLES > ${QMAKE_FILE_OUT}
qfloat16_tables.output = global/qfloat16tables.cpp qfloat16_tables.output = global/qfloat16tables.cpp
qfloat16_tables.depends = $$QMAKE_QFLOAT16_TABLES_EXE qfloat16_tables.depends = $$QMAKE_QFLOAT16_TABLES_EXE
qfloat16_tables.input = QMAKE_QFLOAT16_TABLES_GENERATE qfloat16_tables.input = QMAKE_QFLOAT16_TABLES_GENERATE

View File

@ -1,6 +1,7 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2016 by Southwest Research Institute (R) ** Copyright (C) 2016 by Southwest Research Institute (R)
** Copyright (C) 2019 Intel Corporation.
** Contact: http://www.qt-project.org/legal ** Contact: http://www.qt-project.org/legal
** **
** This file is part of the QtCore module of the Qt Toolkit. ** This file is part of the QtCore module of the Qt Toolkit.
@ -37,13 +38,13 @@
** **
****************************************************************************/ ****************************************************************************/
#include <qfile.h> #include <stdint.h>
#include <qdebug.h> #include <stdio.h>
quint32 convertmantissa(qint32 i) uint32_t convertmantissa(int32_t i)
{ {
quint32 m = i << 13; // Zero pad mantissa bits uint32_t m = i << 13; // Zero pad mantissa bits
quint32 e = 0; // Zero exponent uint32_t e = 0; // Zero exponent
while (!(m & 0x00800000)) { // While not normalized while (!(m & 0x00800000)) { // While not normalized
e -= 0x00800000; // Decrement exponent (1<<23) e -= 0x00800000; // Decrement exponent (1<<23)
@ -56,60 +57,48 @@ quint32 convertmantissa(qint32 i)
// we first build these tables up and then print them out as a separate step in order // we first build these tables up and then print them out as a separate step in order
// to more closely map the implementation given in the paper. // to more closely map the implementation given in the paper.
quint32 basetable[512]; uint32_t basetable[512];
quint32 shifttable[512]; uint32_t shifttable[512];
#define PRINTHEX(a) "0x" + QByteArray::number(a,16).toUpper() + "U,\n" int main()
qint32 main(qint32 argc, char **argv)
{ {
if (argc < 2) { uint32_t i;
qWarning() << "Must provide output filename as argument.";
return -1;
}
QFile fid(QFile::decodeName(argv[1])); printf("/* This file was generated by gen_qfloat16_tables.cpp */\n\n");
if (!fid.open(QIODevice::WriteOnly | QIODevice::Text)) { printf("#include <QtCore/qfloat16.h>\n\n");
qWarning() << "Abort: Failed to open/create file" << fid.fileName();
return -1;
}
quint32 i;
fid.write("/* This file was generated by gen_qfloat16_tables.cpp */\n\n"); printf("QT_BEGIN_NAMESPACE\n\n");
fid.write("#include <QtCore/qfloat16.h>\n\n"); printf("#if !defined(__F16C__) && !defined(__ARM_FP16_FORMAT_IEEE)\n\n");
fid.write("QT_BEGIN_NAMESPACE\n\n"); printf("const quint32 qfloat16::mantissatable[2048] = {\n");
fid.write("#if !defined(__F16C__) && !defined(__ARM_FP16_FORMAT_IEEE)\n\n"); printf("0,\n");
fid.write("const quint32 qfloat16::mantissatable[2048] = {\n");
fid.write("0,\n");
for (i = 1; i < 1024; i++) for (i = 1; i < 1024; i++)
fid.write(PRINTHEX(convertmantissa(i))); printf("0x%XU,\n", convertmantissa(i));
for (i = 1024; i < 2048; i++) for (i = 1024; i < 2048; i++)
fid.write(PRINTHEX(0x38000000U + ((i - 1024) << 13))); printf("0x%XU,\n", 0x38000000U + ((i - 1024) << 13));
fid.write("};\n\n"); printf("};\n\n");
fid.write("const quint32 qfloat16::exponenttable[64] = {\n"); printf("const quint32 qfloat16::exponenttable[64] = {\n");
fid.write("0,\n"); printf("0,\n");
for (i = 1; i < 31; i++) for (i = 1; i < 31; i++)
fid.write(PRINTHEX(i << 23)); printf("0x%XU,\n", i << 23);
fid.write("0x47800000U,\n"); // 31 printf("0x47800000U,\n"); // 31
fid.write("0x80000000U,\n"); // 32 printf("0x80000000U,\n"); // 32
for (i = 33; i < 63; i++) for (i = 33; i < 63; i++)
fid.write(PRINTHEX(0x80000000U + ((i - 32) << 23))); printf("0x%XU,\n", 0x80000000U + ((i - 32) << 23));
fid.write("0xC7800000U,\n"); // 63 printf("0xC7800000U,\n"); // 63
fid.write("};\n\n"); printf("};\n\n");
fid.write("const quint32 qfloat16::offsettable[64] = {\n"); printf("const quint32 qfloat16::offsettable[64] = {\n");
fid.write("0,\n"); printf("0,\n");
for (i = 1; i < 32; i++) for (i = 1; i < 32; i++)
fid.write("1024U,\n"); printf("1024U,\n");
fid.write("0,\n"); printf("0,\n");
for (i = 33; i < 64; i++) for (i = 33; i < 64; i++)
fid.write("1024U,\n"); printf("1024U,\n");
fid.write("};\n\n"); printf("};\n\n");
qint32 e; int32_t e;
for (i = 0; i < 256; ++i) { for (i = 0; i < 256; ++i) {
e = i - 127; e = i - 127;
if (e < -24) { // Very small numbers map to zero if (e < -24) { // Very small numbers map to zero
@ -144,20 +133,19 @@ qint32 main(qint32 argc, char **argv)
} }
} }
fid.write("const quint32 qfloat16::basetable[512] = {\n"); printf("const quint32 qfloat16::basetable[512] = {\n");
for (i = 0; i < 512; i++) for (i = 0; i < 512; i++)
fid.write(PRINTHEX(basetable[i])); printf("0x%XU,\n", basetable[i]);
fid.write("};\n\n"); printf("};\n\n");
fid.write("const quint32 qfloat16::shifttable[512] = {\n"); printf("const quint32 qfloat16::shifttable[512] = {\n");
for (i = 0; i < 512; i++) for (i = 0; i < 512; i++)
fid.write(PRINTHEX(shifttable[i])); printf("0x%XU,\n", shifttable[i]);
fid.write("};\n\n"); printf("};\n\n");
fid.write("#endif // !__F16C__ && !__ARM_FP16_FORMAT_IEEE\n\n"); printf("#endif // !__F16C__ && !__ARM_FP16_FORMAT_IEEE\n\n");
fid.write("QT_END_NAMESPACE\n"); printf("QT_END_NAMESPACE\n");
fid.close();
return 0; return 0;
} }

View File

@ -1,6 +1,6 @@
option(host_build) option(host_build)
CONFIG += force_bootstrap CONFIG -= qt
SOURCES += gen_qfloat16_tables.cpp SOURCES += gen_qfloat16_tables.cpp
load(qt_tool) load(qt_tool)