[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Library files not in their proper distribution?



> As far as efficiency concerned, the m68k family of processors
> has 32-bit registers.  Using 16-bit values actually costs
> performance because the compiler has to insert additional
> assembler instructions to mask out the bits that aren't 
> used.

Well, not exactly. You can access 16-bit integers at the processor level
as easily as 32-bit integers. For a move a 32-bit int (pointed by the reg.
a0) to the data register d0 you use:

	move.l	(a0),d0		; MOVE LONG

while for a 16-bit integer it will be:

	move.w	(a0),d0		; MOVE WORD

In that latter case only low 16-bits of the register are affected and no
masking is necessary. Later you can process this 16-bit word with other
16-bit instructions, like add.w, sub.w, etc.

> When you also consider that for signed variables
> the first (i.e. highest bit for Motorola) holds the sign
> information things get even clearer: This "sign-bit" has to
> be bit #0 for long integers and bit #16 for short ones.

Yeps, but the processor takes the sign bit into consideration rather
automatically. That is, for a LONG operation, the sign is 31th bit of a
register, while for a WORD operation it is the 15th bit, and for a BYTE
operation it is te 7th bit (counting them from 0). That is, if your
integer is negative (highest bit set), you can do:

	move.l	(a0),d0
	bmi	...

or

	move.w	(a0),d0
	bmi	...

or even

	move.b	(a0),d0
	bmi	...

and be sure that the branch (bmi) will be taken without a need to previous
sign-extension of the d0.

Moreover, if the move is done to an address register (where all 32-bits
have to be affected), the processor does sign extensions of 16-bit
integers automagically, that is:

	move.w	#$7fff,a0

produces $00007fff in the register a0, while:

	move.w	#$8000,a0

produces $ffff8000 in the same register.

Data have to be sign-extended "manually" only if you want to cast a 16-bit
integer, previously loaded to a data register, to a 32-bit value, like:

	move.w	#$8000,d0	;load low word of the d0 ($xxxx8000 in d0)
	ext.l	d0		;sign-extension to 32-bit
				;produces $ffff8000 in d0

On the 68030 you can expand 8-bit integers to 32-bit as well:

	move.b	#$ff,d0		;produces $xxxxxxff in d0
	extb.l	d0		;sign-extension to 32-bit
				;produces $ffffffff in d0

where "xxxx" is a previous value of the apprppriate register parts.

Gtx,

--
Konrad M.Kokoszkiewicz
|mail: draco@mi.com.pl                  | Atari Falcon030/TT030/65XE |
|http://www.orient.uw.edu.pl/~conradus/ |  *** FreeMiNT 1.14.7. ***  |

** Ea natura multitudinis est,
** aut servit humiliter, aut superbe dominatur (Liv. XXIV,25)
*************************************************************
** U pospolstwa normalne jest, ze albo sluzy ono unizenie,
** albo bezczelnie sie panoszy.