[Oberon] FPGA - Files.ReadBytes(), Files.WriteBytes()

Jörg joerg.straube at iaeth.ch
Fri Aug 24 15:40:13 CEST 2018


Tomas

If you want to use SYSTEM.COPY(), the "src" and "dst" must be on word boundary.
Please analyze and modify your code that this always true.

Some questions you have to ask yourself:
- What is the influence of ReadByte on r.bpos, src, dst?
- Is there a better place for the ReadByte loop?

Happy coding
Jörg

-----Original Message-----
From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of Tomas Kral
Sent: Friday, August 24, 2018 2:02 PM
To: oberon at lists.inf.ethz.ch
Subject: Re: [Oberon] FPGA - Files.ReadBytes(), Files.WriteBytes()

On Mon, 20 Aug 2018 19:39:39 +0200
Jörg <joerg.straube at iaeth.ch> wrote:

> IF r.bpos MOD 4 # 0 THEN
> 	i := 0; WHILE i < n DO ReadBytes(r, x[i]); INC(i) END (* copy single 
> bytes *) ELSE
> 	(* four times faster by using SYSTEM.COPY() *) END

This just a first try, using above to modify PO.V4 ReadBytes().

PROCEDURE ReadBytes*(VAR r: Rider; VAR x: ARRAY OF BYTE; n: INTEGER);
    VAR i, n0, n1, src, dst, m: INTEGER; buf: Buffer;
  BEGIN i := 0; n0 := n; dst := SYSTEM.ADR(x); (*this implementation is to be improved*) WHILE (n > 0) & (r.bpos MOD 4 # 0) DO ReadByte(r, x[i]); INC(i); DEC(n) END ; (*bytes to word boundary*) IF r.apos # r.buf.apos THEN r.buf := GetBuf(r.file, r.apos) END ; n1 := n MOD 4; (*bytes to copy*) n := n DIV 4; (*words to copy*)
    WHILE n > 0 DO (*words*)
      src := SYSTEM.ADR(r.buf.data) + r.bpos; m := r.bpos + n*4;
      IF m <= r.buf.lim THEN
        SYSTEM.COPY(src, dst, n); r.bpos := m; r.res := 0; (*EXIT*) n := 0 ELSIF r.buf.lim = SS THEN
        m := (r.buf.lim - r.bpos) DIV 4;
        IF m > 0 THEN SYSTEM.COPY(src, dst, m); INC(dst, m*4); DEC(n,
m) END ; IF r.apos < r.file.aleng THEN
          INC(r.apos); r.bpos := 0; buf := Buf(r.file, r.apos);
          IF buf = NIL THEN
            IF r.buf.mod THEN WriteBuf(r.file, r.buf) END ;
            ReadBuf(r.file, r.buf, r.apos)
          ELSE r.buf := buf
          END
        ELSE r.res := n*4; r.eof := TRUE; (*EXIT*) n := 0
        END
      ELSE m := (r.buf.lim - r.bpos) DIV 4;
        IF m > 0 THEN SYSTEM.COPY(src, dst, m); r.bpos := r.buf.lim END ; r.res := (n-m)*4; r.eof := TRUE; (*EXIT*) n := 0
      END
    END; (* n > 0 *)
    FOR i := n0-n1 TO n0 DO ReadByte(r, x[i]) END (*remaining bytes*)
  END ReadBytes;

--
Tomas Kral <thomas.kral at email.cz>
--
Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon



More information about the Oberon mailing list