Paste: Another noise functio

Author: dmpk2k
Mode: factor
Date: Mon, 22 Dec 2008 02:19:11
Plain Text |
USING: kernel hints math math.ranges math.bitwise layouts sequences tools.time ;
IN: noise

<PRIVATE

: mix ( b c roll_num -- i j )
  [ dupd bitxor over ] dip
  bitroll-32 - ; inline

: hash ( a b c -- h )
  14 mix
  rot 11 mix
  rot 25 mix
  rot 16 mix
  rot 4  mix
  rot 14 mix
  rot 24 mix
  2nip ; inline

: noise2 ( x y -- h )
  HEX: deadbeef 
  hash 
  >float most-positive-fixnum / ; inline 

: bench-x ( x-dimension -- )
  0 100000 [a,b] [ over noise2 drop ] each drop ; inline

: bench ( -- )
  0 100000 [a,b] [ bench-x ] each ; 

PRIVATE>

: run-bench ( -- )
  [ bench ] time ;

Annotation: Results of optimized.

Author: dmpk2k
Mode: factor
Date: Mon, 22 Dec 2008 02:50:10
Plain Text |
( scratchpad ) \ bench optimized.
[
    100001 0 swap \ ( gensym ) [
        over over fixnum< [
            >R >R 100001 0 swap \ ( gensym ) [
                over over fixnum<
                [ >R >R R> R> >R 1 fixnum+fast R> ( gensym ) ]
                [ 2drop ] if
            ] label R> R> >R 1 fixnum+fast R> ( gensym )
        ] [ 2drop ] if
    ] label
]
( scratchpad ) \ bench-x optimized.
[
    100001 0 swap \ ( gensym ) [
        over over fixnum< [
            >R >R dup 3735928559 bitxor drop
            R> R> >R 1 fixnum+fast R> ( gensym )
        ] [ 2drop drop ] if
    ] label
]
( scratchpad ) \ noise2 optimized.
[
    3735928559 dupd bitxor over 14 over >R shift
    4294967295 >R >bignum R> bignum-bitand R> -18 shift
    4294967295 >R >bignum R> bignum-bitand bignum-bitor
    >R >bignum R> bignum- rot dupd bitxor
    over dup >R 11 bignum-shift 4294967295 bignum-bitand
    R> -21 bignum-shift 4294967295 bignum-bitand bignum-bitor
    >R >bignum R> bignum- rot dupd >bignum bignum-bitxor
    over dup >R 25 bignum-shift 4294967295 bignum-bitand
    R> -7 bignum-shift 4294967295 bignum-bitand bignum-bitor
    bignum- rot dupd bignum-bitxor over dup >R 16 bignum-shift
    4294967295 bignum-bitand R> -16 bignum-shift
    4294967295 bignum-bitand bignum-bitor bignum-
    rot dupd bignum-bitxor over dup >R 4 bignum-shift
    4294967295 bignum-bitand R> -28 bignum-shift
    4294967295 bignum-bitand bignum-bitor bignum-
    rot dupd bignum-bitxor swap dup >R 14 bignum-shift
    4294967295 bignum-bitand R> -18 bignum-shift
    4294967295 bignum-bitand bignum-bitor bignum-
    swap dupd bignum-bitxor swap dup >R 24 bignum-shift
    4294967295 bignum-bitand R> -8 bignum-shift
    4294967295 bignum-bitand bignum-bitor bignum-
    bignum>float 268435455.0 float/f
]
( scratchpad ) 

New Annotation

Summary:
Author:
Mode:
Body: