home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume1
/
8707
/
49
/
fft.cl
< prev
next >
Wrap
Lisp/Scheme
|
1990-07-13
|
3KB
|
97 lines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; File: fft.cl
; Description: FFT benchmark from the Gabriel tests.
; Author: Harry Barrow
; Created: 8-Apr-85
; Modified: 6-May-85 09:29:22 (Bob Shaw)
; Language: Common Lisp
; Package: User
; Status: Public Domain
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; FFT -- This is an FFT benchmark written by Harry Barrow.
;;; It tests a variety of floating point operations,
;;; including array references.
(defvar *re* (make-array 1025 :element-type 'single-float
:initial-element 0.0))
(defvar *im* (make-array 1025 :element-type 'single-float
:initial-element 0.0))
(defun fft (areal aimag)
(declare (vector areal aimag))
(prog (ar ai i j k m n le le1 ip nv2 nm1 ur ui wr wi tr ti)
(declare (vector ai ai) (fixnum i j k m n le le1 nv2 nm1))
;; initialize
(setq ar areal
ai aimag
n (array-dimension ar 0)
n (1- n)
nv2 (floor n 2)
nm1 (1- n)
m 0 ;compute m = log(n)
i 1)
l1 (cond ((< i n) (setq m (1+ m) i (+ i i)) (go l1)))
(cond ((not (equal n (expt 2 m)))
(princ "error ... array size not a power of two.")
(read)
(return (terpri))))
;; interchange elements in bit-reversed order
(setq j 1 i 1)
l3 (cond ((< i j)
(setq tr (aref ar j) ti (aref ai j))
(setf (aref ar j) (aref ar i))
(setf (aref ai j) (aref ai i))
(setf (aref ar i) tr)
(setf (aref ai i) ti)))
(setq k nv2)
l6 (cond ((< k j)
(setq j (- j k) k (/ k 2))
(go l6)))
(setq j (+ j k) i (1+ i))
(cond ((< i n)
(go l3)))
(do ((l 1 (1+ l))) ;loop thru stages (syntax converted
((> l m)) ; from old MACLISP style \bs)
(declare (fixnum l))
(setq le (expt 2 l)
le1 (floor le 2)
ur 1.0
ui 0.
wr (cos (/ pi (float le1)))
wi (sin (/ pi (float le1))))
;; loop thru butterflies
(do ((j 1 (1+ j)))
((> j le1))
(declare (fixnum j))
;; do a butterfly
(do ((i j (+ i le)))
((> i n))
(declare (fixnum i))
(setq ip (+ i le1)
tr (- (* (aref ar ip) ur)
(* (aref ai ip) ui))
ti (+ (* (aref ar ip) ui)
(* (aref ai ip) ur)))
(setf (aref ar ip) (- (aref ar i) tr))
(setf (aref ai ip) (- (aref ai i) ti))
(setf (aref ar i) (+ (aref ar i) tr))
(setf (aref ai i) (+ (aref ai i) ti))))
(setq tr (- (* ur wr) (* ui wi))
ti (+ (* ur wi) (* ui wr))
ur tr
ui ti))
(return t)))
;;; the timer which does 10 calls on fft
(defmacro fft-bench ()
`(do ((ntimes 0 (1+ ntimes)))
((= ntimes 10))
(fft *re* *im*)))
;;; call: (fft-bench)
(run-benchmark "FFT" '(fft-bench))