Skip to content

Commit

Permalink
vertexcodec: Use generic zigzag() to match unzigzag()
Browse files Browse the repository at this point in the history
Instead of having three versions of zigzag per type we can use a
template similarly to unzigzag. This produces ~same code with less
duplication.
  • Loading branch information
zeux committed Dec 20, 2024
1 parent c9c4869 commit f5404c3
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/vertexcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,15 @@ static size_t getVertexBlockSize(size_t vertex_size)
return (result < kVertexBlockMaxSize) ? result : kVertexBlockMaxSize;
}

inline unsigned char zigzag(unsigned char v)
{
return ((signed char)(v) >> 7) ^ (v << 1);
}

inline unsigned short zigzag(unsigned short v)
{
return ((signed short)(v) >> 15) ^ (v << 1);
}

inline unsigned int zigzag(unsigned int v)
inline unsigned int rotate(unsigned int v, int r)
{
return ((signed int)(v) >> 31) ^ (v << 1);
return (v << r) | (v >> ((32 - r) & 31));
}

inline unsigned int rotate(unsigned int v, int r)
template <typename T>
inline T zigzag(T v)
{
return (v << r) | (v >> ((32 - r) & 31));
return (0 - (v >> (sizeof(T) * 8 - 1))) ^ (v << 1);
}

template <typename T>
Expand Down

0 comments on commit f5404c3

Please sign in to comment.