Hi, Reading `SET - neglected data type', I was wondering, how I could best initialise a SET variable. VAR b: BYTE, i: INTEGER, s: SET; ... SYTEM.GET(adr, s); (* reading 4 bytes from adr, easiest but adr MOD 4! *) ... SYTEM.GET(adr, i); s := {i}; (* same result as above? *) ... (* provided adr MOD = 0 *) SYTEM.GET(adr+0, b); s := {b}; (* same result as above? *) SYTEM.GET(adr+1, b); ASL(s,8); s := s + {b}; SYTEM.GET(adr+2, b); ASL(s,8); s := s + {b}; SYTEM.GET(adr+3, b); ASL(s,8); s := s + {b}; Tomas
s := { 10 }; makes a SET with 10th bit => s = 0x0400 So, I don't think s := { i } does what you think it would. 30.04.2017, 12:44, "Tomas Kral" <thomas.kral@email.cz>:
Hi,
Reading `SET - neglected data type', I was wondering, how I could best initialise a SET variable.
VAR b: BYTE, i: INTEGER, s: SET; ... SYTEM.GET(adr, s); (* reading 4 bytes from adr, easiest but adr MOD 4! *) ... SYTEM.GET(adr, i); s := {i}; (* same result as above? *) ... (* provided adr MOD = 0 *) SYTEM.GET(adr+0, b); s := {b}; (* same result as above? *) SYTEM.GET(adr+1, b); ASL(s,8); s := s + {b}; SYTEM.GET(adr+2, b); ASL(s,8); s := s + {b}; SYTEM.GET(adr+3, b); ASL(s,8); s := s + {b};
Tomas -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
---=====--- Александр
Ah yes, sily me. But how to best initialise a SET variable with an arbitrary byte / integer? TYPE ii = POINTER TO iidsc; iidsc = STRUCT i: INTEGER END; i := b; SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with a byte *) SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with an integer *) Tomas On Sun, 30 Apr 2017 12:59:22 +0300 Alexander Ilin <ajsoft@yandex.ru> wrote:
s := { 10 }; makes a SET with 10th bit => s = 0x0400
So, I don't think s := { i } does what you think it would.
30.04.2017, 12:44, "Tomas Kral" <thomas.kral@email.cz>:
Hi,
Reading `SET - neglected data type', I was wondering, how I could best initialise a SET variable.
VAR b: BYTE, i: INTEGER, s: SET; ... SYTEM.GET(adr, s); (* reading 4 bytes from adr, easiest but adr MOD 4! *) ... SYTEM.GET(adr, i); s := {i}; (* same result as above? *) ... (* provided adr MOD = 0 *) SYTEM.GET(adr+0, b); s := {b}; (* same result as above? *) SYTEM.GET(adr+1, b); ASL(s,8); s := s + {b}; SYTEM.GET(adr+2, b); ASL(s,8); s := s + {b}; SYTEM.GET(adr+3, b); ASL(s,8); s := s + {b};
Tomas -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
---=====--- Александр -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
In my point of view, the most general answer would be this VAR s: SET; (* 32 bit *) i: INTEGER; (* 32 bit *) BEGIN s := SYSTEM.VAL(SET, i) (* low level type conversion, aka compiler cheating. Not really recommended unless absoluetly needed. *) END There are tons of other ways to do it. It depends a little bit, where you get the INTEGER or BYTE value from (constant, memory, over a serial link...) Jörg
Am 30.04.2017 um 12:35 schrieb Tomas Kral <thomas.kral@email.cz>:
Ah yes, sily me.
But how to best initialise a SET variable with an arbitrary byte / integer?
TYPE ii = POINTER TO iidsc; iidsc = STRUCT i: INTEGER END;
i := b; SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with a byte *) SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with an integer *)
Tomas
On Sun, 30 Apr 2017 12:59:22 +0300 Alexander Ilin <ajsoft@yandex.ru> wrote:
s := { 10 }; makes a SET with 10th bit => s = 0x0400
So, I don't think s := { i } does what you think it would.
30.04.2017, 12:44, "Tomas Kral" <thomas.kral@email.cz>:
Hi,
Reading `SET - neglected data type', I was wondering, how I could best initialise a SET variable.
VAR b: BYTE, i: INTEGER, s: SET; ... SYTEM.GET(adr, s); (* reading 4 bytes from adr, easiest but adr MOD 4! *) ... SYTEM.GET(adr, i); s := {i}; (* same result as above? *) ... (* provided adr MOD = 0 *) SYTEM.GET(adr+0, b); s := {b}; (* same result as above? *) SYTEM.GET(adr+1, b); ASL(s,8); s := s + {b}; SYTEM.GET(adr+2, b); ASL(s,8); s := s + {b}; SYTEM.GET(adr+3, b); ASL(s,8); s := s + {b};
Tomas -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
---=====--- Александр -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Sunday, 30 April 2017 8:05 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - SET initialisation
Ah yes, sily me.
But how to best initialise a SET variable with an arbitrary byte / integer?
TYPE ii = POINTER TO iidsc; iidsc = STRUCT i: INTEGER END;
i := b; SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with a byte *) SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with an integer *)
Do you mean how do you typecast an INTEGER / BYTE variable to a SET variable? If so then: VAR s: SET; i: INTEGER; b: BYTE; BEGIN s := SYSTEM.VAL(SET, i); s := SYSTEM.VAL(SET, ORD(b)) I'm curious. What is it that you are trying to do that makes you ask this question? Regards, Chris Burrows CFB Software http://www.astrobe.com/RISC5
Chris, Joerg, Learning, not doing much useful bitmap examples. I was surprised to realise, Bitmaps are easy to be copied/displayed, by lines, after each line destination address is incremented by 128 bytes per display line, source address by bitmap width DIV 8, lines h decremented by 1. This works nicely on any bitmap of widths multiple of 32 bits accross. 32xN, 64xN, etc, and must be aligned horizontally also on 32 bit as well, for x=0,32,64,.. coordinate (x,y = top left). Bitmaps are drawn upwards. (* paints horizontal bitmap line, for x,w=32,64,... *) PROCEDURE PaintHLine(src, dst, w: INTEGER); VAR s,t: SET; BEGIN w := (w+7) DIV 8; (* bytes per bitmap line *) WHILE w > 0 DO SYSTEM.GET(src, t); SYSTEM.GET(dst, s); SYSTEM.PUT(dst, s + t); INC(dst, 4); INC(src, 4); DEC(w, 4) END END PaintHLine; I am looking into a solution where x can spill over byte boundary, also width of finer bitwise granularity. I did a similar exercise in assembly many, many years ago on 8-bit computers. Tomas On Sun, 30 Apr 2017 21:26:09 +0930 Chris Burrows <chris@cfbsoftware.com> wrote:
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Sunday, 30 April 2017 8:05 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - SET initialisation
Ah yes, sily me.
But how to best initialise a SET variable with an arbitrary byte / integer?
TYPE ii = POINTER TO iidsc; iidsc = STRUCT i: INTEGER END;
i := b; SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with a byte *) SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with an integer *)
Do you mean how do you typecast an INTEGER / BYTE variable to a SET variable?
If so then:
VAR s: SET; i: INTEGER; b: BYTE;
BEGIN s := SYSTEM.VAL(SET, i); s := SYSTEM.VAL(SET, ORD(b))
I'm curious. What is it that you are trying to do that makes you ask this question?
Regards, Chris Burrows CFB Software http://www.astrobe.com/RISC5
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hi Tomas One possibilty is to split your algorithm in three parts 1) handle the left border (max 31 bit) until you reach a multiple of 32 bit 2) then copy n words (32 bit) 3) handle the right border = remaining bits up to the width "w" Jörg
Am 30.04.2017 um 16:33 schrieb Tomas Kral <thomas.kral@email.cz>:
Chris, Joerg,
Learning, not doing much useful bitmap examples.
I was surprised to realise, Bitmaps are easy to be copied/displayed, by lines, after each line destination address is incremented by 128 bytes per display line, source address by bitmap width DIV 8, lines h decremented by 1.
This works nicely on any bitmap of widths multiple of 32 bits accross. 32xN, 64xN, etc, and must be aligned horizontally also on 32 bit as well, for x=0,32,64,.. coordinate (x,y = top left). Bitmaps are drawn upwards.
(* paints horizontal bitmap line, for x,w=32,64,... *) PROCEDURE PaintHLine(src, dst, w: INTEGER); VAR s,t: SET; BEGIN w := (w+7) DIV 8; (* bytes per bitmap line *) WHILE w > 0 DO SYSTEM.GET(src, t); SYSTEM.GET(dst, s); SYSTEM.PUT(dst, s + t); INC(dst, 4); INC(src, 4); DEC(w, 4) END END PaintHLine;
I am looking into a solution where x can spill over byte boundary, also width of finer bitwise granularity.
I did a similar exercise in assembly many, many years ago on 8-bit computers.
Tomas
On Sun, 30 Apr 2017 21:26:09 +0930 Chris Burrows <chris@cfbsoftware.com> wrote:
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Sunday, 30 April 2017 8:05 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - SET initialisation
Ah yes, sily me.
But how to best initialise a SET variable with an arbitrary byte / integer?
TYPE ii = POINTER TO iidsc; iidsc = STRUCT i: INTEGER END;
i := b; SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with a byte *) SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with an integer *)
Do you mean how do you typecast an INTEGER / BYTE variable to a SET variable?
If so then:
VAR s: SET; i: INTEGER; b: BYTE;
BEGIN s := SYSTEM.VAL(SET, i); s := SYSTEM.VAL(SET, ORD(b))
I'm curious. What is it that you are trying to do that makes you ask this question?
Regards, Chris Burrows CFB Software http://www.astrobe.com/RISC5
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hi, I arrived at coding this, it may not be correct, but does things on $AAAAA$ patterns. PROCEDURE PaintHLine(x, src, dst, w: INTEGER); VAR bt: BYTE; wd: INTEGER; pix: SET; BEGIN (* (pix * {maskleft*8..31} * {0..maskright*8-1}) *) WHILE w > 0 DO (* this part modified from Display.Mod:CopyPattern *) SYSTEM.GET(src, bt); wd := bt; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*100H; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*10000H; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*1000000H; INC(src); DEC(w, 8) END END END; SYSTEM.GET(dst, pix); SYSTEM.PUT(dst, SYSTEM.VAL(SET, LSL(wd, x MOD 32)) + pix); SYSTEM.GET(dst+4, pix); wd := ROR(wd, x MOD 32); SYSTEM.PUT(dst+4, SYSTEM.VAL(SET, wd)*{0..x MOD 32} + pix); INC(dst, 4) END END PaintHLine; Comments: [a] it now reflects x coordinate, but works only with w*8, need to deal with a remaining bits w MOD 8, as the last step [b] bits shifted left in memory, appears shifted right on display, interestingly also vice versa, as if on reflection in the mirror [c] need to somehow unroll the loop into three parts for speed improvement as suggested, as is, it needs four byte reads from source, two word read/writes per iteration INC(dst,4), but how? [d] bt*100H is defacto shift 8 operation, why normal ASR/LSL were not used instead, how many RISC cycles they got? Tomas On Sun, 30 Apr 2017 17:45:08 +0200 Jörg <joerg.straube@iaeth.ch> wrote:
Hi Tomas
One possibilty is to split your algorithm in three parts 1) handle the left border (max 31 bit) until you reach a multiple of 32 bit 2) then copy n words (32 bit) 3) handle the right border = remaining bits up to the width "w"
Jörg
Am 30.04.2017 um 16:33 schrieb Tomas Kral <thomas.kral@email.cz>:
Chris, Joerg,
Learning, not doing much useful bitmap examples.
I was surprised to realise, Bitmaps are easy to be copied/displayed, by lines, after each line destination address is incremented by 128 bytes per display line, source address by bitmap width DIV 8, lines h decremented by 1.
This works nicely on any bitmap of widths multiple of 32 bits accross. 32xN, 64xN, etc, and must be aligned horizontally also on 32 bit as well, for x=0,32,64,.. coordinate (x,y = top left). Bitmaps are drawn upwards.
(* paints horizontal bitmap line, for x,w=32,64,... *) PROCEDURE PaintHLine(src, dst, w: INTEGER); VAR s,t: SET; BEGIN w := (w+7) DIV 8; (* bytes per bitmap line *) WHILE w > 0 DO SYSTEM.GET(src, t); SYSTEM.GET(dst, s); SYSTEM.PUT(dst, s + t); INC(dst, 4); INC(src, 4); DEC(w, 4) END END PaintHLine;
I am looking into a solution where x can spill over byte boundary, also width of finer bitwise granularity.
I did a similar exercise in assembly many, many years ago on 8-bit computers.
Tomas
On Sun, 30 Apr 2017 21:26:09 +0930 Chris Burrows <chris@cfbsoftware.com> wrote:
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Sunday, 30 April 2017 8:05 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - SET initialisation
Ah yes, sily me.
But how to best initialise a SET variable with an arbitrary byte / integer?
TYPE ii = POINTER TO iidsc; iidsc = STRUCT i: INTEGER END;
i := b; SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with a byte *) SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with an integer *)
Do you mean how do you typecast an INTEGER / BYTE variable to a SET variable?
If so then:
VAR s: SET; i: INTEGER; b: BYTE;
BEGIN s := SYSTEM.VAL(SET, i); s := SYSTEM.VAL(SET, ORD(b))
I'm curious. What is it that you are trying to do that makes you ask this question?
Regards, Chris Burrows CFB Software http://www.astrobe.com/RISC5
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Tomas Kral <thomas.kral@email.cz>
If you write "x * 100H", the compiler will detect that "100H" is a power of two and will convert the multiplication into a shift operation. Jörg -----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Donnerstag, 4. Mai 2017 11:25 To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - Bitmap Paint Horizontal Line Hi, I arrived at coding this, it may not be correct, but does things on $AAAAA$ patterns. PROCEDURE PaintHLine(x, src, dst, w: INTEGER); VAR bt: BYTE; wd: INTEGER; pix: SET; BEGIN (* (pix * {maskleft*8..31} * {0..maskright*8-1}) *) WHILE w > 0 DO (* this part modified from Display.Mod:CopyPattern *) SYSTEM.GET(src, bt); wd := bt; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*100H; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*10000H; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*1000000H; INC(src); DEC(w, 8) END END END; SYSTEM.GET(dst, pix); SYSTEM.PUT(dst, SYSTEM.VAL(SET, LSL(wd, x MOD 32)) + pix); SYSTEM.GET(dst+4, pix); wd := ROR(wd, x MOD 32); SYSTEM.PUT(dst+4, SYSTEM.VAL(SET, wd)*{0..x MOD 32} + pix); INC(dst, 4) END END PaintHLine; Comments: [a] it now reflects x coordinate, but works only with w*8, need to deal with a remaining bits w MOD 8, as the last step [b] bits shifted left in memory, appears shifted right on display, interestingly also vice versa, as if on reflection in the mirror [c] need to somehow unroll the loop into three parts for speed improvement as suggested, as is, it needs four byte reads from source, two word read/writes per iteration INC(dst,4), but how? [d] bt*100H is defacto shift 8 operation, why normal ASR/LSL were not used instead, how many RISC cycles they got? Tomas On Sun, 30 Apr 2017 17:45:08 +0200 Jörg <joerg.straube@iaeth.ch> wrote:
Hi Tomas
One possibilty is to split your algorithm in three parts 1) handle the left border (max 31 bit) until you reach a multiple of 32 bit 2) then copy n words (32 bit) 3) handle the right border = remaining bits up to the width "w"
Jörg
Am 30.04.2017 um 16:33 schrieb Tomas Kral <thomas.kral@email.cz>:
Chris, Joerg,
Learning, not doing much useful bitmap examples.
I was surprised to realise, Bitmaps are easy to be copied/displayed, by lines, after each line destination address is incremented by 128 bytes per display line, source address by bitmap width DIV 8, lines h decremented by 1.
This works nicely on any bitmap of widths multiple of 32 bits accross. 32xN, 64xN, etc, and must be aligned horizontally also on 32 bit as well, for x=0,32,64,.. coordinate (x,y = top left). Bitmaps are drawn upwards.
(* paints horizontal bitmap line, for x,w=32,64,... *) PROCEDURE PaintHLine(src, dst, w: INTEGER); VAR s,t: SET; BEGIN w := (w+7) DIV 8; (* bytes per bitmap line *) WHILE w > 0 DO SYSTEM.GET(src, t); SYSTEM.GET(dst, s); SYSTEM.PUT(dst, s + t); INC(dst, 4); INC(src, 4); DEC(w, 4) END END PaintHLine;
I am looking into a solution where x can spill over byte boundary, also width of finer bitwise granularity.
I did a similar exercise in assembly many, many years ago on 8-bit computers.
Tomas
On Sun, 30 Apr 2017 21:26:09 +0930 Chris Burrows <chris@cfbsoftware.com> wrote:
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Sunday, 30 April 2017 8:05 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - SET initialisation
Ah yes, sily me.
But how to best initialise a SET variable with an arbitrary byte / integer?
TYPE ii = POINTER TO iidsc; iidsc = STRUCT i: INTEGER END;
i := b; SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with a byte *) SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with an integer *)
Do you mean how do you typecast an INTEGER / BYTE variable to a SET variable?
If so then:
VAR s: SET; i: INTEGER; b: BYTE;
BEGIN s := SYSTEM.VAL(SET, i); s := SYSTEM.VAL(SET, ORD(b))
I'm curious. What is it that you are trying to do that makes you ask this question?
Regards, Chris Burrows CFB Software http://www.astrobe.com/RISC5
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Tomas Kral <thomas.kral@email.cz> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hi Joerg, That is good & clever. Below a revised code, seems to work slightly better, is also shorter. PROCEDURE PaintHLine(x, src, dst, w: INTEGER); VAR bt: BYTE; wd: INTEGER; pix: SET; BEGIN (* (pix * {maskleft*8..31} * {0..maskright*8-1}) *) WHILE w > 0 DO (* this part modified from Display.Mod:CopyPattern *) SYSTEM.GET(src, bt); wd := bt; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*100H; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*10000H; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*1000000H; INC(src); DE C(w, 8) END END END; SYSTEM.GET(dst, pix); SYSTEM.PUT(dst, SYSTEM.VAL(SET, LSL(wd, x MOD 32)) + pix); INC(dst, 4); SYSTEM.GET(dst, pix); wd := ROR(wd, -(x MOD 32)); SYSTEM.PUT(dst, SYSTEM.VAL(SET, wd)*{0..x MOD 32-1} + pix); (* Texts.WriteInt(Wr, w, 6); Texts.WriteLn(Wr) *) END END PaintHLine; On Thu, 4 May 2017 16:42:57 +0200 Jörg <joerg.straube@iaeth.ch> wrote:
If you write "x * 100H", the compiler will detect that "100H" is a power of two and will convert the multiplication into a shift operation.
Jörg
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Donnerstag, 4. Mai 2017 11:25 To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - Bitmap Paint Horizontal Line
Hi,
I arrived at coding this, it may not be correct, but does things on $AAAAA$ patterns.
PROCEDURE PaintHLine(x, src, dst, w: INTEGER); VAR bt: BYTE; wd: INTEGER; pix: SET; BEGIN
(* (pix * {maskleft*8..31} * {0..maskright*8-1}) *)
WHILE w > 0 DO
(* this part modified from Display.Mod:CopyPattern *)
SYSTEM.GET(src, bt); wd := bt; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*100H; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*10000H; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*1000000H; INC(src); DEC(w, 8) END END END;
SYSTEM.GET(dst, pix); SYSTEM.PUT(dst, SYSTEM.VAL(SET, LSL(wd, x MOD 32)) + pix); SYSTEM.GET(dst+4, pix); wd := ROR(wd, x MOD 32); SYSTEM.PUT(dst+4, SYSTEM.VAL(SET, wd)*{0..x MOD 32} + pix);
INC(dst, 4) END
END PaintHLine;
Comments:
[a] it now reflects x coordinate, but works only with w*8, need to deal with a remaining bits w MOD 8, as the last step
[b] bits shifted left in memory, appears shifted right on display, interestingly also vice versa, as if on reflection in the mirror
[c] need to somehow unroll the loop into three parts for speed improvement as suggested, as is, it needs four byte reads from source, two word read/writes per iteration INC(dst,4), but how?
[d] bt*100H is defacto shift 8 operation, why normal ASR/LSL were not used instead, how many RISC cycles they got?
Tomas
On Sun, 30 Apr 2017 17:45:08 +0200 Jörg <joerg.straube@iaeth.ch> wrote:
Hi Tomas
One possibilty is to split your algorithm in three parts 1) handle the left border (max 31 bit) until you reach a multiple of 32 bit 2) then copy n words (32 bit) 3) handle the right border = remaining bits up to the width "w"
Jörg
Am 30.04.2017 um 16:33 schrieb Tomas Kral <thomas.kral@email.cz>:
Chris, Joerg,
Learning, not doing much useful bitmap examples.
I was surprised to realise, Bitmaps are easy to be copied/displayed, by lines, after each line destination address is incremented by 128 bytes per display line, source address by bitmap width DIV 8, lines h decremented by 1.
This works nicely on any bitmap of widths multiple of 32 bits accross. 32xN, 64xN, etc, and must be aligned horizontally also on 32 bit as well, for x=0,32,64,.. coordinate (x,y = top left). Bitmaps are drawn upwards.
(* paints horizontal bitmap line, for x,w=32,64,... *) PROCEDURE PaintHLine(src, dst, w: INTEGER); VAR s,t: SET; BEGIN w := (w+7) DIV 8; (* bytes per bitmap line *) WHILE w > 0 DO SYSTEM.GET(src, t); SYSTEM.GET(dst, s); SYSTEM.PUT(dst, s + t); INC(dst, 4); INC(src, 4); DEC(w, 4) END END PaintHLine;
I am looking into a solution where x can spill over byte boundary, also width of finer bitwise granularity.
I did a similar exercise in assembly many, many years ago on 8-bit computers.
Tomas
On Sun, 30 Apr 2017 21:26:09 +0930 Chris Burrows <chris@cfbsoftware.com> wrote:
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Sunday, 30 April 2017 8:05 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - SET initialisation
Ah yes, sily me.
But how to best initialise a SET variable with an arbitrary byte / integer?
TYPE ii = POINTER TO iidsc; iidsc = STRUCT i: INTEGER END;
i := b; SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with a byte *) SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with an integer *)
Do you mean how do you typecast an INTEGER / BYTE variable to a SET variable?
If so then:
VAR s: SET; i: INTEGER; b: BYTE;
BEGIN s := SYSTEM.VAL(SET, i); s := SYSTEM.VAL(SET, ORD(b))
I'm curious. What is it that you are trying to do that makes you ask this question?
Regards, Chris Burrows CFB Software http://www.astrobe.com/RISC5
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Tomas Kral <thomas.kral@email.cz>
Hi, I have coded this improved version. It generally works and seems to handle both x, and w on bitwise level. The main loop goes initially fast over words, and the rest by bytes. This line `w0 := (w MOD 32) DIV 8 + 1' computes remaining bytes on line over MOD 32, and this clips the outstretching bits wd*{0..w0*8+w}. But the above calculation seems complicated, is there an easier invariant I could code instead? `w0' can then be passed as a parameter as its value is known before calling to `PaintHLine'. PROCEDURE PaintHLine(x, src, dst, w: INTEGER); VAR bt: BYTE; w0, w1, wd: INTEGER; pix: SET; BEGIN (* (pix * {maskleft*8..31} * {0..maskright*8-1}) *) w0 := (w MOD 32) DIV 8 + 1; WHILE w > 0 DO IF w > 31 THEN SYSTEM.GET(src, wd); INC(src, 4); DEC(w, 32); ELSE wd := 0; WHILE w > 0 DO SYSTEM.GET(src, bt); wd := LSL(wd, 8)+bt; INC(src); DEC(w, 8) END END; IF w < 0 THEN wd := SYSTEM.VAL(INTEGER, SYSTEM.VAL(SET, wd)*{0..w0*8+w}) END; SYSTEM.GET(dst, pix); SYSTEM.PUT(dst, SYSTEM.VAL(SET, LSL(wd, x MOD 32)) + pix); INC(dst, 4); IF x MOD 32 > 0 THEN SYSTEM.GET(dst, pix); wd := ASR(wd, -(x MOD 32)); SYSTEM.PUT(dst, SYSTEM.VAL(SET, wd)*{0..x MOD 32-1}+ pix) END END END PaintHLine; -- Tomas Kral <thomas.kral@email.cz> On Thu, 4 May 2017 16:42:57 +0200 Jörg <joerg.straube@iaeth.ch> wrote:
If you write "x * 100H", the compiler will detect that "100H" is a power of two and will convert the multiplication into a shift operation.
Jörg
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Donnerstag, 4. Mai 2017 11:25 To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - Bitmap Paint Horizontal Line
Hi,
I arrived at coding this, it may not be correct, but does things on $AAAAA$ patterns.
PROCEDURE PaintHLine(x, src, dst, w: INTEGER); VAR bt: BYTE; wd: INTEGER; pix: SET; BEGIN
(* (pix * {maskleft*8..31} * {0..maskright*8-1}) *)
WHILE w > 0 DO
(* this part modified from Display.Mod:CopyPattern *)
SYSTEM.GET(src, bt); wd := bt; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*100H; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*10000H; INC(src); DEC(w, 8); IF w > 0 THEN SYSTEM.GET(src, bt); wd := wd + bt*1000000H; INC(src); DEC(w, 8) END END END;
SYSTEM.GET(dst, pix); SYSTEM.PUT(dst, SYSTEM.VAL(SET, LSL(wd, x MOD 32)) + pix); SYSTEM.GET(dst+4, pix); wd := ROR(wd, x MOD 32); SYSTEM.PUT(dst+4, SYSTEM.VAL(SET, wd)*{0..x MOD 32} + pix);
INC(dst, 4) END
END PaintHLine;
Comments:
[a] it now reflects x coordinate, but works only with w*8, need to deal with a remaining bits w MOD 8, as the last step
[b] bits shifted left in memory, appears shifted right on display, interestingly also vice versa, as if on reflection in the mirror
[c] need to somehow unroll the loop into three parts for speed improvement as suggested, as is, it needs four byte reads from source, two word read/writes per iteration INC(dst,4), but how?
[d] bt*100H is defacto shift 8 operation, why normal ASR/LSL were not used instead, how many RISC cycles they got?
Tomas
On Sun, 30 Apr 2017 17:45:08 +0200 Jörg <joerg.straube@iaeth.ch> wrote:
Hi Tomas
One possibilty is to split your algorithm in three parts 1) handle the left border (max 31 bit) until you reach a multiple of 32 bit 2) then copy n words (32 bit) 3) handle the right border = remaining bits up to the width "w"
Jörg
Am 30.04.2017 um 16:33 schrieb Tomas Kral <thomas.kral@email.cz>:
Chris, Joerg,
Learning, not doing much useful bitmap examples.
I was surprised to realise, Bitmaps are easy to be copied/displayed, by lines, after each line destination address is incremented by 128 bytes per display line, source address by bitmap width DIV 8, lines h decremented by 1.
This works nicely on any bitmap of widths multiple of 32 bits accross. 32xN, 64xN, etc, and must be aligned horizontally also on 32 bit as well, for x=0,32,64,.. coordinate (x,y = top left). Bitmaps are drawn upwards.
(* paints horizontal bitmap line, for x,w=32,64,... *) PROCEDURE PaintHLine(src, dst, w: INTEGER); VAR s,t: SET; BEGIN w := (w+7) DIV 8; (* bytes per bitmap line *) WHILE w > 0 DO SYSTEM.GET(src, t); SYSTEM.GET(dst, s); SYSTEM.PUT(dst, s + t); INC(dst, 4); INC(src, 4); DEC(w, 4) END END PaintHLine;
I am looking into a solution where x can spill over byte boundary, also width of finer bitwise granularity.
I did a similar exercise in assembly many, many years ago on 8-bit computers.
Tomas
On Sun, 30 Apr 2017 21:26:09 +0930 Chris Burrows <chris@cfbsoftware.com> wrote:
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Sunday, 30 April 2017 8:05 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - SET initialisation
Ah yes, sily me.
But how to best initialise a SET variable with an arbitrary byte / integer?
TYPE ii = POINTER TO iidsc; iidsc = STRUCT i: INTEGER END;
i := b; SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with a byte *) SYSTEM.PUT(ii,i); SYSTEM.GET(ii,s); (* initialise a set with an integer *)
Do you mean how do you typecast an INTEGER / BYTE variable to a SET variable?
If so then:
VAR s: SET; i: INTEGER; b: BYTE;
BEGIN s := SYSTEM.VAL(SET, i); s := SYSTEM.VAL(SET, ORD(b))
I'm curious. What is it that you are trying to do that makes you ask this question?
Regards, Chris Burrows CFB Software http://www.astrobe.com/RISC5
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hi, Just realised `remaining bits' on the line can be coded as w0 := w - (w DIV 32) * 32; The mask is then wd*{0..w0} Not sure I can get it any simpler. Tomas On Wed, 10 May 2017 11:33:19 +0200 Tomas Kral <thomas.kral@email.cz> wrote:
Hi,
I have coded this improved version. It generally works and seems to handle both x, and w on bitwise level.
The main loop goes initially fast over words, and the rest by bytes.
This line `w0 := (w MOD 32) DIV 8 + 1' computes remaining bytes on line over MOD 32, and this clips the outstretching bits wd*{0..w0*8+w}.
But the above calculation seems complicated, is there an easier invariant I could code instead?
`w0' can then be passed as a parameter as its value is known before calling to `PaintHLine'.
PROCEDURE PaintHLine(x, src, dst, w: INTEGER); VAR bt: BYTE; w0, w1, wd: INTEGER; pix: SET; BEGIN
(* (pix * {maskleft*8..31} * {0..maskright*8-1}) *)
w0 := (w MOD 32) DIV 8 + 1;
WHILE w > 0 DO
IF w > 31 THEN SYSTEM.GET(src, wd); INC(src, 4); DEC(w, 32); ELSE wd := 0; WHILE w > 0 DO SYSTEM.GET(src, bt); wd := LSL(wd, 8)+bt; INC(src); DEC(w, 8) END END;
IF w < 0 THEN wd := SYSTEM.VAL(INTEGER, SYSTEM.VAL(SET, wd)*{0..w0*8+w}) END;
SYSTEM.GET(dst, pix); SYSTEM.PUT(dst, SYSTEM.VAL(SET, LSL(wd, x MOD 32)) + pix);
INC(dst, 4); IF x MOD 32 > 0 THEN SYSTEM.GET(dst, pix); wd := ASR(wd, -(x MOD 32)); SYSTEM.PUT(dst, SYSTEM.VAL(SET, wd)*{0..x MOD 32-1}+ pix) END
END END PaintHLine;
-- Tomas Kral <thomas.kral@email.cz>
Hi, This is almost final version. I found it easier to align bitmap lines on word boundaries, as it simplifies the code, but may waste 3 bytes per line at worst case. (w+31+w MOD 32) DIV 32 (* number of words on bitmap line, padded to word boundary *) (x DIV 32)*4 (* x aligned on word boundary *) ---- PROCEDURE PaintHLine(x, src, dst, w: INTEGER); VAR bt: BYTE; w0, wd: INTEGER; pix: SET; BEGIN (* (pix * {maskleft*8..31} * {0..maskright*8-1}) *) w0 := w MOD 32; WHILE w > 0 DO SYSTEM.GET(src, wd); INC(src, 4); DEC(w, 32); IF w < 0 THEN wd := SYSTEM.VAL(INTEGER, SYSTEM.VAL(SET, wd)*{0..w0}) END; SYSTEM.GET(dst, pix); SYSTEM.PUT(dst, SYSTEM.VAL(SET, LSL(wd, x MOD 32)) + pix); INC(dst, 4); IF x MOD 32 > 0 THEN SYSTEM.GET(dst, pix); wd := ASR(wd, -(x MOD 32)); SYSTEM.PUT(dst, SYSTEM.VAL(SET, wd)*{0..x MOD 32-1} + pix) END END END PaintHLine; On Wed, 10 May 2017 21:01:29 +0200 Tomas Kral <thomas.kral@email.cz> wrote:
Hi,
Just realised `remaining bits' on the line can be coded as w0 := w - (w DIV 32) * 32;
The mask is then wd*{0..w0}
Not sure I can get it any simpler.
Tomas
On Wed, 10 May 2017 11:33:19 +0200 Tomas Kral <thomas.kral@email.cz> wrote:
Hi,
I have coded this improved version. It generally works and seems to handle both x, and w on bitwise level.
The main loop goes initially fast over words, and the rest by bytes.
This line `w0 := (w MOD 32) DIV 8 + 1' computes remaining bytes on line over MOD 32, and this clips the outstretching bits wd*{0..w0*8+w}.
But the above calculation seems complicated, is there an easier invariant I could code instead?
`w0' can then be passed as a parameter as its value is known before calling to `PaintHLine'.
PROCEDURE PaintHLine(x, src, dst, w: INTEGER); VAR bt: BYTE; w0, w1, wd: INTEGER; pix: SET; BEGIN
(* (pix * {maskleft*8..31} * {0..maskright*8-1}) *)
w0 := (w MOD 32) DIV 8 + 1;
WHILE w > 0 DO
IF w > 31 THEN SYSTEM.GET(src, wd); INC(src, 4); DEC(w, 32); ELSE wd := 0; WHILE w > 0 DO SYSTEM.GET(src, bt); wd := LSL(wd, 8)+bt; INC(src); DEC(w, 8) END END;
IF w < 0 THEN wd := SYSTEM.VAL(INTEGER, SYSTEM.VAL(SET, wd)*{0..w0*8+w}) END;
SYSTEM.GET(dst, pix); SYSTEM.PUT(dst, SYSTEM.VAL(SET, LSL(wd, x MOD 32)) + pix);
INC(dst, 4); IF x MOD 32 > 0 THEN SYSTEM.GET(dst, pix); wd := ASR(wd, -(x MOD 32)); SYSTEM.PUT(dst, SYSTEM.VAL(SET, wd)*{0..x MOD 32-1}+ pix) END
END END PaintHLine;
-- Tomas Kral <thomas.kral@email.cz>
participants (4)
-
Alexander Ilin -
Chris Burrows -
Jörg -
Tomas Kral