Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/SharedDependencies/Sources/nihstro/disassembler.cpp
2 views
1
// Copyright 2014 Tony Wasserka
2
// All rights reserved.
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
6
//
7
// * Redistributions of source code must retain the above copyright
8
// notice, this list of conditions and the following disclaimer.
9
// * Redistributions in binary form must reproduce the above copyright
10
// notice, this list of conditions and the following disclaimer in the
11
// documentation and/or other materials provided with the distribution.
12
// * Neither the name of the owner nor the names of its contributors may
13
// be used to endorse or promote products derived from this software
14
// without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
#include <algorithm>
29
#include <cassert>
30
#include <cmath>
31
#include <iostream>
32
#include <iomanip>
33
#include <fstream>
34
#include <sstream>
35
#include <vector>
36
#include <map>
37
#include <stdint.h>
38
39
#include "nihstro/bit_field.h"
40
#include "nihstro/shader_bytecode.h"
41
#include "nihstro/parser_shbin.h"
42
43
using namespace nihstro;
44
45
struct float24 {
46
static float24 FromFloat32(float val) {
47
float24 ret;
48
ret.value = val;
49
return ret;
50
}
51
52
// 16 bit mantissa, 7 bit exponent, 1 bit sign
53
// TODO: No idea if this works as intended
54
static float24 FromRawFloat24(uint32_t hex) {
55
float24 ret;
56
if ((hex & 0xFFFFFF) == 0) {
57
ret.value = 0;
58
} else {
59
uint32_t mantissa = hex & 0xFFFF;
60
uint32_t exponent = (hex >> 16) & 0x7F;
61
uint32_t sign = hex >> 23;
62
ret.value = std::pow(2.0f, (float)exponent-63.0f) * (1.0f + mantissa * std::pow(2.0f, -16.f));
63
if (sign)
64
ret.value = -ret.value;
65
}
66
return ret;
67
}
68
69
// Not recommended for anything but logging
70
float ToFloat32() const {
71
return value;
72
}
73
74
private:
75
// Stored as a regular float, merely for convenience
76
// TODO: Perform proper arithmetic on this!
77
float value;
78
};
79
80