blob: 5fcd7be2ea46f9572f8444009ce7e284082e3acc [file] [log] [blame]
Pierre Ossman82c7f312009-03-09 13:21:27 +00001;
2; jsimdext.inc - common declarations
3;
4; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5;
6; Based on
7; x86 SIMD extension for IJG JPEG library - version 1.02
8;
9; Copyright (C) 1999-2006, MIYASAKA Masaru.
10;
11; This software is provided 'as-is', without any express or implied
12; warranty. In no event will the authors be held liable for any damages
13; arising from the use of this software.
14;
15; Permission is granted to anyone to use this software for any purpose,
16; including commercial applications, and to alter it and redistribute it
17; freely, subject to the following restrictions:
18;
19; 1. The origin of this software must not be misrepresented; you must not
20; claim that you wrote the original software. If you use this software
21; in a product, an acknowledgment in the product documentation would be
22; appreciated but is not required.
23; 2. Altered source versions must be plainly marked as such, and must not be
24; misrepresented as being the original software.
25; 3. This notice may not be removed or altered from any source distribution.
26;
27; [TAB8]
28
29; ==========================================================================
30; System-dependent configurations
31
32%ifdef WIN32 ; ----(nasm -fwin32 -DWIN32 ...)--------
33; * Microsoft Visual C++
34; * MinGW (Minimalist GNU for Windows)
35; * CygWin
36; * LCC-Win32
37
38; -- segment definition --
39;
40%define SEG_TEXT .text align=16 public use32 class=CODE
41%define SEG_CONST .rdata align=16 public use32 class=CONST
42
43%elifdef OBJ32 ; ----(nasm -fobj -DOBJ32 ...)----------
44; * Borland C++ (Win32)
45
46; -- segment definition --
47;
48%define SEG_TEXT .text align=16 public use32 class=CODE
49%define SEG_CONST .data align=16 public use32 class=DATA
50
51%elifdef ELF ; ----(nasm -felf -DELF ...)------------
52; * Linux
53; * *BSD family Unix using elf format
54; * Unix System V, including Solaris x86, UnixWare and SCO Unix
55
56; -- segment definition --
57;
58%define SEG_TEXT .text progbits alloc exec nowrite align=16
59%define SEG_CONST .rodata progbits alloc noexec nowrite align=16
60
61; To make the code position-independent, append -DPIC to the commandline
62;
63%define GOT_SYMBOL _GLOBAL_OFFSET_TABLE_ ; ELF supports PIC
64%define EXTN(name) name ; foo() -> foo
65
66%elifdef AOUT ; ----(nasm -faoutb/aout -DAOUT ...)----
67; * Older Linux using a.out format (nasm -f aout -DAOUT ...)
68; * *BSD family Unix using a.out format (nasm -f aoutb -DAOUT ...)
69
70; -- segment definition --
71;
72%define SEG_TEXT .text
73%define SEG_CONST .data
74
75; To make the code position-independent, append -DPIC to the commandline
76;
77%define GOT_SYMBOL __GLOBAL_OFFSET_TABLE_ ; BSD-style a.out supports PIC
78
79%elifdef MACHO ; ----(nasm -fmacho -DMACHO ...)--------
80; * NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (Mach-O format)
81
82; -- segment definition --
83;
84%define SEG_TEXT .text ;align=16 ; nasm doesn't accept align=16. why?
85%define SEG_CONST .rodata align=16
86
87; The generation of position-independent code (PIC) is the default on Darwin.
88;
89%define PIC
90%define GOT_SYMBOL _MACHO_PIC_ ; Mach-O style code-relative addressing
91
92%else ; ----(Other case)----------------------
93
94; -- segment definition --
95;
96%define SEG_TEXT .text
97%define SEG_CONST .data
98
99%endif ; ----------------------------------------------
100
101; ==========================================================================
102
103; --------------------------------------------------------------------------
104; Common types
105;
106%define POINTER dword ; general pointer type
107%define SIZEOF_POINTER SIZEOF_DWORD ; sizeof(POINTER)
108%define POINTER_BIT DWORD_BIT ; sizeof(POINTER)*BYTE_BIT
109
Pierre Ossman3e0e2de2009-03-09 13:25:30 +0000110%define INT dword ; signed integer type
111%define SIZEOF_INT SIZEOF_DWORD ; sizeof(INT)
112%define INT_BIT DWORD_BIT ; sizeof(INT)*BYTE_BIT
113
Pierre Ossman2c2e54b2009-03-09 13:28:10 +0000114%define FP32 dword ; IEEE754 single
115%define SIZEOF_FP32 SIZEOF_DWORD ; sizeof(FP32)
116%define FP32_BIT DWORD_BIT ; sizeof(FP32)*BYTE_BIT
117
Pierre Ossman3e0e2de2009-03-09 13:25:30 +0000118%define MMWORD qword ; int64 (MMX register)
119%define SIZEOF_MMWORD SIZEOF_QWORD ; sizeof(MMWORD)
120%define MMWORD_BIT QWORD_BIT ; sizeof(MMWORD)*BYTE_BIT
121
Pierre Ossman0d37c572009-03-09 13:31:56 +0000122; NASM is buggy and doesn't properly handle operand sizes for SSE
123; instructions, so for now we have to define XMMWORD as blank.
124%define XMMWORD ; int128 (SSE register)
125%define SIZEOF_XMMWORD SIZEOF_OWORD ; sizeof(XMMWORD)
126%define XMMWORD_BIT OWORD_BIT ; sizeof(XMMWORD)*BYTE_BIT
127
Pierre Ossman3e0e2de2009-03-09 13:25:30 +0000128%define SIZEOF_BYTE 1 ; sizeof(BYTE)
129%define SIZEOF_WORD 2 ; sizeof(WORD)
130%define SIZEOF_DWORD 4 ; sizeof(DWORD)
131%define SIZEOF_QWORD 8 ; sizeof(QWORD)
Pierre Ossman0d37c572009-03-09 13:31:56 +0000132%define SIZEOF_OWORD 16 ; sizeof(OWORD)
Pierre Ossman3e0e2de2009-03-09 13:25:30 +0000133
134%define BYTE_BIT 8 ; CHAR_BIT in C
135%define WORD_BIT 16 ; sizeof(WORD)*BYTE_BIT
136%define DWORD_BIT 32 ; sizeof(DWORD)*BYTE_BIT
137%define QWORD_BIT 64 ; sizeof(QWORD)*BYTE_BIT
Pierre Ossman0d37c572009-03-09 13:31:56 +0000138%define OWORD_BIT 128 ; sizeof(OWORD)*BYTE_BIT
Pierre Ossman3e0e2de2009-03-09 13:25:30 +0000139
Pierre Ossman82c7f312009-03-09 13:21:27 +0000140; --------------------------------------------------------------------------
141; External Symbol Name
142;
143%ifndef EXTN
144%define EXTN(name) _ %+ name ; foo() -> _foo
145%endif
146
147; --------------------------------------------------------------------------
148; Macros for position-independent code (PIC) support
149;
150%ifndef GOT_SYMBOL
151%undef PIC
152%endif
153
154%ifdef PIC ; -------------------------------------------
155
156%ifidn GOT_SYMBOL,_MACHO_PIC_ ; --------------------
157
158; At present, nasm doesn't seem to support PIC generation for Mach-O.
159; The PIC support code below is a little tricky.
160
161 SECTION SEG_CONST
162const_base:
163
164%define GOTOFF(got,sym) (got) + (sym) - const_base
165
166%imacro get_GOT 1
167 ; NOTE: this macro destroys ecx resister.
168 call %%geteip
169 add ecx, byte (%%ref - $)
170 jmp short %%adjust
171%%geteip:
172 mov ecx, POINTER [esp]
173 ret
174%%adjust:
175 push ebp
176 xor ebp,ebp ; ebp = 0
177%ifidni %1,ebx ; (%1 == ebx)
178 ; db 0x8D,0x9C + jmp near const_base =
179 ; lea ebx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,9C,E9,(offset32)
180 db 0x8D,0x9C ; 8D,9C
181 jmp near const_base ; E9,(const_base-%%ref)
182%%ref:
183%else ; (%1 != ebx)
184 ; db 0x8D,0x8C + jmp near const_base =
185 ; lea ecx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,8C,E9,(offset32)
186 db 0x8D,0x8C ; 8D,8C
187 jmp near const_base ; E9,(const_base-%%ref)
188%%ref: mov %1, ecx
189%endif ; (%1 == ebx)
190 pop ebp
191%endmacro
192
193%else ; GOT_SYMBOL != _MACHO_PIC_ ----------------
194
195%define GOTOFF(got,sym) (got) + (sym) wrt ..gotoff
196
197%imacro get_GOT 1
198 extern GOT_SYMBOL
199 call %%geteip
200 add %1, GOT_SYMBOL + $$ - $ wrt ..gotpc
201 jmp short %%done
202%%geteip:
203 mov %1, POINTER [esp]
204 ret
205%%done:
206%endmacro
207
208%endif ; GOT_SYMBOL == _MACHO_PIC_ ----------------
209
210%imacro pushpic 1.nolist
211 push %1
212%endmacro
213%imacro poppic 1.nolist
214 pop %1
215%endmacro
216%imacro movpic 2.nolist
217 mov %1,%2
218%endmacro
219
220%else ; !PIC -----------------------------------------
221
222%define GOTOFF(got,sym) (sym)
223
224%imacro get_GOT 1.nolist
225%endmacro
226%imacro pushpic 1.nolist
227%endmacro
228%imacro poppic 1.nolist
229%endmacro
230%imacro movpic 2.nolist
231%endmacro
232
233%endif ; PIC -----------------------------------------
234
235; --------------------------------------------------------------------------
236; Align the next instruction on {2,4,8,16,..}-byte boundary.
237; ".balign n,,m" in GNU as
238;
239%define MSKLE(x,y) (~(((y) & 0xFFFF) - ((x) & 0xFFFF)) >> 16)
240%define FILLB(b,n) (($$-(b)) & ((n)-1))
241
242%imacro alignx 1-2.nolist 0xFFFF
243%%bs: times MSKLE(FILLB(%%bs,%1),%2) & MSKLE(16,FILLB($,%1)) & FILLB($,%1) \
244 db 0x90 ; nop
245 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/9 \
246 db 0x8D,0x9C,0x23,0x00,0x00,0x00,0x00 ; lea ebx,[ebx+0x00000000]
247 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/7 \
248 db 0x8D,0xAC,0x25,0x00,0x00,0x00,0x00 ; lea ebp,[ebp+0x00000000]
249 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/6 \
250 db 0x8D,0xAD,0x00,0x00,0x00,0x00 ; lea ebp,[ebp+0x00000000]
251 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/4 \
252 db 0x8D,0x6C,0x25,0x00 ; lea ebp,[ebp+0x00]
253 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/3 \
254 db 0x8D,0x6D,0x00 ; lea ebp,[ebp+0x00]
255 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/2 \
256 db 0x8B,0xED ; mov ebp,ebp
257 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/1 \
258 db 0x90 ; nop
259%endmacro
260
261; Align the next data on {2,4,8,16,..}-byte boundary.
262;
263%imacro alignz 1.nolist
264 align %1, db 0 ; filling zeros
265%endmacro
266
267
268; --------------------------------------------------------------------------
269; Defines picked up from the C headers
270;
271%include "simd/jsimdcfg.inc"
272
273; --------------------------------------------------------------------------