BBC BASIC for Windows
Programming >> Libraries >> New ASMLIB library
http://bb4w.conforums.com/index.cgi?board=libraries&action=display&num=1247065374

New ASMLIB library
Post by admin on Jul 8th, 2009, 3:02pm

I have developed a new library, ASMLIB:

http://groups.yahoo.com/group/bb4w/files/Libraries/ASMLIB.BBC

This library extends the BB4W assembler to accept the Streaming SIMD Extension (SSE) and Conditional Move (CMOVcc) instructions available on some processors; in total 92 new opcodes are added. Note that SSE2 and later extensions are not included, although they could be in principle.

To use this library you must INSTALL it as usual, and then add this line immediately before the opening bracket ([) of your assembler code:

Code:
ON ERROR LOCAL [OPT FN_asmext 

I have uploaded a test program demonstrating the use of the library:

http://groups.yahoo.com/group/bb4w/files/Libraries/ASMTEST4.BBC

Obviously you must be careful only to use these new instructions on processors which implement them; you can discover that using the CPUID instruction. This is particularly important if you intend to distribute programs for running on other computers!

There are a number of important caveats in the use of the ASMLIB library:

1. Q% is modified (this is in addition to the normal static variables used by the assembler: L%, O%, P%).

2. The new opcodes are accepted only in lower case.

3. Only one instruction per line can be used (this is not a fundamental restriction, but simplifies the library).

4. Code using the new opcodes cannot be crunched so when compiling code using ASMLIB you are recommended to place the relevant source code in a separate file which you execute using CALL. By giving that file an extension other than .BBC you can ensure it is not crunched.

Richard.
Re: New ASMLIB library
Post by David Williams on Jul 8th, 2009, 11:36pm

on Jul 8th, 2009, 3:02pm, Richard Russell wrote:
I have developed a new library, ASMLIB:

http://groups.yahoo.com/group/bb4w/files/Libraries/ASMLIB.BBC


Great! I've been after the CMOVcc instruction for ages (I think I may have once e-mailed you about it), and I definately once e-mailed you concerning SSE instructions. Can't wait to get stuck in...

Thanks smiley


David.
Re: New ASMLIB library
Post by Michael Hutton on Sep 26th, 2009, 4:31pm

I just need an eye cast on these definitions. I have tried to add to the ASMLIB

Code:
          WHEN "movdqu":  IF FN_sse(opt%,&F3,&6F,"movq",opr$,-1)
          WHEN "panda":   IF FN_sse(opt%,&66,&DB,"pand",opr$,-1)
          WHEN "pavgba":  IF FN_sse(opt%,&66,&E0,"pavgb",opr$,-1)
 


I've added an a to the pand and pavgba intructions because the ASMLIB doesn't seem to recognise them 'clean' ie pand and pavgb.

Do these definitions seem correct? I seem to be getting a fatal error with the panda and pavgba instructions. The movdqu *seems* to work..

Michael
Re: New ASMLIB library
Post by admin on Sep 26th, 2009, 10:04pm

Quote:
I just need an eye cast on these definitions. I have tried to add to the ASMLIB

movdqu, pand and pavgb (the latter two with the &66 prefix) are SSE2 instructions. ASMLIB doesn't attempt to implement any SSE2 instructions, largely for the reason you've discovered: since many of the instruction mnemonics are the same as MMX instructions (pand and pavgb are natively accepted by BB4W) the ASMLIB approach doesn't work.

It's not clear why you would want to add just three SSE2 instructions to ASMLIB anyway; unless you add them all the library would no longer be 'general-purpose'. If you happen to want to use those instructions in some specific piece of code you're writing simply encode them yourself using DBs!

Do remember, though, that if you incorporate SSE2 instructions you will need to change the test you make (using CPUID) to check that the processor supports them.

Code:
      WHEN "movdqu":  IF FN_sse(opt%,&F3,&6F,"movq",opr$,-1)
      WHEN "panda":   IF FN_sse(opt%,&66,&DB,"pand",opr$,-1)
      WHEN "pavgba":  IF FN_sse(opt%,&66,&E0,"pavgb",opr$,-1) 

You must have made more changes to ASMLIB than this, because in my version FN_sse takes only five parameters, not six!!

One final point: don't call your patched library ASMLIB; if you do it will be overwritten with the standard version when you install a later release of BB4W!

Richard.
Re: New ASMLIB library
Post by Michael Hutton on Sep 27th, 2009, 01:30am

Quote:
You must have made more changes to ASMLIB than this, because in my version FN_sse takes only five parameters, not six!!


I'm pretty sure the version I have this end is six! I'm using version 1.0, so I have probably missed an update. I will check again later today.

Code:
 DEF FN_sse(opt%, pre%, base%, opc$, opr$, suf%) 


I'll try just poking the bytes in as DB as you say. I haven't included the CPUID check yet but have that in mind. It makes me smile to hear people describe the mmx technology as 'legacy' or 'obsolete'!!

Thanks for the prompt reply as usual.

Michael
Re: New ASMLIB library
Post by admin on Sep 27th, 2009, 09:14am

Quote:
I'm pretty sure the version I have this end is six! I'm using version 1.0

The current version is 1.1 (which has been available for download from the usual place since July 9th).

This is another good reason not to create 'customised' versions of the standard libraries. When a library gets updated your version becomes obsolescent: you either have to carry on using it, risking what might be nasty bugs going uncorrected, or repeat your modifications on the later version.

Richard.