Last active
October 1, 2022 07:00
-
-
Save SmallJoker/4027d7f33a424d1cdc688d651af77e37 to your computer and use it in GitHub Desktop.
v3s16_optimization.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdint.h> | |
#include <vector> | |
#include "vector3d.h" | |
using u8 = unsigned char; | |
using s16 = int16_t; | |
using u16 = uint16_t; | |
using v3s16 = irr::core::vector3d<s16>; | |
struct MapNode | |
{ | |
u16 param0 = 1; | |
u8 param1 = 2; | |
u8 param2 = 3; | |
}; | |
struct MapBlock { | |
MapBlock() | |
{ | |
data.resize(zstride * ystride * 2); | |
} | |
inline MapNode getNodeNoCheck(s16 x, s16 y, s16 z) | |
{ | |
return data[z * zstride + y * ystride + x]; | |
} | |
//inline MapNode getNodeNoCheck(const v3s16 &p) | |
inline MapNode getNodeNoCheck(v3s16 p) | |
{ | |
return getNodeNoCheck(p.X, p.Y, p.Z); | |
} | |
std::vector<MapNode> data; | |
u8 zstride = 2; | |
u8 ystride = 2; | |
}; | |
int main() | |
{ | |
MapBlock block; | |
v3s16 pos; | |
std::cin >> pos.X >> pos.Y >> pos.Z; | |
MapNode n = block.getNodeNoCheck(pos); | |
std::cout << (int)n.param0 << (int)n.param1 << (int)n.param2 << std::endl; | |
return 0; | |
} | |
#if 0 | |
/* v3s16 copying */ | |
main: | |
undefined4 local_4e; <-- v3s16 X & Y | |
short local_4a; <-- v3s16 Z | |
MapBlock local_48 [40]; <-- 40 bytes total (display issue) | |
uVar1 = MapBlock::getNodeNoCheck(local_48,local_4e); | |
^ Stack moved to RSI (2nd argument) using 2x OR, 2x SHL and some moves | |
getNodeNoCheck: | |
short in_register_00000034; | |
short local_18; | |
short sStack22; | |
sStack22 = (short)(param_1 >> 0x10); | |
local_18 = (short)param_1; | |
getNodeNoCheck(this,local_18,sStack22,in_register_00000034); | |
return; | |
/* Const reference to v3s16 */ | |
main: | |
uVar1 = MapBlock::getNodeNoCheck(local_48,(vector3d *)&local_4e); | |
^ single LEA command to retrieve the stack's address to pass directly | |
getNodeNoCheck: | |
getNodeNoCheck(this,*(short *)param_1,*(short *)(param_1 + 2),*(short *)(param_1 + 4)); | |
^ looks shorter but has a few MOV operations more than the copying version | |
return; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment