summaryrefslogtreecommitdiff
path: root/sys/dev/rasops/rasops_masks.h
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2006-08-03 18:42:07 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2006-08-03 18:42:07 +0000
commit2b96bd491076aae2fdac662a6166a97d4fc90ecf (patch)
tree52c7fe91243ba89a0edccf7a9038d1ae3896d332 /sys/dev/rasops/rasops_masks.h
parent3f309a50a7df092f1c0c2f8dc4217c9cf401e247 (diff)
Since rasops is big-endian internally (because it's the logical choice
for frame buffer work), it is no surprise that the less-than-8-bpp code is completely wrong when run on a little endian machine, and only works by accident if character cells are 8-bit wide. Fix the BE<->LE conversions, so that now rasops1 works in all cases. rasops2 and rasops4 might still need some help, but I'm not in a hurry to meet a 4bpp big-endian frame buffer on a little-endian system...
Diffstat (limited to 'sys/dev/rasops/rasops_masks.h')
-rw-r--r--sys/dev/rasops/rasops_masks.h25
1 files changed, 20 insertions, 5 deletions
diff --git a/sys/dev/rasops/rasops_masks.h b/sys/dev/rasops/rasops_masks.h
index 6e9b3afc89b..c73ab5cf42b 100644
--- a/sys/dev/rasops/rasops_masks.h
+++ b/sys/dev/rasops/rasops_masks.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rasops_masks.h,v 1.1 2001/03/18 04:32:45 nate Exp $ */
+/* $OpenBSD: rasops_masks.h,v 1.2 2006/08/03 18:42:06 miod Exp $ */
/* $NetBSD: rasops_masks.h,v 1.5 2000/06/13 13:37:01 ad Exp $ */
/*-
@@ -62,10 +62,17 @@
#define MBL(x,y) ((y) > 31 ? 0 : MBE(MBE(x) << (y)))
#define MBR(x,y) ((y) > 31 ? 0 : MBE(MBE(x) >> (y)))
-#define MBE(x) ( (((x) & 0x000000FFU) << 24) \
- | (((x) & 0x0000FF00U) << 8) \
- | (((x) & 0x00FF0000U) >> 8) \
- | (((x) & 0xFF000000U) >> 24) )
+#define MBE(x) \
+({ \
+ u_int32_t tmp = (x); \
+ tmp = ((tmp >> 1) & 0x55555555) | ((tmp << 1) & 0xaaaaaaaa); \
+ tmp = ((tmp >> 2) & 0x33333333) | ((tmp << 2) & 0xcccccccc); \
+ tmp = ((tmp >> 4) & 0x0f0f0f0f) | ((tmp << 4) & 0xf0f0f0f0); \
+ tmp = ((tmp >> 8) & 0x00ff00ff) | ((tmp << 8) & 0xff00ff00); \
+ tmp = ((tmp >> 16) & 0x0000ffff) | ((tmp << 16) & 0xffff0000); \
+ tmp; \
+})
+
#endif
/*
@@ -96,8 +103,16 @@
} while(0);
/* rasops_masks.c */
+#if BYTE_ORDER == BIG_ENDIAN
extern const int32_t rasops_lmask[32+1];
extern const int32_t rasops_rmask[32+1];
extern const int32_t rasops_pmask[32][32];
+#define rasops_masks_init() do { } while (0)
+#else
+extern int32_t rasops_lmask[32+1];
+extern int32_t rasops_rmask[32+1];
+extern int32_t rasops_pmask[32][32];
+void rasops_masks_init(void);
+#endif
#endif /* _RASOPS_MASKS_H_ */