News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Complex numbers: problem with structure initialisation

Started by jj2007, August 14, 2017, 07:08:21 PM

Previous topic - Next topic

jj2007

From Raymond Filiatreault's zlib:

the real and imaginary coefficients must be at adjacent memory addresses, the real coefficient being at the lower
address. Although structure addressing is not used within the functions, and structures are not an absolute necessity, a
complex number structure could be declared as:

Z_NUM STRUCT
real :DWORD (or QWORD, or TBYTE)
imag :DWORD (or QWORD, or TBYTE)
Z_NUM ENDS

and then for the variable in your data section:

z1 Z_NUM <>


I've tried that for OWORDs aka REAL16, and ran into a problem:include \masm32\include\masm32rt.inc
.686
.xmm

COMPLEX16 STRUCT
real OWORD ?
imag OWORD ?
COMPLEX16 ENDS

.code
MyF16 OWORD ? ; works fine
MyX16 COMPLEX16 <-123, 456> ; chokes with A1016: Internal Assembler Error for ML 6.14 and 6.15

start:
  movups xmm0, MyX16.real
  movd eax, xmm0
  print str$(eax), " "
  movups xmm1, MyX16.imag
  movd eax, xmm1
  inkey str$(eax), "i"
  exit
end start


Works fine with UAsm and ML 8.0+. Any workaround that would satisfy my desperate attempt to remain compatible with ML 6.15?

Siekmanski

Does Masm 6.14 and 6.15 recognize SIMD instructions?
AFAIK they don't.
Maybe you can use SIMD macros for 6.14 an 6.15.
Creative coders use backward thinking techniques as a strategy.

hutch--

If you want to use later instructions that did not exist before 2000, use a later version.

jj2007

Normally my stuff requires ML 6.15, and yes, that includes SIMD. ML 6.15 knows what an OWORD is (but it doesn't know about XMMWORD). However, it can't use the OWORD inside a structure definition - that is only possible from version 8.0 onwards.

Queue

Depending on circumstances, sometimes the old MASM OWORD struct issue can be worked around with unions or QWORD 2 dup(?) substitutions.

For example:
COMPLEX16 STRUCT
union
_real QWORD ?
real OWORD ?
ends
union
_imag QWORD ?
imag OWORD ?
ends
COMPLEX16 ENDS
.errnz COMPLEX16 - OWORD * 2

MyX16 COMPLEX16 <{-123},{456}>

Edit: Note that this specific workaround isn't going to get negative numbers right (they'll only populate the QWORD's width).

The OWORD issue is screwy specifically because it is a bug.
_dummy1 struct
dummy0 OWORD ?
dummy1 OWORD ?
dummy2 OWORD ?
dummy3 QWORD ?
dummy4 QWORD ?
dummy5 QWORD ?
dummy6 QWORD ?
dummy7 QWORD ?
_dummy1 ends
_dummy2 struct
_dummy1 <>
_dummy2 ends

Change QWORDs to OWORDs in this example and note the internal assembler errors thrown for the line "_dummy1 <>" (via MASM 6.15).

Queue

jj2007

Quote from: Queue on August 15, 2017, 04:52:06 AM
Depending on circumstances, sometimes the old MASM OWORD struct issue can be worked around with unions

It seems we have an expert among us - thanks a lot :t

include \masm32\include\masm32rt.inc
.686p
.xmm

COMPLEX16 STRUCT
union
dummy1 QWORD ?, ?
real OWORD ?
ends
union
dummy2 QWORD ?, ?
imag OWORD ?
ends
COMPLEX16 ENDS
; .errnz COMPLEX16 - OWORD * 2

.data
My16 COMPLEX16 <>

.code
q0 dq 5555666677778888h, 1111222233334444h
q1 dq 1212121212121212h, 3434343434343434h
start:
   lea eax, q0
   lea edx, My16
   ; int 3
   movups xmm0, oword ptr q0
   movups xmm1, oword ptr q1
   movups My16.real, xmm0
   movups My16.imag, xmm1
   inkey "ok?"
   exit
end start



P.S.: There is an old thread with similar problems.

Queue

Some other old threads with potentially useful information:
http://www.masmforum.com/board/index.php?topic=2610.0
http://www.masmforum.com/board/index.php?topic=15872.0
You were a major part of that second one. The first one points out using the label directive to allow more freeform structure initialization; could probably make a macro for OWORD and OWORD-containing structure initialization if you're intent on supporting MASM 6.X.

Queue

jj2007

Thanks, Queue. The best (and only) solution seems to be the union with two dummy QWORDs. Weird stuff, really.