--- /dev/null
+#include "markbit.h"
+
+unsigned int markmappingarray[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15};
+
+
+unsigned int bitmarkmappingarray[]={2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 4, 4, 4, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28,
+ 30};
+
+unsigned int revmarkmappingarray[]={0x0, 0x40000000, 0x80000000, 0x90000000, 0x94000000, 0x98000000, 0x9c000000, 0xa0000000, 0xa4000000, 0xa8000000, 0xac000000, 0xb0000000, 0xb4000000, 0xb8000000, 0xbc000000, 0xc0000000};
+
+
+/*int main(int argv, char **argc) {
+ void *ptr=1024;
+ unsigned int i;
+ gcmarktbl[0]=0xf000ffff;
+ gcmarktbl[1]=0xffffffff;
+ for(i=0;i<36;i++) {
+ setLength(ptr, i);
+ printf("%d\n",getMarkedLength(ptr));
+ printf("%x %x %x\n", gcmarktbl[0], gcmarktbl[1], gcmarktbl[2]);
+ clearMark(ptr);
+ printf("%x %x %x\n", gcmarktbl[0], gcmarktbl[1], gcmarktbl[2]);
+ }
+ }*/
+
--- /dev/null
+#ifndef MARKBIT_H
+#define MARKBIT_H
+
+extern unsigned int markmappingarray[];
+extern unsigned int bitmarkmappingarray[];
+extern unsigned int revmarkmappingarray[];
+
+#define NOTMARKED 0
+#define ALIGNOBJSIZE(x) (x)>>5
+
+#define OBJMASK 0x40000000 //set towhatever smallest object mark is
+#define MARKMASK 0xc0000000 //set towhatever smallest object mark is
+
+
+
+/* Return length in units of ALIGNSIZE */
+
+static inline unsigned int getMarkedLength(void *ptr) {
+ unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase));
+ unsigned INTPTR hibits=alignsize>>4;
+ unsigned INTPTR lobits=(alignsize&15)<<1;
+ unsigned INTPTR val;
+ if (lobits==0)
+ val=gcmarktbl[hibits];
+ else {
+ unsigned INTPTR revlobits=32-lobits;
+ unsigned INTPTR val=(gcmarktbl[hibits]<<lobits)
+ |(gcmarktbl[hibits+1]>>(revlobits));
+ }
+ unsigned int index=val>>26;
+ if (index>48)
+ return (val-0xc4000000)+16;
+ else
+ return markmappingarray[index];
+}
+
+/* Return non-zero value if the object is marked */
+
+static inline unsigned int checkMark(void *ptr) {
+ unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase));
+ unsigned INTPTR hibits=alignsize>>4;
+ unsigned INTPTR lobits=(alignsize&15)<<1;
+
+ return (gcmarktbl[hibits]<<lobits)&MARKMASK;
+}
+
+/* Set length in units of ALIGNSIZE */
+
+static inline void setLength(void *ptr, unsigned int length) {
+ unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase));
+ unsigned INTPTR hibits=alignsize>>4;
+ unsigned INTPTR lobits=(alignsize&15)<<1;
+ unsigned int ormask=(length>=16)?0xc4000000+(length-16):revmarkmappingarray[length];
+ if (lobits==0) {
+ gcmarktbl[hibits]|=ormask;
+ } else {
+ gcmarktbl[hibits]|=ormask>>lobits;
+ gcmarktbl[hibits+1]|=ormask<<(32-lobits);
+ }
+}
+
+/* Set length for premarked object */
+
+static inline void setLengthMarked(void *ptr, unsigned int length) {
+ unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase));
+ unsigned INTPTR hibits=alignsize>>4;
+ unsigned INTPTR lobits=(alignsize&15)<<1;
+ unsigned int ormask=(length>=16)?0xc4000000+(length-16):revmarkmappingarray[length];
+ if (lobits==0) {
+ gcmarktbl[hibits]=(gcmarktbl[hibits]^(OBJMASK))|ormask;
+ } else {
+ gcmarktbl[hibits]=(gcmarktbl[hibits]^(OBJMASK>>lobits))|(ormask>>lobits);
+ gcmarktbl[hibits+1]|=ormask<<(32-lobits);
+ }
+}
+/* Set length in units of ALIGNSIZE */
+
+static inline void setMark(void *ptr) {
+ unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase));
+ unsigned INTPTR hibits=alignsize>>4;
+ unsigned INTPTR lobits=(alignsize&15)<<1;
+ gcmarktbl[hibits]|=OBJMASK>>lobits;
+}
+
+static inline void clearMark(void *ptr) {
+ unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase));
+ unsigned INTPTR hibits=alignsize>>4;
+ unsigned INTPTR lobits=(alignsize&15)<<1;
+
+ if (lobits==0) {
+ unsigned int hipart=gcmarktbl[hibits];
+ unsigned int index=hipart>>26;
+ unsigned int bits=(index>48)?32:bitmarkmappingarray[index];
+ unsigned int bitstotoss=32-bits;
+ gcmarktbl[hibits]^=((hipart>>(bitstotoss))<<(bitstotoss));
+
+ } else {
+ unsigned int orighi=gcmarktbl[hibits];
+ unsigned int hipart=orighi<<lobits;
+ unsigned INTPTR revlobits=32-lobits;
+ unsigned int lowpart=gcmarktbl[hibits+1]>>revlobits;
+ unsigned INTPTR val=hipart|lowpart;
+
+ unsigned int index=val>>26;
+ unsigned int bits=(index>48)?32:bitmarkmappingarray[index];
+
+ unsigned int bitstotoss=32-bits;
+ unsigned int bitstotosspluslobits=bitstotoss-lobits;
+ gcmarktbl[hibits]^=((orighi>>(bitstotosspluslobits))<<bitstotosspluslobits);
+ gcmarktbl[hibits+1]^=(lowpart>>bitstotoss)<<(bitstotoss+revlobits);
+ }
+}
+
+#endif