]> gitweb.factorcode.org Git - factor.git/blob - basis/cpu/x86/features/features.factor
Merge Phil Dawes' VM work
[factor.git] / basis / cpu / x86 / features / features.factor
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 ;
6 IN: cpu.x86.features
7
8 <PRIVATE
9
10 FUNCTION: int sse_version ( ) ;
11
12 FUNCTION: longlong read_timestamp_counter ( ) ;
13
14 PRIVATE>
15
16 ALIAS: sse-version sse_version
17
18 : sse-string ( version -- string )
19     {
20         { 00 [ "no SSE" ] }
21         { 10 [ "SSE1" ] }
22         { 20 [ "SSE2" ] }
23         { 30 [ "SSE3" ] }
24         { 33 [ "SSSE3" ] }
25         { 41 [ "SSE4.1" ] }
26         { 42 [ "SSE4.2" ] }
27     } case ;
28
29 HOOK: instruction-count cpu ( -- n )
30
31 M: x86 instruction-count read_timestamp_counter ;
32
33 : count-instructions ( quot -- n )
34     instruction-count [ call ] dip instruction-count swap - ; inline
35
36 USING: cpu.x86.features cpu.x86.features.private ;
37
38 :: install-sse-check ( version -- )
39     [
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
46             flush
47             1 exit
48         ] when
49     ] "cpu.x86" add-init-hook ;
50
51 : enable-sse ( version -- )
52     {
53         { 00 [ ] }
54         { 10 [ ] }
55         { 20 [ enable-sse2 ] }
56         { 30 [ enable-sse3 ] }
57         { 33 [ enable-sse3 ] }
58         { 41 [ enable-sse3 ] }
59         { 42 [ enable-sse3 ] }
60     } case ;
61
62 [ { sse_version } compile ] with-optimizer
63
64 "Checking for multimedia extensions: " write sse-version
65 "sse-version" get [ string>number min ] when*
66 [ sse-string write " detected" print ]
67 [ install-sse-check ]
68 [ enable-sse ] tri