1 /* Copyright (c) 2015 Regents of the University of California
3 * Author: Brian Demsky <bdemsky@uci.edu>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
10 #define __STDC_FORMAT_MACROS
14 #include "libinterface.h"
17 #include "threads-model.h"
18 #include "mcexecution.h"
20 void store_8(void *addr, uint8_t val)
22 DEBUG("addr = %p, val = %" PRIu8 "\n", addr, val);
23 model->get_execution()->store(addr, val, sizeof(val));
26 void store_16(void *addr, uint16_t val)
28 DEBUG("addr = %p, val = %" PRIu16 "\n", addr, val);
29 model->get_execution()->store(addr, val, sizeof(val));
32 void store_32(void *addr, uint32_t val)
34 DEBUG("addr = %p, val = %" PRIu32 "\n", addr, val);
35 model->get_execution()->store(addr, val, sizeof(val));
38 void store_64(void *addr, uint64_t val)
40 DEBUG("addr = %p, val = %" PRIu64 "\n", addr, val);
41 model->get_execution()->store(addr, val, sizeof(val));
44 uint8_t load_8(const void *addr)
46 DEBUG("addr = %p\n", addr);
47 return (uint8_t) model->get_execution()->load(addr, sizeof(uint8_t));
50 uint16_t load_16(const void *addr)
52 DEBUG("addr = %p\n", addr);
53 return (uint16_t) model->get_execution()->load(addr, sizeof(uint16_t));
56 uint32_t load_32(const void *addr)
58 DEBUG("addr = %p\n", addr);
59 return (uint32_t) model->get_execution()->load(addr, sizeof(uint32_t));
62 uint64_t load_64(const void *addr)
64 DEBUG("addr = %p\n", addr);
65 return (uint64_t) model->get_execution()->load(addr, sizeof(uint64_t));
68 uint8_t rmw_8(enum atomicop op, void *addr, uint8_t oldval, uint8_t valarg) {
69 return (uint8_t) model->get_execution()->rmw(op, addr, sizeof(oldval), (uint64_t) *((uint8_t *)addr), (uint64_t) oldval, (uint64_t) valarg);
72 uint16_t rmw_16(enum atomicop op, void *addr, uint16_t oldval, uint16_t valarg) {
73 return (uint16_t) model->get_execution()->rmw(op, addr, sizeof(oldval), (uint64_t) *((uint16_t *)addr), (uint64_t) oldval, (uint64_t) valarg);
76 uint32_t rmw_32(enum atomicop op, void *addr, uint32_t oldval, uint32_t valarg) {
77 return (uint32_t) model->get_execution()->rmw(op, addr, sizeof(oldval), (uint64_t) *((uint32_t *)addr), (uint64_t) oldval, (uint64_t) valarg);
80 uint64_t rmw_64(enum atomicop op, void *addr, uint64_t oldval, uint64_t valarg) {
81 return model->get_execution()->rmw(op, addr, sizeof(oldval), *((uint64_t *)addr), oldval, valarg);
84 void MC2_nextOpThrd_create(MCID startfunc, MCID param) {
87 void MC2_nextOpThrd_join(MCID jointhrd) {
90 MCID MC2_nextOpLoad(MCID addr) {
91 return model->get_execution()->loadMCID(addr, 0);
94 void MC2_nextOpStore(MCID addr, MCID value) {
95 return model->get_execution()->storeMCID(addr, 0, value);
98 MCID MC2_nextOpLoadOffset(MCID addr, uintptr_t offset) {
99 return model->get_execution()->loadMCID(addr, offset);
102 void MC2_nextOpStoreOffset(MCID addr, uintptr_t offset, MCID value) {
103 return model->get_execution()->storeMCID(addr, offset, value);
106 MCID MC2_branchUsesID(MCID condition, int direction, int num_directions, bool anyvalue) {
107 return model->get_execution()->branchDir(condition, direction, num_directions, anyvalue);
110 void MC2_merge(MCID branchid) {
111 model->get_execution()->merge(branchid);
114 MCID MC2_phi(MCID input) {
115 return model->get_execution()->phi(input);
118 MCID MC2_loop_phi(MCID input) {
119 return model->get_execution()->loop_phi(input);
122 uint64_t MC2_equals(MCID op1, uint64_t val1, MCID op2, uint64_t val2, MCID *retval) {
123 return model->get_execution()->equals(op1, val1, op2, val2, retval);
127 MCID MC2_function(uint num_args, int numbytesretval, uint64_t val, ...) {
129 MCID mcids[num_args];
131 uint num_real_args=0;;
132 for(uint i=0;i<num_args;i++) {
133 MCID v=va_arg(vl, MCID);
135 mcids[num_real_args++]=v;
138 MCID m=model->get_execution()->function(0, numbytesretval, val, num_real_args, mcids);
142 MCID MC2_function_id(unsigned int id, uint num_args, int numbytesretval, uint64_t val, ...) {
144 MCID mcids[num_args];
146 uint num_real_args=0;;
147 for(uint i=0;i<num_args;i++) {
148 MCID v=va_arg(vl, MCID);
150 mcids[num_real_args++]=v;
153 MCID m=model->get_execution()->function(id, numbytesretval, val, num_real_args, mcids);
157 void MC2_enterLoop() {
158 model->get_execution()->enterLoop();
161 void MC2_exitLoop() {
162 model->get_execution()->exitLoop();
165 void MC2_loopIterate() {
166 model->get_execution()->loopIterate();
170 model->get_execution()->threadYield();
175 model->get_execution()->fence();
180 MCID MC2_nextRMW(MCID addr, MCID oldval, MCID valarg) {
181 return model->get_execution()->nextRMW(addr, 0, oldval, valarg);
184 MCID MC2_nextRMWOffset(MCID addr, uintptr_t offset, MCID oldval, MCID valarg) {
185 return model->get_execution()->nextRMW(addr, offset, oldval, valarg);