8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / efcode / engine / prims64.c
blob7a4f7fa9d1716bcde17a27553b8d415a26bd19bc
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <fcode/private.h>
33 #include <fcdriver/fcdriver.h>
35 #define LF_PER_XF (sizeof (xforth_t)/sizeof (lforth_t))
36 #define WF_PER_XF (sizeof (xforth_t)/sizeof (wforth_t))
38 void unaligned_xfetch(fcode_env_t *);
39 void unaligned_xstore(fcode_env_t *);
40 static void xbsplit(fcode_env_t *);
42 xforth_t
43 pop_xforth(fcode_env_t *env)
45 if (sizeof (xforth_t) == sizeof (fstack_t))
46 return (POP(DS));
47 return ((xforth_t)pop_double(env));
50 xforth_t
51 peek_xforth(fcode_env_t *env)
53 xforth_t d;
55 d = pop_xforth(env);
56 push_xforth(env, d);
57 return (d);
60 void
61 push_xforth(fcode_env_t *env, xforth_t a)
63 if (sizeof (xforth_t) == sizeof (fstack_t))
64 PUSH(DS, a);
65 else
66 push_double(env, (dforth_t)a);
70 * bxjoin ( b.lo b.2 b.3 b.4 b.5 b.6 b.7 b.hi -- o )
72 static void
73 bxjoin(fcode_env_t *env)
75 union {
76 uchar_t b_bytes[sizeof (xforth_t)];
77 xforth_t b_xf;
78 } b;
79 int i;
81 CHECK_DEPTH(env, sizeof (xforth_t), "bxjoin");
82 for (i = 0; i < sizeof (xforth_t); i++)
83 b.b_bytes[i] = POP(DS);
84 push_xforth(env, b.b_xf);
88 * <l@ ( qaddr -- n )
90 static void
91 lsfetch(fcode_env_t *env)
93 s_lforth_t *addr;
94 xforth_t a;
96 CHECK_DEPTH(env, 1, "<l@");
97 addr = (s_lforth_t *)POP(DS);
98 a = *addr;
99 push_xforth(env, a);
103 * lxjoin ( quad.lo quad.hi -- o )
105 static void
106 lxjoin(fcode_env_t *env)
108 union {
109 lforth_t b_lf[LF_PER_XF];
110 xforth_t b_xf;
111 } b;
112 int i;
114 CHECK_DEPTH(env, LF_PER_XF, "lxjoin");
115 for (i = 0; i < LF_PER_XF; i++)
116 b.b_lf[i] = POP(DS);
117 push_xforth(env, b.b_xf);
121 * wxjoin ( w.lo w.2 w.3 w.hi -- o )
123 static void
124 wxjoin(fcode_env_t *env)
126 union {
127 wforth_t b_wf[WF_PER_XF];
128 xforth_t b_xf;
129 } b;
130 int i;
132 CHECK_DEPTH(env, WF_PER_XF, "wxjoin");
133 for (i = 0; i < WF_PER_XF; i++)
134 b.b_wf[i] = POP(DS);
135 push_xforth(env, b.b_xf);
139 * x, ( o -- )
141 static void
142 xcomma(fcode_env_t *env)
144 CHECK_DEPTH(env, 1, "x,");
145 DEBUGF(COMMA, dump_comma(env, "x,"));
146 PUSH(DS, (fstack_t)HERE);
147 unaligned_xstore(env);
148 set_here(env, HERE + sizeof (xforth_t), "xcomma");
152 * x@ ( xaddr -- o )
154 void
155 xfetch(fcode_env_t *env)
157 xforth_t *addr;
158 xforth_t a;
160 CHECK_DEPTH(env, 1, "x@");
161 addr = (xforth_t *)POP(DS);
162 a = *addr;
163 push_xforth(env, a);
167 * x! ( o xaddr -- )
169 void
170 xstore(fcode_env_t *env)
172 xforth_t *addr;
173 xforth_t a;
175 CHECK_DEPTH(env, 2, "x!");
176 addr = (xforth_t *)POP(DS);
177 a = pop_xforth(env);
178 *addr = a;
182 * /x ( -- n )
184 static void
185 slash_x(fcode_env_t *env)
187 PUSH(DS, sizeof (xforth_t));
191 * /x* ( nu1 -- nu2 )
193 static void
194 slash_x_times(fcode_env_t *env)
196 CHECK_DEPTH(env, 1, "/x*");
197 TOS *= sizeof (xforth_t);
201 * xa+ ( addr1 index -- addr2 )
203 static void
204 xa_plus(fcode_env_t *env)
206 fstack_t index;
208 CHECK_DEPTH(env, 2, "xa+");
209 index = POP(DS);
210 TOS += index * sizeof (xforth_t);
214 * xa1+ ( addr1 -- addr2 )
216 static void
217 xa_one_plus(fcode_env_t *env)
219 CHECK_DEPTH(env, 1, "xa1+");
220 TOS += sizeof (xforth_t);
224 * xbflip ( oct1 -- oct2 )
226 void
227 xbflip(fcode_env_t *env)
229 union {
230 uchar_t b_bytes[sizeof (xforth_t)];
231 xforth_t b_xf;
232 } b, c;
233 int i;
235 CHECK_DEPTH(env, 1, "xbflip");
236 b.b_xf = pop_xforth(env);
237 for (i = 0; i < sizeof (xforth_t); i++)
238 c.b_bytes[i] = b.b_bytes[(sizeof (xforth_t) - 1) - i];
239 push_xforth(env, c.b_xf);
242 void
243 unaligned_xfetch(fcode_env_t *env)
245 fstack_t addr;
246 int i;
248 CHECK_DEPTH(env, 1, "unaligned-x@");
249 addr = POP(DS);
250 for (i = 0; i < sizeof (xforth_t); i++, addr++) {
251 PUSH(DS, addr);
252 cfetch(env);
254 bxjoin(env);
255 xbflip(env);
258 void
259 unaligned_xstore(fcode_env_t *env)
261 fstack_t addr;
262 int i;
264 CHECK_DEPTH(env, 2, "unaligned-x!");
265 addr = POP(DS);
266 xbsplit(env);
267 for (i = 0; i < sizeof (xforth_t); i++, addr++) {
268 PUSH(DS, addr);
269 cstore(env);
274 * xbflips ( xaddr len -- )
276 static void
277 xbflips(fcode_env_t *env)
279 fstack_t len, addr;
280 int i;
282 CHECK_DEPTH(env, 2, "xbflips");
283 len = POP(DS);
284 addr = POP(DS);
285 for (i = 0; i < len; i += sizeof (xforth_t),
286 addr += sizeof (xforth_t)) {
287 PUSH(DS, addr);
288 unaligned_xfetch(env);
289 xbflip(env);
290 PUSH(DS, addr);
291 unaligned_xstore(env);
296 * xbsplit ( o -- b.lo b.2 b.3 b.4 b.5 b.6 b.7 b.hi )
298 static void
299 xbsplit(fcode_env_t *env)
301 union {
302 uchar_t b_bytes[sizeof (xforth_t)];
303 xforth_t b_xf;
304 } b;
305 int i;
307 CHECK_DEPTH(env, 1, "xbsplit");
308 b.b_xf = pop_xforth(env);
309 for (i = 0; i < sizeof (xforth_t); i++)
310 PUSH(DS, b.b_bytes[(sizeof (xforth_t) - 1) - i]);
314 * xlflip ( oct1 -- oct2 )
316 void
317 xlflip(fcode_env_t *env)
319 union {
320 lforth_t b_lf[LF_PER_XF];
321 xforth_t b_xf;
322 } b, c;
323 int i;
325 CHECK_DEPTH(env, 1, "xlflip");
326 b.b_xf = pop_xforth(env);
327 for (i = 0; i < LF_PER_XF; i++)
328 c.b_lf[i] = b.b_lf[(LF_PER_XF - 1) - i];
329 push_xforth(env, c.b_xf);
333 * xlflips ( xaddr len -- )
335 static void
336 xlflips(fcode_env_t *env)
338 fstack_t len, addr;
339 int i;
341 CHECK_DEPTH(env, 2, "xlflips");
342 len = POP(DS);
343 addr = POP(DS);
344 for (i = 0; i < len; i += sizeof (xforth_t),
345 addr += sizeof (xforth_t)) {
346 PUSH(DS, addr);
347 unaligned_xfetch(env);
348 xlflip(env);
349 PUSH(DS, addr);
350 unaligned_xstore(env);
355 * xlsplit ( o -- quad.lo quad.hi )
357 static void
358 xlsplit(fcode_env_t *env)
360 union {
361 lforth_t b_lf[LF_PER_XF];
362 xforth_t b_xf;
363 } b;
364 int i;
366 CHECK_DEPTH(env, 1, "xlsplit");
367 b.b_xf = pop_xforth(env);
368 for (i = 0; i < LF_PER_XF; i++)
369 PUSH(DS, b.b_lf[(LF_PER_XF - 1) - i]);
374 * xwflip ( oct1 -- oct2 )
376 static void
377 xwflip(fcode_env_t *env)
379 union {
380 wforth_t b_wf[WF_PER_XF];
381 xforth_t b_xf;
382 } b, c;
383 int i;
385 CHECK_DEPTH(env, 1, "xwflip");
386 b.b_xf = pop_xforth(env);
387 for (i = 0; i < WF_PER_XF; i++)
388 c.b_wf[i] = b.b_wf[(WF_PER_XF - 1) - i];
389 push_xforth(env, c.b_xf);
393 * xwflips ( xaddr len -- )
395 static void
396 xwflips(fcode_env_t *env)
398 fstack_t len, addr;
399 int i;
401 CHECK_DEPTH(env, 2, "xwflips");
402 len = POP(DS);
403 addr = POP(DS);
404 for (i = 0; i < len; i += sizeof (xforth_t),
405 addr += sizeof (xforth_t)) {
406 PUSH(DS, addr);
407 unaligned_xfetch(env);
408 xwflip(env);
409 PUSH(DS, addr);
410 unaligned_xstore(env);
415 * xwsplit ( o -- w.lo w.2 w.3 w.hi )
417 static void
418 xwsplit(fcode_env_t *env)
420 union {
421 wforth_t b_wf[WF_PER_XF];
422 xforth_t b_xf;
423 } b;
424 int i;
426 CHECK_DEPTH(env, 1, "xwsplit");
427 b.b_xf = pop_xforth(env);
428 for (i = 0; i < WF_PER_XF; i++)
429 PUSH(DS, b.b_wf[(WF_PER_XF - 1) - i]);
432 #pragma init(_init)
434 static void
435 _init(void)
437 fcode_env_t *env = initial_env;
439 ASSERT(env);
440 NOTICE;
441 P1275(0x241, 0, "bxjoin", bxjoin);
442 P1275(0x242, 0, "<l@", lsfetch);
443 P1275(0x243, 0, "lxjoin", lxjoin);
444 P1275(0x244, 0, "wxjoin", wxjoin);
445 P1275(0x245, 0, "x,", xcomma);
446 P1275(0x246, 0, "x@", xfetch);
447 P1275(0x247, 0, "x!", xstore);
448 P1275(0x248, 0, "/x", slash_x);
449 P1275(0x249, 0, "/x*", slash_x_times);
450 P1275(0x24a, 0, "xa+", xa_plus);
451 P1275(0x24b, 0, "xa1+", xa_one_plus);
452 P1275(0x24c, 0, "xbflip", xbflip);
453 P1275(0x24d, 0, "xbflips", xbflips);
454 P1275(0x24e, 0, "xbsplit", xbsplit);
455 P1275(0x24f, 0, "xlflip", xlflip);
456 P1275(0x250, 0, "xlflips", xlflips);
457 P1275(0x251, 0, "xlsplit", xlsplit);
458 P1275(0x252, 0, "xwflip", xwflip);
459 P1275(0x253, 0, "xwflips", xwflips);
460 P1275(0x254, 0, "xwsplit", xwsplit);
462 FORTH(0, "unaligned-x@", unaligned_xfetch);
463 FORTH(0, "unaligned-x!", unaligned_xstore);