2017-10-10 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libhsail-rt / rt / misc.c
blob3b9fddb9d7c4b1737fd56d8a2fddd91f1b989357
1 /* misc.c -- Builtins for HSAIL misc instructions.
3 Copyright (C) 2015-2017 Free Software Foundation, Inc.
4 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
5 for General Processor Tech.
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files
9 (the "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include <stdint.h>
28 #include <time.h>
30 #include "workitems.h"
32 /* Return the monotonic clock as nanoseconds. */
34 uint64_t
35 __hsail_clock ()
37 struct timespec t;
38 clock_gettime (CLOCK_MONOTONIC, &t);
39 return (uint64_t) t.tv_sec * 1000000000 + (uint64_t) t.tv_nsec;
42 uint32_t
43 __hsail_cuid (PHSAWorkItem *wi)
45 /* All WIs are executed with a single compute unit (core/thread)
46 for now. */
47 return 0;
50 uint32_t
51 __hsail_maxcuid (PHSAWorkItem *wi)
53 /* All WIs are executed with a single compute unit (core/thread)
54 for now. */
55 return 0;
58 void
59 __hsail_debugtrap (uint32_t src, PHSAWorkItem *wi)
61 /* Could we produce a SIGTRAP signal here to drop to gdb
62 console, or similar? In any case, the execution of the
63 kernel should halt.
65 return;
68 uint32_t
69 __hsail_groupbaseptr (PHSAWorkItem *wi)
71 return (uint32_t) (uintptr_t) (wi->wg->group_base_ptr
72 - wi->launch_data->group_segment_start_addr);
75 uint64_t
76 __hsail_kernargbaseptr_u64 (PHSAWorkItem *wi)
78 /* For now assume only a single kernarg allocation at a time.
79 Proper kernarg memory management to do. */
80 return (uint64_t) (uintptr_t) wi->launch_data->kernarg_addr;
83 uint32_t
84 __hsail_kernargbaseptr_u32 (PHSAWorkItem *wi)
86 /* For now assume only a single kernarg allocation at a time.
87 Proper kernarg memory management to do. */
88 return 0;