Skip to content

Instantly share code, notes, and snippets.

@Ziemas
Created April 4, 2024 03:20
Show Gist options
  • Save Ziemas/32db33c5c1c8bd8dd666069bf7cef543 to your computer and use it in GitHub Desktop.
Save Ziemas/32db33c5c1c8bd8dd666069bf7cef543 to your computer and use it in GitHub Desktop.
#include <stdio.h>
typedef unsigned long uint64;
#define BIT(x) (1ULL << (uint64)(x))
#define GENMASK(msb, lsb) ((BIT(((uint64)(msb) + 1ULL) - (uint64)(lsb)) - 1ULL) << (uint64)(lsb))
#define _FIELD_LSB(field) ((uint64)(field) & ~((uint64)(field) - 1ULL))
#define FIELD_PREP(field, val) ((uint64)(val) * (_FIELD_LSB((uint64)field)))
#define FIELD_GET(field, val) (((uint64)(val) & (uint64)(field)) / _FIELD_LSB((uint64)(field)))
/* XYZOFFSET Fields */
#define GS_XYOFFSET_OFY GENMASK(47, 32)
#define GS_XYOFFSET_OFX GENMASK(15, 0)
void test(int height) {
printf("height %d\n", height);
printf("working %llx\n", FIELD_PREP(GS_XYOFFSET_OFY, (2048 - 448 / 2) << 4));
printf("broken %llx\n", FIELD_PREP(GS_XYOFFSET_OFY, (2048 - height / 2) << 4));
}
int main() {
test(448);
while (1)
;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment