~ubuntu-branches/ubuntu/trusty/fftw/trusty

« back to all changes in this revision

Viewing changes to gensrc/twiddle.ml

  • Committer: Bazaar Package Importer
  • Author(s): James A. Treacy
  • Date: 2002-03-05 00:28:49 UTC
  • Revision ID: james.westby@ubuntu.com-20020305002849-q0grqhlbeugn4y5j
Tags: upstream-2.1.3
ImportĀ upstreamĀ versionĀ 2.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(*
 
2
 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 *
 
18
 *)
 
19
 
 
20
(* $Id: twiddle.ml,v 1.2 1999/02/19 17:22:19 athena Exp $ *)
 
21
 
 
22
(* This file implements various policies for either loading the twiddle
 
23
 * factors according to various algorithms. *)
 
24
 
 
25
open Complex
 
26
open Util
 
27
 
 
28
let square x = 
 
29
  if (!Magic.use_wsquare) then
 
30
    wsquare x
 
31
  else
 
32
    times x x
 
33
 
 
34
(* various policies for computing/loading twiddle factors *)
 
35
(* load all twiddle factors *)
 
36
let twiddle_policy_load_all =
 
37
  let twiddle_expression n i _ =
 
38
    load_var (access_twiddle (i - 1))
 
39
  and num_twiddle n = (n - 1)
 
40
  and twiddle_order n = forall_flat 1 n (fun i -> [i])
 
41
  in twiddle_expression, num_twiddle, twiddle_order
 
42
 
 
43
(*
 
44
 * if n is even, compute w^n = (w^{n/2})^2, else
 
45
 * load it
 
46
 *)
 
47
let twiddle_policy_load_odd =
 
48
  let twiddle_expression n i twiddles =
 
49
    if ((i mod 2) == 0) then
 
50
      square (twiddles (i / 2))
 
51
    else load_var (access_twiddle ((i - 1) / 2))
 
52
  and num_twiddle n = (n / 2)
 
53
  and twiddle_order n = forall_flat 1 n (fun i -> 
 
54
    if ((i mod 2) == 1) then [i] else [])
 
55
  in twiddle_expression, num_twiddle, twiddle_order
 
56
 
 
57
(* compute w^n = w w^{n-1} *)
 
58
let twiddle_policy_iter =
 
59
  let twiddle_expression n i twiddles =
 
60
    if (i == 1) then load_var (access_twiddle (i - 1))
 
61
    else times (twiddles (i - 1)) (twiddles 1)
 
62
  and num_twiddle n = 1
 
63
  and twiddle_order n = [1]
 
64
  in twiddle_expression, num_twiddle, twiddle_order
 
65
 
 
66
(*
 
67
 * if n is even, compute w^n = (w^{n/2})^2, else
 
68
 *  w^n = w w^{n-1}
 
69
 *)
 
70
let twiddle_policy_square1 =
 
71
  let twiddle_expression n i twiddles =
 
72
    if (i == 1) then load_var (access_twiddle (i - 1))
 
73
    else if ((i mod 2) == 0) then
 
74
      square (twiddles (i / 2))
 
75
    else times (twiddles (i - 1)) (twiddles 1)
 
76
  and num_twiddle n = 1
 
77
  and twiddle_order n = [1]
 
78
  in twiddle_expression, num_twiddle, twiddle_order
 
79
 
 
80
(*
 
81
 * if n is even, compute w^n = (w^{n/2})^2, else
 
82
 * compute  w^n from w^{n-1}, w^{n-2}, and w
 
83
 *)
 
84
let twiddle_policy_square2 =
 
85
  let twiddle_expression n i twiddles =
 
86
    if (i == 1) then load_var (access_twiddle (i - 1))
 
87
    else if ((i mod 2) == 0) then
 
88
      square (twiddles (i / 2))
 
89
    else 
 
90
      wthree (twiddles (i - 1)) (twiddles (i - 2)) (twiddles 1)
 
91
  and num_twiddle n = 1
 
92
  and twiddle_order n = [1]
 
93
  in twiddle_expression, num_twiddle, twiddle_order
 
94
 
 
95
(*
 
96
 * if n is even, compute w^n = (w^{n/2})^2, else
 
97
 *  w^n = w^{floor(n/2)} w^{ceil(n/2)}
 
98
 *)
 
99
let twiddle_policy_square3 =
 
100
  let twiddle_expression n i twiddles =
 
101
    if (i == 1) then load_var (access_twiddle (i - 1))
 
102
    else if ((i mod 2) == 0) then
 
103
      square (twiddles (i / 2))
 
104
    else times (twiddles (i / 2)) (twiddles (i - i / 2))
 
105
  and num_twiddle n = 1
 
106
  and twiddle_order n = [1]
 
107
  in twiddle_expression, num_twiddle, twiddle_order
 
108
 
 
109
let twiddle_policy () = 
 
110
  match !Magic.twiddle_policy with
 
111
    Magic.TWIDDLE_LOAD_ALL -> twiddle_policy_load_all
 
112
  | Magic.TWIDDLE_ITER -> twiddle_policy_iter
 
113
  | Magic.TWIDDLE_LOAD_ODD -> twiddle_policy_load_odd
 
114
  | Magic.TWIDDLE_SQUARE1 -> twiddle_policy_square1
 
115
  | Magic.TWIDDLE_SQUARE2 -> twiddle_policy_square2
 
116
  | Magic.TWIDDLE_SQUARE3 -> twiddle_policy_square3
 
117