Re: [PATCH, PR43920, 1/9] ARM specific part.

2011-04-05 Thread Tom de Vries
On 04/04/2011 02:22 PM, Rainer Orth wrote:
 Richard Guenther richard.guent...@gmail.com writes:
 
 On Sun, Apr 3, 2011 at 9:34 PM, Sergey Ostanevich sergos@gmail.com 
 wrote:
 I would recommend to use 'nm -S a.out' that gives

 [...]
 004004a4 0054 T main
 [...]

 then you can provide a name for the routine you want to test for the size.

 That also sounds reasonable.  Is nm -S more portable than size?
 
 Neither Solaris nor IRIX nm have it.  size isn't particularly portable,
 either: there are many variations in output format.
 
   Rainer
 

In case we ever need it, here's a patch to access nm -S.

Thanks,
- Tom
2011-04-05  Tom de Vries  t...@codesourcery.com

	* lib/scanasm.exp (object-symbol-size): New proc.
Index: gcc/testsuite/lib/scanasm.exp
===
--- gcc/testsuite/lib/scanasm.exp (revision 170556)
+++ gcc/testsuite/lib/scanasm.exp (working copy)
@@ -315,6 +315,90 @@ proc scan-assembler-dem-not { args } {
 }
 }
 
+# Call pass if symbol size is ok, otherwise fail.
+# example: /* { dg-final { object-symbol-size main = 54 } } */
+proc object-symbol-size { args } {
+global nm
+global base_dir
+
+if { [llength $args]  3 } {
+	error object-symbol-size: too few arguments
+return
+}
+if { [llength $args]  4 } {
+	error object-symbol-size: too many arguments
+	return
+}
+if { [llength $args] = 4 } {
+	switch [dg-process-target [lindex $args 1]] {
+	S { }
+	N { return }
+	F { setup_xfail *-*-* }
+	P { }
+	}
+}
+
+# Find nm like we find g++ in g++.exp.
+if ![info exists nm]  {
+	set nm [findfile $base_dir/../../../binutils/nm \
+		$base_dir/../../../binutils/nm \
+		[findfile $base_dir/../../nm $base_dir/../../nm \
+		 [findfile $base_dir/nm $base_dir/nm \
+		  [transform nm
+	verbose -log nm is $nm
+}
+
+upvar 2 name testcase
+set testcase [lindex $testcase 0]
+set output_file [file rootname [file tail $testcase]].o
+set output [remote_exec host $nm -S $output_file]
+set status [lindex $output 0]
+if { $status != 0 } {
+error object-symbol-size: $nm failed
+return
+}
+set text [lindex $output 1]
+
+set symbol [lindex $args 0]
+set match [lsearch -all $text $symbol]
+if { [llength $match] != 1 } {
+error object-symbol-size: number of matches for $symbol: [llength $match]
+return
+}
+
+set type [lindex $text [expr $match - 1]]
+if ![regexp {^[a-zA-Z\-\?]$} $type] {
+error object-symbol-size: type field for $symbol not as expected: $type
+return
+}
+
+set hex [lindex $text [expr $match - 2]]
+set actual [expr 0x$hex]
+if ![string is integer $actual ] {
+error object-symbol-size: size field for $symbol not as expected: $hex
+return
+}
+verbose -log $symbol size is $actual
+
+set cmp [lindex $args 1]
+if { [lsearch {   = = == != } $cmp] == -1 } {
+error object-symbol-size: illegal argument: $cmp
+return
+}
+
+set with [lindex $args 2]
+if ![string is integer $with ] {
+error object-symbol-size: illegal argument: $with
+return
+}
+
+if [expr $actual $cmp $with] {
+	pass $testcase object-symbol-size $symbol $cmp $with
+} else {
+	fail $testcase object-symbol-size $symbol $cmp $with
+}
+}
+
 # Utility for testing that a function is defined on the current line.
 # Call pass if so, otherwise fail.  Invoked directly; the file must
 # have been compiled with -g -dA.


Re: [PATCH, PR43920, 1/9] ARM specific part.

2011-04-04 Thread Richard Guenther
On Sun, Apr 3, 2011 at 9:34 PM, Sergey Ostanevich sergos@gmail.com wrote:
 I would recommend to use 'nm -S a.out' that gives

 [...]
 004004a4 0054 T main
 [...]

 then you can provide a name for the routine you want to test for the size.

That also sounds reasonable.  Is nm -S more portable than size?

Richard.

 Regards,
 Sergos



 2011/4/3 Tom de Vries vr...@codesourcery.com

 On 04/03/2011 09:38 AM, Richard Guenther wrote:
  On Sat, Apr 2, 2011 at 7:05 PM, Tom de Vries vr...@codesourcery.com
  wrote:
  On 04/02/2011 09:47 AM, Richard Guenther wrote:
  On Fri, Apr 1, 2011 at 6:06 PM, Tom de Vries vr...@codesourcery.com
  wrote:
  On 04/01/2011 05:18 PM, Richard Earnshaw wrote:
 
  On Fri, 2011-04-01 at 16:45 +0200, Tom de Vries wrote:
  Reposting, with ChangeLog.
 
   #define BRANCH_COST(speed_p, predictable_p) \
  -  (TARGET_32BIT ? 4 : (optimize  0 ? 2 : 0))
  +  (TARGET_32BIT ? (TARGET_THUMB2  optimize_size ? 1 : 4) \
  +               : (optimize  0 ? 2 : 0))
 
  Don't use optimize_size here, use !speed_p.
 
  Otherwise OK.
 
 
  Replaced optimize_size by !speed_p.
 
  I wonder if we can add a code-size test harness.  Using GNU size
  for examle, if available and a new dg-final { object-size SIZE } that
  fails when the size is greater than the specified one (of course all
  object-size tests with specific target restrictions).
 
  like this?
 
  Yes!
 
  I'm not sure finding the size binary is ok,

 Me neither. I just copied what I saw done for c++filt in
 scan-assembler-dem-not, and found that it works for me.

  and maybe we need to
  verify that size output actually matches our expectation.

 Changes since previous post:
 - split output of size into lines
 - check format of first and second line
 - replaced 'switch $what' with 'lsearch $what'

  Other than that it's exactly what I meant.
 

 Great.

  Mike?  Rainer?
 

 Thanks,
 - Tom




Re: [PATCH, PR43920, 1/9] ARM specific part.

2011-04-04 Thread Rainer Orth
Richard Guenther richard.guent...@gmail.com writes:

 On Sun, Apr 3, 2011 at 9:34 PM, Sergey Ostanevich sergos@gmail.com 
 wrote:
 I would recommend to use 'nm -S a.out' that gives

 [...]
 004004a4 0054 T main
 [...]

 then you can provide a name for the routine you want to test for the size.

 That also sounds reasonable.  Is nm -S more portable than size?

Neither Solaris nor IRIX nm have it.  size isn't particularly portable,
either: there are many variations in output format.

Rainer

-- 
-
Rainer Orth, Center for Biotechnology, Bielefeld University


Re: [PATCH, PR43920, 1/9] ARM specific part.

2011-04-03 Thread Richard Guenther
On Sat, Apr 2, 2011 at 7:05 PM, Tom de Vries vr...@codesourcery.com wrote:
 On 04/02/2011 09:47 AM, Richard Guenther wrote:
 On Fri, Apr 1, 2011 at 6:06 PM, Tom de Vries vr...@codesourcery.com wrote:
 On 04/01/2011 05:18 PM, Richard Earnshaw wrote:

 On Fri, 2011-04-01 at 16:45 +0200, Tom de Vries wrote:
 Reposting, with ChangeLog.

  #define BRANCH_COST(speed_p, predictable_p) \
 -  (TARGET_32BIT ? 4 : (optimize  0 ? 2 : 0))
 +  (TARGET_32BIT ? (TARGET_THUMB2  optimize_size ? 1 : 4) \
 +               : (optimize  0 ? 2 : 0))

 Don't use optimize_size here, use !speed_p.

 Otherwise OK.


 Replaced optimize_size by !speed_p.

 I wonder if we can add a code-size test harness.  Using GNU size
 for examle, if available and a new dg-final { object-size SIZE } that
 fails when the size is greater than the specified one (of course all
 object-size tests with specific target restrictions).

 like this?

Yes!

I'm not sure finding the size binary is ok, and maybe we need to
verify that size output actually matches our expectation.  Other
than that it's exactly what I meant.

Mike?  Rainer?

Thanks,
Richard.

 Thanks,
 - Tom



Re: [PATCH, PR43920, 1/9] ARM specific part.

2011-04-02 Thread Richard Guenther
On Fri, Apr 1, 2011 at 6:06 PM, Tom de Vries vr...@codesourcery.com wrote:
 On 04/01/2011 05:18 PM, Richard Earnshaw wrote:

 On Fri, 2011-04-01 at 16:45 +0200, Tom de Vries wrote:
 Reposting, with ChangeLog.

  #define BRANCH_COST(speed_p, predictable_p) \
 -  (TARGET_32BIT ? 4 : (optimize  0 ? 2 : 0))
 +  (TARGET_32BIT ? (TARGET_THUMB2  optimize_size ? 1 : 4) \
 +               : (optimize  0 ? 2 : 0))

 Don't use optimize_size here, use !speed_p.

 Otherwise OK.


 Replaced optimize_size by !speed_p.

I wonder if we can add a code-size test harness.  Using GNU size
for examle, if available and a new dg-final { object-size SIZE } that
fails when the size is greater than the specified one (of course all
object-size tests with specific target restrictions).

I would have started on this myself, but my TCL-fu causes me to jump
off such tasks very quickly ;)

Richard.

 Thanks,
 - Tom



Re: [PATCH, PR43920, 1/9] ARM specific part.

2011-04-02 Thread Tom de Vries
On 04/02/2011 09:47 AM, Richard Guenther wrote:
 On Fri, Apr 1, 2011 at 6:06 PM, Tom de Vries vr...@codesourcery.com wrote:
 On 04/01/2011 05:18 PM, Richard Earnshaw wrote:

 On Fri, 2011-04-01 at 16:45 +0200, Tom de Vries wrote:
 Reposting, with ChangeLog.

  #define BRANCH_COST(speed_p, predictable_p) \
 -  (TARGET_32BIT ? 4 : (optimize  0 ? 2 : 0))
 +  (TARGET_32BIT ? (TARGET_THUMB2  optimize_size ? 1 : 4) \
 +   : (optimize  0 ? 2 : 0))

 Don't use optimize_size here, use !speed_p.

 Otherwise OK.


 Replaced optimize_size by !speed_p.
 
 I wonder if we can add a code-size test harness.  Using GNU size
 for examle, if available and a new dg-final { object-size SIZE } that
 fails when the size is greater than the specified one (of course all
 object-size tests with specific target restrictions).

like this?

Thanks,
- Tom
2011-04-01  Tom de Vries  t...@codesourcery.com

	PR target/43920
	* lib/scanasm.exp (object-size): New proc.
	* gcc.target/arm/pr43920-2.c: New test.

Index: gcc/testsuite/lib/scanasm.exp
===
--- gcc/testsuite/lib/scanasm.exp	(revision 170556)
+++ gcc/testsuite/lib/scanasm.exp	(working copy)
@@ -315,6 +315,83 @@ proc scan-assembler-dem-not { args } {
 }
 }
 
+# Call pass if object size is ok, otherwise fail.
+# example: /* { dg-final { object-size text = 54 } } */
+proc object-size { args } {
+global size
+global base_dir
+
+if { [llength $args]  3 } {
+	error object-size: too few arguments
+return
+}
+if { [llength $args]  4 } {
+	error object-size: too many arguments
+	return
+}
+if { [llength $args] = 4 } {
+	switch [dg-process-target [lindex $args 1]] {
+	S { }
+	N { return }
+	F { setup_xfail *-*-* }
+	P { }
+	}
+}
+
+# Find size like we find g++ in g++.exp.
+if ![info exists size]  {
+	set size [findfile $base_dir/../../../binutils/size \
+		  $base_dir/../../../binutils/size \
+		  [findfile $base_dir/../../size $base_dir/../../size \
+		   [findfile $base_dir/size $base_dir/size \
+		[transform size
+	verbose -log size is $size
+}
+
+upvar 2 name testcase
+set testcase [lindex $testcase 0]
+set output_file [file rootname [file tail $testcase]].o
+set output [remote_exec host $size $output_file]
+set text [lindex $output 1]
+set status [lindex $output 0]
+if { $status != 0 } {
+error object-size: $size failed
+return
+}
+
+set what [lindex $args 0]
+switch $what {
+total { set where 9 }
+bss   { set where 8 }
+data  { set where 7 }
+text  { set where 6 }
+default {
+error object-size: illegal argument: $what
+return
+}
+}
+set actual [lindex $text $where]
+verbose -log $what size is $actual
+
+set cmp [lindex $args 1]
+if { [lsearch {   = = == != } $cmp] == -1 } {
+error object-size: illegal argument: $cmp
+return
+}
+
+set with [lindex $args 2]
+if { ![string is integer $with ] } {
+error object-size: illegal argument: $with
+return
+}
+
+if { [expr $actual $cmp $with] } {
+	pass $testcase object-size $what $cmp $with
+} else {
+	fail $testcase object-size $what $cmp $with
+}
+}
+
 # Utility for testing that a function is defined on the current line.
 # Call pass if so, otherwise fail.  Invoked directly; the file must
 # have been compiled with -g -dA.
Index: gcc/testsuite/gcc.target/arm/pr43920-2.c
===
--- gcc/testsuite/gcc.target/arm/pr43920-2.c	(revision 0)
+++ gcc/testsuite/gcc.target/arm/pr43920-2.c	(revision 0)
@@ -0,0 +1,30 @@
+/* { dg-do assemble } */
+/* { dg-options -mthumb -Os -save-temps }  */
+/* { dg-require-effective-target arm_thumb2_ok } */
+
+#include stdio.h
+
+int getFileStartAndLength (int fd, int *start_, size_t *length_)
+{
+  int start, end;
+  size_t length;
+
+  start = lseek (fd, 0L, SEEK_CUR);
+  end = lseek (fd, 0L, SEEK_END);
+
+  if (start == -1 || end == -1)
+ return -1;
+
+  length = end - start;
+  if (length == 0)
+ return -1;
+
+  *start_ = start;
+  *length_ = length;
+
+  return 0;
+}
+
+/* { dg-final { scan-assembler-times pop 2 } } */
+/* { dg-final { scan-assembler-times beq 3 } } */
+/* { dg-final { object-size text = 54 } } */


Re: [PATCH, PR43920, 1/9] ARM specific part.

2011-04-01 Thread Tom de Vries
Reposting, with ChangeLog.
2011-04-01  Tom de Vries  t...@codesourcery.com

	PR target/43920
	* config/arm/arm.h (BRANCH_COST): Set to 1 for Thumb-2 when optimizing
	for size.

Index: gcc/config/arm/arm.h
===
--- gcc/config/arm/arm.h	(revision 293961)
+++ gcc/config/arm/arm.h	(revision 293962)
@@ -2201,7 +2201,8 @@ typedef struct
 /* Try to generate sequences that don't involve branches, we can then use
conditional instructions */
 #define BRANCH_COST(speed_p, predictable_p) \
-  (TARGET_32BIT ? 4 : (optimize  0 ? 2 : 0))
+  (TARGET_32BIT ? (TARGET_THUMB2  optimize_size ? 1 : 4) \
+		: (optimize  0 ? 2 : 0))
 
 /* Position Independent Code.  */
 /* We decide which register to use based on the compilation options and


Re: [PATCH, PR43920, 1/9] ARM specific part.

2011-04-01 Thread Richard Earnshaw

On Fri, 2011-04-01 at 16:45 +0200, Tom de Vries wrote:
 Reposting, with ChangeLog.

 #define BRANCH_COST(speed_p, predictable_p) \
-  (TARGET_32BIT ? 4 : (optimize  0 ? 2 : 0))
+  (TARGET_32BIT ? (TARGET_THUMB2  optimize_size ? 1 : 4) \
+   : (optimize  0 ? 2 : 0))

Don't use optimize_size here, use !speed_p.

Otherwise OK.

R.




Re: [PATCH, PR43920, 1/9] ARM specific part.

2011-04-01 Thread Tom de Vries
On 04/01/2011 05:18 PM, Richard Earnshaw wrote:
 
 On Fri, 2011-04-01 at 16:45 +0200, Tom de Vries wrote:
 Reposting, with ChangeLog.
 
  #define BRANCH_COST(speed_p, predictable_p) \
 -  (TARGET_32BIT ? 4 : (optimize  0 ? 2 : 0))
 +  (TARGET_32BIT ? (TARGET_THUMB2  optimize_size ? 1 : 4) \
 +   : (optimize  0 ? 2 : 0))
 
 Don't use optimize_size here, use !speed_p.
 
 Otherwise OK.
 

Replaced optimize_size by !speed_p.

Thanks,
- Tom
2011-04-01  Tom de Vries  t...@codesourcery.com

	PR target/43920
	* config/arm/arm.h (BRANCH_COST): Set to 1 for Thumb-2 when optimizing
	for size.

Index: gcc/config/arm/arm.h
===
--- gcc/config/arm/arm.h	(revision 293961)
+++ gcc/config/arm/arm.h	(revision 293962)
@@ -2201,7 +2201,8 @@ typedef struct
 /* Try to generate sequences that don't involve branches, we can then use
conditional instructions */
 #define BRANCH_COST(speed_p, predictable_p) \
-  (TARGET_32BIT ? 4 : (optimize  0 ? 2 : 0))
+  (TARGET_32BIT ? (TARGET_THUMB2  !speed_p ? 1 : 4) \
+		: (optimize  0 ? 2 : 0))
 
 /* Position Independent Code.  */
 /* We decide which register to use based on the compilation options and