2009-06-30 21:16:09 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov, Doug Coleman.
|
2008-10-20 21:40:15 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-12-17 19:10:01 -05:00
|
|
|
USING: words sequences kernel combinators cpu.architecture
|
2008-10-20 21:40:15 -04:00
|
|
|
compiler.cfg.hats
|
|
|
|
compiler.cfg.instructions
|
|
|
|
compiler.cfg.intrinsics.alien
|
|
|
|
compiler.cfg.intrinsics.allot
|
|
|
|
compiler.cfg.intrinsics.fixnum
|
|
|
|
compiler.cfg.intrinsics.float
|
2008-11-28 07:36:30 -05:00
|
|
|
compiler.cfg.intrinsics.slots
|
2009-07-13 15:42:52 -04:00
|
|
|
compiler.cfg.intrinsics.misc
|
|
|
|
compiler.cfg.comparisons ;
|
2009-08-27 01:06:19 -04:00
|
|
|
QUALIFIED: alien
|
|
|
|
QUALIFIED: alien.accessors
|
2008-10-20 21:46:47 -04:00
|
|
|
QUALIFIED: kernel
|
|
|
|
QUALIFIED: arrays
|
|
|
|
QUALIFIED: byte-arrays
|
2008-10-20 21:40:15 -04:00
|
|
|
QUALIFIED: kernel.private
|
|
|
|
QUALIFIED: slots.private
|
2008-11-06 02:11:28 -05:00
|
|
|
QUALIFIED: strings.private
|
2008-10-20 21:40:15 -04:00
|
|
|
QUALIFIED: classes.tuple.private
|
|
|
|
QUALIFIED: math.private
|
2008-12-06 16:31:17 -05:00
|
|
|
QUALIFIED: math.integers.private
|
2009-08-28 06:21:16 -04:00
|
|
|
QUALIFIED: math.floats.private
|
2009-08-26 00:22:15 -04:00
|
|
|
QUALIFIED: math.libm
|
2008-10-20 21:40:15 -04:00
|
|
|
IN: compiler.cfg.intrinsics
|
|
|
|
|
2009-08-28 20:02:59 -04:00
|
|
|
: enable-intrinsics ( words -- )
|
|
|
|
[ t "intrinsic" set-word-prop ] each ;
|
|
|
|
|
2008-10-20 21:40:15 -04:00
|
|
|
{
|
|
|
|
kernel.private:tag
|
2008-12-06 10:16:29 -05:00
|
|
|
kernel.private:getenv
|
2008-11-28 09:35:02 -05:00
|
|
|
math.private:both-fixnums?
|
2008-11-28 06:33:58 -05:00
|
|
|
math.private:fixnum+
|
|
|
|
math.private:fixnum-
|
2008-11-30 08:26:49 -05:00
|
|
|
math.private:fixnum*
|
2008-10-20 21:40:15 -04:00
|
|
|
math.private:fixnum+fast
|
|
|
|
math.private:fixnum-fast
|
|
|
|
math.private:fixnum-bitand
|
|
|
|
math.private:fixnum-bitor
|
|
|
|
math.private:fixnum-bitxor
|
|
|
|
math.private:fixnum-shift-fast
|
|
|
|
math.private:fixnum-bitnot
|
|
|
|
math.private:fixnum*fast
|
|
|
|
math.private:fixnum<
|
|
|
|
math.private:fixnum<=
|
|
|
|
math.private:fixnum>=
|
|
|
|
math.private:fixnum>
|
2009-07-18 02:07:43 -04:00
|
|
|
! math.private:bignum>fixnum
|
|
|
|
! math.private:fixnum>bignum
|
2008-10-20 21:46:47 -04:00
|
|
|
kernel:eq?
|
2008-10-20 21:40:15 -04:00
|
|
|
slots.private:slot
|
|
|
|
slots.private:set-slot
|
2008-11-06 02:11:28 -05:00
|
|
|
strings.private:string-nth
|
2008-12-05 07:38:51 -05:00
|
|
|
strings.private:set-string-nth-fast
|
2009-07-30 10:19:44 -04:00
|
|
|
classes.tuple.private:<tuple-boa>
|
|
|
|
arrays:<array>
|
|
|
|
byte-arrays:<byte-array>
|
|
|
|
byte-arrays:(byte-array)
|
|
|
|
kernel:<wrapper>
|
2009-08-27 01:06:19 -04:00
|
|
|
alien:<displaced-alien>
|
2008-10-20 21:40:15 -04:00
|
|
|
alien.accessors:alien-unsigned-1
|
|
|
|
alien.accessors:set-alien-unsigned-1
|
|
|
|
alien.accessors:alien-signed-1
|
|
|
|
alien.accessors:set-alien-signed-1
|
|
|
|
alien.accessors:alien-unsigned-2
|
|
|
|
alien.accessors:set-alien-unsigned-2
|
|
|
|
alien.accessors:alien-signed-2
|
|
|
|
alien.accessors:set-alien-signed-2
|
2009-07-30 10:19:44 -04:00
|
|
|
alien.accessors:alien-cell
|
2008-10-20 21:40:15 -04:00
|
|
|
alien.accessors:set-alien-cell
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics
|
2008-10-20 21:40:15 -04:00
|
|
|
|
|
|
|
: enable-alien-4-intrinsics ( -- )
|
|
|
|
{
|
|
|
|
alien.accessors:alien-unsigned-4
|
|
|
|
alien.accessors:set-alien-unsigned-4
|
|
|
|
alien.accessors:alien-signed-4
|
|
|
|
alien.accessors:set-alien-signed-4
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
|
|
|
: enable-float-intrinsics ( -- )
|
|
|
|
{
|
|
|
|
math.private:float+
|
|
|
|
math.private:float-
|
|
|
|
math.private:float*
|
|
|
|
math.private:float/f
|
|
|
|
math.private:fixnum>float
|
|
|
|
math.private:float>fixnum
|
2008-10-23 06:27:54 -04:00
|
|
|
math.private:float<
|
|
|
|
math.private:float<=
|
|
|
|
math.private:float>
|
|
|
|
math.private:float>=
|
2008-11-03 08:15:09 -05:00
|
|
|
math.private:float=
|
2008-10-20 21:40:15 -04:00
|
|
|
alien.accessors:alien-float
|
|
|
|
alien.accessors:set-alien-float
|
|
|
|
alien.accessors:alien-double
|
|
|
|
alien.accessors:set-alien-double
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
2009-08-26 00:22:15 -04:00
|
|
|
: enable-fsqrt ( -- )
|
|
|
|
\ math.libm:fsqrt t "intrinsic" set-word-prop ;
|
|
|
|
|
2009-08-28 06:21:16 -04:00
|
|
|
: enable-float-min/max ( -- )
|
|
|
|
{
|
|
|
|
math.floats.private:float-min
|
|
|
|
math.floats.private:float-max
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics ;
|
|
|
|
|
2009-08-30 05:52:01 -04:00
|
|
|
: enable-float-functions ( -- )
|
|
|
|
! Everything except for fsqrt
|
|
|
|
{
|
|
|
|
math.libm:facos
|
|
|
|
math.libm:fasin
|
|
|
|
math.libm:fatan
|
|
|
|
math.libm:fatan2
|
|
|
|
math.libm:fcos
|
|
|
|
math.libm:fsin
|
|
|
|
math.libm:ftan
|
|
|
|
math.libm:fcosh
|
|
|
|
math.libm:fsinh
|
|
|
|
math.libm:ftanh
|
|
|
|
math.libm:fexp
|
|
|
|
math.libm:flog
|
|
|
|
math.libm:fpow
|
|
|
|
math.libm:facosh
|
|
|
|
math.libm:fasinh
|
|
|
|
math.libm:fatanh
|
|
|
|
} enable-intrinsics ;
|
|
|
|
|
2009-08-28 20:02:59 -04:00
|
|
|
: enable-min/max ( -- )
|
|
|
|
{
|
|
|
|
math.integers.private:fixnum-min
|
|
|
|
math.integers.private:fixnum-max
|
|
|
|
} enable-intrinsics ;
|
2009-08-28 06:21:16 -04:00
|
|
|
|
2008-12-06 16:31:17 -05:00
|
|
|
: enable-fixnum-log2 ( -- )
|
2009-08-28 20:02:59 -04:00
|
|
|
{ math.integers.private:fixnum-log2 } enable-intrinsics ;
|
2008-12-06 16:31:17 -05:00
|
|
|
|
2009-06-30 21:13:35 -04:00
|
|
|
: emit-intrinsic ( node word -- )
|
2008-10-20 21:40:15 -04:00
|
|
|
{
|
2009-06-30 21:13:35 -04:00
|
|
|
{ \ kernel.private:tag [ drop emit-tag ] }
|
|
|
|
{ \ kernel.private:getenv [ emit-getenv ] }
|
|
|
|
{ \ math.private:both-fixnums? [ drop emit-both-fixnums? ] }
|
2009-07-16 19:29:40 -04:00
|
|
|
{ \ math.private:fixnum+ [ drop emit-fixnum+ ] }
|
|
|
|
{ \ math.private:fixnum- [ drop emit-fixnum- ] }
|
|
|
|
{ \ math.private:fixnum* [ drop emit-fixnum* ] }
|
2009-07-14 20:18:57 -04:00
|
|
|
{ \ math.private:fixnum+fast [ drop [ ^^add ] emit-fixnum-op ] }
|
|
|
|
{ \ math.private:fixnum-fast [ drop [ ^^sub ] emit-fixnum-op ] }
|
|
|
|
{ \ math.private:fixnum-bitand [ drop [ ^^and ] emit-fixnum-op ] }
|
|
|
|
{ \ math.private:fixnum-bitor [ drop [ ^^or ] emit-fixnum-op ] }
|
|
|
|
{ \ math.private:fixnum-bitxor [ drop [ ^^xor ] emit-fixnum-op ] }
|
2009-06-30 21:13:35 -04:00
|
|
|
{ \ math.private:fixnum-shift-fast [ emit-fixnum-shift-fast ] }
|
|
|
|
{ \ math.private:fixnum-bitnot [ drop emit-fixnum-bitnot ] }
|
|
|
|
{ \ math.integers.private:fixnum-log2 [ drop emit-fixnum-log2 ] }
|
2009-07-14 20:18:57 -04:00
|
|
|
{ \ math.private:fixnum*fast [ drop emit-fixnum*fast ] }
|
|
|
|
{ \ math.private:fixnum< [ drop cc< emit-fixnum-comparison ] }
|
|
|
|
{ \ math.private:fixnum<= [ drop cc<= emit-fixnum-comparison ] }
|
|
|
|
{ \ math.private:fixnum>= [ drop cc>= emit-fixnum-comparison ] }
|
|
|
|
{ \ math.private:fixnum> [ drop cc> emit-fixnum-comparison ] }
|
|
|
|
{ \ kernel:eq? [ drop cc= emit-fixnum-comparison ] }
|
2009-08-28 20:02:59 -04:00
|
|
|
{ \ math.integers.private:fixnum-min [ drop [ ^^min ] emit-fixnum-op ] }
|
|
|
|
{ \ math.integers.private:fixnum-max [ drop [ ^^max ] emit-fixnum-op ] }
|
2009-06-30 21:13:35 -04:00
|
|
|
{ \ math.private:bignum>fixnum [ drop emit-bignum>fixnum ] }
|
|
|
|
{ \ math.private:fixnum>bignum [ drop emit-fixnum>bignum ] }
|
|
|
|
{ \ math.private:float+ [ drop [ ^^add-float ] emit-float-op ] }
|
|
|
|
{ \ math.private:float- [ drop [ ^^sub-float ] emit-float-op ] }
|
|
|
|
{ \ math.private:float* [ drop [ ^^mul-float ] emit-float-op ] }
|
|
|
|
{ \ math.private:float/f [ drop [ ^^div-float ] emit-float-op ] }
|
|
|
|
{ \ math.private:float< [ drop cc< emit-float-comparison ] }
|
|
|
|
{ \ math.private:float<= [ drop cc<= emit-float-comparison ] }
|
|
|
|
{ \ math.private:float>= [ drop cc>= emit-float-comparison ] }
|
|
|
|
{ \ math.private:float> [ drop cc> emit-float-comparison ] }
|
|
|
|
{ \ math.private:float= [ drop cc= emit-float-comparison ] }
|
|
|
|
{ \ math.private:float>fixnum [ drop emit-float>fixnum ] }
|
|
|
|
{ \ math.private:fixnum>float [ drop emit-fixnum>float ] }
|
2009-08-28 06:21:16 -04:00
|
|
|
{ \ math.floats.private:float-min [ drop [ ^^min-float ] emit-float-op ] }
|
|
|
|
{ \ math.floats.private:float-max [ drop [ ^^max-float ] emit-float-op ] }
|
2009-08-26 00:22:15 -04:00
|
|
|
{ \ math.libm:fsqrt [ drop emit-fsqrt ] }
|
2009-08-30 05:52:01 -04:00
|
|
|
{ \ math.libm:facos [ drop "acos" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:fasin [ drop "asin" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:fatan [ drop "atan" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:fatan2 [ drop "atan2" emit-binary-float-function ] }
|
|
|
|
{ \ math.libm:fcos [ drop "cos" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:fsin [ drop "sin" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:ftan [ drop "tan" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:fcosh [ drop "cosh" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:fsinh [ drop "sinh" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:ftanh [ drop "tanh" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:fexp [ drop "exp" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:flog [ drop "log" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:fpow [ drop "pow" emit-binary-float-function ] }
|
|
|
|
{ \ math.libm:facosh [ drop "acosh" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:fasinh [ drop "asinh" emit-unary-float-function ] }
|
|
|
|
{ \ math.libm:fatanh [ drop "atanh" emit-unary-float-function ] }
|
2009-06-30 21:13:35 -04:00
|
|
|
{ \ slots.private:slot [ emit-slot ] }
|
|
|
|
{ \ slots.private:set-slot [ emit-set-slot ] }
|
|
|
|
{ \ strings.private:string-nth [ drop emit-string-nth ] }
|
|
|
|
{ \ strings.private:set-string-nth-fast [ drop emit-set-string-nth-fast ] }
|
|
|
|
{ \ classes.tuple.private:<tuple-boa> [ emit-<tuple-boa> ] }
|
|
|
|
{ \ arrays:<array> [ emit-<array> ] }
|
|
|
|
{ \ byte-arrays:<byte-array> [ emit-<byte-array> ] }
|
|
|
|
{ \ byte-arrays:(byte-array) [ emit-(byte-array) ] }
|
|
|
|
{ \ kernel:<wrapper> [ emit-simple-allot ] }
|
2009-08-27 01:06:19 -04:00
|
|
|
{ \ alien:<displaced-alien> [ emit-<displaced-alien> ] }
|
2009-06-30 21:13:35 -04:00
|
|
|
{ \ alien.accessors:alien-unsigned-1 [ 1 emit-alien-unsigned-getter ] }
|
|
|
|
{ \ alien.accessors:set-alien-unsigned-1 [ 1 emit-alien-integer-setter ] }
|
|
|
|
{ \ alien.accessors:alien-signed-1 [ 1 emit-alien-signed-getter ] }
|
|
|
|
{ \ alien.accessors:set-alien-signed-1 [ 1 emit-alien-integer-setter ] }
|
|
|
|
{ \ alien.accessors:alien-unsigned-2 [ 2 emit-alien-unsigned-getter ] }
|
|
|
|
{ \ alien.accessors:set-alien-unsigned-2 [ 2 emit-alien-integer-setter ] }
|
|
|
|
{ \ alien.accessors:alien-signed-2 [ 2 emit-alien-signed-getter ] }
|
|
|
|
{ \ alien.accessors:set-alien-signed-2 [ 2 emit-alien-integer-setter ] }
|
|
|
|
{ \ alien.accessors:alien-unsigned-4 [ 4 emit-alien-unsigned-getter ] }
|
|
|
|
{ \ alien.accessors:set-alien-unsigned-4 [ 4 emit-alien-integer-setter ] }
|
|
|
|
{ \ alien.accessors:alien-signed-4 [ 4 emit-alien-signed-getter ] }
|
|
|
|
{ \ alien.accessors:set-alien-signed-4 [ 4 emit-alien-integer-setter ] }
|
|
|
|
{ \ alien.accessors:alien-cell [ emit-alien-cell-getter ] }
|
|
|
|
{ \ alien.accessors:set-alien-cell [ emit-alien-cell-setter ] }
|
2009-08-07 18:44:50 -04:00
|
|
|
{ \ alien.accessors:alien-float [ single-float-rep emit-alien-float-getter ] }
|
|
|
|
{ \ alien.accessors:set-alien-float [ single-float-rep emit-alien-float-setter ] }
|
|
|
|
{ \ alien.accessors:alien-double [ double-float-rep emit-alien-float-getter ] }
|
|
|
|
{ \ alien.accessors:set-alien-double [ double-float-rep emit-alien-float-setter ] }
|
2008-10-20 21:40:15 -04:00
|
|
|
} case ;
|