Path: blob/a-new-beginning/SharedDependencies/Sources/nihstro/disassembler.cpp
2 views
// Copyright 2014 Tony Wasserka1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions are met:5//6// * Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// * Redistributions in binary form must reproduce the above copyright9// notice, this list of conditions and the following disclaimer in the10// documentation and/or other materials provided with the distribution.11// * Neither the name of the owner nor the names of its contributors may12// be used to endorse or promote products derived from this software13// without specific prior written permission.14//15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS16// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT17// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR18// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT19// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,20// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT21// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,22// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE25// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2627#include <algorithm>28#include <cassert>29#include <cmath>30#include <iostream>31#include <iomanip>32#include <fstream>33#include <sstream>34#include <vector>35#include <map>36#include <stdint.h>3738#include "nihstro/bit_field.h"39#include "nihstro/shader_bytecode.h"40#include "nihstro/parser_shbin.h"4142using namespace nihstro;4344struct float24 {45static float24 FromFloat32(float val) {46float24 ret;47ret.value = val;48return ret;49}5051// 16 bit mantissa, 7 bit exponent, 1 bit sign52// TODO: No idea if this works as intended53static float24 FromRawFloat24(uint32_t hex) {54float24 ret;55if ((hex & 0xFFFFFF) == 0) {56ret.value = 0;57} else {58uint32_t mantissa = hex & 0xFFFF;59uint32_t exponent = (hex >> 16) & 0x7F;60uint32_t sign = hex >> 23;61ret.value = std::pow(2.0f, (float)exponent-63.0f) * (1.0f + mantissa * std::pow(2.0f, -16.f));62if (sign)63ret.value = -ret.value;64}65return ret;66}6768// Not recommended for anything but logging69float ToFloat32() const {70return value;71}7273private:74// Stored as a regular float, merely for convenience75// TODO: Perform proper arithmetic on this!76float value;77};787980