blob: 08e3a04be8a6b0ab75f78810f12937b2bed537a9 [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
114%define MMWORD qword ; int64 (MMX register)
115%define SIZEOF_MMWORD SIZEOF_QWORD ; sizeof(MMWORD)
116%define MMWORD_BIT QWORD_BIT ; sizeof(MMWORD)*BYTE_BIT
117
118%define SIZEOF_BYTE 1 ; sizeof(BYTE)
119%define SIZEOF_WORD 2 ; sizeof(WORD)
120%define SIZEOF_DWORD 4 ; sizeof(DWORD)
121%define SIZEOF_QWORD 8 ; sizeof(QWORD)
122
123%define BYTE_BIT 8 ; CHAR_BIT in C
124%define WORD_BIT 16 ; sizeof(WORD)*BYTE_BIT
125%define DWORD_BIT 32 ; sizeof(DWORD)*BYTE_BIT
126%define QWORD_BIT 64 ; sizeof(QWORD)*BYTE_BIT
127
Pierre Ossman82c7f312009-03-09 13:21:27 +0000128; --------------------------------------------------------------------------
129; External Symbol Name
130;
131%ifndef EXTN
132%define EXTN(name) _ %+ name ; foo() -> _foo
133%endif
134
135; --------------------------------------------------------------------------
136; Macros for position-independent code (PIC) support
137;
138%ifndef GOT_SYMBOL
139%undef PIC
140%endif
141
142%ifdef PIC ; -------------------------------------------
143
144%ifidn GOT_SYMBOL,_MACHO_PIC_ ; --------------------
145
146; At present, nasm doesn't seem to support PIC generation for Mach-O.
147; The PIC support code below is a little tricky.
148
149 SECTION SEG_CONST
150const_base:
151
152%define GOTOFF(got,sym) (got) + (sym) - const_base
153
154%imacro get_GOT 1
155 ; NOTE: this macro destroys ecx resister.
156 call %%geteip
157 add ecx, byte (%%ref - $)
158 jmp short %%adjust
159%%geteip:
160 mov ecx, POINTER [esp]
161 ret
162%%adjust:
163 push ebp
164 xor ebp,ebp ; ebp = 0
165%ifidni %1,ebx ; (%1 == ebx)
166 ; db 0x8D,0x9C + jmp near const_base =
167 ; lea ebx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,9C,E9,(offset32)
168 db 0x8D,0x9C ; 8D,9C
169 jmp near const_base ; E9,(const_base-%%ref)
170%%ref:
171%else ; (%1 != ebx)
172 ; db 0x8D,0x8C + jmp near const_base =
173 ; lea ecx, [ecx+ebp*8+(const_base-%%ref)] ; 8D,8C,E9,(offset32)
174 db 0x8D,0x8C ; 8D,8C
175 jmp near const_base ; E9,(const_base-%%ref)
176%%ref: mov %1, ecx
177%endif ; (%1 == ebx)
178 pop ebp
179%endmacro
180
181%else ; GOT_SYMBOL != _MACHO_PIC_ ----------------
182
183%define GOTOFF(got,sym) (got) + (sym) wrt ..gotoff
184
185%imacro get_GOT 1
186 extern GOT_SYMBOL
187 call %%geteip
188 add %1, GOT_SYMBOL + $$ - $ wrt ..gotpc
189 jmp short %%done
190%%geteip:
191 mov %1, POINTER [esp]
192 ret
193%%done:
194%endmacro
195
196%endif ; GOT_SYMBOL == _MACHO_PIC_ ----------------
197
198%imacro pushpic 1.nolist
199 push %1
200%endmacro
201%imacro poppic 1.nolist
202 pop %1
203%endmacro
204%imacro movpic 2.nolist
205 mov %1,%2
206%endmacro
207
208%else ; !PIC -----------------------------------------
209
210%define GOTOFF(got,sym) (sym)
211
212%imacro get_GOT 1.nolist
213%endmacro
214%imacro pushpic 1.nolist
215%endmacro
216%imacro poppic 1.nolist
217%endmacro
218%imacro movpic 2.nolist
219%endmacro
220
221%endif ; PIC -----------------------------------------
222
223; --------------------------------------------------------------------------
224; Align the next instruction on {2,4,8,16,..}-byte boundary.
225; ".balign n,,m" in GNU as
226;
227%define MSKLE(x,y) (~(((y) & 0xFFFF) - ((x) & 0xFFFF)) >> 16)
228%define FILLB(b,n) (($$-(b)) & ((n)-1))
229
230%imacro alignx 1-2.nolist 0xFFFF
231%%bs: times MSKLE(FILLB(%%bs,%1),%2) & MSKLE(16,FILLB($,%1)) & FILLB($,%1) \
232 db 0x90 ; nop
233 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/9 \
234 db 0x8D,0x9C,0x23,0x00,0x00,0x00,0x00 ; lea ebx,[ebx+0x00000000]
235 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/7 \
236 db 0x8D,0xAC,0x25,0x00,0x00,0x00,0x00 ; lea ebp,[ebp+0x00000000]
237 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/6 \
238 db 0x8D,0xAD,0x00,0x00,0x00,0x00 ; lea ebp,[ebp+0x00000000]
239 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/4 \
240 db 0x8D,0x6C,0x25,0x00 ; lea ebp,[ebp+0x00]
241 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/3 \
242 db 0x8D,0x6D,0x00 ; lea ebp,[ebp+0x00]
243 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/2 \
244 db 0x8B,0xED ; mov ebp,ebp
245 times MSKLE(FILLB(%%bs,%1),%2) & FILLB($,%1)/1 \
246 db 0x90 ; nop
247%endmacro
248
249; Align the next data on {2,4,8,16,..}-byte boundary.
250;
251%imacro alignz 1.nolist
252 align %1, db 0 ; filling zeros
253%endmacro
254
255
256; --------------------------------------------------------------------------
257; Defines picked up from the C headers
258;
259%include "simd/jsimdcfg.inc"
260
261; --------------------------------------------------------------------------