2010-04-21 03:08:52 -04:00
|
|
|
! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
|
2008-10-20 21:40:15 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-08-30 23:20:49 -04:00
|
|
|
USING: words sequences kernel combinators cpu.architecture assocs
|
2008-10-20 21:40:15 -04:00
|
|
|
compiler.cfg.hats
|
2010-04-22 04:21:23 -04:00
|
|
|
compiler.cfg.stacks
|
2008-10-20 21:40:15 -04:00
|
|
|
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
|
2010-04-23 06:48:58 -04:00
|
|
|
compiler.cfg.intrinsics.strings
|
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
|
2010-04-23 18:42:09 -04:00
|
|
|
QUALIFIED: alien.c-types
|
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
|
2010-05-15 16:59:47 -04:00
|
|
|
QUALIFIED: math.bitwise.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-30 23:20:49 -04:00
|
|
|
: enable-intrinsics ( alist -- )
|
|
|
|
[ "intrinsic" set-word-prop ] assoc-each ;
|
2009-08-28 20:02:59 -04:00
|
|
|
|
2008-10-20 21:40:15 -04:00
|
|
|
{
|
2009-08-30 23:20:49 -04:00
|
|
|
{ kernel.private:tag [ drop emit-tag ] }
|
2010-03-26 23:11:05 -04:00
|
|
|
{ kernel.private:context-object [ emit-context-object ] }
|
2010-01-13 00:08:18 -05:00
|
|
|
{ kernel.private:special-object [ emit-special-object ] }
|
2010-04-01 20:06:18 -04:00
|
|
|
{ kernel.private:set-special-object [ emit-set-special-object ] }
|
2009-11-11 01:50:57 -05:00
|
|
|
{ kernel.private:(identity-hashcode) [ drop emit-identity-hashcode ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ math.private:both-fixnums? [ drop emit-both-fixnums? ] }
|
|
|
|
{ math.private:fixnum+ [ drop emit-fixnum+ ] }
|
|
|
|
{ math.private:fixnum- [ drop emit-fixnum- ] }
|
|
|
|
{ math.private:fixnum* [ drop emit-fixnum* ] }
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.private:fixnum+fast [ drop [ ^^add ] binary-op ] }
|
|
|
|
{ math.private:fixnum-fast [ drop [ ^^sub ] binary-op ] }
|
|
|
|
{ math.private:fixnum*fast [ drop [ ^^mul ] binary-op ] }
|
|
|
|
{ math.private:fixnum-bitand [ drop [ ^^and ] binary-op ] }
|
|
|
|
{ math.private:fixnum-bitor [ drop [ ^^or ] binary-op ] }
|
|
|
|
{ math.private:fixnum-bitxor [ drop [ ^^xor ] binary-op ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ math.private:fixnum-shift-fast [ emit-fixnum-shift-fast ] }
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.private:fixnum-bitnot [ drop [ ^^not ] unary-op ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ 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 ] }
|
2010-04-22 04:21:23 -04:00
|
|
|
{ kernel:eq? [ emit-eq ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ slots.private:slot [ emit-slot ] }
|
|
|
|
{ slots.private:set-slot [ emit-set-slot ] }
|
2010-04-25 20:19:50 -04:00
|
|
|
{ strings.private:string-nth-fast [ drop emit-string-nth-fast ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ 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 ] }
|
|
|
|
{ alien:<displaced-alien> [ emit-<displaced-alien> ] }
|
2010-04-23 18:42:09 -04:00
|
|
|
{ alien.accessors:alien-unsigned-1 [ int-rep alien.c-types:uchar emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-unsigned-1 [ int-rep alien.c-types:uchar emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-signed-1 [ int-rep alien.c-types:char emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-signed-1 [ int-rep alien.c-types:char emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-unsigned-2 [ int-rep alien.c-types:ushort emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-unsigned-2 [ int-rep alien.c-types:ushort emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-signed-2 [ int-rep alien.c-types:short emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-signed-2 [ int-rep alien.c-types:short emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-cell [ emit-alien-cell ] }
|
|
|
|
{ alien.accessors:set-alien-cell [ emit-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 ( -- )
|
|
|
|
{
|
2010-04-23 18:42:09 -04:00
|
|
|
{ alien.accessors:alien-signed-4 [ int-rep alien.c-types:int emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-signed-4 [ int-rep alien.c-types:int emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-unsigned-4 [ int-rep alien.c-types:uint emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-unsigned-4 [ int-rep alien.c-types:uint emit-store-memory ] }
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics ;
|
2008-10-20 21:40:15 -04:00
|
|
|
|
|
|
|
: enable-float-intrinsics ( -- )
|
|
|
|
{
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.private:float+ [ drop [ ^^add-float ] binary-op ] }
|
|
|
|
{ math.private:float- [ drop [ ^^sub-float ] binary-op ] }
|
|
|
|
{ math.private:float* [ drop [ ^^mul-float ] binary-op ] }
|
|
|
|
{ math.private:float/f [ drop [ ^^div-float ] binary-op ] }
|
2009-09-12 23:20:13 -04:00
|
|
|
{ math.private:float< [ drop cc< emit-float-ordered-comparison ] }
|
|
|
|
{ math.private:float<= [ drop cc<= emit-float-ordered-comparison ] }
|
|
|
|
{ math.private:float>= [ drop cc>= emit-float-ordered-comparison ] }
|
|
|
|
{ math.private:float> [ drop cc> emit-float-ordered-comparison ] }
|
|
|
|
{ math.private:float-u< [ drop cc< emit-float-unordered-comparison ] }
|
|
|
|
{ math.private:float-u<= [ drop cc<= emit-float-unordered-comparison ] }
|
|
|
|
{ math.private:float-u>= [ drop cc>= emit-float-unordered-comparison ] }
|
|
|
|
{ math.private:float-u> [ drop cc> emit-float-unordered-comparison ] }
|
|
|
|
{ math.private:float= [ drop cc= emit-float-unordered-comparison ] }
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.private:float>fixnum [ drop [ ^^float>integer ] unary-op ] }
|
|
|
|
{ math.private:fixnum>float [ drop [ ^^integer>float ] unary-op ] }
|
2009-09-12 23:20:13 -04:00
|
|
|
{ math.floats.private:float-unordered? [ drop cc/<>= emit-float-unordered-comparison ] }
|
2010-04-23 18:42:09 -04:00
|
|
|
{ alien.accessors:alien-float [ float-rep f emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-float [ float-rep f emit-store-memory ] }
|
|
|
|
{ alien.accessors:alien-double [ double-rep f emit-load-memory ] }
|
|
|
|
{ alien.accessors:set-alien-double [ double-rep f emit-store-memory ] }
|
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 ( -- )
|
2009-08-30 23:20:49 -04:00
|
|
|
{
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.libm:fsqrt [ drop [ ^^sqrt ] unary-op ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
} enable-intrinsics ;
|
2009-08-26 00:22:15 -04:00
|
|
|
|
2009-08-28 06:21:16 -04:00
|
|
|
: enable-float-min/max ( -- )
|
|
|
|
{
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.floats.private:float-min [ drop [ ^^min-float ] binary-op ] }
|
|
|
|
{ math.floats.private:float-max [ drop [ ^^max-float ] binary-op ] }
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics ;
|
|
|
|
|
2009-08-30 05:52:01 -04:00
|
|
|
: enable-float-functions ( -- )
|
|
|
|
{
|
2009-08-30 23:20:49 -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 ] }
|
2009-09-14 17:19:58 -04:00
|
|
|
{ math.libm:flog10 [ drop "log10" emit-unary-float-function ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
{ 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-09-01 16:19:26 -04:00
|
|
|
{ math.libm:fsqrt [ drop "sqrt" emit-unary-float-function ] }
|
|
|
|
{ math.floats.private:float-min [ drop "fmin" emit-binary-float-function ] }
|
|
|
|
{ math.floats.private:float-max [ drop "fmax" emit-binary-float-function ] }
|
2009-09-11 22:00:17 -04:00
|
|
|
{ math.private:float-mod [ drop "fmod" emit-binary-float-function ] }
|
2009-08-30 05:52:01 -04:00
|
|
|
} enable-intrinsics ;
|
|
|
|
|
2009-08-28 20:02:59 -04:00
|
|
|
: enable-min/max ( -- )
|
|
|
|
{
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.integers.private:fixnum-min [ drop [ ^^min ] binary-op ] }
|
|
|
|
{ math.integers.private:fixnum-max [ drop [ ^^max ] binary-op ] }
|
2009-08-28 20:02:59 -04:00
|
|
|
} enable-intrinsics ;
|
2009-08-28 06:21:16 -04:00
|
|
|
|
2010-04-21 03:08:52 -04:00
|
|
|
: enable-log2 ( -- )
|
2009-08-30 23:20:49 -04:00
|
|
|
{
|
2010-04-22 04:21:23 -04:00
|
|
|
{ math.integers.private:fixnum-log2 [ drop [ ^^log2 ] unary-op ] }
|
2009-08-30 23:20:49 -04:00
|
|
|
} enable-intrinsics ;
|
2008-12-06 16:31:17 -05:00
|
|
|
|
2010-05-15 16:59:47 -04:00
|
|
|
: enable-bit-count ( -- )
|
|
|
|
{
|
|
|
|
{ math.bitwise.private:fixnum-bit-count [ drop [ ^^bit-count ] unary-op ] }
|
|
|
|
} enable-intrinsics ;
|
|
|
|
|
2009-06-30 21:13:35 -04:00
|
|
|
: emit-intrinsic ( node word -- )
|
2009-08-30 23:20:49 -04:00
|
|
|
"intrinsic" word-prop call( node -- ) ;
|