1#
2# Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# This code is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 2 only, as
7# published by the Free Software Foundation.  Oracle designates this
8# particular file as subject to the "Classpath" exception as provided
9# by Oracle in the LICENSE file that accompanied this code.
10#
11# This code is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14# version 2 for more details (a copy is included in the LICENSE file that
15# accompanied this code).
16#
17# You should have received a copy of the GNU General Public License version
18# 2 along with this work; if not, write to the Free Software Foundation,
19# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22# or visit www.oracle.com if you need additional information or have any
23# questions.
24#
25
26GENSRC_BUFFER :=
27
28GENSRC_BUFFER_DST := $(SUPPORT_OUTPUTDIR)/gensrc/java.base/java/nio
29
30GENSRC_BUFFER_SRC := $(JDK_TOPDIR)/src/java.base/share/classes/java/nio
31
32###
33
34$(GENSRC_BUFFER_DST)/_the.buffer.dir:
35	$(call LogInfo, Generating buffer classes)
36	$(call MakeDir, $(@D))
37	$(TOUCH) $@
38
39define fixRw
40  $1_RW := $2
41  $1_rwkey := rw
42  ifeq (R, $2)
43    $1_rwkey := ro
44  endif
45endef
46
47define typesAndBits
48  # param 1 target
49  # param 2 type
50  # param 3 BO
51  $1_a := a
52  $1_A := A
53
54  $1_type := $2
55
56  ifeq ($2, byte)
57    $1_x        := b
58    $1_Type     := Byte
59    $1_fulltype := byte
60    $1_Fulltype := Byte
61    $1_category := integralType
62    $1_LBPV     := 0
63  endif
64
65  ifeq ($2, char)
66    $1_x        := c
67    $1_Type     := Char
68    $1_fulltype := character
69    $1_Fulltype := Character
70    $1_category := integralType
71    $1_streams  := streamableType
72    $1_streamtype := int
73    $1_Streamtype := Int
74    $1_LBPV     := 1
75  endif
76
77  ifeq ($2, short)
78    $1_x        := s
79    $1_Type     := Short
80    $1_fulltype := short
81    $1_Fulltype := Short
82    $1_category := integralType
83    $1_LBPV     := 1
84  endif
85
86  ifeq ($2, int)
87    $1_a        := an
88    $1_A        := An
89    $1_x        := i
90    $1_Type     := Int
91    $1_fulltype := integer
92    $1_Fulltype := Integer
93    $1_category := integralType
94    $1_LBPV     := 2
95  endif
96
97  ifeq ($2, long)
98    $1_x        := l
99    $1_Type     := Long
100    $1_fulltype := long
101    $1_Fulltype := Long
102    $1_category := integralType
103    $1_LBPV     := 3
104  endif
105
106  ifeq ($2, float)
107    $1_x        := f
108    $1_Type     := Float
109    $1_fulltype := float
110    $1_Fulltype := Float
111    $1_category := floatingPointType
112    $1_LBPV     := 2
113  endif
114
115  ifeq ($2, double)
116    $1_x        := d
117    $1_Type     := Double
118    $1_fulltype := double
119    $1_Fulltype := Double
120    $1_category := floatingPointType
121    $1_LBPV     := 3
122  endif
123
124  $1_Swaptype := $$($1_Type)
125  $1_memtype := $2
126  $1_Memtype := $$($1_Type)
127
128  ifeq ($2, float)
129    $1_memtype := int
130    $1_Memtype := Int
131    ifneq ($3, U)
132      $1_Swaptype := Int
133      $1_fromBits := Float.intBitsToFloat
134      $1_toBits   := Float.floatToRawIntBits
135    endif
136  endif
137
138  ifeq ($2, double)
139    $1_memtype := long
140    $1_Memtype := Long
141    ifneq ($3, U)
142      $1_Swaptype := Long
143      $1_fromBits := Double.longBitsToDouble
144      $1_toBits   := Double.doubleToRawLongBits
145    endif
146  endif
147
148  ifeq ($3, S)
149    $1_swap := Bits.swap
150  endif
151endef
152
153define genBinOps
154  # param 1 target
155  # param 2 type
156  # param 3 BO
157  # param 4 RW
158  # param 5 nbytes
159  # param 6 nbytesButOne
160  $(call typesAndBits,$1,$2,$3)
161  $(call fixRw,$1,$4)
162  $1_nbytes := $5
163  $1_nbytesButOne := $6
164  $1_CMD := $(TOOL_SPP) \
165    -Dtype=$$($1_type) \
166    -DType=$$($1_Type) \
167    -Dfulltype=$$($1_fulltype) \
168    -Dmemtype=$$($1_memtype) \
169    -DMemtype=$$($1_Memtype) \
170    -DfromBits=$$($1_fromBits) \
171    -DtoBits=$$($1_toBits) \
172    -DLG_BYTES_PER_VALUE=$$($1_LBPV) \
173    -DBYTES_PER_VALUE="(1 << $$($1_LBPV))" \
174    -Dnbytes=$$($1_nbytes) \
175    -DnbytesButOne=$$($1_nbytesButOne) \
176    -DRW=$$($1_RW) \
177    -K$$($1_rwkey) \
178    -Da=$$($1_a) \
179    -be
180endef
181
182define SetupGenBuffer
183  # param 1 is for output file
184  # param 2 is template dependency
185  # param 3-9 are named args.
186  #   type :=
187  #   BIN :=
188  #   RW := Mutability (R)ead-only (W)ritable
189  #   BO := (U)nswapped/(S)wapped/(L)ittle/(B)ig
190  #
191  $(if $3,$1_$(strip $3))
192  $(if $4,$1_$(strip $4))
193  $(if $5,$1_$(strip $5))
194  $(if $6,$1_$(strip $6))
195  $(if $7,$1_$(strip $7))
196  $(if $8,$1_$(strip $8))
197  $(if $9,$1_$(strip $9))
198  $(if $(10),$1_$(strip $(10)))
199  $(if $(11),$1_$(strip $(11)))
200  $(if $(12),$1_$(strip $(12)))
201  $(if $(13),$1_$(strip $(13)))
202  $(if $(14),$1_$(strip $(14)))
203  $(foreach i,3 4 5 6 7 8 9 10 11 12 13 14 15,$(if $($i),$1_$(strip $($i)))$(NEWLINE))
204  $(call LogSetupMacroEntry,SetupGenBuffer($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15))
205  $(if $(16),$(error Internal makefile error: Too many arguments to SetupGenBuffer, please update GensrcBuffer.gmk))
206
207  $(call fixRw,$1,$$($1_RW))
208  $(call typesAndBits,$1,$$($1_type),$$($1_BO))
209
210  $1_DST := $(GENSRC_BUFFER_DST)/$1.java
211  $1_SRC := $(GENSRC_BUFFER_SRC)/$(strip $2).java.template
212  $1_SRC_BIN := $(GENSRC_BUFFER_SRC)/$(strip $2)-bin.java.template
213
214  $1_DEP := $$($1_SRC)
215  ifneq ($$($1_BIN), 1)
216    $1_DEP := $$($1_SRC)
217    $1_OUT := $$($1_DST)
218  else
219    $1_DEP += $$($1_SRC) $$($1_SRC_BIN)
220    $1_OUT := $(GENSRC_BUFFER_DST)/$1.binop.0.java
221  endif
222
223  ifeq ($$($1_BIN), 1)
224    $(call genBinOps,$1_char,char,$$($1_BO),$$($1_RW),two,one)
225    $(call genBinOps,$1_short,short,$$($1_BO),$$($1_RW),two,one)
226    $(call genBinOps,$1_int,int,$$($1_BO),$$($1_RW),four,three)
227    $(call genBinOps,$1_long,long,$$($1_BO),$$($1_RW),eight,seven)
228    $(call genBinOps,$1_float,float,$$($1_BO),$$($1_RW),four,three)
229    $(call genBinOps,$1_double,double,$$($1_BO),$$($1_RW),eight,seven)
230  endif
231
232  $$($1_DST): $$($1_DEP) $(GENSRC_BUFFER_DST)/_the.buffer.dir
233	$(TOOL_SPP) < $$($1_SRC) > $$($1_OUT).tmp \
234	    -K$$($1_type) \
235	    -K$$($1_category) \
236	    -K$$($1_streams) \
237	    -Dtype=$$($1_type) \
238	    -DType=$$($1_Type) \
239	    -Dfulltype=$$($1_fulltype) \
240	    -DFulltype=$$($1_Fulltype) \
241	    -Dstreamtype=$$($1_streamtype) \
242	    -DStreamtype=$$($1_Streamtype) \
243	    -Dx=$$($1_x) \
244	    -Dmemtype=$$($1_memtype) \
245	    -DMemtype=$$($1_Memtype) \
246	    -DSwaptype=$$($1_Swaptype) \
247	    -DfromBits=$$($1_fromBits) \
248	    -DtoBits=$$($1_toBits) \
249	    -DLG_BYTES_PER_VALUE=$$($1_LBPV) \
250	    -DBYTES_PER_VALUE="(1 << $$($1_LBPV))" \
251	    -DBO=$$($1_BO) \
252	    -Dswap=$$($1_swap) \
253	    -DRW=$$($1_RW) \
254	    -K$$($1_rwkey) \
255	    -Da=$$($1_a) \
256	    -DA=$$($1_A) \
257	    -Kbo$$($1_BO)
258	$(MV) $$($1_OUT).tmp $$($1_OUT)
259        # Do the extra bin thing
260        ifeq ($$($1_BIN), 1)
261	  $(SED) -e '/#BIN/,$$$$d' < $$($1_OUT) > $$($1_DST).tmp
262	  $(RM) $$($1_OUT)
263	  $$($1_char_CMD) < $$($1_SRC_BIN) >> $$($1_DST).tmp
264	  $$($1_short_CMD) < $$($1_SRC_BIN) >> $$($1_DST).tmp
265	  $$($1_int_CMD) < $$($1_SRC_BIN) >> $$($1_DST).tmp
266	  $$($1_long_CMD) < $$($1_SRC_BIN) >> $$($1_DST).tmp
267	  $$($1_float_CMD) < $$($1_SRC_BIN) >> $$($1_DST).tmp
268	  $$($1_double_CMD) < $$($1_SRC_BIN) >> $$($1_DST).tmp
269	  $(PRINTF) "}\n" >> $$($1_DST).tmp
270	  mv $$($1_DST).tmp $$($1_DST)
271        endif
272
273  GENSRC_BUFFER += $$($1_DST)
274
275endef
276
277###
278
279X_BUF := X-Buffer
280
281$(eval $(call SetupGenBuffer,ByteBuffer,  $(X_BUF), type:=byte, BIN:=1))
282$(eval $(call SetupGenBuffer,CharBuffer,  $(X_BUF), type:=char))
283$(eval $(call SetupGenBuffer,ShortBuffer, $(X_BUF), type:=short))
284$(eval $(call SetupGenBuffer,IntBuffer,   $(X_BUF), type:=int))
285$(eval $(call SetupGenBuffer,LongBuffer,  $(X_BUF), type:=long))
286$(eval $(call SetupGenBuffer,FloatBuffer, $(X_BUF), type:=float))
287$(eval $(call SetupGenBuffer,DoubleBuffer,$(X_BUF), type:=double))
288
289# Buffers whose contents are heap-allocated
290#
291HEAP_X_BUF := Heap-X-Buffer
292
293$(eval $(call SetupGenBuffer,HeapByteBuffer,   $(HEAP_X_BUF), type:=byte))
294$(eval $(call SetupGenBuffer,HeapByteBufferR,  $(HEAP_X_BUF), type:=byte, RW:=R))
295$(eval $(call SetupGenBuffer,HeapCharBuffer,   $(HEAP_X_BUF), type:=char))
296$(eval $(call SetupGenBuffer,HeapCharBufferR,  $(HEAP_X_BUF), type:=char, RW:=R))
297$(eval $(call SetupGenBuffer,HeapShortBuffer,  $(HEAP_X_BUF), type:=short))
298$(eval $(call SetupGenBuffer,HeapShortBufferR, $(HEAP_X_BUF), type:=short, RW:=R))
299$(eval $(call SetupGenBuffer,HeapIntBuffer,    $(HEAP_X_BUF), type:=int))
300$(eval $(call SetupGenBuffer,HeapIntBufferR,   $(HEAP_X_BUF), type:=int, RW:=R))
301$(eval $(call SetupGenBuffer,HeapLongBuffer,   $(HEAP_X_BUF), type:=long))
302$(eval $(call SetupGenBuffer,HeapLongBufferR,  $(HEAP_X_BUF), type:=long, RW:=R))
303$(eval $(call SetupGenBuffer,HeapFloatBuffer,  $(HEAP_X_BUF), type:=float))
304$(eval $(call SetupGenBuffer,HeapFloatBufferR, $(HEAP_X_BUF), type:=float, RW:=R))
305$(eval $(call SetupGenBuffer,HeapDoubleBuffer, $(HEAP_X_BUF), type:=double))
306$(eval $(call SetupGenBuffer,HeapDoubleBufferR,$(HEAP_X_BUF), type:=double, RW:=R))
307
308# Direct byte buffer
309#
310DIRECT_X_BUF := Direct-X-Buffer
311
312$(eval $(call SetupGenBuffer,DirectByteBuffer, $(DIRECT_X_BUF), type:=byte, BIN:=1))
313$(eval $(call SetupGenBuffer,DirectByteBufferR,$(DIRECT_X_BUF), type:=byte, BIN:=1, RW:=R))
314
315# Unswapped views of direct byte buffers
316#
317$(eval $(call SetupGenBuffer,DirectCharBufferU,   $(DIRECT_X_BUF), type:=char, BO:=U))
318$(eval $(call SetupGenBuffer,DirectCharBufferRU,  $(DIRECT_X_BUF), type:=char, RW:=R, BO:=U))
319$(eval $(call SetupGenBuffer,DirectShortBufferU,  $(DIRECT_X_BUF), type:=short, BO:=U))
320$(eval $(call SetupGenBuffer,DirectShortBufferRU, $(DIRECT_X_BUF), type:=short, RW:=R, BO:=U))
321$(eval $(call SetupGenBuffer,DirectIntBufferU,    $(DIRECT_X_BUF), type:=int, BO:=U))
322$(eval $(call SetupGenBuffer,DirectIntBufferRU,   $(DIRECT_X_BUF), type:=int, RW:=R, BO:=U))
323$(eval $(call SetupGenBuffer,DirectLongBufferU,   $(DIRECT_X_BUF), type:=long, BO:=U))
324$(eval $(call SetupGenBuffer,DirectLongBufferRU,  $(DIRECT_X_BUF), type:=long, RW:=R, BO:=U))
325$(eval $(call SetupGenBuffer,DirectFloatBufferU,  $(DIRECT_X_BUF), type:=float, BO:=U))
326$(eval $(call SetupGenBuffer,DirectFloatBufferRU, $(DIRECT_X_BUF), type:=float, RW:=R, BO:=U))
327$(eval $(call SetupGenBuffer,DirectDoubleBufferU, $(DIRECT_X_BUF), type:=double, BO:=U))
328$(eval $(call SetupGenBuffer,DirectDoubleBufferRU,$(DIRECT_X_BUF), type:=double, RW:=R, BO:=U))
329
330# Swapped views of direct byte buffers
331#
332$(eval $(call SetupGenBuffer,DirectCharBufferS,   $(DIRECT_X_BUF), type:=char, BO:=S))
333$(eval $(call SetupGenBuffer,DirectCharBufferRS,  $(DIRECT_X_BUF), type:=char, RW:=R, BO:=S))
334$(eval $(call SetupGenBuffer,DirectShortBufferS,  $(DIRECT_X_BUF), type:=short, BO:=S))
335$(eval $(call SetupGenBuffer,DirectShortBufferRS, $(DIRECT_X_BUF), type:=short, RW:=R, BO:=S))
336$(eval $(call SetupGenBuffer,DirectIntBufferS,    $(DIRECT_X_BUF), type:=int, BO:=S))
337$(eval $(call SetupGenBuffer,DirectIntBufferRS,   $(DIRECT_X_BUF), type:=int, RW:=R, BO:=S))
338$(eval $(call SetupGenBuffer,DirectLongBufferS,   $(DIRECT_X_BUF), type:=long, BO:=S))
339$(eval $(call SetupGenBuffer,DirectLongBufferRS,  $(DIRECT_X_BUF), type:=long, RW:=R, BO:=S))
340$(eval $(call SetupGenBuffer,DirectFloatBufferS,  $(DIRECT_X_BUF), type:=float, BO:=S))
341$(eval $(call SetupGenBuffer,DirectFloatBufferRS, $(DIRECT_X_BUF), type:=float, RW:=R, BO:=S))
342$(eval $(call SetupGenBuffer,DirectDoubleBufferS, $(DIRECT_X_BUF), type:=double, BO:=S))
343$(eval $(call SetupGenBuffer,DirectDoubleBufferRS,$(DIRECT_X_BUF), type:=double, RW:=R, BO:=S))
344
345# Big-endian views of byte buffers
346#
347BYTE_X_BUF := ByteBufferAs-X-Buffer
348
349$(eval $(call SetupGenBuffer,ByteBufferAsCharBufferB,   $(BYTE_X_BUF), type:=char, BO:=B))
350$(eval $(call SetupGenBuffer,ByteBufferAsCharBufferRB,  $(BYTE_X_BUF), type:=char, RW:=R, BO:=B))
351$(eval $(call SetupGenBuffer,ByteBufferAsShortBufferB,  $(BYTE_X_BUF), type:=short, BO:=B))
352$(eval $(call SetupGenBuffer,ByteBufferAsShortBufferRB, $(BYTE_X_BUF), type:=short, RW:=R, BO:=B))
353$(eval $(call SetupGenBuffer,ByteBufferAsIntBufferB,    $(BYTE_X_BUF), type:=int, BO:=B))
354$(eval $(call SetupGenBuffer,ByteBufferAsIntBufferRB,   $(BYTE_X_BUF), type:=int, RW:=R, BO:=B))
355$(eval $(call SetupGenBuffer,ByteBufferAsLongBufferB,   $(BYTE_X_BUF), type:=long, BO:=B))
356$(eval $(call SetupGenBuffer,ByteBufferAsLongBufferRB,  $(BYTE_X_BUF), type:=long, RW:=R, BO:=B))
357$(eval $(call SetupGenBuffer,ByteBufferAsFloatBufferB,  $(BYTE_X_BUF), type:=float, BO:=B))
358$(eval $(call SetupGenBuffer,ByteBufferAsFloatBufferRB, $(BYTE_X_BUF), type:=float, RW:=R, BO:=B))
359$(eval $(call SetupGenBuffer,ByteBufferAsDoubleBufferB, $(BYTE_X_BUF), type:=double, BO:=B))
360$(eval $(call SetupGenBuffer,ByteBufferAsDoubleBufferRB,$(BYTE_X_BUF), type:=double, RW:=R, BO:=B))
361
362# Little-endian views of byte buffers
363#
364$(eval $(call SetupGenBuffer,ByteBufferAsCharBufferL,   $(BYTE_X_BUF), type:=char, BO:=L))
365$(eval $(call SetupGenBuffer,ByteBufferAsCharBufferRL,  $(BYTE_X_BUF), type:=char, RW:=R, BO:=L))
366$(eval $(call SetupGenBuffer,ByteBufferAsShortBufferL,  $(BYTE_X_BUF), type:=short, BO:=L))
367$(eval $(call SetupGenBuffer,ByteBufferAsShortBufferRL, $(BYTE_X_BUF), type:=short, RW:=R, BO:=L))
368$(eval $(call SetupGenBuffer,ByteBufferAsIntBufferL,    $(BYTE_X_BUF), type:=int, BO:=L))
369$(eval $(call SetupGenBuffer,ByteBufferAsIntBufferRL,   $(BYTE_X_BUF), type:=int, RW:=R, BO:=L))
370$(eval $(call SetupGenBuffer,ByteBufferAsLongBufferL,   $(BYTE_X_BUF), type:=long, BO:=L))
371$(eval $(call SetupGenBuffer,ByteBufferAsLongBufferRL,  $(BYTE_X_BUF), type:=long, RW:=R, BO:=L))
372$(eval $(call SetupGenBuffer,ByteBufferAsFloatBufferL,  $(BYTE_X_BUF), type:=float, BO:=L))
373$(eval $(call SetupGenBuffer,ByteBufferAsFloatBufferRL, $(BYTE_X_BUF), type:=float, RW:=R, BO:=L))
374$(eval $(call SetupGenBuffer,ByteBufferAsDoubleBufferL, $(BYTE_X_BUF), type:=double, BO:=L))
375$(eval $(call SetupGenBuffer,ByteBufferAsDoubleBufferRL,$(BYTE_X_BUF), type:=double, RW:=R, BO:=L))
376
377###
378
379$(GENSRC_BUFFER): $(BUILD_TOOLS_JDK)
380GENSRC_JAVA_BASE += $(GENSRC_BUFFER)
381