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.
! 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

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." }
{ $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." } ;

View 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 ( -- )

View 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? ] [

View File

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

View 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

View 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

View 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
: 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
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 ;

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 -- )
[ [ FUCOMI ] compare-op ] (%compare-float-branch) ;
enable-float-intrinsics
enable-fsqrt