///////////////////////////////////////////////////////////////////////////1//2// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas3// Digital Ltd. LLC4//5// All rights reserved.6//7// Redistribution and use in source and binary forms, with or without8// modification, are permitted provided that the following conditions are9// met:10// * Redistributions of source code must retain the above copyright11// notice, this list of conditions and the following disclaimer.12// * Redistributions in binary form must reproduce the above13// copyright notice, this list of conditions and the following disclaimer14// in the documentation and/or other materials provided with the15// distribution.16// * Neither the name of Industrial Light & Magic nor the names of17// its contributors may be used to endorse or promote products derived18// from this software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31//32///////////////////////////////////////////////////////////////////////////33343536#include <iostream>37#include <iomanip>3839using namespace std;4041//-----------------------------------------------------42// Compute a lookup table for float-to-half conversion.43//44// When indexed with the combined sign and exponent of45// a float, the table either returns the combined sign46// and exponent of the corresponding half, or zero if47// the corresponding half may not be normalized (zero,48// denormalized, overflow).49//-----------------------------------------------------5051void52initELut (unsigned short eLut[])53{54for (int i = 0; i < 0x100; i++)55{56int e = (i & 0x0ff) - (127 - 15);5758if (e <= 0 || e >= 30)59{60//61// Special case62//6364eLut[i] = 0;65eLut[i | 0x100] = 0;66}67else68{69//70// Common case - normalized half, no exponent overflow possible71//7273eLut[i] = (e << 10);74eLut[i | 0x100] = ((e << 10) | 0x8000);75}76}77}787980//------------------------------------------------------------81// Main - prints the sign-and-exponent conversion lookup table82//------------------------------------------------------------8384int85main ()86{87const int tableSize = 1 << 9;88unsigned short eLut[tableSize];89initELut (eLut);9091cout << "//\n"92"// This is an automatically generated file.\n"93"// Do not edit.\n"94"//\n\n";9596cout << "{\n ";9798for (int i = 0; i < tableSize; i++)99{100cout << setw (5) << eLut[i] << ", ";101102if (i % 8 == 7)103{104cout << "\n";105106if (i < tableSize - 1)107cout << " ";108}109}110111cout << "};\n";112return 0;113}114115116