binary integer constants in gcc

2013-06-21 Thread Jonathan Gray
Both gcc and clang have an extension for binary integer constants.
In gcc's case this has been around since 4.3.

The mesa backend for newer intel parts (i965) assumes this extension
is present in recent versions.

Below is a diff to add support for this to our in tree gcc4.  While the
i965 backend is only built on gcc4 archs the concern is that abuse
of this extension in ports or other places may make gcc3/gcc2 archs
worse off unless similiar patches can be done...

From 
http://gcc.gnu.org/git/?p=gcc.git;a=patch;h=d7282a2b2cacdf62e80c1f29f06933f38a70d743
still under the GPLv2.

Index: libcpp/expr.c
===
RCS file: /cvs/src/gnu/gcc/libcpp/expr.c,v
retrieving revision 1.2
diff -u -p -r1.2 expr.c
--- libcpp/expr.c   4 Apr 2013 22:01:32 -   1.2
+++ libcpp/expr.c   21 Jun 2013 06:34:53 -
@@ -188,6 +188,11 @@ cpp_classify_number (cpp_reader *pfile, 
  radix = 16;
  str++;
}
+  else if ((*str == 'b' || *str == 'B')  (str[1] == '0' || str[1] == 
'1'))
+   {
+ radix = 2;
+ str++;
+   }
 }
 
   /* Now scan for a well-formed integer or float.  */
@@ -226,10 +231,22 @@ cpp_classify_number (cpp_reader *pfile, 
 radix = 10;
 
   if (max_digit = radix)
-SYNTAX_ERROR2 (invalid digit \%c\ in octal constant, '0' + max_digit);
+{
+  if (radix == 2)
+   SYNTAX_ERROR2 (invalid digit \%c\ in binary constant, '0' + 
max_digit);
+  else
+   SYNTAX_ERROR2 (invalid digit \%c\ in octal constant, '0' + 
max_digit);
+}
 
   if (float_flag != NOT_FLOAT)
 {
+  if (radix == 2)
+   {
+ cpp_error (pfile, CPP_DL_ERROR,
+invalid prefix \0b\ for floating constant);
+ return CPP_N_INVALID;
+   }
+
   if (radix == 16  CPP_PEDANTIC (pfile)  !CPP_OPTION (pfile, c99))
cpp_error (pfile, CPP_DL_PEDWARN,
   use of C99 hexadecimal floating constant);
@@ -321,11 +338,16 @@ cpp_classify_number (cpp_reader *pfile, 
   if ((result  CPP_N_IMAGINARY)  CPP_PEDANTIC (pfile))
 cpp_error (pfile, CPP_DL_PEDWARN,
   imaginary constants are a GCC extension);
+  if (radix == 2  CPP_PEDANTIC (pfile))
+cpp_error (pfile, CPP_DL_PEDWARN,
+  binary constants are a GCC extension);
 
   if (radix == 10)
 result |= CPP_N_DECIMAL;
   else if (radix == 16)
 result |= CPP_N_HEX;
+  else if (radix == 2)
+result |= CPP_N_BINARY;
   else
 result |= CPP_N_OCTAL;
 
@@ -376,6 +398,11 @@ cpp_interpret_integer (cpp_reader *pfile
  base = 16;
  p += 2;
}
+  else if ((type  CPP_N_RADIX) == CPP_N_BINARY)
+   {
+ base = 2;
+ p += 2;
+   }
 
   /* We can add a digit to numbers strictly less than this without
 needing the precision and slowness of double integers.  */
@@ -431,12 +458,25 @@ static cpp_num
 append_digit (cpp_num num, int digit, int base, size_t precision)
 {
   cpp_num result;
-  unsigned int shift = 3 + (base == 16);
+  unsigned int shift;
   bool overflow;
   cpp_num_part add_high, add_low;
 
-  /* Multiply by 8 or 16.  Catching this overflow here means we don't
+  /* Multiply by 2, 8 or 16.  Catching this overflow here means we don't
  need to worry about add_high overflowing.  */
+  switch (base)
+{
+case 2:
+  shift = 1;
+  break;
+
+case 16:
+  shift = 4;
+  break;
+
+default:
+  shift = 3;
+}
   overflow = !!(num.high  (PART_PRECISION - shift));
   result.high = num.high  shift;
   result.low = num.low  shift;
Index: libcpp/include/cpplib.h
===
RCS file: /cvs/src/gnu/gcc/libcpp/include/cpplib.h,v
retrieving revision 1.2
diff -u -p -r1.2 cpplib.h
--- libcpp/include/cpplib.h 4 Apr 2013 22:01:32 -   1.2
+++ libcpp/include/cpplib.h 21 Jun 2013 06:34:53 -
@@ -744,6 +744,7 @@ struct cpp_num
 #define CPP_N_DECIMAL  0x0100
 #define CPP_N_HEX  0x0200
 #define CPP_N_OCTAL0x0400
+#define CPP_N_BINARY   0x0800
 
 #define CPP_N_UNSIGNED 0x1000  /* Properties.  */
 #define CPP_N_IMAGINARY0x2000



Re: binary integer constants in gcc

2013-06-21 Thread Landry Breuil
On Fri, Jun 21, 2013 at 10:20:01AM +0200, Mark Kettenis wrote:
  Date: Fri, 21 Jun 2013 17:31:39 +1000
  From: Jonathan Gray j...@jsg.id.au
  
  Both gcc and clang have an extension for binary integer constants.
  In gcc's case this has been around since 4.3.
  
  The mesa backend for newer intel parts (i965) assumes this extension
  is present in recent versions.
 
 Sigh...  Can't these people just write portable C?
 
  Below is a diff to add support for this to our in tree gcc4.  While the
  i965 backend is only built on gcc4 archs the concern is that abuse
  of this extension in ports or other places may make gcc3/gcc2 archs
  worse off unless similiar patches can be done...
 
 Well, lots of ports stuff is compiled with newer gcc versions anyway.

Actually, not so many:

$echo select count(*) from modules where value='gcc4'; | 
sqlite3/usr/local/share/sqlports 
34

And if you rip out all the subpackages, the actual list is:

audio/mscore
editors/libreoffice
lang/classpath
lang/luajit
net/rtorrent
print/cups-filters
textproc/pdftk
www/mozilla-firefox
www/seamonkey
www/squid

Landry



Re: binary integer constants in gcc

2013-06-21 Thread Mark Kettenis
 Date: Fri, 21 Jun 2013 10:50:42 +0200
 From: Landry Breuil lan...@rhaalovely.net
 
 On Fri, Jun 21, 2013 at 10:20:01AM +0200, Mark Kettenis wrote:
  
  Well, lots of ports stuff is compiled with newer gcc versions anyway.
 
 Actually, not so many:
 
 $echo select count(*) from modules where value='gcc4'; | 
 sqlite3/usr/local/share/sqlports 
 34
 
 And if you rip out all the subpackages, the actual list is:
 
 audio/mscore
 editors/libreoffice
 lang/classpath
 lang/luajit
 net/rtorrent
 print/cups-filters
 textproc/pdftk
 www/mozilla-firefox
 www/seamonkey
 www/squid

Don't libreoffice and mozilla-firefox account for about half the lines
of code that's in ports? ;)

Seriously though; I was under the impression that it was a lot more.
Thanks for enlightening me Landry.



Re: binary integer constants in gcc

2013-06-21 Thread Marc Espie
On Fri, Jun 21, 2013 at 11:03:16AM +0200, Mark Kettenis wrote:
  Date: Fri, 21 Jun 2013 10:50:42 +0200
  From: Landry Breuil lan...@rhaalovely.net
  
  On Fri, Jun 21, 2013 at 10:20:01AM +0200, Mark Kettenis wrote:
   
   Well, lots of ports stuff is compiled with newer gcc versions anyway.
  
  Actually, not so many:
  
  $echo select count(*) from modules where value='gcc4'; | 
  sqlite3/usr/local/share/sqlports 
  34
  
  And if you rip out all the subpackages, the actual list is:
  
  audio/mscore
  editors/libreoffice
  lang/classpath
  lang/luajit
  net/rtorrent
  print/cups-filters
  textproc/pdftk
  www/mozilla-firefox
  www/seamonkey
  www/squid
 
 Don't libreoffice and mozilla-firefox account for about half the lines
 of code that's in ports? ;)
 
 Seriously though; I was under the impression that it was a lot more.
 Thanks for enlightening me Landry.

Some of the big ones have moved to llvm (chromium).
In actuality, as you know, we're playing linking games, since we mix
both libstdc++ from base and libstdc++ from the ports gcc4.

The only clean option would be to move all the ports that want C++ to
using a single compiler... or to a single libstdc++/libcxxrt...



Re: binary integer constants in gcc

2013-06-21 Thread David Coppa
On Fri, Jun 21, 2013 at 1:03 PM, Stuart Henderson st...@openbsd.org wrote:

 only for sparc64:
 net/rtorrent

Yes, this is due to a gcc bug:

https://github.com/rakshasa/rtorrent/issues/28



Re: binary integer constants in gcc

2013-06-21 Thread Brian Callahan

On 6/21/2013 7:03 AM, Stuart Henderson wrote:


ICE with base gcc (lacking info about arch etc)

audio/mscore




For completeness, the ICE was on amd64:
[ 11%] Building CXX object 
singleapp/src/CMakeFiles/qtsingleapp.dir/moc_qtsingleapplication.cxx.o

command-line:0: internal compiler error: Segmentation fault

But I had trouble compiling on powerpc without gcc-4.6 too iirc.

~Brian



fix pf counters with match rules

2013-06-21 Thread Bret Lambert
When using match vice pass/block rules when wanting counters, e.g.,

match in from mahtable counters

counters were not being updated. reyk@ and I tracked this down to
a failure to check the matched rules for the need to increment stats.

the following diff fixes that here

- Bert

Index: pf.c
===
RCS file: /cvs/src/sys/net/pf.c,v
retrieving revision 1.835
diff -u -p -r1.835 pf.c
--- pf.c17 Jun 2013 19:50:06 -  1.835
+++ pf.c21 Jun 2013 15:16:25 -
@@ -6526,6 +6526,23 @@ pf_counters_inc(int action, struct pf_pd
SLIST_FOREACH(ri, s-match_rules, entry) {
ri-r-packets[dirndx]++;
ri-r-bytes[dirndx] += pd-tot_len;
+
+   if (ri-r-src.addr.type == PF_ADDR_TABLE)
+   pfr_update_stats(ri-r-src.addr.p.tbl,
+   s-key[(s-direction == PF_IN)]-
+   addr[(s-direction == PF_OUT)],
+   pd-af, pd-tot_len,
+   pd-dir == PF_OUT,
+   ri-r-action == PF_PASS,
+   ri-r-src.neg);
+   if (ri-r-dst.addr.type == PF_ADDR_TABLE)
+   pfr_update_stats(ri-r-dst.addr.p.tbl,
+   s-key[(s-direction == PF_IN)]-
+   addr[(s-direction == PF_IN)],
+   pd-af, pd-tot_len,
+   pd-dir == PF_OUT,
+   ri-r-action == PF_PASS,
+   ri-r-dst.neg);
}
}
if (r-src.addr.type == PF_ADDR_TABLE)



panic while resuming with connected ucom

2013-06-21 Thread Otto Moerbeek
Hi,

I have a Thinkpad T430 with an internal 3G modem that shows up as a
(couple of) umodem. If I have a connection to the corresponding ucom
active (with cu or pppd) and suspend the machine followed by a resume,
it panics (or rather gets a trap) during resume; hand typed:

kernel: protection fault trap, code=0
Stopped at  ehci_check_intr+0xe:movbzl  0x3(%rax),%eax
dddb{0} trace
ehci_check_intr at ehci_check_int+0xe
ehci_softintr() at ehci_softint+0x35
softintr_dispatch at softintr_dispatch+0x5d
Xsoftnet() at Xsoftnet+0x2d

rax holds 0xdead0065deadbeef

This is 100% reproducable. If I do not have an active connection to
cuaU0 at the moment of suspend all is fine and the machine resumes ok.

Could it be the refcounting is still rong in some cases?

What might matter: the detach messages for the various usb devices
show up after resume, and then the panic happens. If I did not have a
connection at the moment of suspend, I see the detach messages followed
by attach messages during resume. 

You might try to reproduce this using a USB serial dongle, although
the umodem might also play a role here?

I do not use the modem very often, so it's hard for me to tell when
this started to happen. But it is relatively recent (say a few weeks).

-Otto

OpenBSD 5.3-current (GENERIC.MP) #21: Fri Jun 21 18:16:54 CEST 2013
o...@tp.intra.drijf.net:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8256528384 (7874MB)
avail mem = 8029011968 (7657MB)
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.7 @ 0xdae9d000 (71 entries)
bios0: vendor LENOVO version G1ET91WW (2.51 ) date 01/09/2013
bios0: LENOVO 2347CTO
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP TCPA SSDT SSDT SSDT HPET APIC MCFG ECDT FPDT ASF! UEFI 
UEFI MSDM SSDT SSDT UEFI DBG2
acpi0: wakeup devices LID_(S4) SLPB(S3) IGBE(S4) EXP3(S4) XHCI(S3) EHC1(S3) 
EHC2(S3) HDEF(S4)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 14318179 Hz
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz, 1197.50 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
cpu0: apic clock running at 99MHz
cpu1 at mainbus0: apid 1 (application processor)
cpu1: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz, 1197.29 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 1, core 0, package 0
cpu2 at mainbus0: apid 2 (application processor)
cpu2: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz, 1197.29 MHz
cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 1, package 0
cpu3 at mainbus0: apid 3 (application processor)
cpu3: Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz, 1197.29 MHz
cpu3: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,LONG,LAHF,PERF,ITSC,FSGSBASE,SMEP,ERMS
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 1, core 1, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 24 pins
acpimcfg0 at acpi0 addr 0xf800, bus 0-63
acpiec0 at acpi0
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus -1 (PEG_)
acpiprt2 at acpi0: bus 2 (EXP1)
acpiprt3 at acpi0: bus 3 (EXP2)
acpiprt4 at acpi0: bus 4 (EXP3)
acpicpu0 at acpi0: C3, C2, C1, PSS
acpicpu1 at acpi0: C3, C2, C1, PSS
acpicpu2 at acpi0: C3, C2, C1, PSS
acpicpu3 at acpi0: C3, C2, C1, PSS
acpipwrres0 at acpi0: PUBS
acpitz0 at acpi0: critical temperature is 200 degC
acpibtn0 at acpi0: LID_
acpibtn1 at acpi0: SLPB
acpibat0 at acpi0: BAT0 model 45N1001 serial  5140 type LION oem SANYO
acpibat1 at acpi0: BAT1 not present
acpiac0 at acpi0: AC unit offline
acpithinkpad0 at acpi0
cpu0: Enhanced SpeedStep 1197 MHz: speeds: 2601, 2600, 2500, 2400, 2300, 2200, 
2100, 2000, 1900, 1800, 1700, 1600, 1500, 1400, 1300, 1200 MHz
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 Intel Core 3G Host rev 0x09
vga1 at pci0 dev 2 function 0 Intel HD Graphics 4000 rev 0x09
intagp0 at vga1
agp0