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)
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.depends = $$QMAKE_QFLOAT16_TABLES_EXE
qfloat16_tables.input = QMAKE_QFLOAT16_TABLES_GENERATE

View File

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

View File

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