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