This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gfortran,patch] Add ACCESS, CHMOD, GMTIME, LTIME, RSHIFT and LSHIFT g77 intrinsics


On Thu, Jul 27, 2006 at 04:35:30PM +0200, Fran?ois-Xavier Coudert wrote:
> >void mpz_mul_2exp (mpz_t ROP, mpz_t OP1, unsigned long int OP2)
> >     Set ROP to OP1 times 2 raised to OP2.  This operation can also be
> >     defined as a left shift by OP2 bits.
> >
> >For positive N both `mpz_fdiv_q_2exp' and `mpz_tdiv_q_2exp' are
> >simple bitwise right shifts.  For negative N, `mpz_fdiv_q_2exp' is
> >effectively an arithmetic right shift treating N as twos complement
> >the same as the bitwise logical functions do, whereas
> >`mpz_tdiv_q_2exp' effectively treats N as sign and magnitude.
> 
> Hum, I'm not sure how we do this. So, if SHIFT >= 0, I << SHIFT is
> done using mpz_mul_2exp and I >> SHIFT is done using mpz_fdiv_q_2exp,
> right? What about negative shifts?

Isn't a negative left shift simply a right shift?

> >Of course, pointing out gmp functions exist and actually writing
> >the simplification routines are different.
> 
> Well, if an "algorithm" to relate << and >> to actualy GMP functions
> is established, I'll be happy to write the code. I just don't know how
> to handle all the cases.

I need to read the g77 docs and think about an algorithm.  OTOH,
the lack of simplification routines isn't showstopper if your
patch works for

   integer i
   i = lshift(1,4)
   end

Although simplification routines do constant folding, these
routine do other things (as the big comment at the top of
simplify.c suggests), and I suspect we don't use those features.
For example, a simplification would be needed for

   integer, parameter :: i(4) = lshift((/1,2,3,4/), 3)
   integer, parameter :: j(4) = rshift(i,2)

> >FreeBSD has a library routine named chmod().  I would
> >be surprised if other Unix-like OSs did not have a similar
> >library routine.
> 
> chmod() takes a mode_t argument, while the g77 CHMOD has to deal with
> a string mode, which is a comma-separated list of octal or symbolic
> modes, symbolic modes being of the form:
> [ugoa...][[+-=][rwxXstugo...]...][,...]. Writing the parser to gives
> the mode_t for a given mode string is not a simple task (the glibc
> code for that is far from trivial), and I'd better not spend to much
> energy on that.

I guess I should have looked at the g77 docs. :(
Hopefully, no one is doing thousands of chmod() calls from a
Fortran program.

-- 
Steve


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]