Skip to content
This repository
Browse code

Merge branch 'gh925_ffa_sort'

  • Loading branch information...
commit 99676a6663eef9913ce51a60fd4adb44bb27f366 2 parents 285bd0a + 08e2d38
Duke Leto authored January 15, 2013
11  ChangeLog
... ...
@@ -1,11 +1,12 @@
1 1
 2013-01-15    release 5.0.0
2 2
     - Core
3 3
         + Remove duplicate library search path entries, move "." from the beginning to
4  
-          the end. [GH #368]
  4
+          the end. This is a non-backward compatible change, but emulating the old
  5
+          behavior is possible. [GH #368]
5 6
         + Install forgotten runtime include files:
6  
-          cloneflags.pasm
7  
-          packfile_annotation_keytype.pasm
8  
-          packfile_segments.pasm
  7
+            cloneflags.pasm
  8
+            packfile_annotation_keytype.pasm
  9
+            packfile_segments.pasm
9 10
         + Install include/parrot/pbcversion.h with the main package, not devel.
10 11
         + Install headers for dynpmc files.
11 12
         + Install libraries tgc.pbc, NCI/Utils.pbc, OpenGL/Math.pbc, PCT/Dumper.pbc,
@@ -14,6 +15,7 @@
14 15
         + New experimental PARROT_DYNEXT environment variable
15 16
         + New experimental dynext_dirs config entry (same as PARROT_DYNEXT and -X)
16 17
         + Add OS error messages to FileHandle.open() error messages [GH #911]
  18
+        + Add a .sort method to FixedFloatArrays [GH #925]
17 19
     - Build
18 20
         + Generate MANIFEST.generated, cleanup MANIFEST,
19 21
           removed MANIFEST_configure.generated, add installation of forgotten files
@@ -33,6 +35,7 @@
33 35
         + Document FileHandle.open() exceptions and error messages
34 36
     - Tests
35 37
         + Added t/library/lib_search_path.t
  38
+        + Added tests to t/pmc/fixedfloatarrays.t
36 39
 
37 40
 2012-12-18    release 4.11.0
38 41
     - Core
1  MANIFEST
@@ -507,6 +507,7 @@ examples/benchmarks/primes2_i.pir                           [examples]
507 507
 examples/benchmarks/primes_i.pasm                           [examples]
508 508
 examples/benchmarks/rand.pir                                [examples]
509 509
 examples/benchmarks/sort.pir                                [examples]
  510
+examples/benchmarks/sort_ffa.pir                            [examples]
510 511
 examples/benchmarks/stress.pasm                             [examples]
511 512
 examples/benchmarks/stress.pl                               [examples]
512 513
 examples/benchmarks/stress.rb                               [examples]
59  examples/benchmarks/sort_ffa.pir
... ...
@@ -0,0 +1,59 @@
  1
+# Copyright (C) 2013, Parrot Foundation.
  2
+
  3
+=head1 NAME
  4
+
  5
+examples/benchmarks/sort_ffa.pir - Sort an FixedFloatArray of N floats
  6
+
  7
+=head1 SYNOPSIS
  8
+
  9
+    % time ./parrot examples/benchmarks/sort_ffa.pir 100000
  10
+
  11
+Or use the default number of iterations:
  12
+
  13
+    % time ./parrot examples/benchmarks/sort.pir
  14
+
  15
+=head1 DESCRIPTION
  16
+
  17
+Sorts an FixedFloatArray of N random integers using builtin sort
  18
+function for FixedFloatArray. The argument N is specified from the
  19
+command line.
  20
+
  21
+=cut
  22
+
  23
+.loadlib 'math_ops'
  24
+
  25
+.sub main :main
  26
+  .param pmc argv
  27
+  .local int N, i, j
  28
+
  29
+  N = argv[1]
  30
+  if N < 1 goto USE_DEFAULT_SIZE
  31
+  goto USE_DEFINED_SIZE
  32
+
  33
+USE_DEFAULT_SIZE:
  34
+  N = 1000000
  35
+
  36
+USE_DEFINED_SIZE:
  37
+  $P0 = new ['FixedFloatArray'], N
  38
+  i = 0
  39
+  j = 0
  40
+
  41
+LOOP:
  42
+  j = rand 0, N
  43
+  $P0[i] = j
  44
+  inc i
  45
+  if i < N goto LOOP
  46
+
  47
+  $P0.'sort'()
  48
+
  49
+.end
  50
+
  51
+
  52
+=cut
  53
+
  54
+# Local Variables:
  55
+#   mode: pir
  56
+#   fill-column: 100
  57
+# End:
  58
+# vim: expandtab shiftwidth=4 ft=pir:
  59
+
66  src/pmc/fixedfloatarray.pmc
@@ -20,6 +20,17 @@ stored FLOATVALs.  It uses Float PMCs to do all necessary conversions.
20 20
 
21 21
 /* HEADERIZER HFILE: none */
22 22
 /* HEADERIZER BEGIN: static */
  23
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
  24
+
  25
+PARROT_PURE_FUNCTION
  26
+static int auxcmpfunc(ARGIN(const FLOATVAL *i), ARGIN(const FLOATVAL *j))
  27
+        __attribute__nonnull__(1)
  28
+        __attribute__nonnull__(2);
  29
+
  30
+#define ASSERT_ARGS_auxcmpfunc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
  31
+       PARROT_ASSERT_ARG(i) \
  32
+    , PARROT_ASSERT_ARG(j))
  33
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
23 34
 /* HEADERIZER END: static */
24 35
 
25 36
 pmclass FixedFloatArray auto_attrs provides array {
@@ -34,6 +45,37 @@ pmclass FixedFloatArray auto_attrs provides array {
34 45
 
35 46
 =over 4
36 47
 
  48
+=item C<PMC *sort()>
  49
+
  50
+Sort the array and return self.
  51
+
  52
+=cut
  53
+
  54
+*/
  55
+
  56
+    METHOD sort(PMC *cmp_func :optional) {
  57
+        UINTVAL n;
  58
+        INTVAL  size;
  59
+
  60
+        GET_ATTR_size(INTERP, SELF, size);
  61
+        n = (UINTVAL)size;
  62
+
  63
+        if (n > 1) {
  64
+            FLOATVAL *float_array;
  65
+            GET_ATTR_float_array(INTERP, SELF, float_array);
  66
+            if (PMC_IS_NULL(cmp_func))
  67
+                qsort(float_array, n, sizeof (INTVAL),
  68
+                        (int (*)(const void *, const void*))auxcmpfunc);
  69
+            else
  70
+                Parrot_util_quicksort(INTERP, (void**)float_array, n, cmp_func, "NN->N");
  71
+        }
  72
+        RETURN(PMC *SELF);
  73
+    }
  74
+
  75
+/*
  76
+
  77
+=over 4
  78
+
37 79
 =item C<void destroy()>
38 80
 
39 81
 Destroys the array.
@@ -535,6 +577,30 @@ Reverse the contents of the array.
535 577
 
536 578
 =back
537 579
 
  580
+=head2 Auxiliary functions
  581
+
  582
+=over 4
  583
+
  584
+=item C<static int auxcmpfunc(const FLOATVAL *i, const FLOATVAL *j)>
  585
+
  586
+INTVAL compare function for qsort usage.
  587
+
  588
+=cut
  589
+
  590
+*/
  591
+
  592
+PARROT_PURE_FUNCTION
  593
+static int
  594
+auxcmpfunc(ARGIN(const FLOATVAL *i), ARGIN(const FLOATVAL *j))
  595
+{
  596
+    ASSERT_ARGS(auxcmpfunc)
  597
+    return (int) (*i - *j);
  598
+}
  599
+
  600
+/*
  601
+
  602
+=back
  603
+
538 604
 =head1 SEE ALSO
539 605
 
540 606
 F<docs/pdds/pdd17_basic_types.pod>.
20  t/pmc/fixedfloatarray.t
@@ -19,7 +19,7 @@ out-of-bounds test. Checks INT and PMC keys.
19 19
 .sub main :main
20 20
     .include 'fp_equality.pasm'
21 21
     .include 'test_more.pir'
22  
-    plan(32)
  22
+    plan(36)
23 23
 
24 24
     array_size_tests()
25 25
     element_set_tests()
@@ -32,6 +32,24 @@ out-of-bounds test. Checks INT and PMC keys.
32 32
     test_new_style_init()
33 33
     test_invalid_init_tt1509()
34 34
     test_get_string()
  35
+    test_sort()
  36
+.end
  37
+
  38
+.sub test_sort
  39
+    $P0 = new ['FixedFloatArray'], 4
  40
+    set $P0[0],10.0
  41
+    set $P0[1],5.0
  42
+    set $P0[2],3.0
  43
+    set $P0[3],1.0
  44
+    $P0.'sort'()
  45
+    $I0 = $P0[0]
  46
+    is($I0,1,'sort works')
  47
+    $I1 = $P0[1]
  48
+    is($I1,3,'sort works')
  49
+    $I2 = $P0[2]
  50
+    is($I2,5,'sort works')
  51
+    $I3 = $P0[3]
  52
+    is($I3,10,'sort works')
35 53
 .end
36 54
 
37 55
 .sub array_size_tests

0 notes on commit 99676a6

Please sign in to comment.
Something went wrong with that request. Please try again.