cpu.*: new generic word enable-cpu-features

The word is used during bootstrap to enable available cpu specific
intrinsics.
char-rename
Björn Lindqvist 2016-08-11 18:05:39 +02:00
parent 67f38302d8
commit 1c94c60541
9 changed files with 39 additions and 34 deletions

View File

@ -1,7 +1,7 @@
! Copyright (C) 2007, 2010 Slava Pestov. ! Copyright (C) 2007, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs assocs.private classes 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 hashtables.private io kernel libc math math.parser memory
namespaces namespaces.private quotations quotations.private namespaces namespaces.private quotations quotations.private
sbufs sequences sequences.private splitting system vectors sbufs sequences sequences.private splitting system vectors
@ -20,6 +20,8 @@ IN: bootstrap.compiler
"cpu." cpu name>> append require "cpu." cpu name>> append require
enable-cpu-features
enable-optimizer enable-optimizer
! Push all tuple layouts to tenured space to improve method caching ! Push all tuple layouts to tenured space to improve method caching

View 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." } { $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 } ; { $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 HELP: %replace-imm
{ $values { $values
{ "src" integer } { "src" integer }
@ -325,6 +321,9 @@ HELP: fused-unboxing?
{ $values { "?" boolean } } { $values { "?" boolean } }
{ $description "Whether this architecture support " { $link %load-float } ", " { $link %load-double } ", and " { $link %load-vector } "." } ; { $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 HELP: gc-root-offset
{ $values { "spill-slot" spill-slot } { "n" integer } } { $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." } { $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 } } { $values { "rep" representation } { "n" integer } }
{ $description "Size in bytes of a representation." } ; { $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 HELP: return-regs
{ $values { "regs" assoc } } { $values { "regs" assoc } }
{ $description "What registers that will be used for function return values of which class." } ; { $description "What registers that will be used for function return values of which class." } ;

View File

@ -601,3 +601,5 @@ HOOK: %callback-inputs cpu ( reg-outputs stack-outputs -- )
HOOK: %callback-outputs cpu ( reg-inputs -- ) HOOK: %callback-outputs cpu ( reg-inputs -- )
HOOK: stack-cleanup cpu ( stack-size return abi -- n ) HOOK: stack-cleanup cpu ( stack-size return abi -- n )
HOOK: enable-cpu-features cpu ( -- )

View File

@ -44,8 +44,6 @@ CONSTANT: ds-reg 14
CONSTANT: rs-reg 15 CONSTANT: rs-reg 15
CONSTANT: vm-reg 16 CONSTANT: vm-reg 16
enable-float-intrinsics
M: ppc machine-registers ( -- assoc ) M: ppc machine-registers ( -- assoc )
{ {
{ int-regs $[ 3 12 [a,b] 17 29 [a,b] append ] } { 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-bitwise? ( n -- ? ) 0 65535 between? ;
M: ppc immediate-store? ( n -- ? ) immediate-comparand? ; M: ppc immediate-store? ( n -- ? ) immediate-comparand? ;
M: ppc enable-cpu-features ( -- )
enable-float-intrinsics ;
USE: vocabs USE: vocabs
{ {
{ [ os linux? ] [ { [ os linux? ] [

View File

@ -238,5 +238,3 @@ M: x86.32 (cpuid) ( eax ecx regs -- )
EDI 12 [+] EDX MOV EDI 12 [+] EDX MOV
EDI POP EDI POP
] alien-assembly ; ] alien-assembly ;
check-cpu-features

View File

@ -134,13 +134,7 @@ M: x86.64 (cpuid) ( rax rcx regs -- )
RSI 12 [+] EDX MOV RSI 12 [+] EDX MOV
] alien-assembly ; ] 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 unix? ] [ "cpu.x86.64.unix" require ] }
{ [ os windows? ] [ "cpu.x86.64.windows" require ] } { [ os windows? ] [ "cpu.x86.64.windows" require ] }
} cond } cond
check-cpu-features

View File

@ -923,7 +923,3 @@ M: x86.64 %scalar>integer ( dst src rep -- )
M: x86 %vector>scalar %copy ; M: x86 %vector>scalar %copy ;
M: x86 %scalar>vector %copy ; M: x86 %scalar>vector %copy ;
enable-float-intrinsics
enable-float-min/max
enable-fsqrt

View File

@ -774,28 +774,40 @@ M: x86 immediate-bitwise? ( n -- ? )
{ cc/<>= [ src1 src2 compare call( a b -- ) label JP ] } { cc/<>= [ src1 src2 compare call( a b -- ) label JP ] }
} case ; } case ;
enable-min/max
enable-log2
M:: x86 %bit-test ( dst src1 src2 temp -- ) M:: x86 %bit-test ( dst src1 src2 temp -- )
src1 src2 BT src1 src2 BT
dst temp \ CMOVB (%boolean) ; dst temp \ CMOVB (%boolean) ;
enable-bit-test M: x86 enable-cpu-features ( -- )
enable-min/max
enable-log2
enable-bit-test
: check-sse ( -- ) ! 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
! SSE floats
"Checking for multimedia extensions... " write flush "Checking for multimedia extensions... " write flush
sse-version sse-version
[ sse-string " detected" append print ] [ 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? [ enable-popcnt? [
"Building with POPCNT support" print "Building with POPCNT support" print
enable-bit-count enable-bit-count
] when ; ] when
: check-cpu-features ( -- ) enable-float-intrinsics
[ { (sse-version) popcnt? } compile ] with-optimizer enable-fsqrt ;
check-sse
check-popcnt ;

View 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 -- ) M: x86 %compare-float-unordered-branch ( label src1 src2 cc -- )
[ [ FUCOMI ] compare-op ] (%compare-float-branch) ; [ [ FUCOMI ] compare-op ] (%compare-float-branch) ;
enable-float-intrinsics
enable-fsqrt