The Memory Unit

Written by Thomas Schatzl

FEATURES

BACKGROUND

This unit was done because I need fast memory copy routines and boolean bit operation for a greater project of mine, a graphics library which uses the 2D acceleration features of most graphics chips nowadays. Some procedures are needed to support all functions (bitblt, HW memory copies..) in software for chipsets which don't support HW acceleration or miss one or another feature or are simply older.
On the other hand I wanted to know what comes out if you take advantage of modern chipsets available instruction sets. And it seems it was worth the effort, because there's a speed gain of up to 400% when using FPU or MMX instructions to copy memory, or using Intel's MMX extensions for boolean operations on my P200 MMX.

SYSTEM REQUIREMENTS

This unit requires an IBM PC or compatible with an 80386 or higher processor.

PROGRAMMING LANGUAGE

This Memory unit can be compiled with FPC Pascal (32-bit protected mode freeware DOS compiler) and a GNU assembler version of 2.9.1 or higher. (BEWARE that FPC 0.99.10 still packages AS 2.8.1!!!!, you can get the newer 2.9.1 Tom's page

Supports following extenders:

Needs the following switches enabled:

WHERE TO GET FPC PASCAL COMPILER

You will find latest version of FPC Pascal compiler on (Deleted, see the links section)


MEMORY UNIT REFERENCE


Memory Types

Mem_Op (enumeration)

Description :

The following table shows these operation modes:

Enumeration name Boolean bit operation resultDescription / Note
MEM_CLEAR dst = 0 zero out destination
MEM_NOT_DSTORSRC dst = not (dst or src)
MEM_DST_AND_NOTSRC dst = dst and (not src)
MEM_NOTSRC dst = not src invert source and copy
MEM_SRC_AND_NOTDST dst = src and (not dst)
MEM_NOTDST dst = not dst invert destination
MEM_DST_XOR_SRC dst = dst xor src
MEM_NOT_DSTANDSRC dst = not (dst and src)
MEM_DST_AND_SRC dst = dst and src
MEM_NOT_DSTXORSRC dst = not (dst xor src)
MEM_DST dst = dst does nothing
MEM_DST_OR_NOTSRC dst = dst or (not src)
MEM_SRC dst = src copy / fill
MEM_NOTDST_OR_SRC dst = (not dst) or src
MEM_DST_OR_SRC dst = dst or src
MEM_SET dst = 1 set destination

The result is archieved by combining src and dst values bit by bit.

Example 1:

src = %10001
dst = %01011
selected operation : MEM_DST_OR_NOTSRC

dst = dst or (not src)
    = %01011 or (not %10001)
    = %01011 or %01111
    = %01111

Example 2:

src = %10001
dst = %01001
selected operation : MEM_CLEAR

dst = 0
    = %00000

In this case the src and dst memory contents are not important at all.

The next table shows the results of the four different basic operations according to given expressions A and B.

AND OR XOR NOT
A B result A B result A B result A result
0 0 0 0 0 0 0 0 0 1 0
1 0 0 1 0 1 1 0 1 0 1
0 1 0 0 1 1 0 1 1
1 1 1 1 1 1 1 1 0

Example:

A = %10100
B = %01001
operation : XOR
result = %10100 xor %01001 = %10101

DWord (type)

This type defines a 32 bit unsigned integer.

type DWord = Cardinal;

Memory functions

memcpy

procedure memcpy (var src, dst; size : DWord);

Description See also seg_memcpy


memsetB, W and D

procedure memsetB (var x; size : DWord; value : Byte);
procedure memsetW (var x; size : DWord; value : Word);
procedure memsetD (var x; size : DWord; value : DWord);
Description See also seg_memset range of procedures


memchange

procedure memchange (var src, dst; size : DWord; op : Mem_Op);


Does a boolean operation between two memory areas

Description

See also

memchangeValueB, memchangeValueW and memchangeValueD

procedure memchangeValueB (var x; size : DWord; value : Byte; op : Mem_Op);
procedure memchangeValueW (var x; size : DWord; value : Word; op : Mem_Op);
procedure memchangeValueD (var x; size : DWord; value : DWord; op :Mem_Op);
Does a boolean operation between a value and a memory area

Description

See also


seg_memcpy

procedure seg_memcpy (srcsel : Word; srcofs : DWord; dstsel : Word; dstofs: Dword; size : DWord);

Copies bytes from src to dst across selector boundaries.

Description

See also

seg_memsetB, W and D

procedure seg_memsetB (sel : Word; ofs : DWord; size : DWord; value : Byte);
procedure seg_memsetW (sel : Word; ofs : DWord; size : DWord; value : Word);
procedure seg_memsetD (sel : Word; ofs : DWord; size : DWord; value : DWord);
Sets size bytes across selector boundaries.

Description

See also memset range of procedures


seg_memchange

procedure seg_memchange (srcsel : Word; srcofs : DWord; dstsel : Word;dstofs : DWord; size : DWord);
Combines two memory areas by a boolean operation which aren't in the DS selector range

Description

See also

seg_memchangeValueB, seg_memchangeValueW and seg_memchangeValueD

procedure seg_memchangeValueB (sel : Word; ofs : DWord; size : DWord; value: Byte; op : Mem_Op);
procedure seg_memchangeValueW (sel : Word; ofs : DWord; size : DWord; value: Word; op : Mem_Op);
procedure seg_memchangeValueD (sel : Word; ofs : DWord; size : DWord; value: DWord; op : Mem_Op);
Combines a memory area with a value by a boolean operation which is outside the DS selector range.

Description

See also


If you have any questions or feedback then e-mail me at tom_at_work@geocities.com

Conversion to HTML by Marco van de Voort

Last update : 02.01.1999