Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'gh925_ffa_sort'

  • Loading branch information...
commit 99676a6663eef9913ce51a60fd4adb44bb27f366 2 parents 285bd0a + 08e2d38
@leto leto authored
View
11 ChangeLog
@@ -1,11 +1,12 @@
2013-01-15 release 5.0.0
- Core
+ Remove duplicate library search path entries, move "." from the beginning to
- the end. [GH #368]
+ the end. This is a non-backward compatible change, but emulating the old
+ behavior is possible. [GH #368]
+ Install forgotten runtime include files:
- cloneflags.pasm
- packfile_annotation_keytype.pasm
- packfile_segments.pasm
+ cloneflags.pasm
+ packfile_annotation_keytype.pasm
+ packfile_segments.pasm
+ Install include/parrot/pbcversion.h with the main package, not devel.
+ Install headers for dynpmc files.
+ Install libraries tgc.pbc, NCI/Utils.pbc, OpenGL/Math.pbc, PCT/Dumper.pbc,
@@ -14,6 +15,7 @@
+ New experimental PARROT_DYNEXT environment variable
+ New experimental dynext_dirs config entry (same as PARROT_DYNEXT and -X)
+ Add OS error messages to FileHandle.open() error messages [GH #911]
+ + Add a .sort method to FixedFloatArrays [GH #925]
- Build
+ Generate MANIFEST.generated, cleanup MANIFEST,
removed MANIFEST_configure.generated, add installation of forgotten files
@@ -33,6 +35,7 @@
+ Document FileHandle.open() exceptions and error messages
- Tests
+ Added t/library/lib_search_path.t
+ + Added tests to t/pmc/fixedfloatarrays.t
2012-12-18 release 4.11.0
- Core
View
1  MANIFEST
@@ -507,6 +507,7 @@ examples/benchmarks/primes2_i.pir [examples]
examples/benchmarks/primes_i.pasm [examples]
examples/benchmarks/rand.pir [examples]
examples/benchmarks/sort.pir [examples]
+examples/benchmarks/sort_ffa.pir [examples]
examples/benchmarks/stress.pasm [examples]
examples/benchmarks/stress.pl [examples]
examples/benchmarks/stress.rb [examples]
View
59 examples/benchmarks/sort_ffa.pir
@@ -0,0 +1,59 @@
+# Copyright (C) 2013, Parrot Foundation.
+
+=head1 NAME
+
+examples/benchmarks/sort_ffa.pir - Sort an FixedFloatArray of N floats
+
+=head1 SYNOPSIS
+
+ % time ./parrot examples/benchmarks/sort_ffa.pir 100000
+
+Or use the default number of iterations:
+
+ % time ./parrot examples/benchmarks/sort.pir
+
+=head1 DESCRIPTION
+
+Sorts an FixedFloatArray of N random integers using builtin sort
+function for FixedFloatArray. The argument N is specified from the
+command line.
+
+=cut
+
+.loadlib 'math_ops'
+
+.sub main :main
+ .param pmc argv
+ .local int N, i, j
+
+ N = argv[1]
+ if N < 1 goto USE_DEFAULT_SIZE
+ goto USE_DEFINED_SIZE
+
+USE_DEFAULT_SIZE:
+ N = 1000000
+
+USE_DEFINED_SIZE:
+ $P0 = new ['FixedFloatArray'], N
+ i = 0
+ j = 0
+
+LOOP:
+ j = rand 0, N
+ $P0[i] = j
+ inc i
+ if i < N goto LOOP
+
+ $P0.'sort'()
+
+.end
+
+
+=cut
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
+
View
66 src/pmc/fixedfloatarray.pmc
@@ -20,6 +20,17 @@ stored FLOATVALs. It uses Float PMCs to do all necessary conversions.
/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+
+PARROT_PURE_FUNCTION
+static int auxcmpfunc(ARGIN(const FLOATVAL *i), ARGIN(const FLOATVAL *j))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+#define ASSERT_ARGS_auxcmpfunc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(i) \
+ , PARROT_ASSERT_ARG(j))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
pmclass FixedFloatArray auto_attrs provides array {
@@ -34,6 +45,37 @@ pmclass FixedFloatArray auto_attrs provides array {
=over 4
+=item C<PMC *sort()>
+
+Sort the array and return self.
+
+=cut
+
+*/
+
+ METHOD sort(PMC *cmp_func :optional) {
+ UINTVAL n;
+ INTVAL size;
+
+ GET_ATTR_size(INTERP, SELF, size);
+ n = (UINTVAL)size;
+
+ if (n > 1) {
+ FLOATVAL *float_array;
+ GET_ATTR_float_array(INTERP, SELF, float_array);
+ if (PMC_IS_NULL(cmp_func))
+ qsort(float_array, n, sizeof (INTVAL),
+ (int (*)(const void *, const void*))auxcmpfunc);
+ else
+ Parrot_util_quicksort(INTERP, (void**)float_array, n, cmp_func, "NN->N");
+ }
+ RETURN(PMC *SELF);
+ }
+
+/*
+
+=over 4
+
=item C<void destroy()>
Destroys the array.
@@ -535,6 +577,30 @@ Reverse the contents of the array.
=back
+=head2 Auxiliary functions
+
+=over 4
+
+=item C<static int auxcmpfunc(const FLOATVAL *i, const FLOATVAL *j)>
+
+INTVAL compare function for qsort usage.
+
+=cut
+
+*/
+
+PARROT_PURE_FUNCTION
+static int
+auxcmpfunc(ARGIN(const FLOATVAL *i), ARGIN(const FLOATVAL *j))
+{
+ ASSERT_ARGS(auxcmpfunc)
+ return (int) (*i - *j);
+}
+
+/*
+
+=back
+
=head1 SEE ALSO
F<docs/pdds/pdd17_basic_types.pod>.
View
20 t/pmc/fixedfloatarray.t
@@ -19,7 +19,7 @@ out-of-bounds test. Checks INT and PMC keys.
.sub main :main
.include 'fp_equality.pasm'
.include 'test_more.pir'
- plan(32)
+ plan(36)
array_size_tests()
element_set_tests()
@@ -32,6 +32,24 @@ out-of-bounds test. Checks INT and PMC keys.
test_new_style_init()
test_invalid_init_tt1509()
test_get_string()
+ test_sort()
+.end
+
+.sub test_sort
+ $P0 = new ['FixedFloatArray'], 4
+ set $P0[0],10.0
+ set $P0[1],5.0
+ set $P0[2],3.0
+ set $P0[3],1.0
+ $P0.'sort'()
+ $I0 = $P0[0]
+ is($I0,1,'sort works')
+ $I1 = $P0[1]
+ is($I1,3,'sort works')
+ $I2 = $P0[2]
+ is($I2,5,'sort works')
+ $I3 = $P0[3]
+ is($I3,10,'sort works')
.end
.sub array_size_tests
Please sign in to comment.
Something went wrong with that request. Please try again.