12bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan/* ===-- negvdi2.c - Implement __negvdi2 -----------------------------------===
22bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan *
32bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan *                     The LLVM Compiler Infrastructure
42bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan *
59ad441ffec97db647fee3725b3424284fb913e14Howard Hinnant * This file is dual licensed under the MIT and the University of Illinois Open
69ad441ffec97db647fee3725b3424284fb913e14Howard Hinnant * Source Licenses. See LICENSE.TXT for details.
72bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan *
82bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan * ===----------------------------------------------------------------------===
92bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan *
102bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan * This file implements __negvdi2 for the compiler_rt library.
112bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan *
122bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan * ===----------------------------------------------------------------------===
132bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan */
14b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
15b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar#include "int_lib.h"
16b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
172bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan/* Returns: -a */
18b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
192bf62728b8ce00e295c7bf0fb328427496cc85aaEdward O'Callaghan/* Effects: aborts if -a overflows */
20b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar
211c5f89b1dd741135a4007ab577723d422f421eecAnton KorobeynikovCOMPILER_RT_ABI di_int
22b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar__negvdi2(di_int a)
23b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar{
24b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    const di_int MIN = (di_int)1 << ((int)(sizeof(di_int) * CHAR_BIT)-1);
25b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    if (a == MIN)
2648f46ac1d9a82210f6e469567cb60aa7e7cd2f3bDaniel Dunbar        compilerrt_abort();
27b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar    return -a;
28b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar}
29