]> gitweb.factorcode.org Git - factor.git/commitdiff
cpu.*: new generic word enable-cpu-features
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 11 Aug 2016 16:05:39 +0000 (18:05 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Fri, 12 Aug 2016 09:41:45 +0000 (11:41 +0200)
The word is used during bootstrap to enable available cpu specific
intrinsics.

basis/bootstrap/compiler/compiler.factor
basis/cpu/architecture/architecture-docs.factor
basis/cpu/architecture/architecture.factor
basis/cpu/ppc/ppc.factor
basis/cpu/x86/32/32.factor
basis/cpu/x86/64/64.factor
basis/cpu/x86/sse/sse.factor
basis/cpu/x86/x86.factor
basis/cpu/x86/x87/x87.factor

index 91e1c0de79529f9e304ac305f5bf29e0680e8fdc..15bbec1be8095cc9a1dcfa82164083497212ae7a 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs assocs.private classes
-classes.tuple.private compiler.units hashtables
+classes.tuple.private compiler.units cpu.architecture hashtables
 hashtables.private io kernel libc math math.parser memory
 namespaces namespaces.private quotations quotations.private
 sbufs sequences sequences.private splitting system vectors
@@ -20,6 +20,8 @@ IN: bootstrap.compiler
 
 "cpu." cpu name>> append require
 
+enable-cpu-features
+
 enable-optimizer
 
 ! Push all tuple layouts to tenured space to improve method caching
index 3f7ef19503eda8af64a3b0811732bf6f777747be..c19133cdf8196edc6b69266dbb2edf73e6dc9734 100644 (file)
@@ -207,10 +207,6 @@ HELP: %local-allot
 { $description "Emits machine code for stack \"allocating\" a chunk of memory. No memory is really allocated and instead a pointer to it is just put in the destination register." }
 { $see-also ##local-allot } ;
 
-HELP: reg-class-of
-{ $values { "rep" representation } { "reg-class" reg-class } }
-{ $description "Register class for values of the given representation." } ;
-
 HELP: %replace-imm
 { $values
   { "src" integer }
@@ -325,6 +321,9 @@ HELP: fused-unboxing?
 { $values { "?" boolean } }
 { $description "Whether this architecture support " { $link %load-float } ", " { $link %load-double } ", and " { $link %load-vector } "." } ;
 
+HELP: enable-cpu-features
+{ $description "This word is run when compiling the compiler during bootstrap and enables optional features that the processor is found to support." } ;
+
 HELP: gc-root-offset
 { $values { "spill-slot" spill-slot } { "n" integer } }
 { $description "Offset in the " { $link stack-frame } " for the word being constructed where the spill slot is located. The value is given in " { $link cell } " units." }
@@ -361,6 +360,10 @@ HELP: rep-size
 { $values { "rep" representation } { "n" integer } }
 { $description "Size in bytes of a representation." } ;
 
+HELP: reg-class-of
+{ $values { "rep" representation } { "reg-class" reg-class } }
+{ $description "Register class for values of the given representation." } ;
+
 HELP: return-regs
 { $values { "regs" assoc } }
 { $description "What registers that will be used for function return values of which class." } ;
index 66dddc453ab7a0864b2d538d7bdb7c980db838d3..55b13c48b56b41615646a5f7776e7d8424d04ffe 100644 (file)
@@ -601,3 +601,5 @@ HOOK: %callback-inputs cpu ( reg-outputs stack-outputs -- )
 HOOK: %callback-outputs cpu ( reg-inputs -- )
 
 HOOK: stack-cleanup cpu ( stack-size return abi -- n )
+
+HOOK: enable-cpu-features cpu ( -- )
index 80e54f606dfd4dfd2c8381e0f8b4f5035dbc9eb1..f4a75c75cc56a56eee565595f16501ddfd499fdc 100644 (file)
@@ -44,8 +44,6 @@ CONSTANT: ds-reg         14
 CONSTANT: rs-reg         15
 CONSTANT: vm-reg         16
 
-enable-float-intrinsics
-
 M: ppc machine-registers ( -- assoc )
     {
         { int-regs $[ 3 12 [a,b] 17 29 [a,b] append ] }
@@ -1059,6 +1057,9 @@ M: ppc immediate-arithmetic? ( n -- ? ) -32768 32767 between? ;
 M: ppc immediate-bitwise?    ( n -- ? ) 0 65535 between? ;
 M: ppc immediate-store?      ( n -- ? ) immediate-comparand? ;
 
+M: ppc enable-cpu-features ( -- )
+    enable-float-intrinsics ;
+
 USE: vocabs
 {
     { [ os linux? ] [
index 6d9a92d9aa6656137c4a75ae4691d87346944ff1..7dbf72cb74c45411030d34f6bb959b47c8dde267 100755 (executable)
@@ -238,5 +238,3 @@ M: x86.32 (cpuid) ( eax ecx regs -- )
         EDI 12 [+] EDX MOV
         EDI POP
     ] alien-assembly ;
-
-check-cpu-features
index 4df2ef61d9c3c268fd1db4982cc70cce91d728ed..f098b6339ca420d39344056d8133f940db7f6bbe 100644 (file)
@@ -134,13 +134,7 @@ M: x86.64 (cpuid) ( rax rcx regs -- )
         RSI 12 [+] EDX MOV
     ] alien-assembly ;
 
-! The result of reading 4 bytes from memory is a fixnum on
-! x86-64.
-enable-alien-4-intrinsics
-
 {
     { [ os unix? ] [ "cpu.x86.64.unix" require ] }
     { [ os windows? ] [ "cpu.x86.64.windows" require ] }
 } cond
-
-check-cpu-features
index d977e07f0c59a7e0d83844ee78353fa5773df202..dfdd19efc304f2396003925c82de66ab24f7be53 100644 (file)
@@ -923,7 +923,3 @@ M: x86.64 %scalar>integer ( dst src rep -- )
 M: x86 %vector>scalar %copy ;
 
 M: x86 %scalar>vector %copy ;
-
-enable-float-intrinsics
-enable-float-min/max
-enable-fsqrt
index 54059236fef3e5798f0e93cabd011793917ba653..6a6e5dca3fce3284ddb8c5dc2843e481d7874b91 100644 (file)
@@ -774,28 +774,40 @@ M: x86 immediate-bitwise? ( n -- ? )
         { cc/<>= [ src1 src2 compare call( a b -- ) label JP ] }
     } case ;
 
-enable-min/max
-enable-log2
-
 M:: x86 %bit-test ( dst src1 src2 temp -- )
     src1 src2 BT
     dst temp \ CMOVB (%boolean) ;
 
-enable-bit-test
+M: x86 enable-cpu-features ( -- )
+    enable-min/max
+    enable-log2
+    enable-bit-test
+
+    ! The result of reading 4 bytes from memory is a fixnum on
+    ! x86-64.
+    cpu x86.64? [ enable-alien-4-intrinsics ] when
+
+    ! These words uses alien-assembly
+    optimizing-compiler compiler-impl [
+        { (sse-version) popcnt? } compile
+    ] with-variable
 
-: check-sse ( -- )
+    ! SSE floats
     "Checking for multimedia extensions... " write flush
     sse-version
     [ sse-string " detected" append print ]
-    [ 20 < "cpu.x86.x87" "cpu.x86.sse" ? require ] bi ;
+    [
+        20 < [ "cpu.x86.x87" require ] [
+            "cpu.x86.sse" require
+            enable-float-min/max
+        ] if
+    ] bi
 
-: check-popcnt ( -- )
+    ! POPCNT
     enable-popcnt? [
         "Building with POPCNT support" print
         enable-bit-count
-    ] when ;
+    ] when
 
-: check-cpu-features ( -- )
-    [ { (sse-version) popcnt? } compile ] with-optimizer
-    check-sse
-    check-popcnt ;
+    enable-float-intrinsics
+    enable-fsqrt ;
index 739399b5814c3c76fe81375d2893988c64410ca5..f8997b78f754528b7a891e3b2b3e0eee2f4319e3 100644 (file)
@@ -97,6 +97,3 @@ M: x86 %compare-float-ordered-branch ( label src1 src2 cc -- )
 
 M: x86 %compare-float-unordered-branch ( label src1 src2 cc -- )
     [ [ FUCOMI ] compare-op ] (%compare-float-branch) ;
-
-enable-float-intrinsics
-enable-fsqrt