Skip to content
Browse files

Unbox Ints, at the expense of making them 31 bit

...and they are much faster as a result.

darcs-hash:20080727191035-6ac22-e2a9e4ed708c6e13c6901c9369dfe0d0eadf81fd.gz
  • Loading branch information...
1 parent a4eae90 commit 4225154aad745ad94ef8de37843b2f32e55ef084 eb committed Jul 27, 2008
Showing with 16 additions and 17 deletions.
  1. +7 −6 evm/closure.c
  2. +6 −8 evm/closure.h
  3. +1 −1 examples/intthing.e
  4. +1 −1 examples/testprog.e
  5. +1 −1 examples/testprogslow.e
View
13 evm/closure.c
@@ -24,7 +24,7 @@ void dumpClosure(Closure* c) {
dumpCon((con*)c->info);
break;
case INT:
- printf("INT[%d", (int)c->info);
+ printf("INT[%d", ((int)c)>>1);
break;
case BIGINT:
printf("BIGINT[");
@@ -586,10 +586,11 @@ void* DO_PROJECT(VAL x, int arg)
void* MKINT(int x)
{
- VAL c = MKCLOSURE;
- SETTY(c, INT);
- c->info = (void*)x;
- return c;
+ return (void*)((x<<1)+1);
+// VAL c = MKCLOSURE;
+// SETTY(c, INT);
+// c->info = (void*)x;
+// return c;
}
void* NEWBIGINT(char* intstr)
@@ -620,7 +621,7 @@ void* MKBIGINT(mpz_t* big)
int GETINT(void* x)
{
- return (int)(((VAL)x)->info);
+ return ((int)x)>>1;
}
mpz_t* GETBIGINT(void* x)
View
14 evm/closure.h
@@ -23,7 +23,7 @@
#define MKCLOSURE (Closure*)EMALLOC(sizeof(Closure))
#define MKUNIT (void*)0
-#define INTOP(op,x,y) MKINT((int)(((VAL)x)->info) op (int)(((VAL)y)->info))
+#define INTOP(op,x,y) MKINT((((int)x)>>1) op (((int)y)>>1))
#define CHECKEVALUATED(x) if(ISFUN(x) || ISTHUNK(x) \
|| ISFV(x)) return 0;
@@ -52,7 +52,8 @@ void dumpClosure(Closure* c);
typedef Closure* VAL;
-#define GETTY(x) ((ClosureType)(((x)->ty) >> 24))
+#define GETTY(x) (ISINT(x) ? INT : ((ClosureType)(((x)->ty) >> 24)))
+#define QGETTY(x) ((ClosureType)(((x)->ty) >> 24))
#define SETTY(x,t) (x)->ty = (((int)t) << 24)
#define REF(x) x
@@ -82,7 +83,7 @@ typedef struct {
#define TAG(x) ((con*)((Closure*)x)->info)->tag
#define ISCON(x) GETTY(((Closure*)(x)))==CON
-#define ISINT(x) GETTY(((Closure*)(x)))==INT
+#define ISINT(x) (((int)x)&1 == 1)
#define ISTHUNK(x) GETTY(((Closure*)(x)))==THUNK
#define ISFUN(x) GETTY(((Closure*)(x)))==FUN
#define ISFV(x) GETTY(((Closure*)(x)))==FREEVAR
@@ -124,12 +125,9 @@ VAL CLOSURE_APPLY5(VAL x, VAL a1, VAL a2, VAL a3, VAL a4, VAL a5);
#define PROJECT(x,arg) (((con*)((x)->info))->args[arg])
//void* DO_PROJECT(VAL x, int arg);
-// Create new primitive values
-// Treating one specially is temporary -- actually, the compiler should
-// make a special value for each integer that's used.
-#define ASSIGNINT(t, x) if (x==1) t=one; else t=MKINT(x);
+#define ASSIGNINT(t, x) t=MKINT(x);
-extern VAL one;
+//extern VAL one;
void* MKINT(int x);
void* NEWBIGINT(char* bigint);
View
2 examples/intthing.e
@@ -1,7 +1,7 @@
include "Prelude.e"
main () -> Unit =
- printInt(foo(9))
+ printInt(foo(10))
foo (x:Int) -> Int =
if x<=0 then 1 else x*foo(x-1)
View
2 examples/testprog.e
@@ -3,7 +3,7 @@ include "Prelude.e"
{- Depending how much memory you have, you may need to reduce 'nine' -}
main () -> Unit =
- printInt(natToInt(fact(nine)))
+ printInt(natToInt(fact(eight)))
zero () -> Data = Con 0 ()
one () -> Data = Con 1 (zero)
View
2 examples/testprogslow.e
@@ -1,7 +1,7 @@
include "Prelude.e"
main () -> Unit =
- printInt(apply(natToInt, fact(nine())))
+ printInt(apply(natToInt, fact(eight())))
zero () -> Data = Con 0 ()
one () -> Data = Con 1 (zero())

0 comments on commit 4225154

Please sign in to comment.
Something went wrong with that request. Please try again.