1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: system kernel math math.order math.parser namespaces
4 alien.c-types alien.syntax combinators locals init io cpu.x86
5 compiler compiler.units accessors ;
10 FUNCTION: int sse_version ( ) ;
12 FUNCTION: longlong read_timestamp_counter ( ) ;
16 ALIAS: sse-version sse_version
18 : sse-string ( version -- string )
29 HOOK: instruction-count cpu ( -- n )
31 M: x86 instruction-count read_timestamp_counter ;
33 : count-instructions ( quot -- n )
34 instruction-count [ call ] dip instruction-count swap - ; inline
36 USING: cpu.x86.features cpu.x86.features.private ;
38 :: install-sse-check ( version -- )
40 sse-version version < [
41 "This image was built to use " write
42 version sse-string write
43 " but your CPU only supports " write
44 sse-version sse-string write "." print
45 "You will need to bootstrap Factor again." print
49 ] "cpu.x86" add-init-hook ;
51 : enable-sse ( version -- )
55 { 20 [ enable-sse2 ] }
56 { 30 [ enable-sse3 ] }
57 { 33 [ enable-sse3 ] }
58 { 41 [ enable-sse3 ] }
59 { 42 [ enable-sse3 ] }
62 [ { sse_version } compile ] with-optimizer
64 "Checking for multimedia extensions: " write sse-version
65 "sse-version" get [ string>number min ] when*
66 [ sse-string write " detected" print ]