]> gitweb.factorcode.org Git - factor.git/commitdiff
x86 intrinsic fixnum>bignum bignum>fixnum
authorslava <slava@factorcode.org>
Fri, 10 Nov 2006 08:33:07 +0000 (08:33 +0000)
committerslava <slava@factorcode.org>
Fri, 10 Nov 2006 08:33:07 +0000 (08:33 +0000)
TODO.FACTOR.txt
library/compiler/x86/intrinsics.factor

index b30c33587fd98870fb54c4d8bbbdc864c4f5a400..4826560c40cf5a8cd2892a1211c7012388047eb9 100644 (file)
@@ -44,7 +44,7 @@
 - cross-word type inference
 - callback scheduling issue
 - amd64 structs-by-value bug
-- intrinsic fixnum>float float>fixnum fixnum>bignum bignum>fixnum
+- intrinsic fixnum>float float>fixnum
 - we may be able to remove the dlsym primitive
 - [ [ dup call ] dup call ] infer hangs
 - stdcall callbacks
index 00dc9c2660c70f1177a0388f1035ca8b117e1d2a..780f2f0858167cd028c851d9b78bf0581bea3500 100644 (file)
@@ -246,6 +246,53 @@ IN: compiler
     first2 define-fixnum-jump
 ] each
 
+\ fixnum>bignum [
+    "nonzero" define-label
+    "end" define-label
+    "x" operand 0 CMP ! is it zero?
+    "nonzero" get JNE
+    0 >bignum "x" get load-literal
+    "end" get JMP
+    "nonzero" resolve-label
+    "x" operand tag-bits SAR
+    "x" operand dup %allot-bignum-signed-1
+    "end" resolve-label
+] H{
+    { +input+ { { f "x" } } }
+    { +output+ { "x" } }
+} define-intrinsic
+
+\ bignum>fixnum [
+    "nonzero" define-label
+    "positive" define-label
+    "end" define-label
+    "x" operand %untag
+    "y" operand "x" operand cell [+] MOV
+     ! if the length is 1, its just the sign and nothing else,
+     ! so output 0
+    "y" operand 1 tag-bits shift CMP
+    "nonzero" get JMP
+    "y" operand 0 MOV
+    "end" get JMP
+    "nonzero" resolve-label
+    ! load the value
+    "y" operand "x" operand 3 cells [+] MOV
+    ! load the sign
+    "x" operand "x" operand 2 cells [+] MOV
+    ! is the sign negative?
+    "x" operand 0 CMP
+    "positive" get JMP
+    "y" operand -1 IMUL2
+    "positive" resolve-label
+    "y" operand 3 SHL
+    "end" resolve-label
+] H{
+    { +input+ { { f "x" } } }
+    { +scratch+ { { f "y" } } }
+    { +clobber+ { "x" } }
+    { +output+ { "y" } }
+} define-intrinsic
+
 ! User environment
 : %userenv ( -- )
     "x" operand 0 MOV