Skip to content

Instantly share code, notes, and snippets.

View Subv's full-sized avatar

Sebastian Valle Subv

  • Barranquilla, Colombia
View GitHub Profile
const Info& GetInfo() const {
#define unknown_instruction { OpCode::Type::Unknown, 0, "UNK" }
#define dummy { OpCode::Type::Unknown, 0, "DMY" }
static const OpCode::Info info_table[] = {
{ OpCode::Type::Arithmetic, OpCode::Info::TwoArguments, "add" },
{ OpCode::Type::Arithmetic, OpCode::Info::TwoArguments, "dp3" },
{ OpCode::Type::Arithmetic, OpCode::Info::TwoArguments, "dp4" },
{ OpCode::Type::Arithmetic, OpCode::Info::TwoArguments, "dph" },
unknown_instruction,
{ OpCode::Type::Arithmetic, OpCode::Info::OneArgument, "exp" },
00007FF6CD8C0E90 mov edx,dword ptr [rcx]
00007FF6CD8C0E92 mov eax,edx
00007FF6CD8C0E94 and eax,0FFFFFFF8h
00007FF6CD8C0E97 cmp eax,38h
00007FF6CD8C0E9A jne nihstro::OpCode::GetInfo+1Fh (07FF6CD8C0EAFh)
00007FF6CD8C0E9C mov edx,eax
00007FF6CD8C0E9E mov eax,eax
00007FF6CD8C0EA0 lea rcx,[`nihstro::OpCode::GetInfo'::`2'::info_table (07FF6CDA45230h)]
00007FF6CD8C0EA7 shl rax,4
00007FF6CD8C0EAB add rax,rcx
00007FF62A820EA0 mov edx,dword ptr [rcx]
00007FF62A820EA2 mov eax,edx
00007FF62A820EA4 and eax,0FFFFFFF8h
00007FF62A820EA7 cmp eax,38h
00007FF62A820EAA jne nihstro::OpCode::GetInfo+20h (07FF62A820EC0h)
00007FF62A820EAC mov eax,38h
00007FF62A820EB1 lea rcx,[`nihstro::OpCode::GetInfo'::`2'::info_table (07FF62A9A5230h)]
00007FF62A820EB8 shl rax,4
00007FF62A820EBC add rax,rcx
00007FF62A820EBF ret
size_t EffectiveOpCode() const {
uint32_t op = static_cast<uint32_t>(value);
if (static_cast<Id>(op & ~0x7) == Id::MAD)
return static_cast<size_t>(Id::MAD);
else if (static_cast<Id>(op & ~0x7) == Id::MADI)
return static_cast<size_t>(Id::MADI);
else if (static_cast<Id>(op & ~0x1) == Id::CMP)
return static_cast<size_t>(Id::CMP);
else
return static_cast<size_t>(value);
00007FF758460E80 mov eax,dword ptr [rcx]
00007FF758460E82 lea rcx,[`nihstro::OpCode::EffectiveOpCode'::`2'::vals (07FF7585E5230h)]
00007FF758460E89 mov rax,qword ptr [rcx+rax*8]
00007FF758460E8D lea rcx,[`nihstro::OpCode::GetInfo'::`2'::info_table (07FF7585E54A0h)]
00007FF758460E94 shl rax,4
00007FF758460E98 add rax,rcx
00007FF758460E9B ret
size_t EffectiveOpCode() const {
static const size_t vals[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 46, // CMP
48, 48, 48, 48, 48, 48, 48, 48,
56, 56, 56, 56, 56, 56, 56, 56 };
size_t op = static_cast<size_t>(value);
return vals[op];
}
@Subv
Subv / gist:9cabcdda5f607d46edfd
Last active August 29, 2015 14:23
ASM generated by the new nihstro::OpCode::GetInfo.
00007FF7CAB60EA0 mov eax,dword ptr [rcx]
00007FF7CAB60EA2 lea rcx,[`nihstro::OpCode::GetInfo'::`2'::info_table (07FF7CACE5230h)]
00007FF7CAB60EA9 shl rax,4
00007FF7CAB60EAD add rax,rcx
00007FF7CAB60EB0 ret
@Subv
Subv / gist:fd53c4407894e742d6c6
Created June 26, 2015 02:50
Nihstro super-speedup
diff --git a/include/nihstro/shader_bytecode.h b/include/nihstro/shader_bytecode.h
index 4b609eb..ff3217c 100644
--- a/include/nihstro/shader_bytecode.h
+++ b/include/nihstro/shader_bytecode.h
@@ -380,8 +380,8 @@ struct OpCode {
}
const Info& GetInfo() const {
- static const OpCode::Info unknown_instruction = { OpCode::Type::Unknown, 0, "UNK" };
- static const OpCode::Info dummy = { OpCode::Type::Unknown, 0, "DMY" };
const Info& GetInfo() const {
#define unknown_instruction { OpCode::Type::Unknown, 0, "UNK" }
#define dummy { OpCode::Type::Unknown, 0, "DMY" }
static const OpCode::Info info_table[] = {
{ OpCode::Type::Arithmetic, OpCode::Info::TwoArguments, "add" },
{ OpCode::Type::Arithmetic, OpCode::Info::TwoArguments, "dp3" },
{ OpCode::Type::Arithmetic, OpCode::Info::TwoArguments, "dp4" },
{ OpCode::Type::Arithmetic, OpCode::Info::TwoArguments, "dph" },
unknown_instruction,
{ OpCode::Type::Arithmetic, OpCode::Info::OneArgument, "exp" },
00007FF74C0617D0 sub rsp,18h
00007FF74C0617D4 mov r8d,dword ptr [rcx]
00007FF74C0617D7 mov eax,r8d
00007FF74C0617DA shr eax,0Bh
00007FF74C0617DD and eax,3
00007FF74C0617E0 mov dword ptr [rsp],eax
00007FF74C0617E3 mov eax,r8d
00007FF74C0617E6 shr eax,9
00007FF74C0617E9 and eax,3
00007FF74C0617EC mov dword ptr [rsp+4],eax