Skip to content

Commit

Permalink
Reland "Reland "Reland "Add build file for PFFFT""" [reland^3]
Browse files Browse the repository at this point in the history
This is a reland of a2fafd3

Hopefully the last reland. This CL adds the following:
- M_PI was also missing in fftpack.c
- temporary disable SIMD for iOS as well
- M_SQRT2 missing

Original change's description:
> Reland "Reland "Add build file for PFFFT""
>
> This is a reland of c1086af
>
> This CL fixes the compile issues of the reverted CL by defining M_LN2 when not defined.
>
> TBR=thakis@chromium.org
>
> Original change's description:
> > Reland "Add build file for PFFFT"
> >
> > This is a reland of 8e4cf15
> >
> > This CL includes the following changes:
> > 1. when fuzzing, PFFFT is compiled disabling SIMD
> > 2. SIMD is also disabled on fuchsia and android because PFFFT only checks __arm__
> > 3. unit test to validate the output of PFFFT (compared against that of FFTPACK)
> >
> > The first change fixes the problem due to which the original CL has been reverted;
> > however, it makes fuzzing slower and reduces the coverage since SIMD cannot be used.
> >
> > Similarly, the second change is a temporary solution to allow landing this CL.
> > SIMD will be re-enabled in a follow-up CL.
> >
> > Original change's description:
> > > Add build file for PFFFT
> > >
> > > - fuzzer corpus generator and fuzzer targets
> > > - fftpack isolated as private test only target (only needed for the benchmark)
> > >
> > > Bug: webrtc:9577
> > > Change-Id: Idc904bc4b05f945a7461a14893518551bbe34b84
> > > Reviewed-on: https://chromium-review.googlesource.com/c/1452000
> > > Commit-Queue: Ale Bzk <alessiob@chromium.org>
> > > Reviewed-by: Nico Weber <thakis@chromium.org>
> > > Reviewed-by: Olga Sharonova <olka@chromium.org>
> > > Reviewed-by: Max Moroz <mmoroz@chromium.org>
> > > Cr-Commit-Position: refs/heads/master@{#629627}
> >
> > Bug: webrtc:9577
> > Change-Id: Icfbb4b966c3ad866e9e2970b63363e0e258b1fea
> > Reviewed-on: https://chromium-review.googlesource.com/c/1458076
> > Commit-Queue: Ale Bzk <alessiob@chromium.org>
> > Reviewed-by: Nico Weber <thakis@chromium.org>
> > Reviewed-by: Max Moroz <mmoroz@chromium.org>
> > Reviewed-by: Max Morin <maxmorin@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#630085}
>
> Bug: webrtc:9577
> Change-Id: I6bfe6d5f103570cebb6ca7909bd0369ecd8a7c45
> Reviewed-on: https://chromium-review.googlesource.com/c/1460616
> Commit-Queue: Ale Bzk <alessiob@chromium.org>
> Reviewed-by: Olga Sharonova <olka@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#630278}

Bug: webrtc:9577
Change-Id: I0f5055026132d49357ebbf483dc6b0da9ed23c97
Reviewed-on: https://chromium-review.googlesource.com/c/1459630
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Olga Sharonova <olka@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630305}
  • Loading branch information
alebzk authored and Commit Bot committed Feb 8, 2019
1 parent 1ceb83e commit 383dcef
Show file tree
Hide file tree
Showing 17 changed files with 747 additions and 102 deletions.
7 changes: 7 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,13 @@ group("gn_all") {
"//tools/accessibility/inspect:ax_dump_tree",
]
}

# PFFFT.
deps += [
"//third_party/pffft:fuzzers",
"//third_party/pffft:pffft_benchmark",
"//third_party/pffft:pffft_unittest",
]
}

if ((is_linux || is_win) && enable_remoting && !use_ozone) {
Expand Down
107 changes: 107 additions & 0 deletions third_party/pffft/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//testing/libfuzzer/fuzzer_test.gni")
import("//testing/test.gni")

# TODO(crbug.com/webrtc/9577): Add architecture specific flags.

config("simd_config") {
# TODO(crbug.com/webrtc/9577): Use SIMD while fuzzing.
# TODO(crbug.com/webrtc/9577): Fix SIMD not detected on Android, fuchsia, iOS.
if (use_fuzzing_engine || is_android || is_fuchsia || is_ios) {
cflags = [ "-DPFFFT_SIMD_DISABLE" ]
}
}

static_library("pffft") {
configs += [ ":simd_config" ]
sources = [
"src/pffft.c",
"src/pffft.h",
]
}

# Fuzzing.

group("fuzzers") {
testonly = true
deps = [
":pffft_complex_fuzzer",
":pffft_real_fuzzer",
]
}

fuzzer_testdata_dir = "$target_gen_dir/testdata"

action("generate_pffft_fuzzer_corpus") {
script = "generate_seed_corpus.py"
sources = [
"generate_seed_corpus.py",
]
args = [ rebase_path(fuzzer_testdata_dir, root_build_dir) ]
outputs = [
fuzzer_testdata_dir,
]
}

fuzzer_test("pffft_complex_fuzzer") {
sources = [
"pffft_fuzzer.cc",
]
cflags = [ "-DTRANSFORM_COMPLEX" ]
deps = [
":pffft",
]
seed_corpus = fuzzer_testdata_dir
seed_corpus_deps = [ ":generate_pffft_fuzzer_corpus" ]
}

fuzzer_test("pffft_real_fuzzer") {
sources = [
"pffft_fuzzer.cc",
]
cflags = [ "-DTRANSFORM_REAL" ]
deps = [
":pffft",
]
seed_corpus = fuzzer_testdata_dir
seed_corpus_deps = [ ":generate_pffft_fuzzer_corpus" ]
}

# Unit tests and benchmark.

# This target must be used only for testing and benchmark purposes.
static_library("fftpack") {
testonly = true
sources = [
"src/fftpack.c",
"src/fftpack.h",
]
visibility = [ ":*" ]
}

executable("pffft_benchmark") {
configs += [ ":simd_config" ]
testonly = true
sources = [
"src/test_pffft.c",
]
deps = [
":fftpack",
":pffft",
]
}

test("pffft_unittest") {
sources = [
"pffft_unittest.cc",
]
deps = [
":fftpack",
":pffft",
"//testing/gtest",
"//testing/gtest:gtest_main",
]
}
3 changes: 3 additions & 0 deletions third_party/pffft/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+testing/gtest/include/gtest",
]
6 changes: 6 additions & 0 deletions third_party/pffft/README.chromium
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ Description:
PFFFT does 1D Fast Fourier Transforms, of single precision real and complex vectors. It tries do it fast, it tries to be correct, and it tries to be small. Computations do take advantage of SSE1 instructions on x86 cpus, Altivec on powerpc cpus, and NEON on ARM cpus.

Local Modifications:
* 01-add_m_pi.diff: define M_PI if not defined
* 02-rmv_printf.diff: remove printf and stop including stdio.h
* 03-decl_validate_simd.diff: declare validate_pffft_simd() in pffft.h
* 04-add_m_ln2.diff: define M_LN2 if not defined
* 05-add_m_sqrt2.diff: define M_SQRT2 if not defined
* 06-add_m_pi_fftpack.diff: define M_PI if not defined (fftpack)
72 changes: 72 additions & 0 deletions third_party/pffft/generate_seed_corpus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import division
from __future__ import print_function

from array import array
import os
import random
import sys

MAX_INPUT_SIZE = int(1e6)
MAX_FLOAT32 = 3.4028235e+38


def IsValidSize(n):
if n == 0:
return False
# PFFFT only supports transforms for inputs of length N of the form
# N = (2^a)*(3^b)*(5^c) where a >= 5, b >=0, c >= 0.
FACTORS = [2, 3, 5]
factorization = [0, 0, 0]
for i, factor in enumerate(FACTORS):
while n % factor == 0:
n = n // factor
factorization[i] += 1
return factorization[0] >= 5 and n == 1


def WriteFloat32ArrayToFile(file_path, size, generator):
"""Generate an array of float32 values and writes to file."""
with open(file_path, 'wb') as f:
float_array = array('f', [generator() for _ in range(size)])
float_array.tofile(f)


def main():
if len(sys.argv) < 2:
print('Usage: %s <path to output directory>' % sys.argv[0])
sys.exit(1)

output_path = sys.argv[1]
# Create output directory if missing.
if not os.path.exists(output_path):
os.makedirs(output_path)

# List of valid input sizes.
N = [n for n in range(MAX_INPUT_SIZE) if IsValidSize(n)]

# Set the seed to always generate the same random data.
random.seed(0)

# Generate different types of input arrays for each target length.
for n in N:
# Zeros.
WriteFloat32ArrayToFile(
os.path.join(output_path, 'zeros_%d' % n), n, lambda: 0)
# Max float 32.
WriteFloat32ArrayToFile(
os.path.join(output_path, 'max_%d' % n), n, lambda: MAX_FLOAT32)
# Random values in the s16 range.
rnd_s16 = lambda: 32768.0 * 2.0 * (random.random() - 0.5)
WriteFloat32ArrayToFile(
os.path.join(output_path, 'rnd_s16_%d' % n), n, rnd_s16)

sys.exit(0)


if __name__ == '__main__':
main()
14 changes: 14 additions & 0 deletions third_party/pffft/patches/01-add_m_pi.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/third_party/pffft/src/pffft.c b/third_party/pffft/src/pffft.c
index 0603f2b1f698..7934db448a09 100644
--- a/third_party/pffft/src/pffft.c
+++ b/third_party/pffft/src/pffft.c
@@ -82,6 +82,9 @@
# define VLA_ARRAY_ON_STACK(type__, varname__, size__) type__ *varname__ = (type__*)_alloca(size__ * sizeof(type__))
#endif

+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif

/*
vector support macros: the rest of the code is independant of
60 changes: 60 additions & 0 deletions third_party/pffft/patches/02-rmv_printf.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
diff --git a/third_party/pffft/src/pffft.c b/third_party/pffft/src/pffft.c
index 7934db448a09..2e0c2f651438 100644
--- a/third_party/pffft/src/pffft.c
+++ b/third_party/pffft/src/pffft.c
@@ -59,7 +59,7 @@

#include "pffft.h"
#include <stdlib.h>
-#include <stdio.h>
+// #include <stdio.h>
#include <math.h>
#include <assert.h>

@@ -222,31 +222,35 @@ void validate_pffft_simd() {
memcpy(a3.f, f+12, 4*sizeof(float));

t = a0; u = a1; t.v = VZERO();
- printf("VZERO=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]); assertv4(t, 0, 0, 0, 0);
+ // printf("VZERO=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]);
+ assertv4(t, 0, 0, 0, 0);
t.v = VADD(a1.v, a2.v);
- printf("VADD(4:7,8:11)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]); assertv4(t, 12, 14, 16, 18);
+ // printf("VADD(4:7,8:11)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]);
+ assertv4(t, 12, 14, 16, 18);
t.v = VMUL(a1.v, a2.v);
- printf("VMUL(4:7,8:11)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]); assertv4(t, 32, 45, 60, 77);
+ // printf("VMUL(4:7,8:11)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]);
+ assertv4(t, 32, 45, 60, 77);
t.v = VMADD(a1.v, a2.v,a0.v);
- printf("VMADD(4:7,8:11,0:3)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]); assertv4(t, 32, 46, 62, 80);
+ // printf("VMADD(4:7,8:11,0:3)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]);
+ assertv4(t, 32, 46, 62, 80);

INTERLEAVE2(a1.v,a2.v,t.v,u.v);
- printf("INTERLEAVE2(4:7,8:11)=[%2g %2g %2g %2g] [%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3], u.f[0], u.f[1], u.f[2], u.f[3]);
+ // printf("INTERLEAVE2(4:7,8:11)=[%2g %2g %2g %2g] [%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3], u.f[0], u.f[1], u.f[2], u.f[3]);
assertv4(t, 4, 8, 5, 9); assertv4(u, 6, 10, 7, 11);
UNINTERLEAVE2(a1.v,a2.v,t.v,u.v);
- printf("UNINTERLEAVE2(4:7,8:11)=[%2g %2g %2g %2g] [%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3], u.f[0], u.f[1], u.f[2], u.f[3]);
+ // printf("UNINTERLEAVE2(4:7,8:11)=[%2g %2g %2g %2g] [%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3], u.f[0], u.f[1], u.f[2], u.f[3]);
assertv4(t, 4, 6, 8, 10); assertv4(u, 5, 7, 9, 11);

t.v=LD_PS1(f[15]);
- printf("LD_PS1(15)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]);
+ // printf("LD_PS1(15)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]);
assertv4(t, 15, 15, 15, 15);
t.v = VSWAPHL(a1.v, a2.v);
- printf("VSWAPHL(4:7,8:11)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]);
+ // printf("VSWAPHL(4:7,8:11)=[%2g %2g %2g %2g]\n", t.f[0], t.f[1], t.f[2], t.f[3]);
assertv4(t, 8, 9, 6, 7);
VTRANSPOSE4(a0.v, a1.v, a2.v, a3.v);
- printf("VTRANSPOSE4(0:3,4:7,8:11,12:15)=[%2g %2g %2g %2g] [%2g %2g %2g %2g] [%2g %2g %2g %2g] [%2g %2g %2g %2g]\n",
- a0.f[0], a0.f[1], a0.f[2], a0.f[3], a1.f[0], a1.f[1], a1.f[2], a1.f[3],
- a2.f[0], a2.f[1], a2.f[2], a2.f[3], a3.f[0], a3.f[1], a3.f[2], a3.f[3]);
+ // printf("VTRANSPOSE4(0:3,4:7,8:11,12:15)=[%2g %2g %2g %2g] [%2g %2g %2g %2g] [%2g %2g %2g %2g] [%2g %2g %2g %2g]\n",
+ // a0.f[0], a0.f[1], a0.f[2], a0.f[3], a1.f[0], a1.f[1], a1.f[2], a1.f[3],
+ // a2.f[0], a2.f[1], a2.f[2], a2.f[3], a3.f[0], a3.f[1], a3.f[2], a3.f[3]);
assertv4(a0, 0, 4, 8, 12); assertv4(a1, 1, 5, 9, 13); assertv4(a2, 2, 6, 10, 14); assertv4(a3, 3, 7, 11, 15);
}
#endif //!PFFFT_SIMD_DISABLE
16 changes: 16 additions & 0 deletions third_party/pffft/patches/03-decl_validate_simd.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/third_party/pffft/src/pffft.h b/third_party/pffft/src/pffft.h
index 2bfa7b3ebcfb..bb6f78d4b795 100644
--- a/third_party/pffft/src/pffft.h
+++ b/third_party/pffft/src/pffft.h
@@ -83,6 +83,11 @@
extern "C" {
#endif

+#ifndef PFFFT_SIMD_DISABLE
+ // Detects compiler bugs with respect to simd instruction.
+ void validate_pffft_simd();
+#endif
+
/* opaque struct holding internal stuff (precomputed twiddle factors)
this struct can be shared by many threads as it contains only
read-only data.
15 changes: 15 additions & 0 deletions third_party/pffft/patches/04-add_m_ln2.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/third_party/pffft/src/test_pffft.c b/third_party/pffft/src/test_pffft.c
index ab78b4dcc0d5..deaf98ed9f09 100644
--- a/third_party/pffft/src/test_pffft.c
+++ b/third_party/pffft/src/test_pffft.c
@@ -45,6 +45,10 @@
# include <fftw3.h>
#endif

+#ifndef M_LN2
+#define M_LN2 0.693147180559945309417
+#endif
+
#define MAX(x,y) ((x)>(y)?(x):(y))

double frand() {
15 changes: 15 additions & 0 deletions third_party/pffft/patches/05-add_m_sqrt2.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/third_party/pffft/src/pffft.c b/third_party/pffft/src/pffft.c
index 2e0c2f651438..b89e6d7b6fbc 100644
--- a/third_party/pffft/src/pffft.c
+++ b/third_party/pffft/src/pffft.c
@@ -86,6 +86,10 @@
#define M_PI 3.14159265358979323846
#endif

+#ifndef M_SQRT2
+#define M_SQRT2 1.41421356237309504880
+#endif
+
/*
vector support macros: the rest of the code is independant of
SSE/Altivec/NEON -- adding support for other platforms with 4-element
15 changes: 15 additions & 0 deletions third_party/pffft/patches/06-add_m_pi_fftpack.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/third_party/pffft/src/fftpack.c b/third_party/pffft/src/fftpack.c
index b6375a80dab4..d801d16602b2 100644
--- a/third_party/pffft/src/fftpack.c
+++ b/third_party/pffft/src/fftpack.c
@@ -54,6 +54,10 @@
#include "fftpack.h"
#include <math.h>

+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
typedef fftpack_real real;
typedef fftpack_int integer;

Loading

0 comments on commit 383dcef

Please sign in to comment.