file_pos.c (unformatted_backspace): Normal case is GFC_CONVERT_NATIVE.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Thu, 16 Oct 2008 18:23:25 +0000 (18:23 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Thu, 16 Oct 2008 18:23:25 +0000 (18:23 +0000)
2008-10-16  Thomas Koenig  <tkoenig@gcc.gnu.org>

* io/file_pos.c (unformatted_backspace): Normal case is
GFC_CONVERT_NATIVE.
* io/transfer.c (read_sf):  Mark paths leading to generate_error()
as unlikely.
(readl_block_form):  Likewise.
(read_block_direct):  Likewise.
(write_block):  Likewise.
(write_buf):  Likewise.
(us_read):  Likewise.  Normal case is GFC_CONVERT_NATIVE.
(next_record_w_unf):  Mark paths leading to generate_error()
as unlikely.

From-SVN: r141179

libgfortran/ChangeLog
libgfortran/io/file_pos.c
libgfortran/io/transfer.c

index acc1016..049f0dd 100644 (file)
@@ -1,5 +1,19 @@
 2008-10-16  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
+       * io/file_pos.c (unformatted_backspace): Normal case is
+       GFC_CONVERT_NATIVE.
+       * io/transfer.c (read_sf):  Mark paths leading to generate_error()
+       as unlikely.
+       (readl_block_form):  Likewise.
+       (read_block_direct):  Likewise.
+       (write_block):  Likewise.
+       (write_buf):  Likewise.
+       (us_read):  Likewise.  Normal case is GFC_CONVERT_NATIVE.
+       (next_record_w_unf):  Mark paths leading to generate_error()
+       as unlikely.
+
+2008-10-16  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
        PR libfortran/34670
        * generated/spread_r4.c: Regenerated.
 
index 6dafbe5..25b0108 100644 (file)
@@ -120,7 +120,7 @@ unformatted_backspace (st_parameter_filepos *fpp, gfc_unit *u)
         goto io_error;
 
       /* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here.  */
-      if (u->flags.convert == GFC_CONVERT_NATIVE)
+      if (likely (u->flags.convert == GFC_CONVERT_NATIVE))
        {
          switch (length)
            {
index acc7cbe..8d4f785 100644 (file)
@@ -205,7 +205,8 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error)
   if (is_internal_unit (dtp))
     {
       readlen = *length;
-      if (sread (dtp->u.p.current_unit->s, p, &readlen) != 0 || readlen < (size_t) *length)
+      if (unlikely (sread (dtp->u.p.current_unit->s, p, &readlen) != 0
+                   || readlen < (size_t) *length))
        {
          generate_error (&dtp->common, LIBERROR_END, NULL);
          return NULL;
@@ -219,7 +220,7 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error)
 
   do
     {
-      if (sread (dtp->u.p.current_unit->s, &q, &readlen) != 0)
+      if (unlikely (sread (dtp->u.p.current_unit->s, &q, &readlen) != 0))
         {
          generate_error (&dtp->common, LIBERROR_END, NULL);
          return NULL;
@@ -229,7 +230,7 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error)
         EOR below.  */
       if (readlen < 1 && n == 0)
        {
-         if (no_error)
+         if (likely (no_error))
            break;
          generate_error (&dtp->common, LIBERROR_END, NULL);
          return NULL;
@@ -250,7 +251,8 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error)
            {
              readlen = 1;
              pos = stream_offset (dtp->u.p.current_unit->s);
-             if (sread (dtp->u.p.current_unit->s, &q, &readlen) != 0)
+             if (unlikely (sread (dtp->u.p.current_unit->s, &q, &readlen)
+                           != 0))
                {
                  generate_error (&dtp->common, LIBERROR_END, NULL);
                  return NULL;
@@ -266,7 +268,7 @@ read_sf (st_parameter_dt *dtp, int *length, int no_error)
             so we can just continue with a short read.  */
          if (dtp->u.p.current_unit->pad_status == PAD_NO)
            {
-             if (no_error)
+             if (likely (no_error))
                break;
              generate_error (&dtp->common, LIBERROR_EOR, NULL);
              return NULL;
@@ -332,7 +334,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes)
             dtp->u.p.current_unit->bytes_left = dtp->u.p.current_unit->recl;
          else
            {
-             if (dtp->u.p.current_unit->pad_status == PAD_NO)
+             if (unlikely (dtp->u.p.current_unit->pad_status == PAD_NO))
                {
                  /* Not enough data left.  */
                  generate_error (&dtp->common, LIBERROR_EOR, NULL);
@@ -340,7 +342,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes)
                }
            }
 
-         if (dtp->u.p.current_unit->bytes_left == 0)
+         if (unlikely (dtp->u.p.current_unit->bytes_left == 0))
            {
              dtp->u.p.current_unit->endfile = AT_ENDFILE;
              generate_error (&dtp->common, LIBERROR_END, NULL);
@@ -368,7 +370,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes)
   dtp->u.p.current_unit->bytes_left -= (gfc_offset) *nbytes;
 
   nread = *nbytes;
-  if (sread (dtp->u.p.current_unit->s, buf, &nread) != 0)
+  if (unlikely (sread (dtp->u.p.current_unit->s, buf, &nread) != 0))
     {
       generate_error (&dtp->common, LIBERROR_OS, NULL);
       return FAILURE;
@@ -379,7 +381,7 @@ read_block_form (st_parameter_dt *dtp, void *buf, size_t *nbytes)
 
   if (nread != *nbytes)
     {                          /* Short read, this shouldn't happen.  */
-      if (dtp->u.p.current_unit->pad_status == PAD_YES)
+      if (likely (dtp->u.p.current_unit->pad_status == PAD_YES))
        *nbytes = nread;
       else
        {
@@ -410,7 +412,8 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
     {
       to_read_record = *nbytes;
       have_read_record = to_read_record;
-      if (sread (dtp->u.p.current_unit->s, buf, &have_read_record) != 0)
+      if (unlikely (sread (dtp->u.p.current_unit->s, buf, &have_read_record)
+                   != 0))
        {
          generate_error (&dtp->common, LIBERROR_OS, NULL);
          return;
@@ -418,7 +421,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
 
       dtp->u.p.current_unit->strm_pos += (gfc_offset) have_read_record; 
 
-      if (to_read_record != have_read_record)
+      if (unlikely (to_read_record != have_read_record))
        {
          /* Short read,  e.g. if we hit EOF.  For stream files,
           we have to set the end-of-file condition.  */
@@ -445,7 +448,8 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
 
       dtp->u.p.current_unit->bytes_left -= to_read_record;
 
-      if (sread (dtp->u.p.current_unit->s, buf, &to_read_record) != 0)
+      if (unlikely (sread (dtp->u.p.current_unit->s, buf, &to_read_record)
+                   != 0))
        {
          generate_error (&dtp->common, LIBERROR_OS, NULL);
          return;
@@ -459,7 +463,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
          return;
        }
 
-      if (short_record)
+      if (unlikely (short_record))
        {
          generate_error (&dtp->common, LIBERROR_SHORT_RECORD, NULL);
          return;
@@ -471,7 +475,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
      until the request has been fulfilled or the record has run out
      of continuation subrecords.  */
 
-  if (dtp->u.p.current_unit->endfile == AT_ENDFILE)
+  if (unlikely (dtp->u.p.current_unit->endfile == AT_ENDFILE))
     {
       generate_error (&dtp->common, LIBERROR_END, NULL);
       return;
@@ -509,8 +513,8 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
       dtp->u.p.current_unit->bytes_left_subrecord -= to_read_subrecord;
 
       have_read_subrecord = to_read_subrecord;
-      if (sread (dtp->u.p.current_unit->s, buf + have_read_record,
-                &have_read_subrecord) != 0)
+      if (unlikely (sread (dtp->u.p.current_unit->s, buf + have_read_record,
+                          &have_read_subrecord) != 0))
        {
          generate_error (&dtp->common, LIBERROR_OS, NULL);
          return;
@@ -518,7 +522,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
 
       have_read_record += have_read_subrecord;
 
-      if (to_read_subrecord != have_read_subrecord)  
+      if (unlikely (to_read_subrecord != have_read_subrecord))
                        
        {
          /* Short read, e.g. if we hit EOF.  This means the record
@@ -532,7 +536,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
 
       if (to_read_record > 0)
        {
-         if (dtp->u.p.current_unit->continued)
+         if (likely (dtp->u.p.current_unit->continued))
            {
              next_record_r_unf (dtp, 0);
              us_read (dtp, 1);
@@ -556,7 +560,7 @@ read_block_direct (st_parameter_dt *dtp, void *buf, size_t *nbytes)
     }
 
   dtp->u.p.current_unit->bytes_left -= have_read_record;
-  if (short_record)
+  if (unlikely (short_record))
     {
       generate_error (&dtp->common, LIBERROR_SHORT_RECORD, NULL);
       return;
@@ -581,9 +585,11 @@ write_block (st_parameter_dt *dtp, int length)
        {
          /* For preconnected units with default record length, set bytes left
             to unit record length and proceed, otherwise error.  */
-         if ((dtp->u.p.current_unit->unit_number == options.stdout_unit
-               || dtp->u.p.current_unit->unit_number == options.stderr_unit)
-               && dtp->u.p.current_unit->recl == DEFAULT_RECL)
+         if (likely ((dtp->u.p.current_unit->unit_number
+                      == options.stdout_unit
+                      || dtp->u.p.current_unit->unit_number
+                      == options.stderr_unit)
+                     && dtp->u.p.current_unit->recl == DEFAULT_RECL))
            dtp->u.p.current_unit->bytes_left = dtp->u.p.current_unit->recl;
          else
            {
@@ -605,7 +611,7 @@ write_block (st_parameter_dt *dtp, int length)
         return NULL;
       }
 
-    if (dtp->u.p.current_unit->endfile == AT_ENDFILE)
+    if (unlikely (dtp->u.p.current_unit->endfile == AT_ENDFILE))
       generate_error (&dtp->common, LIBERROR_END, NULL);
     }
   else
@@ -642,7 +648,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes)
 
   if (is_stream_io (dtp))
     {
-      if (swrite (dtp->u.p.current_unit->s, buf, &nbytes) != 0)
+      if (unlikely (swrite (dtp->u.p.current_unit->s, buf, &nbytes) != 0))
        {
          generate_error (&dtp->common, LIBERROR_OS, NULL);
          return FAILURE;
@@ -657,7 +663,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes)
 
   if (dtp->u.p.current_unit->flags.access == ACCESS_DIRECT)
     {
-      if (dtp->u.p.current_unit->bytes_left < (gfc_offset) nbytes)
+      if (unlikely (dtp->u.p.current_unit->bytes_left < (gfc_offset) nbytes))
        {
          generate_error (&dtp->common, LIBERROR_DIRECT_EOR, NULL);
          return FAILURE;
@@ -666,7 +672,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes)
       if (buf == NULL && nbytes == 0)
        return SUCCESS;
 
-      if (swrite (dtp->u.p.current_unit->s, buf, &nbytes) != 0)
+      if (unlikely (swrite (dtp->u.p.current_unit->s, buf, &nbytes) != 0))
        {
          generate_error (&dtp->common, LIBERROR_OS, NULL);
          return FAILURE;
@@ -703,8 +709,8 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes)
       dtp->u.p.current_unit->bytes_left_subrecord -=
        (gfc_offset) to_write_subrecord;
 
-      if (swrite (dtp->u.p.current_unit->s, buf + have_written,
-                 &to_write_subrecord) != 0)
+      if (unlikely (swrite (dtp->u.p.current_unit->s, buf + have_written,
+                           &to_write_subrecord) != 0))
        {
          generate_error (&dtp->common, LIBERROR_OS, NULL);
          return FAILURE;
@@ -721,7 +727,7 @@ write_buf (st_parameter_dt *dtp, void *buf, size_t nbytes)
       us_write (dtp, 1);
     }
   dtp->u.p.current_unit->bytes_left -= have_written;
-  if (short_record)
+  if (unlikely (short_record))
     {
       generate_error (&dtp->common, LIBERROR_SHORT_RECORD, NULL);
       return FAILURE;
@@ -973,7 +979,7 @@ formatted_transfer_scalar (st_parameter_dt *dtp, bt type, void *p, int kind,
       if (f == NULL)
        {
          /* No data descriptors left.  */
-         if (n > 0)
+         if (unlikely (n > 0))
            generate_error (&dtp->common, LIBERROR_FORMAT,
                "Insufficient data descriptors in format after reversion");
          return;
@@ -1671,7 +1677,7 @@ us_read (st_parameter_dt *dtp, int continued)
 
   nr = n;
 
-  if (sread (dtp->u.p.current_unit->s, &i, &n) != 0)
+  if (unlikely (sread (dtp->u.p.current_unit->s, &i, &n) != 0))
     {
       generate_error (&dtp->common, LIBERROR_BAD_US, NULL);
       return;
@@ -1683,14 +1689,14 @@ us_read (st_parameter_dt *dtp, int continued)
       return;  /* end of file */
     }
 
-  if (n != nr)
+  if (unlikely (n != nr))
     {
       generate_error (&dtp->common, LIBERROR_BAD_US, NULL);
       return;
     }
 
   /* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here.  */
-  if (dtp->u.p.current_unit->flags.convert == GFC_CONVERT_NATIVE)
+  if (likely (dtp->u.p.current_unit->flags.convert == GFC_CONVERT_NATIVE))
     {
       switch (nr)
        {
@@ -2535,7 +2541,7 @@ write_us_marker (st_parameter_dt *dtp, const gfc_offset buf)
     len = compile_options.record_marker;
 
   /* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here.  */
-  if (dtp->u.p.current_unit->flags.convert == GFC_CONVERT_NATIVE)
+  if (likely (dtp->u.p.current_unit->flags.convert == GFC_CONVERT_NATIVE))
     {
       switch (len)
        {
@@ -2600,7 +2606,7 @@ next_record_w_unf (st_parameter_dt *dtp, int next_subrecord)
   else
     m_write = m;
 
-  if (write_us_marker (dtp, m_write) != 0)
+  if (unlikely (write_us_marker (dtp, m_write) != 0))
     goto io_error;
 
   if (compile_options.record_marker == 0)
@@ -2611,8 +2617,8 @@ next_record_w_unf (st_parameter_dt *dtp, int next_subrecord)
   /* Seek to the head and overwrite the bogus length with the real
      length.  */
 
-  if (sseek (dtp->u.p.current_unit->s, c - m - record_marker)
-      == FAILURE)
+  if (unlikely (sseek (dtp->u.p.current_unit->s, c - m - record_marker)
+               == FAILURE))
     goto io_error;
 
   if (next_subrecord)
@@ -2620,12 +2626,13 @@ next_record_w_unf (st_parameter_dt *dtp, int next_subrecord)
   else
     m_write = m;
 
-  if (write_us_marker (dtp, m_write) != 0)
+  if (unlikely (write_us_marker (dtp, m_write) != 0))
     goto io_error;
 
   /* Seek past the end of the current record.  */
 
-  if (sseek (dtp->u.p.current_unit->s, c + record_marker) == FAILURE)
+  if (unlikely (sseek (dtp->u.p.current_unit->s, c + record_marker)
+               == FAILURE))
     goto io_error;
 
   return;