From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jim Blandy To: Daniel Jacobowitz Cc: gdb-patches@sources.redhat.com Subject: Re: RFA: Test ability to access i386 SSE registers Date: Wed, 12 May 2004 06:40:00 -0000 Message-id: References: <20040512060858.GA17711@nevyn.them.org> X-SW-Source: 2004-05/msg00363.html Daniel Jacobowitz writes: > On Wed, May 12, 2004 at 12:25:40AM -0500, Jim Blandy wrote: > > > > It's late; there is surely some Kool-Aid around here I have forgotten > > to drink. > > There better be! > > > + if ![runto_main] then { > > + gdb_suppress_tests > > + } > > + > > + gdb_test "break [gdb_get_line_number "first breakpoint here"]" \ > > + "Breakpoint .* at .*i386-sse.c.*" \ > > + "set breakpoint in main" > > + gdb_continue_to_breakpoint "continue to first breakpoint in main" > > So, all that trouble to make the SSE testcase not use movaps if it > isn't available... and you never check in the test script? Oh yeah. That was it. [vacant stare] > If you're going to be thorough in the test case, be more thorough. See > gcc.dg/i386-cpuid.h in GCC. Okay. How about: 2004-05-12 Jim Blandy * gdb.arch/i386-sse.exp, gdb.arch/i386-sse.c: New tests. * gdb.arch/i386-cpuid.h: New helper file. Index: gdb/testsuite/gdb.arch/i386-cpuid.h =================================================================== RCS file: gdb/testsuite/gdb.arch/i386-cpuid.h diff -N gdb/testsuite/gdb.arch/i386-cpuid.h *** gdb/testsuite/gdb.arch/i386-cpuid.h 1 Jan 1970 00:00:00 -0000 --- gdb/testsuite/gdb.arch/i386-cpuid.h 12 May 2004 06:38:44 -0000 *************** *** 0 **** --- 1,77 ---- + /* Helper file for i386 platform. Runtime check for MMX/SSE/SSE2 support. + + Copyright 2004 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + + /* Used by 20020523-2.c and i386-sse-6.c, and possibly others. */ + /* Plagarized from 20020523-2.c. */ + /* Plagarized from gcc. */ + + #define bit_CMOV (1 << 15) + #define bit_MMX (1 << 23) + #define bit_SSE (1 << 25) + #define bit_SSE2 (1 << 26) + + #ifndef NOINLINE + #define NOINLINE __attribute__ ((noinline)) + #endif + + unsigned int i386_cpuid (void) NOINLINE; + + unsigned int NOINLINE + i386_cpuid (void) + { + int fl1, fl2; + + #ifndef __x86_64__ + /* See if we can use cpuid. On AMD64 we always can. */ + __asm__ ("pushfl; pushfl; popl %0; movl %0,%1; xorl %2,%0;" + "pushl %0; popfl; pushfl; popl %0; popfl" + : "=&r" (fl1), "=&r" (fl2) + : "i" (0x00200000)); + if (((fl1 ^ fl2) & 0x00200000) == 0) + return (0); + #endif + + /* Host supports cpuid. See if cpuid gives capabilities, try + CPUID(0). Preserve %ebx and %ecx; cpuid insn clobbers these, we + don't need their CPUID values here, and %ebx may be the PIC + register. */ + #ifdef __x86_64__ + __asm__ ("pushq %%rcx; pushq %%rbx; cpuid; popq %%rbx; popq %%rcx" + : "=a" (fl1) : "0" (0) : "rdx", "cc"); + #else + __asm__ ("pushl %%ecx; pushl %%ebx; cpuid; popl %%ebx; popl %%ecx" + : "=a" (fl1) : "0" (0) : "edx", "cc"); + #endif + if (fl1 == 0) + return (0); + + /* Invoke CPUID(1), return %edx; caller can examine bits to + determine what's supported. */ + #ifdef __x86_64__ + __asm__ ("pushq %%rcx; pushq %%rbx; cpuid; popq %%rbx; popq %%rcx" + : "=d" (fl2), "=a" (fl1) : "1" (1) : "cc"); + #else + __asm__ ("pushl %%ecx; pushl %%ebx; cpuid; popl %%ebx; popl %%ecx" + : "=d" (fl2), "=a" (fl1) : "1" (1) : "cc"); + #endif + + return fl2; + } Index: gdb/testsuite/gdb.arch/i386-sse.c =================================================================== RCS file: gdb/testsuite/gdb.arch/i386-sse.c diff -N gdb/testsuite/gdb.arch/i386-sse.c *** gdb/testsuite/gdb.arch/i386-sse.c 1 Jan 1970 00:00:00 -0000 --- gdb/testsuite/gdb.arch/i386-sse.c 12 May 2004 06:38:44 -0000 *************** *** 0 **** --- 1,90 ---- + /* Test program for SSE registers. + + Copyright 2004 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + + #include + #include "i386-cpuid.h" + + typedef struct { + float f[4]; + } v4sf_t; + + + v4sf_t data[8] = + { + { { 0.0, 0.25, 0.50, 0.75 } }, + { { 1.0, 1.25, 1.50, 1.75 } }, + { { 2.0, 2.25, 2.50, 2.75 } }, + { { 3.0, 3.25, 3.50, 3.75 } }, + { { 4.0, 4.25, 4.50, 4.75 } }, + { { 5.0, 5.25, 5.50, 5.75 } }, + { { 6.0, 6.25, 6.50, 6.75 } }, + { { 7.0, 7.25, 7.50, 7.75 } }, + }; + + + int + have_sse (void) + { + int edx = i386_cpuid (); + + if (edx & bit_SSE) + return 1; + else + return 0; + } + + int + main (int argc, char **argv) + { + if (have_sse ()) + { + asm ("movaps 0(%0), %%xmm0\n\t" + "movaps 16(%0), %%xmm1\n\t" + "movaps 32(%0), %%xmm2\n\t" + "movaps 48(%0), %%xmm3\n\t" + "movaps 64(%0), %%xmm4\n\t" + "movaps 80(%0), %%xmm5\n\t" + "movaps 96(%0), %%xmm6\n\t" + "movaps 112(%0), %%xmm7\n\t" + : /* no output operands */ + : "r" (data) + : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); + + puts ("Hi!"); /* first breakpoint here */ + + asm ( + "movaps %%xmm0, 0(%0)\n\t" + "movaps %%xmm1, 16(%0)\n\t" + "movaps %%xmm2, 32(%0)\n\t" + "movaps %%xmm3, 48(%0)\n\t" + "movaps %%xmm4, 64(%0)\n\t" + "movaps %%xmm5, 80(%0)\n\t" + "movaps %%xmm6, 96(%0)\n\t" + "movaps %%xmm7, 112(%0)\n\t" + : /* no output operands */ + : "r" (data) + : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"); + + puts ("Bye!"); /* second breakpoint here */ + } + + return 0; + } Index: gdb/testsuite/gdb.arch/i386-sse.exp =================================================================== RCS file: gdb/testsuite/gdb.arch/i386-sse.exp diff -N gdb/testsuite/gdb.arch/i386-sse.exp *** gdb/testsuite/gdb.arch/i386-sse.exp 1 Jan 1970 00:00:00 -0000 --- gdb/testsuite/gdb.arch/i386-sse.exp 12 May 2004 06:38:44 -0000 *************** *** 0 **** --- 1,91 ---- + # Copyright 2004 Free Software Foundation, Inc. + + # This program is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation; either version 2 of the License, or + # (at your option) any later version. + # + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with this program; if not, write to the Free Software + # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + # Please email any bugs, comments, and/or additions to this file to: + # bug-gdb@gnu.org + + # This file is part of the gdb testsuite. + + if $tracelevel { + strace $tracelevel + } + + set prms_id 0 + set bug_id 0 + + if ![istarget "i?86-*-*"] then { + verbose "Skipping i386 SSE tests." + return + } + + set testfile "i386-sse" + set srcfile ${testfile}.c + set binfile ${objdir}/${subdir}/${testfile} + if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." + } + + gdb_exit + gdb_start + gdb_reinitialize_dir $srcdir/$subdir + gdb_load ${binfile} + + if ![runto_main] then { + gdb_suppress_tests + } + + send_gdb "print have_sse ()\r" + gdb_expect { + -re ".. = 1\r\n$gdb_prompt " { + pass "check whether processor supports SSE" + } + -re ".. = 0\r\n$gdb_prompt " { + verbose "processor does not support SSE; skipping SSE tests" + return + } + -re ".*$gdb_prompt $" { + fail "check whether processor supports SSE" + } + timeout { + fail "check whether processor supports SSE (timeout)" + } + } + + gdb_test "break [gdb_get_line_number "first breakpoint here"]" \ + "Breakpoint .* at .*i386-sse.c.*" \ + "set breakpoint in main" + gdb_continue_to_breakpoint "continue to first breakpoint in main" + + foreach r {0 1 2 3 4 5 6 7} { + gdb_test "print \$xmm$r.v4_float" \ + ".. = {$r, $r.25, $r.5, $r.75}.*" \ + "check contents of %xmm$r" + } + + foreach r {0 1 2 3 4 5 6 7} { + gdb_test "set var \$xmm$r.v4_float\[0\] = $r + 10" "" "set %xmm$r" + } + + gdb_test "break [gdb_get_line_number "second breakpoint here"]" \ + "Breakpoint .* at .*i386-sse.c.*" \ + "set breakpoint in main" + gdb_continue_to_breakpoint "continue to second breakpoint in main" + + foreach r {0 1 2 3 4 5 6 7} { + gdb_test "print data\[$r\]" \ + ".. = {f = {[expr $r + 10], $r.25, $r.5, $r.75}}.*" \ + "check contents of data\[$r\]" + }